/**
 * eLibris Mobile Responsive Styles
 * Enhanced mobile-first responsive design
 */

/* ============================================
   MOBILE-FIRST BASE STYLES
   ============================================ */

/* Prevent zoom on input focus for iOS */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    input[type="search"],
    input[type="tel"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ============================================
   TOUCH-FRIENDLY IMPROVEMENTS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets for mobile */
    button,
    .btn,
    .btn-pup,
    .btn-primary,
    .btn-secondary,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    .side-panel button,
    nav button {
        min-height: 48px;
        padding: 12px 16px;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover,
    .btn-pup:hover,
    button:hover {
        transform: none !important;
    }
    
    /* Better tap highlights */
    a, button, input, select, textarea {
        -webkit-tap-highlight-color: rgba(128, 0, 32, 0.2);
    }
}

/* ============================================
   SMALL PHONE OPTIMIZATIONS (< 480px)
   ============================================ */
@media (max-width: 480px) {
    /* Compact spacing */
    body {
        font-size: 14px;
    }
    
    .container {
        padding: 10px !important;
    }
    
    /* Smaller headers */
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
    
    /* Mobile-optimized forms */
    .form-control-elibris,
    input,
    select,
    textarea {
        padding: 12px;
        font-size: 16px;
    }
    
    .form-label-elibris {
        font-size: 0.8rem;
    }
    
    /* Stack buttons vertically */
    .btn-group,
    .button-group,
    .dashboard-buttons,
    #button-container {
        flex-direction: column !important;
        width: 100%;
    }
    
    .btn-group .btn,
    .button-group button,
    .dashboard-buttons button,
    #button-container button {
        width: 100%;
        margin: 5px 0;
    }
    
    /* Mobile cards */
    .card-elibris,
    .card,
    .panel {
        margin: 10px 0;
        padding: 15px;
        border-radius: 8px;
    }
    
    .card-elibris .card-body {
        padding: 15px;
    }
    
    /* Mobile tables - horizontal scroll */
    .table-responsive-wrapper,
    .scrollable-table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: 1px solid #ddd;
        border-radius: 8px;
    }
    
    .table-elibris,
    .data-table,
    table {
        min-width: 600px;
        font-size: 0.85rem;
    }
    
    .table-elibris thead th,
    .table-elibris tbody td {
        padding: 8px;
        white-space: nowrap;
    }
    
    /* Compact navbar */
    .top-panel {
        padding: 10px 15px;
        min-height: 56px;
    }
    
    .top-panel h1 {
        font-size: 1.1rem;
    }
    
    .top-panel .logo {
        height: 35px;
        width: 35px;
    }
    
    /* Mobile sidebar as bottom nav */
    .side-panel {
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto !important;
        width: 100% !important;
        height: 60px !important;
        flex-direction: row !important;
        justify-content: space-around;
        padding: 5px !important;
        border-right: none !important;
        border-top: 1px solid #e0e0e0;
        z-index: 1000;
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    .side-panel button {
        flex: 1;
        min-width: 60px;
        max-width: 80px;
        padding: 8px 5px !important;
        font-size: 11px !important;
        text-align: center;
        flex-direction: column !important;
        gap: 3px !important;
        margin: 0 2px !important;
        border-radius: 8px;
    }
    
    .side-panel button i {
        font-size: 18px !important;
        margin: 0 !important;
    }
    
    .side-panel button span,
    .side-panel button::after {
        font-size: 10px;
    }
    
    /* Adjust main content for bottom nav */
    .main-content {
        padding-bottom: 70px !important;
        height: calc(100vh - 56px - 60px) !important;
    }
    
    /* Mobile modal */
    .modal-elibris .modal-content,
    .modal-content {
        width: 95%;
        max-height: 85vh;
        margin: 10px;
        border-radius: 12px;
    }
    
    .modal-elibris .modal-body,
    .modal-body {
        padding: 15px;
        max-height: calc(85vh - 120px);
    }
    
    /* Mobile QR scanner */
    #qr-reader,
    .qr-scanner-container {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Toast notifications */
    .toast-container {
        left: 10px !important;
        right: 10px !important;
        top: auto !important;
        bottom: 70px !important;
        max-width: none !important;
    }
    
    .toast-elibris {
        padding: 12px;
        font-size: 0.9rem;
    }
    
    /* Mobile search */
    .search-input {
        max-width: 100%;
    }
    
    /* Stats cards mobile */
    .analytics-stats-row,
    .analytics-alert-row {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }
    
    .analytics-stat-card,
    .analytics-alert-card {
        padding: 15px;
    }
    
    .analytics-stat-value {
        font-size: 1.5rem;
    }
    
    /* Mobile attendance layout */
    #left-section,
    #right-section {
        width: 100% !important;
        padding: 15px !important;
    }
    
    #left-section {
        min-height: 200px !important;
        order: 2;
    }
    
    #right-section {
        order: 1;
    }
    
    #container {
        flex-direction: column !important;
    }
}

