/* ==========================================================================
   RESPONSIVE & MOBILE-FIRST OPTIMIZATION
   Specially tuned for Teachers & Students on smartphones & tablets
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. TABLET BREAKPOINT (<= 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
    .admin-layout {
        flex-direction: column;
    }

    .admin-sidebar {
        width: 100%;
        position: static;
    }

    .admin-sidebar-nav {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 0.35rem;
    }

    .metrics-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 0.65rem;
    }

    .slot-picker-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --------------------------------------------------------------------------
   2. MOBILE BREAKPOINT (<= 768px)
   Main screen size for Teachers & Students using phones
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    /* Prevent viewport overflow */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Prevent Safari zoom on form focus */
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px !important;
    }

    .main-wrapper {
        padding: 0.65rem 0.55rem;
    }

    /* App-like Topbar on Mobile */
    .topbar {
        position: sticky;
        top: 0;
        z-index: 100;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0.65rem 0.85rem;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(12px);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    }

    .brand-wrapper {
        gap: 0.5rem;
    }

    .brand-icon {
        width: 34px;
        height: 34px;
    }

    .brand-text h1 {
        font-size: 0.92rem !important;
        font-weight: 800;
        line-height: 1.2;
    }

    .brand-text p {
        display: none !important; /* Hide subtitle to keep app bar compact */
    }

    #btn-reset-db {
        display: none !important; /* Hide test DB reset button on mobile to prevent clutter */
    }

    .user-profile-widget {
        gap: 0.4rem;
    }

    .user-profile-widget .btn-logout {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }

    /* KPI / Metric Cards Grid */
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.55rem;
        margin-bottom: 0.75rem;
    }

    .metric-box {
        padding: 0.75rem 0.85rem;
        min-height: auto;
    }

    .metric-value {
        font-size: 1.25rem;
    }

    .metric-label {
        font-size: 0.75rem;
    }

    .metric-sub {
        font-size: 0.7rem;
    }

    /* Cards & Containers */
    .glass-card {
        padding: 0.85rem;
        border-radius: var(--radius-md);
        margin-bottom: 0.85rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
        margin-bottom: 0.75rem;
        padding-bottom: 0.55rem;
    }

    /* Navigation Tabs: Swipeable Pill Strip */
    .nav-tabs {
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0.35rem;
        padding-bottom: 0.3rem;
        margin-bottom: 0.75rem;
        border-bottom: 1px solid var(--border-subtle);
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tab-btn {
        flex-shrink: 0;
        padding: 0.5rem 0.85rem;
        font-size: 0.82rem;
        border-radius: 99px;
    }

    /* ======================================================================
       TEACHER PORTAL MOBILE EXPERIENCE
       ====================================================================== */
    
    /* Teacher Main Navigation Tabs (Segmented App Control) */
    #teacher-portal-view > div[style*="display:flex"] {
        background: #f1f5f9;
        padding: 4px;
        border-radius: 12px;
        gap: 4px !important;
        margin-bottom: 0.85rem !important;
    }

    #teacher-tab-btn-schedule,
    #teacher-tab-btn-students {
        flex: 1;
        justify-content: center;
        padding: 0.65rem 0.5rem !important;
        font-size: 0.84rem !important;
        border-radius: 8px !important;
        min-height: 42px;
    }

    /* Teacher Smart Filter Bar */
    .teacher-quick-filter-row {
        display: flex;
        gap: 0.45rem;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 0.15rem;
    }

    .teacher-quick-filter-row::-webkit-scrollbar {
        display: none;
    }

    .teacher-filter-pill {
        background: #f8fafc;
        border: 1px solid var(--border-subtle);
        border-radius: 99px;
        padding: 0.5rem 0.9rem;
        font-size: 0.82rem;
        font-weight: 700;
        color: var(--text-muted);
        cursor: pointer;
        flex-shrink: 0;
        transition: all 0.2s ease;
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        min-height: 40px;
    }

    .teacher-filter-pill.active {
        background: var(--primary);
        color: #ffffff;
        border-color: var(--primary);
        box-shadow: 0 4px 12px var(--primary-glow);
    }

    .teacher-filter-pill:active {
        transform: scale(0.97);
    }

    /* Teacher Schedule Table -> Mobile Responsive Cards */
    .teacher-schedule-table {
        display: block;
        width: 100%;
        border: none;
    }

    .teacher-schedule-table thead {
        display: none !important;
    }

    .teacher-schedule-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.85rem;
        width: 100%;
    }

    .teacher-schedule-table tr {
        display: block;
        width: 100%;
        background: #ffffff;
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-lg);
        padding: 1rem;
        box-shadow: var(--shadow-card);
        position: relative;
        transition: var(--transition);
    }

    .teacher-schedule-table tr:active,
    .teacher-schedule-table tr:hover {
        border-color: var(--primary-light);
        box-shadow: var(--shadow-elevated);
    }

    .teacher-schedule-table td {
        display: block;
        width: 100%;
        padding: 0.3rem 0 !important;
        border: none !important;
        text-align: left;
    }

    /* Date & Slot Header in Mobile Card */
    .teacher-schedule-table td[data-label="Thời Gian"] {
        border-bottom: 1px solid var(--border-subtle) !important;
        padding-bottom: 0.55rem !important;
        margin-bottom: 0.45rem;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    /* Student Information in Mobile Card */
    .teacher-schedule-table td[data-label="Học Viên"] {
        background: #f8fafc;
        border-radius: 10px;
        padding: 0.75rem !important;
        margin: 0.4rem 0;
        border: 1px solid #e2e8f0 !important;
    }

    /* Call Student Button (Big Green Mobile CTA) */
    .btn-call-student {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.45rem;
        background: linear-gradient(135deg, #10b981, #059669);
        color: #ffffff !important;
        text-decoration: none !important;
        font-weight: 800;
        font-size: 0.88rem;
        padding: 0.65rem 1rem;
        border-radius: 10px;
        box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
        transition: all 0.2s ease;
        min-height: 46px;
        width: 100%;
    }

    .btn-call-student:active,
    .btn-call-student:hover {
        background: linear-gradient(135deg, #059669, #047857);
        transform: translateY(-1px);
        box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
    }

    /* Vehicle & Session Type row */
    .teacher-schedule-table td[data-label="Xe Tập Lái"],
    .teacher-schedule-table td[data-label="Loại Buổi"],
    .teacher-schedule-table td[data-label="Trạng Thái"] {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 0.84rem;
    }

    .teacher-schedule-table td[data-label="Xe Tập Lái"]::before {
        content: "🚘 Xe: ";
        font-weight: 700;
        color: var(--text-muted);
        min-width: 65px;
    }

    .teacher-schedule-table td[data-label="Loại Buổi"]::before {
        content: "📋 Loại: ";
        font-weight: 700;
        color: var(--text-muted);
        min-width: 65px;
    }

    .teacher-schedule-table td[data-label="Trạng Thái"]::before {
        content: "📍 Trạng thái: ";
        font-weight: 700;
        color: var(--text-muted);
        min-width: 65px;
    }

    .teacher-schedule-table td[data-label="Báo Cáo / Nhận Xét"] {
        background: #f0fdf4;
        border: 1px dashed #86efac !important;
        border-radius: 8px;
        padding: 0.5rem 0.65rem !important;
        margin-top: 0.4rem;
        font-size: 0.8rem;
    }

    /* Touch-Friendly Action Buttons */
    .teacher-schedule-table td[data-label="Thao Tác"] {
        border-top: 1px solid var(--border-subtle) !important;
        padding-top: 0.75rem !important;
        margin-top: 0.65rem;
    }

    .teacher-action-buttons {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }

    .teacher-action-buttons .btn {
        width: 100%;
        min-height: 48px;
        font-size: 0.9rem;
        font-weight: 800;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
    }

    /* Quick Preset Chips in Report Modal */
    .quick-chip-row {
        display: flex;
        gap: 0.35rem;
        flex-wrap: wrap;
        margin-top: 0.35rem;
    }

    .quick-chip-btn {
        background: #f1f5f9;
        border: 1px solid #cbd5e1;
        border-radius: 6px;
        padding: 0.35rem 0.65rem;
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--text-main);
        cursor: pointer;
        transition: all 0.15s ease;
        min-height: 32px;
    }

    .quick-chip-btn:active,
    .quick-chip-btn:hover {
        background: #e2e8f0;
        border-color: var(--primary);
        color: var(--primary);
    }

    /* ======================================================================
       STUDENT PORTAL MOBILE EXPERIENCE
       ====================================================================== */

    /* Student Hero Card & Fast Actions */
    .student-hero-card {
        border: 1px solid rgba(37,99,235,0.18);
        background: linear-gradient(180deg, #ffffff, #f8fafc);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.04);
    }

    .student-hero-avatar {
        width: 48px;
        height: 48px;
        border-radius: var(--radius-md);
        background: linear-gradient(135deg, var(--primary), var(--secondary));
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.4rem;
        color: white;
        font-weight: 800;
        box-shadow: 0 4px 12px var(--primary-glow);
        flex-shrink: 0;
    }

    .student-fast-progress-box {
        margin-top: 0.85rem;
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        padding: 0.75rem 0.85rem;
        box-shadow: 0 2px 6px rgba(0,0,0,0.02);
    }

    .student-quick-actions {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
        margin-top: 0.85rem;
    }

    .student-action-pill {
        background: #f1f5f9;
        border: 1px solid #cbd5e1;
        border-radius: 10px;
        padding: 0.65rem 0.5rem;
        font-size: 0.84rem;
        font-weight: 800;
        color: var(--text-main);
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.35rem;
        cursor: pointer;
        transition: all 0.2s ease;
        min-height: 46px;
    }

    .student-action-pill:active,
    .student-action-pill:hover {
        background: var(--primary);
        color: #ffffff;
        border-color: var(--primary);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px var(--primary-glow);
    }

    /* Digital ID Card */
    .digital-id-card {
        padding: 1.15rem 1rem;
        border-radius: var(--radius-md);
    }

    .id-card-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.65rem;
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
    }

    .id-card-top > div:last-child {
        text-align: left !important;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .id-card-body {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .id-avatar {
        width: 60px;
        height: 60px;
        font-size: 1.8rem;
        align-self: flex-start;
    }

    .id-details-grid {
        grid-template-columns: 1fr;
        gap: 0.45rem;
    }

    /* Student Schedule Table -> Mobile Responsive Cards */
    .student-schedule-table {
        display: block;
        width: 100%;
        border: none;
    }

    .student-schedule-table thead {
        display: none !important;
    }

    .student-schedule-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.85rem;
        width: 100%;
    }

    .student-schedule-table tr {
        display: block;
        width: 100%;
        background: #ffffff;
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-lg);
        padding: 0.95rem;
        box-shadow: var(--shadow-card);
        position: relative;
    }

    .student-schedule-table td {
        display: block;
        width: 100%;
        padding: 0.3rem 0 !important;
        border: none !important;
        text-align: left;
    }

    .student-schedule-table td[data-label="Ngày Học"] {
        border-bottom: 1px solid var(--border-subtle) !important;
        padding-bottom: 0.5rem !important;
        margin-bottom: 0.45rem;
        font-size: 1rem;
        color: var(--primary);
    }

    .student-schedule-table td[data-label="Ca Học"]::before {
        content: "⏰ Ca học: ";
        font-weight: 700;
        color: var(--text-muted);
    }

    .student-schedule-table td[data-label="Loại Buổi"]::before {
        content: "🎯 Loại ca: ";
        font-weight: 700;
        color: var(--text-muted);
    }

    .student-schedule-table td[data-label="Giáo Viên"]::before {
        content: "👨‍🏫 Giáo viên: ";
        font-weight: 700;
        color: var(--text-muted);
    }

    .student-schedule-table td[data-label="Xe Tập Lái"]::before {
        content: "🚗 Xe tập: ";
        font-weight: 700;
        color: var(--text-muted);
    }

    .student-schedule-table td[data-label="Trạng Thái"] {
        margin-top: 0.35rem;
    }

    .student-schedule-table td[data-label="Thao Tác"] {
        border-top: 1px solid var(--border-subtle) !important;
        padding-top: 0.65rem !important;
        margin-top: 0.5rem;
    }

    .btn-cancel-schedule {
        width: 100%;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.88rem !important;
    }

    /* Student Booking Tab Controls */
    .week-nav-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
    }

    .week-nav-btns {
        display: flex;
        width: 100%;
        justify-content: space-between;
    }

    .week-nav-btns .btn {
        flex: 1;
        text-align: center;
        padding: 0.5rem 0.5rem;
        min-height: 40px;
    }

    .week-days-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.45rem;
    }

    .slot-picker-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .selection-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    /* Confirm Booking Button - Full Width Touch CTA */
    #btn-confirm-booking {
        width: 100%;
        min-height: 50px;
        font-size: 1.05rem !important;
        font-weight: 800;
        border-radius: 10px;
    }

    /* Availability Matrix Presets Bar */
    .avail-presets-bar {
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0.4rem;
        padding-bottom: 0.4rem;
    }

    .avail-presets-bar::-webkit-scrollbar {
        display: none;
    }

    .avail-preset-btn {
        flex-shrink: 0;
        min-height: 42px;
        padding: 0.5rem 0.85rem;
        font-size: 0.82rem;
        border-radius: 8px;
    }

    /* Availability Staged Summary */
    .avail-summary-card {
        padding: 0.85rem;
        border-radius: 12px;
    }

    .avail-summary-card button#btn-submit-avail {
        width: 100%;
        min-height: 50px;
        font-size: 1rem;
        font-weight: 800;
        border-radius: 10px;
    }

    /* Modals on Mobile */
    .modal-dialog {
        width: 96vw !important;
        max-width: 96vw !important;
        margin: 0.4rem auto !important;
        max-height: 94vh !important;
        border-radius: var(--radius-md);
    }

    .modal-header {
        padding: 0.85rem 1rem;
    }

    .modal-body {
        padding: 0.85rem 1rem;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
        min-height: 46px;
        font-size: 0.95rem;
        font-weight: 700;
    }

    /* Modal Form Grids Collapse to 1 Column */
    .modal-body .form-grid,
    .modal-body div[style*="grid-template-columns"],
    .schedule-detail-grid {
        grid-template-columns: 1fr !important;
        gap: 0.65rem !important;
    }

    .schedule-detail-section.full-width {
        grid-column: span 1 !important;
    }

    /* Toast */
    .toast-container {
        left: 0.75rem;
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .toast {
        min-width: 100%;
        max-width: 100%;
    }
}

/* --------------------------------------------------------------------------
   3. EXTRA SMALL SCREENS (<= 480px - Compact Phones)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
    /* 1-column KPI cards for maximum readability */
    .metrics-grid {
        grid-template-columns: 1fr !important;
    }

    .week-days-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .student-quick-actions {
        grid-template-columns: 1fr !important;
    }

    .brand-title {
        font-size: 0.95rem;
    }

    .role-switcher {
        width: 100%;
        justify-content: space-between;
    }

    .role-tab-btn {
        flex: 1;
        text-align: center;
        padding: 0.45rem 0.35rem;
        font-size: 0.78rem;
    }
}
