/* ==========================================================================
   Responsive breakpoints
   - Large desktop  ≥ 1440px
   - Laptop         1024–1439px   (default styles)
   - Tablet         768–1023px    (sidebar becomes a drawer)
   - Large mobile   431–767px     (single column, tables → cards, bottom nav)
   - Small mobile   ≤ 430px / ≤ 360px
   ========================================================================== */

@media (min-width: 1440px) {
  .content { padding: 28px 36px; max-width: 1600px; }
  .stats { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 1199px) {
  .quiz { grid-template-columns: minmax(0, 1fr) 250px; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Tablet & below: off-canvas sidebar ---------- */
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-105%); width: min(300px, 86vw); box-shadow: var(--shadow-lg); }
  .shell.drawer-open .sidebar { transform: none; }
  .shell.drawer-open .drawer-backdrop { display: block; }
  .shell-main, .shell.collapsed .shell-main { margin-left: 0; }
  .shell.collapsed .sidebar { width: min(300px, 86vw); }
  .shell.collapsed .brand-text, .shell.collapsed .nav-link span, .shell.collapsed .nav-group-label, .shell.collapsed .sidebar-foot { display: revert; }
  .shell.collapsed .nav-link { justify-content: flex-start; }
  .menu-toggle { display: inline-grid; }
  .collapse-toggle { display: none; }
  .content { padding: 20px; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .quiz { grid-template-columns: minmax(0, 1fr); }
  .q-nav { position: static; }
}

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
  body { font-size: 16px; }
  h1 { font-size: 1.35rem; }
  .content { padding: 14px 14px 20px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .user-chip .uc-name { display: none; }
  .user-chip { padding: 3px; }
  .net-status .ns-text { display: none; }
  .net-status { padding: 6px; }
  .demo-banner { padding: 8px 12px; font-size: .8rem; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .page-head { align-items: flex-start; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .card { padding: 14px; border-radius: 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat-icon { width: 36px; height: 36px; }
  .stat-value { font-size: 1.2rem; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 92dvh; }
  .modal-foot .btn { flex: 1 1 auto; }
  .toasts { left: 12px; right: 12px; bottom: calc(12px + var(--bottomnav-h)); max-width: none; }
  .hbar { grid-template-columns: minmax(70px, 110px) 1fr auto; }
  .q-card { padding: 16px; }
  .q-text { font-size: 1.06rem; }
  .q-option { padding: 12px; min-height: 56px; }
  .q-actions .btn { flex: 1 1 auto; }
  .q-actions .grp { width: 100%; }
  .prose { font-size: 1.02rem; }
  .editor-area { padding: 12px; min-height: 280px; }
  .steps li { font-size: .78rem; }

  /* Tables become stacked cards */
  .table-wrap.stackable { border: 0; background: none; overflow: visible; }
  .stackable .table, .stackable .table tbody, .stackable .table tr, .stackable .table td { display: block; width: 100%; }
  .stackable .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .stackable .table tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; }
  .stackable .table td { border: 0; padding: 6px 14px; display: flex; gap: 12px; justify-content: space-between; text-align: right; }
  .stackable .table td::before { content: attr(data-label); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; text-align: left; flex: none; max-width: 45%; }
  .stackable .table td.cell-title { display: block; text-align: left; font-size: 1rem; padding-top: 8px; }
  .stackable .table td.cell-title::before { display: none; }
  .stackable .table td.cell-actions { justify-content: flex-end; flex-wrap: wrap; white-space: normal; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; }
  .stackable .table td.cell-actions::before { display: none; }
  .stackable .table td.cell-check { justify-content: flex-start; }

  /* Student bottom navigation */
  .portal-student .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -2px 10px rgba(20, 26, 63, .06);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; min-width: 0; }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a[aria-current="page"] { color: var(--ink-700); }
  .bottom-nav a[aria-current="page"] svg { color: var(--marigold-600); }
  .portal-student .content { padding-bottom: calc(var(--bottomnav-h) + 24px + env(safe-area-inset-bottom)); }
  .exam-mode .bottom-nav { display: none; }
  .exam-mode .content { padding-bottom: 24px; }
}

@media (max-width: 430px) {
  .btn { padding: 8px 12px; }
  .topbar-title { font-size: 1rem; }
  .tab { padding: 10px; }
  .timer { font-size: 1rem; padding: 5px 11px; }
}

@media (max-width: 360px) {
  .content { padding: 12px 10px 20px; }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .brand-text span { display: none; }
  .q-option { gap: 8px; }
}