/* ============================================
   TABLET OPTIMIZATIONS (481px - 768px)
   ============================================ */
@media (min-width: 481px) and (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .side-panel {
        width: 200px;
        min-width: 200px;
    }
    
    .side-panel button {
        padding: 12px;
        font-size: 14px;
    }
    
    .analytics-stats-row {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .table-elibris {
        font-size: 0.9rem;
    }
    
    .card-elibris .card-body {
        padding: 1.25rem;
    }
}

/* ============================================
   NOTCH & SAFE AREA SUPPORT (iPhone X+)
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
    @media (max-width: 768px) {
        .top-panel {
            padding-top: max(10px, env(safe-area-inset-top));
            padding-left: max(15px, env(safe-area-inset-left));
            padding-right: max(15px, env(safe-area-inset-right));
        }
        
        .side-panel {
            padding-bottom: max(5px, env(safe-area-inset-bottom)) !important;
        }
        
        .main-content {
            padding-bottom: calc(70px + env(safe-area-inset-bottom)) !important;
        }
        
        .toast-container {
            bottom: calc(70px + env(safe-area-inset-bottom)) !important;
        }
    }
}

/* ============================================
   LANDSCAPE MODE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .side-panel {
        height: 50px !important;
    }
    
    .side-panel button {
        padding: 5px !important;
        flex-direction: row !important;
    }
    
    .side-panel button i {
        font-size: 16px !important;
    }
    
    .main-content {
        padding-bottom: 60px !important;
        height: calc(100vh - 56px - 50px) !important;
    }
    
    .modal-elibris .modal-content {
        max-height: 80vh;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .side-panel,
    .top-panel button,
    .toast-container,
    .analytics-quick-actions {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
        height: auto !important;
    }
    
    body {
        background: white !important;
    }
    
    .card,
    .card-elibris {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        break-inside: avoid;
    }
}

/* ============================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   DARK MODE SUPPORT (Optional)
   ============================================ */
@media (prefers-color-scheme: dark) {
    @media (max-width: 768px) {
        body {
            background-color: #1a1a1a;
            color: #f0f0f0;
        }
        
        .side-panel {
            background: #2d2d2d;
            border-color: #404040;
        }
        
        .card-elibris,
        .card {
            background: #2d2d2d;
            border-color: #404040;
        }
    }
}

/* ============================================
   MOBILE-SPECIFIC UTILITY CLASSES
   ============================================ */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    
    .show-mobile {
        display: block !important;
    }
    
    .text-center-mobile {
        text-align: center !important;
    }
    
    .full-width-mobile {
        width: 100% !important;
    }
    
    .stack-mobile {
        flex-direction: column !important;
    }
    
    .no-margin-mobile {
        margin: 0 !important;
    }
    
    .no-padding-mobile {
        padding: 0 !important;
    }
}

@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
}
