/* ============================================
   QLHT v2 — Responsive Overrides
   Loaded LAST to fix mobile/tablet layout issues.
   Breakpoints: 1100px (tablet), 768px (iPad), 480px (iPhone)
   ============================================ */

/* ============================================
   1. GLOBAL TABLE SCROLL
   The .table-wrapper divs in HTML had NO CSS.
   This is the #1 cause of table overflow.
   ============================================ */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrapper .student-table,
.table-wrapper .data-table {
  min-width: 600px;
}

/* ============================================
   2. SCHEDULE GRID — Horizontal Scroll
   .stk-grid has min-width:700px but no scroll container.
   ============================================ */
.sch-card {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   3. SIDEBAR — Mobile Backdrop Overlay
   ============================================ */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 150;
  opacity: 0;
  transition: opacity 0.3s ease;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* ============================================
   TABLET — ≤ 1100px
   iPad landscape, small laptops
   ============================================ */
@media (max-width: 1100px) {
  /* Already handled by existing CSS for most parts */
  /* Accounting table fix */
  .acc-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================
   TABLET & IPAD PORTRAIT — 769px to 1024px
   Fixes "Dead Zone" on iPad Gen 7-10, Air, Pro 11"
   Mini-Rail Sidebar (68px) + Maximized Work Area
   ============================================ */
@media (min-width: 769px) and (max-width: 1024px) {
  /* ---- Mini-Rail Sidebar ---- */
  .sidebar {
    width: 68px !important;
    overflow: visible;
    transition: width 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s ease;
  }

  .sidebar .sidebar-header {
    padding: 16px 8px;
    justify-content: center;
  }

  .sidebar .sidebar-header .logo {
    justify-content: center;
    gap: 0;
  }

  .sidebar .sidebar-header .logo-icon {
    width: 38px;
    height: 38px;
  }

  .sidebar .sidebar-header .logo-text,
  .sidebar .nav-section-title,
  .sidebar .nav-item .nav-label,
  .sidebar .user-profile .user-info {
    display: none !important;
  }

  .sidebar .nav-item {
    justify-content: center;
    padding: 12px 0;
    margin: 6px 8px;
    border-radius: 12px;
    position: relative;
  }

  .sidebar .nav-item .material-symbols-rounded {
    margin: 0;
    font-size: 24px;
  }

  /* Main Content: Mở rộng vùng làm việc khả dụng lên ~750px */
  .main-content {
    margin-left: 68px !important;
    width: calc(100% - 68px) !important;
    max-width: calc(100% - 68px) !important;
  }

  /* Bật nút Sidebar Toggle trên Header cho phép mở full menu nếu muốn */
  .sidebar-toggle {
    display: flex !important;
  }

  /* Khi người dùng bấm toggle mở full sidebar trên iPad */
  .sidebar.open {
    width: 260px !important;
    z-index: 200;
    box-shadow: 8px 0 32px rgba(15, 23, 42, 0.2);
  }

  .sidebar.open .sidebar-header .logo-text,
  .sidebar.open .nav-section-title,
  .sidebar.open .nav-item .nav-label,
  .sidebar.open .user-profile .user-info {
    display: flex !important;
  }

  .sidebar.open .nav-item {
    justify-content: flex-start;
    padding: 10px 14px;
    margin: 4px 12px;
  }

  .sidebar.open .nav-item .material-symbols-rounded {
    margin-right: 10px;
  }

  /* Dashboard KPI & Stats: Tối ưu 2x2 gọn gàng */
  .dashboard-kpi-grid,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px;
  }

  /* Bảng dữ liệu: Đảm bảo scroll container */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================
   MOBILE & SMALL TABLET — ≤ 768px
   ============================================ */
@media (max-width: 768px) {

  /* ---- Layout ---- */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }

  .sidebar.open {
    transform: translateX(0);
    z-index: 200;
  }

  .main-content {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: flex;
  }

  /* ---- Page Content ---- */
  .page-content {
    padding: 16px;
  }

  .dashboard-content {
    padding: 16px;
  }

  /* ---- Header ---- */
  .header {
    padding: 0 12px;
    gap: 8px;
    justify-content: space-between;
  }

  .header-left {
    gap: 10px;
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: center;
  }

  .header-greeting {
    min-width: 0;
  }

  .header-greeting h2 {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
  }

  .header-greeting p {
    display: none;
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  /* ---- Adaptive Search Box on Mobile ---- */
  .search-box {
    display: inline-flex !important;
    width: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
    height: 38px !important;
    padding: 0 !important;
    gap: 0 !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    cursor: pointer;
    background: var(--bg-hover, #f1f5f9) !important;
    border: 1px solid var(--card-border, #e2e8f0) !important;
    overflow: hidden !important;
    flex-shrink: 0 !important;
  }

  .search-box input {
    display: none !important;
  }

  .search-box .feature-badge {
    display: none !important;
  }

  .search-box .material-symbols-rounded {
    font-size: 20px;
    color: var(--text-secondary, #64748b);
    margin: 0;
  }

  /* ---- Dashboard Stats Grid & Tuition Summary — 2x2 Compact (Anti-Vertical Bloat) ---- */
  .dashboard-kpi-grid,
  .stats-grid,
  .tuition-summary {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .stat-card,
  .tuition-stat-card {
    padding: 12px 14px !important;
    border-radius: 14px !important;
  }

  .stat-card .stat-value,
  .tuition-stat-value {
    font-size: 1.25rem !important;
    line-height: 1.2;
  }

  .stat-card .stat-label,
  .tuition-stat-label {
    font-size: 0.78rem !important;
  }

  .stat-card-header {
    margin-bottom: 8px !important;
  }

  /* ---- Touch Targets Ergonomics (>= 42-44px) ---- */
  .table-action-btn,
  .action-btn,
  .btn-icon,
  .sch-nav-btn,
  .pagination-btn {
    min-width: 42px !important;
    min-height: 42px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 10px !important;
  }

  /* ---- Exam Management Header & Actions ---- */
  .exam-header,
  .em-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }

  .exam-header .header-left,
  .em-header .header-left {
    width: 100%;
  }

  .exam-header .header-right,
  .em-header .header-right,
  .em-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  /* ---- ALL Toolbar Buttons — Icon-Only ---- */
  .toolbar-right .btn-secondary span:not(.material-symbols-rounded),
  .toolbar-right .btn-primary span:not(.material-symbols-rounded) {
    display: none;
  }

  .toolbar-right .btn-secondary,
  .toolbar-right .btn-primary {
    min-height: 42px !important;
    padding: 8px 12px !important;
    border-radius: 10px !important;
    gap: 0;
  }

  /* Typography Minimal Constraints */
  .nav-section-title {
    font-size: 11.5px !important;
    letter-spacing: 0.5px;
  }

  .logo-text span {
    font-size: 11px !important;
  }

  /* ---- Summary Bar ---- */
  .summary-bar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }

  .summary-divider {
    display: none;
  }

  .summary-item {
    gap: 6px;
  }

  .summary-count {
    font-size: 1rem;
  }

  /* ---- Data Tables — Scroll ---- */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1px;
  }

  .table-wrapper .student-table,
  .table-wrapper .data-table {
    min-width: 580px;
  }

  /* ---- Schedule — Grid Scroll ---- */
  .sch-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .stk-grid {
    min-width: 600px;
  }

  /* Schedule toolbar */
  .sch-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .sch-toolbar .toolbar-left {
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  .period-nav {
    width: 100%;
    justify-content: center;
  }

  .view-toggle {
    align-self: center;
  }

  /* ---- Attendance Modal ---- */
  .att-footer {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }

  .att-footer-left {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  .att-footer-left .btn-danger-outline,
  .att-footer-left .btn-warning-outline,
  .att-footer-left .btn-edit-outline {
    flex: 1;
    justify-content: center;
    font-size: 0.72rem;
    padding: 6px 8px;
  }

  /* Hide text labels on attendance footer buttons */
  .att-footer-left .btn-danger-outline span:not(.material-symbols-rounded),
  .att-footer-left .btn-warning-outline span:not(.material-symbols-rounded),
  .att-footer-left .btn-edit-outline span:not(.material-symbols-rounded) {
    display: none;
  }

  .att-footer .btn-primary {
    width: 100%;
    justify-content: center;
  }

  /* ---- Courses Layout ---- */
  .courses-layout {
    grid-template-columns: 1fr;
  }

  .courses-panel-left {
    max-height: 260px;
  }

  /* ---- Enrollment Table ---- */
  .enrollment-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .enrollment-table-wrapper .data-table {
    min-width: 550px;
  }

  /* ---- Grades — Detail Table ---- */
  .detail-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .detail-table-wrapper .data-table {
    min-width: 500px;
  }

  /* Exam stats wrap */
  .exam-stats-row {
    flex-wrap: wrap;
  }

  .exam-stat-card {
    min-width: calc(50% - 8px);
  }

  /* Score entry wrap */
  .score-entry {
    flex-wrap: wrap;
  }

  .score-entry input[type="text"],
  .score-entry textarea {
    flex: none;
    width: 100%;
  }

  .score-entry-labels {
    display: none;
  }

  /* ---- Tuition — History Grid ---- */
  .student-history-row {
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }

  .student-history-course {
    grid-column: 1 / -1;
  }

  /* Tuition course rows */
  .course-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .course-row-right {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  /* ---- Statistics ---- */
  .stats-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .stats-charts-grid {
    grid-template-columns: 1fr;
  }

  .stats-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .stats-date-range {
    flex-direction: column;
  }

  .date-field input[type="date"] {
    width: 100%;
  }

  /* ---- Settings ---- */
  .settings-grid {
    grid-template-columns: 1fr;
  }

  /* Log Table */
  .log-toolbar-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 16px;
  }

  .log-search-wrap {
    width: 100%;
  }

  .log-filter-select {
    width: 100%;
  }

  .log-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .log-table {
    min-width: 500px;
  }

  /* ---- Backup ---- */
  .cloud-backup-list-header,
  .cloud-backup-row {
    grid-template-columns: 1fr 100px;
  }

  /* ---- Modals ---- */
  .modal {
    width: 95%;
    max-height: 88vh;
    border-radius: var(--radius-lg);
  }

  .modal .modal-body {
    max-height: 60vh;
    overflow-y: auto;
  }

  .modal-lg {
    width: 95vw;
  }

  /* Forms */
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-group.full-width {
    grid-column: 1;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .detail-item.full-width {
    grid-column: 1;
  }

  .form-row-2 {
    grid-template-columns: 1fr;
  }

  /* ---- Accounting ---- */
  .acc-controls {
    flex-direction: column;
    gap: 8px;
  }

  .acc-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Dashboard ---- */
  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: grid !important;
  }

  /* Keep the two core KPIs visible without duplicating the mobile reminders. */
  .stats-grid.dashboard-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 10px;
  }

  .dashboard-kpi-grid .stat-card-attendance,
  .dashboard-kpi-grid .stat-card-tuition {
    display: none;
  }

  .dashboard-kpi-grid .stat-card {
    min-height: 92px;
    padding: 13px 14px;
  }

  .dashboard-kpi-grid .stat-card-header {
    margin-bottom: 7px;
  }

  .dashboard-kpi-grid .stat-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }

  .dashboard-kpi-grid .stat-icon .material-symbols-rounded {
    font-size: 18px;
  }

  .dashboard-kpi-grid .stat-trend,
  .dashboard-kpi-grid .stat-card-footer {
    display: none;
  }

  .dashboard-kpi-grid .stat-card-body {
    margin-bottom: 0;
  }

  .dashboard-kpi-grid .stat-value {
    font-size: 1.45rem;
    letter-spacing: -0.7px;
  }

  .dashboard-kpi-grid .stat-label {
    margin-top: 2px;
    font-size: 0.73rem;
    line-height: 1.25;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .bottom-grid {
    grid-template-columns: 1fr;
    display: flex;
    flex-direction: column;
  }

  /* Reset desktop order — schedule first, course second */
  .bottom-grid .schedule-card {
    order: 1;
  }

  .bottom-grid .course-card {
    order: 2;
  }

  .stat-value {
    font-size: 1.7rem;
  }

  /* ---- Toasts ---- */
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 16px;
  }

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

/* ============================================
   IPHONE — ≤ 480px
   Smaller screens, compact mode
   ============================================ */
@media (max-width: 480px) {

  /* ---- Page Content ---- */
  .page-content {
    padding: 12px;
  }

  .dashboard-content {
    padding: 12px;
  }

  /* ---- Header ---- */
  .header {
    height: 56px;
    padding: 0 12px;
  }

  .header-greeting h2 {
    font-size: 0.92rem;
  }

  /* Hide notification on very small screens */
  .notification-btn {
    display: none;
  }

  /* ---- Stat Cards ---- */
  .stat-card {
    padding: 16px;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
  }

  .stat-icon .material-symbols-rounded {
    font-size: 18px;
  }

  /* ---- Summary Bar ---- */
  .summary-bar {
    padding: 10px 12px;
    gap: 8px;
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-item {
    width: 100%;
    justify-content: space-between;
  }

  .summary-item.summary-right {
    border-top: 1px solid var(--card-border);
    padding-top: 8px;
    margin-top: 2px;
  }

  /* ---- Toolbar ---- */
  .toolbar {
    gap: 8px;
  }

  .toolbar-left {
    flex-direction: column;
    gap: 8px;
  }

  .toolbar-right {
    width: 100%;
    justify-content: flex-end;
    gap: 6px;
  }

  .search-box-lg {
    max-width: 100%;
    min-width: unset;
  }

  .filter-group {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  .select-filter {
    flex: 1;
    min-width: 0;
  }

  /* ---- Table Scroll Tighter ---- */
  .table-wrapper .student-table,
  .table-wrapper .data-table {
    min-width: 520px;
  }

  .student-table th {
    padding: 10px 10px;
    font-size: 0.62rem;
  }

  .student-table td {
    padding: 10px 10px;
    font-size: 0.78rem;
  }

  /* Table footer */
  .table-footer {
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px;
    align-items: center;
  }

  /* ---- Schedule ---- */
  .stk-grid {
    min-width: 560px;
  }

  .stk-lesson {
    padding: 6px 8px;
  }

  .stk-lesson-name {
    font-size: 0.68rem;
  }

  .stk-lesson-time {
    font-size: 0.58rem;
  }

  .stk-day-col {
    padding: 4px;
    min-height: 100px;
  }

  .period-label {
    font-size: 0.78rem;
    min-width: 140px;
  }

  /* ---- Modals ---- */
  .modal {
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
  }

  .modal .modal-body {
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    padding: 12px 16px;
  }

  .modal-header {
    padding: 14px 16px 0;
  }

  .modal-footer {
    padding: 0 16px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .modal-title {
    font-size: 1rem;
  }

  /* ---- Exam Modal — Fullscreen on Mobile ---- */
  #exam-overlay {
    align-items: flex-start;
  }

  #exam-modal {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    max-width: 100%;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
  }

  #exam-modal .modal-body {
    max-height: none;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Xoá scroll riêng của danh sách học sinh — để toàn bộ form cuộn
     theo 1 thanh cuộn duy nhất của modal-body, tránh "bẫy" scroll */
  #exam-modal .score-entry-list {
    max-height: none;
    overflow-y: visible;
  }

  #exam-modal .form-divider {
    margin: 8px 0;
  }

  /* Hide thang điểm on mobile (default is 10) */
  #exam-modal .form-row .form-group.flex-1:has(#exam-max-score) {
    display: none;
  }

  /* Make exam form row single column */
  #exam-modal .form-row {
    flex-direction: column;
    gap: 8px;
  }

  #exam-modal .form-row .form-group {
    flex: none !important;
    width: 100%;
  }

  /* Compact inputs in exam modal */
  #exam-modal input,
  #exam-modal select {
    font-size: 0.82rem;
    padding: 8px 10px;
  }

  #exam-modal label {
    font-size: 0.78rem;
    margin-bottom: 2px;
  }

  /* Compact course/date side-by-side */
  #exam-modal .form-row:has(#exam-course) {
    flex-direction: row;
    gap: 8px;
  }

  #exam-modal .form-row:has(#exam-course) .form-group {
    flex: 1 !important;
    width: auto;
  }

  /* Attendance modal */
  .att-footer-left {
    gap: 4px;
  }

  .att-footer-left .btn-danger-outline,
  .att-footer-left .btn-warning-outline,
  .att-footer-left .btn-edit-outline {
    padding: 5px 6px;
    font-size: 0.68rem;
  }

  /* Score entry on small screens */
  .score-entry {
    padding: 8px 10px;
    gap: 6px;
  }

  .score-entry-name {
    font-size: 0.82rem;
  }

  .score-entry input[type="number"] {
    width: 56px;
    padding: 6px 8px;
    font-size: 0.82rem;
  }

  .score-entry .comment-input {
    font-size: 0.78rem;
    padding: 6px 8px;
  }

  /* ---- Statistics ---- */
  .stats-summary {
    grid-template-columns: 1fr;
  }

  .stat-card-v2 {
    padding: 12px;
  }

  .stat-card-value {
    font-size: 0.95rem;
  }

  .chart-container {
    height: 200px;
  }

  /* ---- Tuition ---- */
  .student-history-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .tuition-view-toggle {
    width: 100%;
  }

  .tuition-view-btn {
    flex: 1;
    justify-content: center;
    font-size: 0.72rem;
    padding: 6px 10px;
  }

  .class-section-header {
    padding: 12px 14px;
  }

  .course-row {
    padding: 10px 14px 10px 24px;
  }

  /* ---- Courses ---- */
  .detail-header {
    padding: 12px 14px;
  }

  .detail-header-info h3 {
    font-size: 0.88rem;
  }

  .detail-header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .detail-header-actions .btn-label {
    display: none;
  }

  .detail-header-actions .btn-secondary,
  .detail-header-actions .btn-primary,
  .detail-header-actions .btn-warning {
    padding: 6px 8px;
  }

  .course-card-meta {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Class selector full width */
  .class-selector-group {
    flex-wrap: wrap;
    width: 100%;
  }

  .select-filter-lg {
    min-width: auto;
    width: 100%;
  }

  #course-selector {
    width: 100%;
  }

  /* ---- Settings ---- */
  .log-col-desc {
    max-width: 200px;
  }

  /* Log toolbar full width */
  .log-toolbar-inner {
    padding: 10px 12px;
  }

  /* ---- Cards ---- */
  .card-body {
    padding: 14px 16px 16px;
  }

  .card-header {
    padding: 14px 16px 0;
  }

  .card-header-row {
    gap: 8px;
    padding-bottom: 10px;
  }

  /* ---- Debt section ---- */
  .debt-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 14px 16px;
  }

  .debt-item {
    padding: 10px 14px;
    gap: 8px;
  }

  .debt-item-avatar {
    display: none;
  }

  /* ---- Accounting ---- */
  .accounting-content {
    padding: 12px;
  }

  /* ---- Backup / Settings Cards ---- */
  .settings-card {
    padding: 16px;
  }

  .card-header-row h3 {
    font-size: 0.88rem;
  }
}

