/**
 * Mobile Responsiveness Optimizations
 * Zentrale CSS-Datei für mobile Optimierungen
 */

/* ============================================
   ROTATE DEVICE HINT
   ============================================ */

/* Default: hidden on all devices */
.md-rotate-hint {
    display: none;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
    border-radius: 8px;
    padding: 10px 14px;
    margin: 10px 0;
    color: #0369a1;
    font-size: 13px;
    text-align: center;
}

.md-rotate-hint i {
    margin-right: 8px;
    animation: md-rotate-wiggle 2s ease-in-out infinite;
}

@keyframes md-rotate-wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(15deg); }
    75% { transform: rotate(-15deg); }
}

/* Show only on mobile portrait mode */
@media (max-width: 768px) and (orientation: portrait) {
    .md-rotate-hint {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Always hide on landscape (including desktop) */
@media (orientation: landscape) {
    .md-rotate-hint {
        display: none !important;
    }
}

/* Also hide on larger screens regardless of orientation */
@media (min-width: 992px) {
    .md-rotate-hint {
        display: none !important;
    }
}

/* ============================================
   MOBILE OPTIMIZATIONS - Allgemein
   ============================================ */

@media (max-width: 768px) {
    /* Header Navigation - Mobile */
    #header1 .header-center .breadcrumb {
        font-size: 11px;
    }
    
    #header2 .navbar .nav > li > a {
        padding: 12px 10px;
        font-size: 12px;
    }
    
    #header2 .navbar .nav > li > a span {
        display: none;
    }
    
    /* Cards - Mobile */
    .card {
        margin-bottom: 15px;
    }
    
    .card-body {
        padding: 15px;
    }
    
    /* Tables - Mobile Card Layout */
    .table-mobile-card tbody tr {
        display: block;
        border: 1px solid #e3e6f0;
        border-radius: 8px;
        margin-bottom: 15px;
        padding: 15px;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    }

    .table-mobile-card tbody tr td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0;
        border: none;
        border-bottom: 1px solid #f0f0f0;
        gap: 10px;
    }

    .table-mobile-card tbody tr td:last-child {
        border-bottom: none;
    }

    /* Data label styling - shows "Label:" format */
    .table-mobile-card tbody tr td::before {
        content: attr(data-label) ":";
        font-weight: 600;
        color: #4a5568;
        flex-shrink: 0;
        min-width: 100px;
        font-size: 0.85em;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }

    /* Hide colon for empty labels */
    .table-mobile-card tbody tr td[data-label=""]::before {
        content: "";
        min-width: 0;
    }

    /* Value styling - right side of card row */
    .table-mobile-card tbody tr td > *:first-child,
    .table-mobile-card tbody tr td > a:first-child,
    .table-mobile-card tbody tr td > span:first-child,
    .table-mobile-card tbody tr td > strong:first-child {
        text-align: right;
        flex-grow: 0;
        flex-shrink: 1;
        max-width: 65%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Hide desktop-only columns in mobile card view */
    .table-mobile-card tbody tr td.d-none,
    .table-mobile-card tbody tr td.d-md-table-cell,
    .table-mobile-card tbody tr td.d-lg-table-cell {
        display: none !important;
    }

    .table-mobile-card thead {
        display: none;
    }

    /* Hide filter rows in mobile card view */
    .table-mobile-card thead tr.filters,
    .table-mobile-card thead tr.md-table-filter {
        display: none !important;
    }

    /* Fix text-right alignment in card cells */
    .table-mobile-card tbody tr td.text-right {
        justify-content: space-between;
        text-align: left;
    }

    /* Buttons inside table cards - don't make full width */
    .table-mobile-card tbody tr td .btn {
        width: auto;
        margin-bottom: 0;
        margin-right: 5px;
    }

    /* Action buttons group in mobile card */
    .table-mobile-card tbody tr td .btn:last-child {
        margin-right: 0;
    }

    /* Fix td content wrapping */
    .table-mobile-card tbody tr td > * {
        flex-shrink: 1;
        word-break: break-word;
    }

    /* Empty state in table (colspan cells) */
    .table-mobile-card tbody tr td[colspan] {
        display: block;
        text-align: center;
    }

    .table-mobile-card tbody tr td[colspan]::before {
        display: none;
    }
    
    /* Filter Sidebar - Mobile */
    .filter-sidebar {
        width: 100% !important;
        right: -100% !important;
    }
    
    .filter-sidebar.active {
        right: 0 !important;
    }
    
    #main-content.filter-active {
        margin-right: 0 !important;
    }
    
    /* View Toggle Buttons - Mobile */
    .btn-group {
        flex-wrap: wrap;
    }
    
    /* Tile Grid - Mobile: 2 Kacheln pro Reihe */
    .md-system-tiles-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

    .md-system-tile {
        grid-column: auto !important;
        padding: 8px;
        font-size: 0.85rem;
    }

    .md-system-tile__title {
        font-size: 0.9rem;
    }

    .md-system-tile__meta,
    .md-system-tile__row {
        font-size: 0.75rem;
    }

    .md-system-tile img {
        width: 28px !important;
        height: 28px !important;
        margin-right: 6px !important;
    }
    
    /* Form Groups - Mobile */
    .form-group {
        margin-bottom: 15px;
    }
    
    .form-row {
        flex-direction: column;
    }
    
    .form-row .col,
    .form-row [class*="col-"] {
        max-width: 100%;
        padding-left: 0;
        padding-right: 0;
    }
    
    /* Buttons - Mobile: Only make full-width in content areas, NOT in headers/navbars */
    .content .btn:not(.btn-sm):not(.btn-group .btn),
    .card-body .btn:not(.btn-sm):not(.btn-group .btn),
    .modal-footer .btn:not(.btn-sm):not(.btn-group .btn) {
        width: 100%;
        margin-bottom: 10px;
    }

    .btn-group .btn {
        width: auto;
        margin-bottom: 0;
    }

    /* Header buttons should NOT be full width */
    #header1 .btn,
    #header2 .btn,
    .navbar-actions .btn,
    .mobile-quick-actions .btn {
        width: auto !important;
        margin-bottom: 0 !important;
    }
    
    /* Actions Dropdown - Mobile */
    .dropdown-menu {
        position: static !important;
        float: none;
        width: 100%;
        margin-top: 5px;
        border: 1px solid #e3e6f0;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    /* Badges - Mobile */
    .badge {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    /* Page Header - Mobile */
    .page-header-compact {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 15px;
    }

    .page-header-compact h3,
    .page-header-compact h4 {
        font-size: 1.3rem;
    }

    /* Card Headers - Mobile */
    .card-header.d-flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }

    .card-header.d-flex .btn,
    .card-header.d-flex .btn-group {
        width: 100%;
        justify-content: center;
    }

    .card-header h4,
    .card-header h5 {
        font-size: 1.1rem;
        margin-bottom: 5px;
    }
    
    /* Stats Cards - Mobile: 2x2 Grid */
    .status-cards-compact {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        width: 100%;
        margin-top: 15px;
    }

    .status-cards-compact .stat-mini {
        width: 100%;
        min-width: 0;
        padding: 12px 8px;
    }

    .status-cards-compact .stat-mini-number {
        font-size: 1.5rem;
    }

    .status-cards-compact .stat-mini-label {
        font-size: 0.7rem;
    }

    .dashboard-stats-row,
    .praxis-stats-row {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }

    .dashboard-stats-row > .col,
    .dashboard-stats-row > [class*="col-"],
    .praxis-stats-row > .col,
    .praxis-stats-row > [class*="col-"] {
        flex: 0 0 calc(50% - 5px);
        max-width: calc(50% - 5px);
        margin-bottom: 0;
        padding-left: 0;
        padding-right: 0;
    }

    /* Fallback for generic stats cards */
    .row .col-md-2,
    .row .col-md-3 {
        flex: 0 0 calc(50% - 5px);
        max-width: calc(50% - 5px);
        margin-bottom: 10px;
    }

    .row .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 15px;
    }

    /* Bug Report Button - Mobile: Less intrusive */
    .bug-report-btn,
    [class*="bug-melden"],
    .btn-bug-report {
        position: fixed;
        bottom: 70px; /* Above theme toggle */
        left: 10px;
        z-index: 1000;
        opacity: 0.7;
        transform: scale(0.85);
        transition: opacity 0.2s, transform 0.2s;
    }

    .bug-report-btn:hover,
    [class*="bug-melden"]:hover,
    .btn-bug-report:hover {
        opacity: 1;
        transform: scale(1);
    }

    /* Theme Toggle - Mobile position fix */
    .theme-toggle,
    [class*="theme-switch"] {
        position: fixed;
        bottom: 10px;
        right: 10px;
        z-index: 1001;
    }

    /* Empty State - Mobile */
    .empty-state {
        padding: 2rem 1rem;
    }
    
    .empty-state i {
        font-size: 3rem !important;
    }
    
    /* DataTables Info - Mobile */
    .dataTables_info {
        font-size: 12px;
        padding: 10px 15px;
    }
    
    .dataTables_paginate {
        padding: 10px 15px;
    }
    
    .dataTables_paginate .paginate_button {
        padding: 5px 8px;
        font-size: 12px;
        margin: 2px;
    }

    /* ============================================
       ADDITIONAL MOBILE FIXES - Priority 1-4
       ============================================ */

    /* Fix 1: Cart Quantity Group - Remove fixed width */
    .cart-quantity-group,
    .input-group[style*="width: 120px"],
    .input-group[style*="width:120px"] {
        width: 100% !important;
        max-width: 150px;
    }

    /* Fix 2: Quick Actions Grid - Smaller minmax for small phones */
    .quick-actions-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)) !important;
        gap: 10px !important;
    }

    .quick-actions-grid .btn,
    .quick-actions-grid > a,
    .quick-actions-grid > div {
        padding: 12px 8px;
        font-size: 0.85rem;
    }

    /* Fix 3: Table Filter Rows - Hide on mobile, use separate filter */
    .table thead tr.filters,
    .table thead tr[class*="filter"],
    .md-table-filter {
        display: none !important;
    }

    /* Fix 4: Improve cart/checkout stacking */
    .col-md-8 + .col-md-4,
    .col-lg-7 + .col-lg-5,
    .col-lg-8 + .col-lg-4 {
        margin-top: 1rem;
    }

    /* Checkout summary card - make sticky on mobile for visibility */
    .checkout-summary,
    .card:has(form[action*="checkout"]) {
        position: sticky;
        top: 60px;
        z-index: 10;
    }

    /* Fix 5: Modal Forms - Better mobile width */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

    .modal-body .row > [class*="col-md-6"],
    .modal-body .row > [class*="col-6"] {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 10px;
    }

    .modal-body .form-control {
        font-size: 16px; /* Prevent iOS zoom */
    }

    /* Fix 6: Filter Controls - Better spacing */
    .filter-controls,
    .table-filters,
    .documents-filters {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .filter-controls select,
    .filter-controls input,
    .documents-filters select,
    .documents-filters input {
        width: 100%;
        min-height: 44px;
    }

    /* Fix 7: Button Touch Targets - Minimum 44px */
    .period-selector .btn,
    .btn-sm,
    .btn-group .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 12px;
    }

    .period-selector {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .period-selector .btn {
        flex: 1 1 auto;
        text-align: center;
    }

    /* Fix 8: People Table - Compact mobile rows */
    .table-mobile-card tbody tr td[data-label=""] img,
    .table-mobile-card tbody tr td:first-child img {
        width: 32px !important;
        height: 32px !important;
    }

    .person-item,
    .people-list .list-item {
        padding: 10px;
    }

    /* Fix 9: Flex Gap - Responsive gaps */
    .d-flex[style*="gap: 0.5rem"],
    .d-flex[style*="gap:0.5rem"] {
        gap: 10px !important;
    }

    .btn-group,
    .action-buttons {
        gap: 8px;
    }

    /* Fix 10: Code Tag - Prevent overflow */
    code,
    .table code,
    td code {
        word-break: break-all;
        font-size: 0.8em;
        max-width: 100%;
        display: inline-block;
    }

    /* Additional: Ensure all form inputs are large enough */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    input[type="date"],
    input[type="search"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    /* Additional: Better spacing for action button groups */
    .table-mobile-card td .btn + .btn,
    .table-mobile-card td .btn + form,
    .table-mobile-card td form + .btn {
        margin-left: 8px;
    }
}

/* ============================================
   TABLET OPTIMIZATIONS
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    /* Tile Grid - Tablet */
    .md-system-tiles-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .md-system-tile {
        grid-column: span 6;
    }
    
    /* Filter Sidebar - Tablet */
    .filter-sidebar {
        width: 450px;
    }
    
    #main-content.filter-active {
        margin-right: 450px;
    }
}

