/* ==========================================================================
   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);
    }

    /* Enable hamburger button on tablet screens */
    #btn-mobile-hamburger,
    .btn-hamburger {
        display: inline-flex !important;
    }

    .assign-schedule-container {
        grid-template-columns: 1fr !important;
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 1rem !important;
    }
}

/* --------------------------------------------------------------------------
   PC / DESKTOP (Width > 768px): STRICTLY HIDE MOBILE BOTTOM NAV BAR
   -------------------------------------------------------------------------- */
@media (min-width: 769px) {
    .mobile-bottom-nav,
    body.has-bottom-nav .mobile-bottom-nav {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    body.has-bottom-nav {
        padding-bottom: 0 !important;
    }
}

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

    body {
        padding-bottom: 0 !important;
    }

    body.has-bottom-nav {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* ======================================================================
       MOBILE BOTTOM NAVIGATION BAR (ONLY ON MOBILE PHONES <= 768px)
       ====================================================================== */
    .mobile-bottom-nav {
        display: none;
    }

    body.has-bottom-nav .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: rgba(255, 255, 255, 0.97);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
        border-top: 1px solid rgba(226, 232, 240, 0.9);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
        z-index: 9000 !important;
        align-items: center;
        justify-content: space-around;
        padding: 0 0.25rem;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        background: transparent;
        border: none;
        padding: 0.35rem 0.15rem;
        color: #64748b;
        font-size: 0.72rem;
        font-weight: 700;
        cursor: pointer;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 10px;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
        min-height: 48px;
    }

    .mobile-nav-btn .mobile-nav-icon {
        font-size: 1.25rem;
        line-height: 1;
        transition: transform 0.2s ease;
    }

    .mobile-nav-btn.active {
        color: var(--primary, #2563eb);
    }

    .mobile-nav-btn.active .mobile-nav-icon {
        transform: scale(1.18);
    }

    .mobile-nav-btn.active .mobile-nav-label {
        font-weight: 800;
        color: var(--primary, #2563eb);
    }

    .mobile-nav-btn:active {
        transform: scale(0.92);
    }

    /* 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: 1000; /* Stays above normal page content but below drawer menu (9995) */
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0.6rem 0.75rem;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(12px);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    }

    .brand-wrapper {
        display: flex;
        align-items: center;
        gap: 0.45rem;
        min-width: 0;
        flex: 1;
        overflow: hidden;
    }

    .brand-icon {
        width: 32px;
        height: 32px;
        flex-shrink: 0;
    }

    .brand-text {
        min-width: 0;
        overflow: hidden;
    }

    .brand-text h1 {
        font-size: 0.86rem !important;
        font-weight: 800;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0;
    }

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

    #btn-reset-db {
        display: none !important;
    }

    /* Hide user profile widget on mobile - it lives in the drawer instead */
    .user-profile-widget {
        display: none !important;
    }

    /* Topbar right group - hide reset db, only show hamburger */
    .topbar-right-group {
        display: none !important;
    }

    /* Hamburger is always visible when logged in on mobile */
    #btn-mobile-hamburger {
        display: inline-flex !important;
    }

    /* 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;
    }

    /* ======================================================================
       STREAMLINED MOBILE APP LAYOUT:
       Hide bulky horizontal student tab bar on mobile.
       Replaced by sleek Hamburger Drawer Menu + Fixed Bottom Nav Bar!
       ====================================================================== */
    .student-nav-tabs {
        display: none !important;
    }

    /* Hide teacher nav tabs on mobile - replaced by hamburger drawer */
    .teacher-nav-tabs {
        display: none !important;
    }

    /* ======================================================================
       ADMIN MOBILE LAYOUT:
       Hide sidebar on mobile, use hamburger drawer + fixed bottom nav instead
       ====================================================================== */
    .admin-layout {
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.75rem !important;
    }

    .admin-sidebar {
        display: none !important;
    }

    .admin-main-content {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: 0 !important;
    }

    /* Admin mobile tab pills shown as compact strip */
    .admin-tab-content {
        display: none;
        width: 100% !important;
        max-width: 100% !important;
    }

    .admin-tab-content.active {
        display: block;
    }

    /* Fix Assign Schedule Container blowing out on mobile */
    .assign-schedule-container {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
        width: 100% !important;
    }

    .assign-schedule-container > div {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 1rem !important;
    }

    .session-type-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    /* Admin forms & multi-column inline grids collapse on mobile */
    .admin-main-content div[style*="grid-template-columns: 1fr 1fr"],
    .admin-main-content div[style*="grid-template-columns: 1fr 1fr 1fr"],
    .admin-main-content div[style*="grid-template-columns:repeat"],
    #admin-tab-license_classes_mgmt div[style*="grid-template-columns"],
    #admin-tab-dat_import div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 0.65rem !important;
    }

    /* Admin Timetable Week Controller & Scroll */
    #timetable-week-controller {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.65rem !important;
        padding: 0.75rem 0.85rem !important;
    }

    #timetable-week-controller > div {
        width: 100% !important;
        justify-content: space-between !important;
        flex-wrap: wrap !important;
    }

    .timetable-mode-toggle {
        width: 100% !important;
        display: flex !important;
    }

    .timetable-mode-toggle .btn-mode {
        flex: 1 !important;
        text-align: center !important;
        justify-content: center !important;
    }

    #timetable-day-picker-wrap {
        width: 100% !important;
        justify-content: space-between !important;
    }

    #timetable-day-picker-wrap input {
        flex: 1 !important;
    }

    #timetable-week-view-container {
        padding: 0.35rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .timetable-week-scroll {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: 8px;
        border: 1px solid var(--border-subtle);
    }

    /* Admin filter bars & inputs */
    .table-filter-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.65rem !important;
        padding: 0.75rem !important;
    }

    .table-filter-bar .search-input-wrap,
    .table-filter-bar > div {
        width: 100% !important;
        max-width: 100% !important;
    }

    .table-filter-bar select,
    .table-filter-bar input[type="text"],
    .table-filter-bar input[type="date"] {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Admin Payroll Filter Card */
    #admin-tab-training_stats .glass-card > div[style*="display:flex"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    #admin-tab-training_stats .glass-card > div[style*="display:flex"] > div {
        width: 100% !important;
        flex-direction: column !important;
        align-items: stretch !important;
    }

    #admin-tab-training_stats .glass-card input[type="date"],
    #admin-tab-training_stats .glass-card select,
    #admin-tab-training_stats .glass-card button {
        width: 100% !important;
    }

    /* Admin Card Header on Mobile */
    .glass-card .card-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.65rem !important;
    }

    .glass-card .card-header > div:last-child {
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.45rem !important;
    }

    .glass-card .card-header .btn {
        width: 100% !important;
        justify-content: center !important;
        min-height: 42px !important;
    }

    /* ======================================================================
       MOBILE HAMBURGER BUTTON & SLIDE-OUT DRAWER
       ====================================================================== */
    .btn-hamburger,
    #btn-mobile-hamburger {
        display: inline-flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 4.5px;
        width: 38px;
        height: 38px;
        background: #f1f5f9;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        cursor: pointer;
        padding: 0;
        flex-shrink: 0;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }

    .btn-hamburger:active,
    #btn-mobile-hamburger:active {
        transform: scale(0.92);
        background: #e2e8f0;
    }

    .hamburger-bar {
        display: block;
        width: 18px;
        height: 2.2px;
        background: #1e293b;
        border-radius: 2px;
        pointer-events: none;
        transition: all 0.2s ease;
    }

    /* Drawer Overlay Backdrop */
    .drawer-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(15, 23, 42, 0.65);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 9990 !important;
        opacity: 0;
        visibility: hidden;
        display: none;
        pointer-events: none;
        transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s;
    }

    .drawer-overlay.open {
        opacity: 1 !important;
        visibility: visible !important;
        display: block !important;
        pointer-events: auto !important;
    }

    /* Mobile Slide-out Drawer Menu */
    .mobile-drawer {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 320px;
        max-width: 86vw;
        height: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        background: #ffffff;
        z-index: 9995 !important;
        box-shadow: none !important; /* Không đổ bóng khi đóng */
        visibility: hidden !important;
        pointer-events: none !important;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s, box-shadow 0.3s;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .mobile-drawer.open {
        transform: translateX(0) !important;
        visibility: visible !important;
        display: flex !important;
        pointer-events: auto !important;
        box-shadow: 10px 0 35px rgba(0, 0, 0, 0.22) !important;
    }

    .drawer-header {
        background: linear-gradient(135deg, #1e3a8a, #2563eb);
        color: #ffffff;
        padding: 1.25rem 1.15rem;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .drawer-user-info {
        display: flex;
        align-items: center;
        gap: 0.85rem;
        flex: 1;
    }

    .drawer-avatar {
        width: 46px;
        height: 46px;
        border-radius: 50%;
        background: linear-gradient(135deg, #f59e0b, #d97706);
        color: #ffffff;
        font-weight: 800;
        font-size: 1.25rem;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
        flex-shrink: 0;
    }

    .drawer-name {
        font-size: 1.05rem;
        font-weight: 800;
        margin: 0;
        color: #ffffff;
        line-height: 1.25;
    }

    .drawer-meta {
        font-size: 0.78rem;
        color: rgba(255, 255, 255, 0.85);
        margin-top: 0.25rem;
    }

    .drawer-close-btn {
        background: rgba(255, 255, 255, 0.18);
        border: none;
        color: #ffffff;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        font-size: 1rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.15s ease;
    }

    .drawer-close-btn:active {
        background: rgba(255, 255, 255, 0.35);
    }

    .drawer-body {
        flex: 1;
        overflow-y: auto;
        padding: 1rem 0.85rem;
        -webkit-overflow-scrolling: touch;
    }

    .drawer-section-title {
        font-size: 0.72rem;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: #94a3b8;
        margin-bottom: 0.65rem;
        padding-left: 0.4rem;
    }

    .drawer-nav {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
    }

    .drawer-nav-item {
        display: flex;
        align-items: center;
        gap: 0.85rem;
        padding: 0.85rem 0.95rem;
        border-radius: 12px;
        border: 1px solid transparent;
        background: transparent;
        color: #334155;
        cursor: pointer;
        width: 100%;
        text-align: left;
        transition: all 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .drawer-nav-item:active {
        background: #f1f5f9;
        transform: scale(0.98);
    }

    .drawer-nav-item.active {
        background: #eff6ff;
        border-color: #bfdbfe;
        color: #1d4ed8;
    }

    .drawer-nav-item.active .drawer-item-title {
        color: #1d4ed8;
        font-weight: 800;
    }

    .drawer-icon {
        font-size: 1.35rem;
        line-height: 1;
        flex-shrink: 0;
    }

    .drawer-item-text {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .drawer-item-title {
        font-size: 0.92rem;
        font-weight: 700;
        color: #1e293b;
    }

    .drawer-item-desc {
        font-size: 0.75rem;
        color: #64748b;
    }

    .drawer-footer {
        padding: 1rem 0.85rem;
        border-top: 1px solid #f1f5f9;
        background: #fafafa;
    }

    /* Drawer logout button */
    .drawer-logout-btn {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        background: transparent;
        border: 1.5px solid #e2e8f0;
        border-radius: 10px;
        color: #64748b;
        font-size: 0.9rem;
        font-weight: 700;
        padding: 0.75rem 1rem;
        cursor: pointer;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .drawer-logout-btn:active {
        background: #fee2e2;
        border-color: #fca5a5;
        color: #dc2626;
    }

    /* Teacher drawer header - green gradient */
    .drawer-header-teacher {
        background: linear-gradient(135deg, #065f46, #059669) !important;
    }

    .drawer-avatar-teacher {
        background: linear-gradient(135deg, #10b981, #059669) !important;
        box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4) !important;
    }

    /* Admin drawer header - purple gradient */
    .drawer-header-admin {
        background: linear-gradient(135deg, #4c1d95, #7c3aed) !important;
    }

    .drawer-avatar-admin {
        background: linear-gradient(135deg, #7c3aed, #a78bfa) !important;
        box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4) !important;
        font-size: 1rem !important;
    }

    /* Admin drawer items are more compact (no description) */
    .admin-drawer-item {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.7rem 0.95rem !important;
    }

    .admin-drawer-item .drawer-item-title {
        font-size: 0.88rem;
    }

    /* Teacher nav tabs hidden on mobile - navigation via drawer only */

    /* Compact Header on Mobile */
    #student-header-card .student-hero-card {
        padding: 0.85rem 1rem !important;
        margin-bottom: 0.75rem !important;
        border-radius: var(--radius-lg) !important;
    }

    #student-header-card .student-hero-avatar {
        width: 38px !important;
        height: 38px !important;
        font-size: 1.15rem !important;
    }

    #student-header-card h2 {
        font-size: 1.05rem !important;
    }

    #teacher-header-box .glass-card {
        padding: 0.85rem 1rem !important;
        margin-bottom: 0.75rem !important;
        border-radius: var(--radius-lg) !important;
    }

    #teacher-header-box div[style*="width:52px"] {
        width: 38px !important;
        height: 38px !important;
        font-size: 1.15rem !important;
    }

    #teacher-header-box h2 {
        font-size: 1.05rem !important;
    }

    /* 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: #ffffff;
        border: 1.5px solid var(--border-subtle);
        border-radius: 9999px;
        padding: 0.45rem 0.95rem;
        font-size: 0.82rem;
        font-weight: 700;
        color: #475569;
        cursor: pointer;
        flex-shrink: 0;
        transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        min-height: 38px;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    }

    .teacher-filter-pill.active {
        background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
        color: #ffffff !important;
        border-color: #1d4ed8 !important;
        box-shadow: 0 4px 12px var(--primary-glow) !important;
    }

    .teacher-filter-pill:active {
        transform: scale(0.96) !important;
    }

    /* 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 & Compact for Mobile) */
    .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-compact {
        display: inline-flex;
        align-items: center;
        gap: 0.3rem;
        background: linear-gradient(135deg, #10b981, #059669);
        color: #ffffff !important;
        text-decoration: none !important;
        font-weight: 700;
        font-size: 0.78rem;
        padding: 0.3rem 0.65rem;
        border-radius: 99px;
        box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
        transition: all 0.15s ease;
    }

    .btn-call-student-compact:active {
        transform: scale(0.95);
        background: #047857;
    }

    .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;
    }

    /* ======================================================================
       TEACHER PAYROLL TABLE -> MODERN MOBILE CARDS
       ====================================================================== */
    .teacher-payroll-table {
        display: block;
        width: 100%;
        border: none;
    }

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

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

    .teacher-payroll-table tr {
        display: block;
        width: 100%;
        background: #ffffff;
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-lg);
        padding: 0.85rem 1rem;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
        position: relative;
        transition: all 0.2s ease;
    }

    .teacher-payroll-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding: 0.3rem 0 !important;
        border: none !important;
        font-size: 0.84rem;
        text-align: right;
    }

    .teacher-payroll-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted);
        font-size: 0.78rem;
        min-width: 105px;
        text-align: left;
    }

    .teacher-payroll-table td[data-label="Ngày Dạy"] {
        border-bottom: 1px solid var(--border-subtle) !important;
        padding-bottom: 0.45rem !important;
        margin-bottom: 0.35rem;
        font-size: 0.98rem;
        color: var(--primary);
        font-weight: 800;
    }

    .teacher-payroll-table td[data-label="Km Tính Lương"] {
        background: #ecfdf5;
        border: 1px dashed #86efac !important;
        border-radius: 8px;
        padding: 0.5rem 0.75rem !important;
        margin: 0.35rem 0;
        font-size: 0.95rem;
    }

    .teacher-payroll-table td[data-label="Km Tính Lương"]::before {
        color: #065f46;
        font-weight: 800;
    }

    /* 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);
    }

    /* Hide redundant quick action pills on mobile because bottom nav bar is always available */
    .student-quick-actions {
        display: none !important;
    }

    /* 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 -> APP-STYLE BOOKING 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 1rem;
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.04);
        position: relative;
        transition: all 0.2s ease;
    }

    .student-schedule-table td {
        display: block;
        width: 100%;
        padding: 0.28rem 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.45rem !important;
        margin-bottom: 0.4rem;
        font-size: 1rem;
        font-weight: 800;
        color: var(--primary);
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .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;
    }

    .student-schedule-table td[data-label="Thao Tác"] .btn {
        width: 100%;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.88rem !important;
        border-radius: 10px;
    }

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

    /* ======================================================================
       STUDENT RATINGS TAB & BOTTOM SHEET MODAL (PREMIUM MOBILE POLISH)
       ====================================================================== */
    .review-card-item {
        background: #ffffff !important;
        border: 1px solid rgba(226, 232, 240, 0.9) !important;
        padding: 1rem 1.15rem !important;
        border-radius: 14px !important;
        margin-bottom: 0.85rem !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04) !important;
    }

    .review-quote-box {
        background: #f8fafc !important;
        border-left: 3.5px solid #f59e0b !important;
        border-radius: 0 10px 10px 0 !important;
        padding: 0.75rem 0.95rem !important;
        font-size: 0.86rem !important;
        line-height: 1.55 !important;
        color: #1e293b !important;
    }

    /* Full-width CTA for + Đánh Giá Giáo Viên Mới on Mobile */
    #student-tab-ratings .card-header button.btn-primary {
        width: 100% !important;
        min-height: 48px !important;
        justify-content: center !important;
        font-size: 0.92rem !important;
        font-weight: 800 !important;
        border-radius: 12px !important;
        background: linear-gradient(135deg, #f59e0b, #ea580c) !important;
        border: none !important;
        box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4) !important;
    }

    /* Mobile Bottom Sheet for Teacher Rating */
    #student-rate-teacher-modal {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    #student-rate-teacher-modal .modal-dialog {
        width: 100vw !important;
        max-width: 100vw !important;
        margin: 0 !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25) !important;
    }

    #student-rate-teacher-modal .star-rating-picker {
        display: flex !important;
        justify-content: center !important;
        gap: 0.65rem !important;
        padding: 0.6rem 0 !important;
    }

    #student-rate-teacher-modal .star-pick-btn {
        width: 48px !important;
        height: 48px !important;
        font-size: 2.3rem !important;
        min-width: 48px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    #student-rate-teacher-modal .star-pick-btn:active {
        transform: scale(1.3) !important;
    }

    #student-rate-teacher-modal textarea {
        min-height: 100px !important;
        border-radius: 10px !important;
        font-size: 0.92rem !important;
    }

    #student-rate-teacher-modal #btn-submit-teacher-rating {
        width: 100% !important;
        min-height: 48px !important;
        font-size: 0.95rem !important;
        font-weight: 800 !important;
        border-radius: 12px !important;
        background: linear-gradient(135deg, #f59e0b, #d97706) !important;
        box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4) !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;
    }
}