/* ============================================
   MOBILE CARD VIEWS
   Hidden on desktop (>768px), shown on mobile.
   Replaces horizontal tables with vertical cards.
   ============================================ */

/* Desktop: hide mobile cards */
.mobile-card-list,
.mobile-schedule-list,
.mobile-enroll-list {
  display: none;
}

@media (max-width: 768px) {
  /* ---- HIDE desktop tables, SHOW mobile cards ---- */
  .table-card .table-wrapper {
    display: none;
  }

  .table-card .table-footer {
    display: none;
  }

  .table-card .student-pagination-footer {
    display: flex;
    padding: 12px;
    gap: 10px;
    flex-wrap: wrap;
  }

  /* Enrollment table (inside courses panel, not .table-card) */
  .enrollment-table-wrapper {
    display: none !important;
  }

  .mobile-card-list,
  .mobile-enroll-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  /* Schedule: hide grid, show mobile list */
  .stk-grid {
    display: none !important;
  }

  .mobile-schedule-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  /* ---- Mobile Card — Base ---- */
  .m-card {
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: var(--card-shadow);
    transition: all var(--t-fast);
  }

  .m-card:active {
    transform: scale(0.99);
  }

  .m-card.row-inactive {
    opacity: 0.55;
  }

  /* Card top row: name + badge */
  .m-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
  }

  .m-card-name {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .m-card-name .m-card-idx {
    color: var(--text-muted);
    font-weight: 500;
    margin-right: 4px;
  }

  /* Card info rows */
  .m-card-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
  }

  .m-card-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
  }

  .m-card-row .material-symbols-rounded {
    font-size: 15px;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .m-card-label {
    color: var(--text-muted);
    font-weight: 500;
    min-width: 55px;
    flex-shrink: 0;
  }

  .m-card-value {
    font-weight: 500;
    color: var(--text-primary);
  }

  /* Card actions row */
  .m-card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--bg-secondary);
    justify-content: flex-end;
  }

  .m-card-actions .btn-icon-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: var(--bg-hover);
    cursor: pointer;
    transition: all var(--t-fast);
  }

  .m-card-actions .btn-icon-sm .material-symbols-rounded {
    font-size: 17px;
    color: var(--text-secondary);
  }

  .m-card-actions .btn-icon-sm:hover {
    background: var(--accent-bg);
    border-color: var(--accent);
  }

  .m-card-actions .btn-icon-sm:hover .material-symbols-rounded {
    color: var(--accent);
  }

  .m-card-actions .btn-icon-sm.danger:hover {
    background: var(--danger-bg);
    border-color: var(--danger);
  }

  .m-card-actions .btn-icon-sm.danger:hover .material-symbols-rounded {
    color: var(--danger);
  }

  /* Fee action buttons in enrollment cards */
  .m-card-actions .btn-collect,
  .m-card-actions .btn-paid {
    padding: 6px 12px;
    font-size: 0.76rem;
    border-radius: 8px;
  }

  /* ---- Mobile Schedule — Vertical Day List ---- */
  .m-day-section {
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
  }

  .m-day-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--bg-secondary);
    background: var(--bg-hover);
  }

  .m-day-header.is-today {
    background: var(--accent-bg);
    border-left: 3px solid var(--accent);
  }

  .m-day-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
  }

  .m-day-header.is-today .m-day-title {
    color: var(--accent);
  }

  .m-day-count {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 12px;
    background: var(--accent-bg);
    color: var(--accent);
  }

  .m-day-count.empty {
    background: var(--bg-secondary);
    color: var(--text-muted);
  }

  .m-day-lessons {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--bg-secondary);
  }

  .m-lesson-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    cursor: pointer;
    transition: background var(--t-fast);
  }

  .m-lesson-card:active {
    background: var(--bg-hover);
  }

  .m-lesson-bar {
    width: 4px;
    height: 36px;
    border-radius: 2px;
    flex-shrink: 0;
  }

  .m-lesson-info {
    flex: 1;
    min-width: 0;
  }

  .m-lesson-name {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--text-primary);
  }

  .m-lesson-time {
    font-size: 0.76rem;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
  }

  .m-lesson-time .material-symbols-rounded {
    font-size: 13px;
  }

  .m-lesson-status {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    flex-shrink: 0;
  }

  .m-lesson-status.done {
    background: var(--success-bg);
    color: var(--success);
  }

  .m-lesson-status.cancelled {
    background: var(--danger-bg);
    color: var(--danger);
    text-decoration: line-through;
  }

  .m-lesson-status.pending {
    background: var(--warning-bg);
    color: var(--warning);
  }

  .m-lesson-card.cancelled {
    opacity: 0.5;
  }

  .m-lesson-reason {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 2px;
  }

  .m-day-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    background: var(--bg-card);
  }

  .m-day-empty .material-symbols-rounded {
    font-size: 18px;
    vertical-align: middle;
    margin-right: 4px;
  }

  /* ---- Enrollment Mobile Cards ---- */
  .m-enroll-card {
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: var(--card-shadow);
  }

  .m-enroll-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
  }

  .m-enroll-name {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
  }

  .m-enroll-idx {
    color: var(--text-muted);
    font-weight: 500;
    margin-right: 4px;
  }

  .m-enroll-info {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
  }

  .m-enroll-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: var(--bg-hover);
    padding: 4px 10px;
    border-radius: 8px;
  }

  .m-enroll-chip .material-symbols-rounded {
    font-size: 14px;
    color: var(--text-muted);
  }

  .m-enroll-chip .m-enroll-val {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    color: var(--text-primary);
  }

  .m-enroll-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--bg-secondary);
  }

  .m-enroll-actions .btn-collect,
  .m-enroll-actions .btn-paid,
  .m-enroll-actions .btn-partial {
    flex: 1;
    justify-content: center;
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  .m-enroll-actions .btn-secondary,
  .m-enroll-actions .btn-xs {
    padding: 12px 20px;
    font-size: 0.88rem;
    gap: 5px;
    border-radius: 8px;
  }

  .m-enroll-actions .btn-secondary .material-symbols-rounded,
  .m-enroll-actions .btn-xs .material-symbols-rounded {
    font-size: 20px;
  }
}

/* ============================================
   SAFE AREA — iPhone Notch / Home Indicator
   ============================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .toast-container {
    padding-bottom: env(safe-area-inset-bottom);
  }

  @media (max-width: 480px) {
    .modal-footer {
      padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
  }
}

/* ============================================
   PREVENT HORIZONTAL OVERFLOW — Root Level
   ============================================ */
html, body {
  overflow-x: hidden;
}

.main-content {
  overflow-x: hidden;
}

/* ============================================
   PWA STANDALONE MODE — Safe Area Adjustments
   When the app runs fullscreen (no Safari chrome),
   we need to account for the status bar and home
   indicator on notched iPhones.
   ============================================ */
@media all and (display-mode: standalone) {
  body {
    /* Prevent pull-to-refresh and overscroll in standalone */
    overscroll-behavior-y: contain;
  }

  .sidebar {
    padding-top: env(safe-area-inset-top, 0px);
  }

  .header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  }

  /* Login overlay — push content below status bar */
  .login-overlay {
    padding-top: env(safe-area-inset-top, 0px);
  }
}