/* ============================================
   TOUCH OPTIMIZATIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Größere Touch-Targets */
    .btn {
        min-height: 44px;
        padding: 10px 20px;
    }
    
    .btn-sm {
        min-height: 36px;
        padding: 8px 16px;
    }
    
    /* Größere Links */
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    
    /* Größere Form Controls */
    .form-control {
        min-height: 44px;
        font-size: 16px; /* Verhindert Zoom auf iOS */
    }
    
    .form-control-sm {
        min-height: 36px;
    }
    
    /* Größere Checkboxes/Radios */
    .form-check-input {
        width: 20px;
        height: 20px;
    }
    
    /* Größere Dropdown Items */
    .dropdown-item {
        min-height: 44px;
        padding: 12px 20px;
    }
}

/* ============================================
   PRINT OPTIMIZATIONS
   ============================================ */

/* ============================================
   MODAL TOUCH OPTIMIZATIONS
   ============================================ */

/* Fix Bootstrap 5 modal touch issues on mobile */
@media (hover: none) and (pointer: coarse) {
    /* Ensure modals are touchable and not blocked */
    .modal {
        -webkit-tap-highlight-color: transparent;
    }

    .modal-backdrop {
        touch-action: auto;
    }

    .modal-dialog {
        touch-action: auto;
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }

    /* Ensure buttons in modals have proper touch targets */
    .modal .btn {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    /* Fix close button */
    .modal-header .btn-close {
        min-width: 44px;
        min-height: 44px;
        padding: 12px;
        touch-action: manipulation;
    }

    /* Improve form controls in modals */
    .modal .form-control,
    .modal .form-select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom */
        touch-action: manipulation;
    }
}

@media print {
    .filter-sidebar,
    .filter-overlay,
    .btn,
    .actions-dropdown,
    #header1,
    #header2 {
        display: none !important;
    }

    .content {
        padding: 0 !important;
    }

    .table {
        font-size: 10px;
    }
}

