/* Mobile-First Enhancements for Grade-A Experience */

/* Touch-Friendly Interactions */
* {
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    -webkit-touch-callout: none;
}

button, a, input, select, textarea {
    touch-action: manipulation;
}

/* Improved Touch Targets (min 44x44px) */
.btn, button, a.btn, input[type="submit"], input[type="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
}

.attendance-btn {
    min-height: 48px;
    padding: 12px 16px;
}

/* Mobile Navigation */
@media (max-width: 768px) {
    /* Header Optimization */
    header {
        padding: 15px;
        flex-direction: column;
        gap: 12px;
    }
    
    header h1 {
        font-size: 18px;
        text-align: center;
    }
    
    .user-info {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
    
    /* Logo Display */
    .school-logo-header {
        width: 50px;
        height: 50px;
        object-fit: contain;
    }
    
    /* Dashboard Cards */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .dashboard-card {
        padding: 20px;
    }
    
    .card-btn {
        padding: 16px;
        font-size: 15px;
    }
    
    /* Stats Overview */
    .stats-overview {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .stat-box {
        padding: 15px;
    }
    
    .stat-number {
        font-size: 28px;
    }
    
    /* Form Improvements */
    .form-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 14px;
    }
    
    /* Student Attendance */
    .student-row {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 15px;
    }
    
    .student-number {
        width: 35px;
        height: 35px;
        font-size: 13px;
    }
    
    .student-name-text {
        font-size: 15px;
    }
    
    .student-meta {
        flex-direction: column;
        gap: 5px;
        font-size: 12px;
    }
    
    .attendance-buttons {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }
    
    .attendance-btn {
        width: 100%;
        justify-content: center;
        font-size: 14px;
    }
    
    /* Action Bar */
    .action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 15px;
        flex-direction: column;
        gap: 10px;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
        z-index: 1000;
    }
    
    .quick-actions {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }
    
    .quick-actions button {
        width: 100%;
        padding: 14px;
    }
    
    .save-btn {
        width: 100%;
        padding: 16px;
        font-size: 16px;
    }
    
    /* Add padding to prevent content hiding behind fixed action bar */
    .attendance-grid {
        padding-bottom: 200px;
    }
    
    /* Toolbar */
    .attendance-toolbar {
        padding: 15px;
    }
    
    .toolbar-row {
        flex-direction: column;
        gap: 12px;
    }
    
    .date-nav {
        width: 100%;
        justify-content: space-between;
    }
    
    .date-nav button {
        padding: 10px 16px;
    }
    
    .search-box {
        width: 100%;
        min-width: auto;
    }
    
    /* Stats Bar */
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    .stat-number {
        font-size: 24px;
    }
    
    .stat-label {
        font-size: 11px;
    }
    
    /* Tables */
    .attendance-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .attendance-table table {
        min-width: 600px;
    }
    
    .attendance-table th,
    .attendance-table td {
        padding: 10px 8px;
        font-size: 13px;
    }
    
    /* Report Tables */
    .report-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .report-table table {
        min-width: 800px;
    }
    
    /* Settings */
    .settings-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        padding-bottom: 5px;
    }
    
    .settings-tab {
        white-space: nowrap;
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .settings-section {
        padding: 20px 15px;
    }
    
    /* Holiday Cards */
    .holiday-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .holiday-card .btn {
        width: 100%;
    }
    
    /* Login Page */
    .login-box {
        padding: 30px 20px;
    }
    
    .logo {
        font-size: 50px;
    }
    
    .login-box h1 {
        font-size: 20px;
    }
    
    /* MPIN */
    .numpad {
        gap: 12px;
    }
    
    .num-btn {
        font-size: 22px;
    }
    
    /* Modal */
    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 20px;
        max-height: 85vh;
    }
    
    /* Empty State */
    .empty-icon {
        font-size: 60px;
    }
    
    /* Filter Section */
    .filter-section {
        padding: 15px;
    }
    
    /* Summary Cards */
    .summary-cards {
        grid-template-columns: 1fr;
    }
    
    .card {
        padding: 20px;
        font-size: 16px;
    }
    
    /* Report Tabs */
    .report-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }
    
    .tab-btn {
        white-space: nowrap;
        padding: 10px 16px;
        font-size: 13px;
    }
    
    /* Export Buttons */
    .export-btn {
        width: 100%;
        margin: 5px 0;
    }
}

/* Small Mobile (< 480px) */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    .dashboard {
        padding: 15px;
    }
    
    header h1 {
        font-size: 16px;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .stat-number {
        font-size: 20px;
    }
    
    .student-name-text {
        font-size: 14px;
    }
    
    .attendance-btn {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .stats-bar {
        grid-template-columns: 1fr;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .stats-bar {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .attendance-buttons {
        flex-direction: row;
    }
    
    .action-bar {
        flex-direction: row;
    }
    
    .quick-actions {
        flex-direction: row;
    }
}

/* iOS Safe Area */
@supports (padding: max(0px)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .action-bar {
        padding-bottom: calc(15px + env(safe-area-inset-bottom));
    }
    
    header {
        padding-top: calc(20px + env(safe-area-inset-top));
    }
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Better Focus States for Accessibility */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
}

/* Loading States */
.loading {
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Pull to Refresh Indicator */
.ptr-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border-radius: 0 0 10px 10px;
    font-size: 14px;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s;
}

.ptr-indicator.active {
    opacity: 1;
}

/* Offline Indicator */
.offline-indicator {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: #dc3545;
    color: white;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: none;
}

/* PWA Install Button */
.pwa-install-button {
    position: fixed;
    bottom: 80px;
    right: 20px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 9998;
    transition: all 0.3s;
}

.pwa-install-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

/* PWA Notifications */
.pwa-update-notification,
.pwa-success-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 10000;
    max-width: 90%;
    width: 400px;
    animation: slideUp 0.3s ease-out;
}

.pwa-notification-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.pwa-notification-content button {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.pwa-notification-content button:first-of-type {
    background: white;
    color: #667eea;
}

.pwa-notification-content button:last-of-type {
    background: rgba(255,255,255,0.2);
    color: white;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* Improved Animations */
@media (prefers-reduced-motion: no-preference) {
    .student-row,
    .dashboard-card,
    .holiday-card {
        transition: transform 0.2s, box-shadow 0.2s;
    }
    
    .student-row:active,
    .dashboard-card:active {
        transform: scale(0.98);
    }
}

/* Print Styles */
@media print {
    .no-print,
    header,
    .action-bar,
    .attendance-toolbar,
    .btn,
    button {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .student-row {
        break-inside: avoid;
    }
}
