/* ============================================================
   mobile.css — Phase 7.1 Responsive overrides
   Loaded AFTER all page-specific CSS so it wins cleanly.

   Breakpoints:
     768px  — tablet landscape / most tablets portrait
     600px  — large phones landscape / small tablets
     480px  — phones portrait (most common phone width)
     360px  — small phones
   ============================================================ */

/* ── Prevent horizontal overflow on everything ────────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* ═══════════════════════════════════════════════════════════
   AUTH PAGES (login / forgot / reset)
═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .auth-card {
        margin: 16px;
        padding: 28px 20px;
        border-radius: 12px;
    }

    .auth-logo { font-size: 28px; }
    .auth-title { font-size: 20px; }
}

/* ═══════════════════════════════════════════════════════════
   ADMIN LAYOUT — Sidebar + Main + Topbar
═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .admin-main {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .admin-topbar {
        padding: 0 12px;
    }

    .topbar-center {
        font-size: 12px;
        max-width: 160px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .admin-content {
        padding: 16px 12px;
    }
}

/* ═══════════════════════════════════════════════════════════
   PAGE HEADER
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .page-header .header-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    .page-header .header-actions .btn-primary,
    .page-header .header-actions .btn-secondary {
        flex: 1;
        min-width: 120px;
        justify-content: center;
        text-align: center;
    }

    .page-title { font-size: 20px; }
    .page-subtitle { font-size: 12px; }
}

/* ═══════════════════════════════════════════════════════════
   DATA TABLES — horizontal scroll on mobile
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    }

    .data-table {
        min-width: 560px; /* force scroll before columns crush */
    }

    /* Hide less important columns on mobile */
    .data-table .hide-mobile {
        display: none;
    }

    .action-btns {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
    }
}

@media (max-width: 480px) {
    .data-table { min-width: 480px; }
    .data-table th, .data-table td { padding: 8px 8px; font-size: 12px; }
}

/* ═══════════════════════════════════════════════════════════
   SECTION CARDS
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .section-card { border-radius: var(--radius-md); }
    .section-card-header { padding: 12px 14px; }
}

/* ═══════════════════════════════════════════════════════════
   SUMMARY / STAT CARDS (dashboard, analytics)
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .summary-cards,
    .dash-stats,
    .results-stats,
    .analytics-summary-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }
}

@media (max-width: 400px) {
    .summary-cards,
    .dash-stats,
    .results-stats,
    .analytics-summary-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   ADMIN DASHBOARD — Class cards
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .classes-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   SESSIONS — Session and term cards
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .session-card { padding: 14px; }

    .session-card-title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .session-card-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .session-card-actions .btn-sm {
        flex: 1;
        min-width: 80px;
        text-align: center;
        justify-content: center;
    }

    .term-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
    }

    .term-row-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .term-row-actions .btn-xs { flex: 1; justify-content: center; text-align: center; }
}

/* ═══════════════════════════════════════════════════════════
   MODALS — full width on small screens
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .modal-overlay {
        align-items: flex-end; /* slide up from bottom on mobile */
        padding: 0;
    }

    .modal {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal--lg { width: 100% !important; }

    .modal-body { padding: 14px 16px; }
    .modal-footer { padding: 12px 16px; }

    .form-row-2 {
        grid-template-columns: 1fr !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   TEACHER DASHBOARD — Student list + Subject list
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .dash-grid {
        grid-template-columns: 1fr !important;
    }

    .dash-panel { margin-bottom: 16px; }
}

@media (max-width: 600px) {
    .student-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
    }

    .student-row-right {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .progress-pills { flex-wrap: wrap; }

    .subject-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 14px;
    }

    .subject-row-right {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .subject-row-right .btn-xs { flex: 1; text-align: center; justify-content: center; }
}

/* ═══════════════════════════════════════════════════════════
   SCORE ENTRY — modal iframe
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .score-modal {
        width: 100% !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
    }

    #scoreModal {
        align-items: flex-end !important;
    }

    .score-modal-body iframe {
        height: 460px;
    }

    .score-fields {
        grid-template-columns: 1fr 1fr !important;
    }

    .score-field--wide {
        grid-column: span 2 !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   AFFECTIVE ASSESSMENT — sidebar + main layout
═══════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
    .affective-layout {
        grid-template-columns: 1fr !important;
    }

    .affective-sidebar {
        position: static !important;
        max-height: 200px;
        overflow-y: auto;
    }

    .affective-student-list {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        padding: 8px;
        max-height: none;
    }

    .affective-student-item {
        flex: 1;
        min-width: 140px;
        padding: 8px 10px;
    }

    .affective-progress-bar { display: none; }
}

@media (max-width: 600px) {
    .affective-table-wrap { overflow-x: auto; }
    .affective-table { min-width: 360px; }
    .affective-table .col-criteria { min-width: 120px; }
}

/* ═══════════════════════════════════════════════════════════
   ATTENDANCE PAGE
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .attendance-total-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .attendance-total-input { width: 100% !important; }
}

/* ═══════════════════════════════════════════════════════════
   REMARKS PAGE — remark cards
═══════════════════════════════════════════════════════════ */
@media (max-width: 700px) {
    .remark-fields {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .remark-card-header { flex-wrap: wrap; gap: 8px; }
}

/* ═══════════════════════════════════════════════════════════
   ANALYTICS PAGE
═══════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
    .analytics-grid-2 {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 600px) {
    .analytics-term-filter { width: 100%; }
    .analytics-term-filter select { width: 100%; }

    .subject-perf-row { gap: 8px; }
    .subject-perf-name { font-size: 12px; }

    .top-student-row { padding: 8px 14px; gap: 8px; }
    .top-student-name { font-size: 12px; }

    .attendance-grid { gap: 12px; }
    .attendance-card { min-width: 80px; }
}

/* ═══════════════════════════════════════════════════════════
   SUBJECTS PAGE — subject cards
═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .subject-cards {
        grid-template-columns: 1fr 1fr !important;
    }
}

@media (max-width: 360px) {
    .subject-cards {
        grid-template-columns: 1fr !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   RESULT VIEW (print preview)
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .result-toolbar {
        padding: 10px 14px;
        gap: 8px;
    }

    .result-toolbar-info {
        font-size: 12px;
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .result-print-btn { padding: 6px 12px; font-size: 12px; }
    .result-back-btn  { font-size: 12px; }

    .result-sheet {
        width: 100% !important;
        margin: 0 !important;
        padding: 10px !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }

    .result-two-col {
        display: block !important;
    }

    .result-two-col td {
        display: block !important;
        width: 100% !important;
        padding: 0 0 8px 0 !important;
    }
}

@media (max-width: 600px) {
    .result-scores-table,
    .result-affective-table,
    .result-scale-table,
    .result-remarks-table,
    .result-info-table {
        font-size: 9pt;
    }
}

/* ═══════════════════════════════════════════════════════════
   STUDENT PORTAL — result cards
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .student-welcome {
        padding: 16px 18px;
        gap: 12px;
    }

    .student-welcome-avatar { width: 44px; height: 44px; font-size: 18px; }
    .student-welcome-name   { font-size: 16px; }

    .student-result-cards {
        grid-template-columns: 1fr 1fr !important;
    }
}

@media (max-width: 400px) {
    .student-result-cards {
        grid-template-columns: 1fr !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   PROFILE PAGES
═══════════════════════════════════════════════════════════ */
@media (max-width: 780px) {
    .profile-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   FILTER BAR
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .filter-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .filter-bar select,
    .filter-form select { width: 100%; }
}

/* ═══════════════════════════════════════════════════════════
   BULK ACTIONS BAR
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .bulk-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    .bulk-actions form,
    .bulk-actions a,
    .bulk-actions button {
        flex: 1;
        min-width: 120px;
        text-align: center;
        justify-content: center;
    }
}

/* ═══════════════════════════════════════════════════════════
   FORMS — general
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .form-actions .btn-primary,
    .form-actions .btn-secondary {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .form-input, .form-textarea, .form-select {
        font-size: 16px; /* prevent iOS zoom on focus */
    }
}