/* ==========================================================================
   TỐI ƯU SIÊU GỌN THANH TOPBAR KHI THI & ÔN TẬP TRÊN MOBILE (<= 768px)
   ========================================================================== */
@media (max-width: 768px) {
    /* 1. Màn hình thi hỗ trợ VÙNG AN TOÀN TAI THỎ (Safe Area Inset) trên iPhone */
    body.theory-quiz-mode {
        padding-top: env(safe-area-inset-top, 0px) !important;
    }

    /* Tấm chắn nền thanh trạng thái trên iOS khi cuộn trang */
    body.theory-quiz-mode::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: max(16px, env(safe-area-inset-top, 0px));
        background: #f8fafc;
        z-index: 999;
        pointer-events: none;
    }

    body.theory-quiz-mode #theory-quiz-screen {
        padding-top: max(0.65rem, calc(env(safe-area-inset-top, 0px) + 8px)) !important;
        padding-bottom: max(1.5rem, calc(env(safe-area-inset-bottom, 0px) + 1.25rem)) !important;
        padding-left: max(0.5rem, env(safe-area-inset-left, 0px)) !important;
        padding-right: max(0.5rem, env(safe-area-inset-right, 0px)) !important;
    }

    /* 2. Topbar gộp 1 hàng duy nhất, GHIM DÍNH TRÊN CÙNG KHI CUỘN XUỐNG */
    .theory-modern-topbar {
        position: -webkit-sticky !important;
        position: sticky !important;
        top: max(0.5rem, calc(env(safe-area-inset-top, 0px) + 8px)) !important;
        z-index: 1000 !important;
        border-radius: 14px !important;
        margin-bottom: 0.65rem !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1) !important;
        background: rgba(255, 255, 255, 0.98) !important;
        border: 1px solid rgba(226, 232, 240, 0.95) !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        -webkit-transform: translate3d(0, 0, 0) !important;
        transform: translate3d(0, 0, 0) !important;
        overflow: visible !important;
    }

    .theory-topbar-row {
        padding: 0.45rem 0.65rem !important;
        gap: 0.45rem !important;
        min-height: 44px !important; /* Đạt chuẩn Apple Touch Target 44x44pt */
        align-items: center !important;
    }

    /* Ẩn hoàn toàn hàng phụ gây chiếm diện tích và cắt chữ */
    .theory-topbar-subrow {
        display: none !important;
    }

    /* Nút Thoát rõ ràng, to rộng, dễ chạm 100% trên iPhone */
    .theory-btn-exit {
        padding: 0.45rem 0.85rem !important;
        font-size: 0.85rem !important;
        border-radius: 9px !important;
        background: #fee2e2 !important;
        color: #b91c1c !important;
        border: 1px solid #fca5a5 !important;
        font-weight: 800 !important;
        min-height: 38px !important;
        min-width: 68px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0.35rem !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        pointer-events: auto !important;
        -webkit-tap-highlight-color: rgba(220, 38, 38, 0.2) !important;
        z-index: 1001 !important;
    }
    .theory-btn-exit .theory-btn-exit-text {
        display: inline !important; /* Luôn hiện chữ "Thoát" để người dùng nhận diện ngay */
        font-weight: 800 !important;
    }

    /* Đồng hồ đếm ngược nổi bật giữa màn hình */
    .theory-modern-timer {
        padding: 0.28rem 0.65rem !important;
        border-radius: 99px !important;
        gap: 0.3rem !important;
        background: #fee2e2 !important;
        border: 1px solid #fca5a5 !important;
        min-height: 36px !important;
        display: inline-flex !important;
        align-items: center !important;
    }
    .theory-modern-timer .timer-icon {
        font-size: 0.85rem !important;
    }
    .theory-modern-timer .timer-text {
        font-size: 1.05rem !important;
        letter-spacing: 0.02em !important;
        font-weight: 800 !important;
    }

    /* Badge ôn tập khi không thi */
    .theory-modern-mode-badge {
        padding: 0.25rem 0.6rem !important;
        font-size: 0.78rem !important;
        max-width: 140px !important;
        min-height: 36px !important;
        display: inline-flex !important;
        align-items: center !important;
    }

    /* Nút Bảng câu gọn gàng nhưng chạm cực nhạy */
    .theory-btn-palette {
        padding: 0.45rem 0.75rem !important;
        font-size: 0.82rem !important;
        border-radius: 9px !important;
        min-height: 38px !important;
        min-width: 64px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        pointer-events: auto !important;
        -webkit-tap-highlight-color: rgba(37, 99, 235, 0.2) !important;
        z-index: 1001 !important;
    }
    .theory-btn-palette .palette-text {
        display: none !important; /* Ẩn chữ "Bảng câu", chỉ giữ lại icon ⊞ và số câu "1/30" */
    }
    .palette-counter-badge {
        padding: 0.15rem 0.45rem !important;
        font-size: 0.78rem !important;
        margin-left: 0.2rem !important;
    }

    /* Thẻ câu hỏi đẩy sát lên trên, padding thoáng mắt */
    .theory-question-card {
        padding: 0.85rem 0.95rem 1rem !important;
        border-radius: 14px !important;
        margin-bottom: 0.65rem !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04) !important;
        touch-action: pan-y !important; /* Cuộn dọc tự nhiên, quản lý lướt ngang bằng JS */
        will-change: transform, opacity;
    }

    .theory-question-meta {
        margin-bottom: 0.4rem !important;
        gap: 0.4rem !important;
    }

    .theory-question-index {
        font-size: 0.85rem !important;
    }

    .theory-question-title {
        font-size: 0.98rem !important;
        line-height: 1.45 !important;
        margin-bottom: 0.75rem !important;
        font-weight: 700 !important;
    }

    .theory-option-item {
        padding: 0.65rem 0.85rem !important;
        margin-bottom: 0.45rem !important;
        border-radius: 10px !important;
        gap: 0.65rem !important;
    }

    .theory-option-label {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        font-size: 0.78rem !important;
    }

    .theory-option-text {
        font-size: 0.88rem !important;
        line-height: 1.4 !important;
    }

    .theory-bottom-nav {
        padding: 0.6rem 0.75rem !important;
        border-radius: 12px !important;
        gap: 0.4rem !important;
    }
}