/* ═══════════════════════════════════════════════════════════
   FLASH MESSAGES
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .flash {
        padding: 10px 12px;
        font-size: 13px;
        gap: 8px;
    }

    .flash-container {
        padding: 0 12px 12px;
    }
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR FOOTER — name truncation
═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .sidebar-user-name {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ═══════════════════════════════════════════════════════════
   TEACHER RESULTS MANAGE — action buttons
═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .action-btns {
        flex-wrap: wrap;
        gap: 4px;
    }

    .btn-xs {
        font-size: 11px;
        padding: 4px 8px;
    }
}

/* ═══════════════════════════════════════════════════════════
   SCORE ENTRY (inline form, not modal)
═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .score-entry-wrap { padding: 14px; }

    .score-result-row {
        flex-wrap: wrap;
        gap: 10px;
    }

    .score-result-block { min-width: 60px; }
}

/* ═══════════════════════════════════════════════════════════
   CREDENTIALS BOX
═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .credentials-grid {
        grid-template-columns: 80px 1fr !important;
    }

    .cred-password { font-size: 13px; }
}

/* ═══════════════════════════════════════════════════════════
   UTILITY — touch targets
   All tappable elements minimum 44px tall on touch devices
═══════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
    .btn-primary,
    .btn-secondary,
    .btn-danger {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .btn-xs {
        min-height: 36px;
        padding: 6px 10px;
    }

    .nav-item {
        min-height: 44px;
        padding: 12px 16px;
    }

    .data-table td, .data-table th {
        padding: 10px 8px;
    }

    input[type="number"],
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px; /* prevents iOS Safari zoom */
        min-height: 44px;
    }
}

/* ═══════════════════════════════════════════════════════════
   PRINT — ensure mobile.css doesn't affect print
═══════════════════════════════════════════════════════════ */
@media print {
    .sidebar, .admin-topbar, .flash-container, .result-toolbar {
        display: none !important;
    }

    .admin-main { margin-left: 0 !important; }
    .result-sheet { width: 100% !important; margin: 0 !important; }
}