:root {
  --sidebar-width: 280px;
  --bg: #f3f4f6;
  --sidebar-bg: #0f172a;        /* dark brand color — reused as fg elsewhere (buttons, headings, clock) */
  --sidebar-surface: #e8f1fb;   /* the actual sidebar panel background (light blue) */
  --sidebar-hover: rgba(14, 165, 233, 0.10);
  --sidebar-text: #1e293b;
  --sidebar-text-muted: #64748b;
  --sidebar-line: rgba(15, 23, 42, 0.08);
  --sidebar-overlay: rgba(15, 23, 42, 0.04);
  --accent: #6366f1;
  --accent-light: #c7d2fe;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --text-main: #1e293b;
  --text-muted: #64748b;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  --radius: 16px;
  --border-width: 1px;

  /* ── Typography Scale ── */
  --text-xs:   11px;   /* meta、timestamp、badge label */
  --text-sm:   13px;   /* table cell、副标题、input */
  --text-base: 14px;   /* 正文、nav item */
  --text-md:   16px;   /* card 标题 */
  --text-lg:   20px;   /* section 标题 */
  --text-xl:   24px;   /* page 标题 */
  --text-2xl:  32px;   /* stat 大数字 */

  /* ── Font Weights ── */
  --fw-normal:  500;
  --fw-semi:    600;
  --fw-bold:    700;
  --fw-black:   800;
  --fw-900:     900;

  /* ── Spacing Scale ── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;

  /* ── Badge / Pill ── */
  --badge-radius: 6px;
  --badge-px: 8px;
  --badge-py: 3px;
  --badge-fs: var(--text-xs);
  --badge-fw: var(--fw-black);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', 'Noto Sans TC', sans-serif;
  background-color: var(--bg);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

#console-app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-surface);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 32px 0 24px;
  z-index: 100;
  box-shadow: 10px 0 30px rgba(0,0,0,0.06);
  position: relative;
  border-right: 1px solid var(--sidebar-line);
}

.brand {
  display: flex;
  flex-direction: column;
  padding: 0 24px;
  margin-bottom: 32px;
  gap: 16px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
  border: 2px solid rgba(255,255,255,0.1);
}

.brand-name {
  font-weight: 900;
  font-size: 20px;
  background: linear-gradient(to right, #0f172a, #475569);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.brand-tag {
  font-size: 10px;
  font-weight: 800;
  color: #6366f1;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 2px;
}

.nav-menu {
  flex: 1;
  padding: 0 12px;
  overflow-y: auto;
}

/* Sleek Scrollbar for Sidebar */
.nav-menu::-webkit-scrollbar {
  width: 4px;
}
.nav-menu::-webkit-scrollbar-thumb {
  background: rgba(15,23,42,0.15);
  border-radius: 10px;
}

.nav-section-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: #64748b;
  text-transform: uppercase;
  padding: 24px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: color 0.2s ease;
}

.nav-section-label:hover {
  color: #0f172a;
}

.nav-section-chevron {
  font-size: 12px;
  transition: transform 0.25s ease;
  opacity: 0.7;
}

.nav-section-label.collapsed .nav-section-chevron {
  transform: rotate(-90deg);
}

.nav-section {
  overflow: hidden;
  max-height: 1000px;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  opacity: 1;
}

.nav-section.collapsed {
  max-height: 0;
  opacity: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  margin: 2px 12px;
  color: var(--sidebar-text-muted);
  position: relative;
  border: 1px solid transparent;
}

.nav-item:hover {
  background-color: var(--sidebar-hover);
  color: #0369a1;
  transform: translateX(4px);
}

.nav-item.active {
  background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
  color: white;
  box-shadow: 0 10px 15px -3px rgba(14, 165, 233, 0.35);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 20%;
  height: 60%;
  width: 4px;
  background: white;
  border-radius: 0 4px 4px 0;
}

.nav-icon {
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(15,23,42,0.05);
  transition: all 0.2s;
}

.nav-item:hover .nav-icon {
  background: rgba(14,165,233,0.12);
}

.nav-item.active .nav-icon {
  background: rgba(255,255,255,0.2);
}

.nav-text {
  font-weight: 700;
  font-size: 13.5px;
}

.sidebar-footer {
  padding: 24px 16px;
  border-top: 1px solid var(--sidebar-line);
  background: rgba(15,23,42,0.03);
}

.user-profile-card {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--sidebar-line);
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 12px;
}

.user-profile-card:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(14, 165, 233, 0.3);
  transform: translateY(-2px);
}

.user-profile-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.user-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.user-info {
  min-width: 0;
}

.user-name-wrapper {
  margin-bottom: 2px;
}

.user-display-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.user-role-badge {
  font-size: 9px;
  font-weight: 900;
  color: #6366f1;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.user-org-badge {
  font-size: 11px;
  color: var(--sidebar-text-muted);
  background: rgba(15,23,42,0.05);
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid var(--sidebar-line);
}

.footer-actions {
  display: flex;
  gap: 8px;
}

.footer-btn {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--sidebar-line);
  color: var(--sidebar-text-muted);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.footer-btn:hover {
  background: rgba(14,165,233,0.12);
  color: #0369a1;
  border-color: rgba(14,165,233,0.3);
}

.footer-btn.logout:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.content-header {
  height: 70px;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  flex-shrink: 0;
}

.content-header h1 {
  font-size: 20px;
  font-weight: 800;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
  flex-wrap: nowrap;
}

/* Header nav tabs absorb the squeeze and scroll instead of pushing the toolbar.
   Hide the scrollbar chrome (functionality kept). */
#header-tabs { scrollbar-width: none; -ms-overflow-style: none; }
#header-tabs::-webkit-scrollbar { display: none; }

/* Mid-width desktop: when space gets tight, collapse the header action
   buttons to icon-only (keep tooltip via title=) so labels never wrap/stack.
   Starts at 1025px — at/below 1024px the tablet layout takes over with its
   own full-width action row, so this desktop-header rule must not overlap it. */
@media screen and (min-width: 1025px) and (max-width: 1200px) {
  .header-action-btn .header-action-label { display: none; }
  .header-action-btn { padding: 10px 12px !important; gap: 0 !important; }
  .header-action-btn .header-action-icon { font-size: 16px; line-height: 1; }
}

#content-body {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

/* ── Global Badge / Pill System ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: var(--badge-py) var(--badge-px);
  border-radius: var(--badge-radius);
  font-size: var(--badge-fs);
  font-weight: var(--badge-fw);
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-green  { color: #065f46; background: #d1fae5; border-color: #86efac; }
.badge-red    { color: #991b1b; background: #fee2e2; border-color: #fca5a5; }
.badge-yellow { color: #92400e; background: #fef3c7; border-color: #fde68a; }
.badge-blue   { color: #1e40af; background: #dbeafe; border-color: #93c5fd; }
.badge-gray   { color: #475569; background: #f1f5f9; border-color: #e2e8f0; }
.badge-purple { color: #3730a3; background: #ede9fe; border-color: #c4b5fd; }

/* ── Table Header Consistent ── */
.th-label {
  font-size: var(--text-xs);
  font-weight: var(--fw-black);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Card Section Title ── */
.section-title {
  font-size: var(--text-md);
  font-weight: var(--fw-black);
  color: var(--text-main);
  margin: 0 0 var(--sp-4);
}

/* ── Meta Text (timestamp, secondary info) ── */
.text-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: var(--fw-semi);
}

/* Common Components */
.card {
  background: var(--card-bg);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px -5px rgba(0,0,0,0.05);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

.stat-card {
  padding: 24px;
  background: white;
  border-radius: var(--radius);
  border: var(--border-width) solid var(--border);
}

.stat-val {
  font-size: 32px;
  font-weight: 800;
  color: var(--accent);
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: #f1f5f9;
}

.btn-icon:active {
  transform: scale(0.9);
}

/* Rule Chips (出题模块选择器) */
.rule-chip {
  padding: 8px 6px;
  border-radius: 8px;
  border: 1.5px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.rule-chip:hover {
  border-color: var(--accent);
  background: #eef2ff;
  color: var(--accent);
}

.rule-chip.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.rule-chip.selected:hover {
  background: #4f46e5;
  border-color: #4f46e5;
}

.rule-chip:active {
  transform: scale(0.95);
}

/* Generator UI Specifics */
.gen-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.control-group {
  margin-bottom: 20px;
}

.control-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-main);
}

select, input {
  width: 100%;
  padding: 12px 16px;
  border: var(--border-width) solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  background: #f8fafc;
  transition: all 0.2s;
}

select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select:focus, input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.primary-btn:active {
  transform: scale(0.98);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.primary-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.secondary-btn {
  background: white;
  color: var(--text-muted);
  border: 2px solid var(--border);
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.2s, color 0.2s;
}

.secondary-btn:hover {
  border-color: var(--text-muted);
  color: var(--text-main);
  background: #f8fafc;
}

.secondary-btn:active {
  transform: scale(0.98);
}

.secondary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.secondary-btn:focus-visible {
  outline: 2px solid var(--text-muted);
  outline-offset: 3px;
}

.danger-btn {
  background: #ef4444;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background-color 0.2s, opacity 0.2s;
}

.danger-btn:hover {
  background-color: #dc2626;
}

.danger-btn:active {
  transform: scale(0.98);
}

.danger-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.danger-btn:focus-visible {
  outline: 2px solid #ef4444;
  outline-offset: 3px;
}

/* Table Enhancements */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table-row-hover:hover {
  background-color: #f8fafc !important;
}

.data-table th {
  background: #f8fafc;
  color: #64748b;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 12px;
  border-bottom: 2px solid #e2e8f0;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: white;
  padding: 32px;
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.03); opacity: 0.9; }
}

@keyframes popUp {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes skeletonShimmer {
  0% { opacity: 1; }
  50% { opacity: 0.45; }
  100% { opacity: 1; }
}

.skeleton-pulse {
  animation: skeletonShimmer 1.4s ease-in-out infinite;
}

/* Top-level two-column page layouts (Reward Center, Homework, Classroom,
   Announcements, etc.). min-width:0 lets grid tracks shrink instead of
   forcing horizontal overflow. */
.reward-two-col > *,
.page-two-col > * { min-width: 0; }

/* Mobile Responsiveness */
/* Phone + tablet share the drawer/card layout. Two triggers (comma = OR):
     1. max-width:1024px  — phones + small/portrait tablets, any pointer.
     2. up to 1366px AND a coarse pointer — large-tablet LANDSCAPE (iPad Pro
        11" 1194 / Android 1280 / iPad Pro 12.9" 1366). These exceed 1024 so
        used to fall back to the desktop layout: sidebar pinned at 260px, the
        8-column table wrapping/colliding. Gating the upper band on
        `pointer: coarse` gives touch tablets the drawer/card layout while a
        1280/1366 laptop (fine pointer + mouse) keeps the real desktop UI. */
@media screen and (max-width: 1024px),
       screen and (min-width: 1025px) and (max-width: 1366px) and (pointer: coarse) {
  :root {
    --sidebar-width: 100%;
  }

  #console-app {
    flex-direction: column;
    overflow: auto;
  }

  .sidebar {
    width: 100%;
    position: fixed;
    top: 0;
    left: -100%;
    height: 100vh;
    transition: left 0.3s ease;
    padding-top: 80px;
    box-shadow: 10px 0 30px rgba(0,0,0,0.2);
    overflow-y: auto;
  }

  .sidebar.mobile-active {
    left: 0;
  }

  .sidebar .brand {
    display: none; /* Hide brand in mobile sidebar as it's in header */
  }

  .main-content {
    /* Fixed header is now two rows on mobile: title row + the restored
       quick-action toolbar row (~52px each). Clear both so page content
       never tucks under the header. */
    margin-top: 118px;
    height: auto;
    overflow: visible;
  }

  /* Tabs now live in their own in-document sub-nav row (#header-tabs-bar)
     below the fixed header, so they flow normally and need no extra header
     offset. Give the bar compact mobile padding aligned to the content gutter. */
  #header-tabs-bar {
    padding: 8px 12px;
  }

  .content-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 101;
    padding: 0 12px;
    min-height: 64px;        /* grow when the tab strip wraps to a 2nd row */
    height: auto !important;  /* override inline height:80px */
    background: white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border-bottom: none;
    flex-wrap: wrap;         /* let the quick-action toolbar drop to its own row */
    padding-bottom: 6px;
  }

  .mobile-logo {
    display: block !important;
  }

  .content-header h1 {
    font-size: 16px !important;
    font-weight: 900;
  }

  .mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    color: #0f172a;
  }

  .header-tools {
    display: none !important; /* Hide tools in header on mobile to save space */
  }

  #content-body {
    padding: 16px;
    overflow-y: visible;
    margin-top: 10px;
  }

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

  .gen-controls {
    grid-template-columns: 1fr;
  }

  /* Reward Center: stack the students list and change history vertically on
     phones instead of two side-by-side columns (prevents horizontal overflow). */
  .reward-two-col,
  .page-two-col,
  .worksheet-grid,
  .responsive-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Let the search input flow to full card width on phones. */
  .reward-search-wrap {
    width: 100%;
  }
  .reward-search-input {
    width: 100% !important;
  }

  .modal {
    width: 95%;
    padding: 20px;
  }

  .header-tools {
    gap: 10px;
    font-size: 12px;
  }

  /* Responsive Table to Card View */
  .data-table, .data-table thead, .data-table tbody, .data-table th, .data-table td, .data-table tr {
    display: block;
  }
  .data-table thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  .data-table tr {
    border: 1px solid #e2e8f0;
    margin-bottom: 15px;
    border-radius: 14px;
    background: white;
    padding: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
  }
  .data-table td {
    border: none;
    position: relative;
    padding-left: 50% !important;
    text-align: right !important;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
    min-height: 40px;
  }
  .data-table td:before {
    content: attr(data-label);
    position: absolute;
    left: 12px;
    width: 45%;
    padding-right: 10px;
    white-space: nowrap;
    text-align: left;
    font-weight: 800;
    color: #64748b;
    font-size: 11px;
    text-transform: uppercase;
  }
  .data-table td:first-child {
    padding-left: 12px !important;
    text-align: left !important;
    background: #f8fafc;
    border-radius: 10px;
    margin-bottom: 10px;
  }
  .data-table td:first-child:before {
    content: none;
  }

  /* Sidebar Overlay Logic */
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 99; /* Just below sidebar */
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .sidebar.mobile-active ~ .sidebar-overlay {
    display: block;
    opacity: 1;
  }

  /* ----------------------------------------------------------------
     Mobile Header Tabs - Segmented Pill Control
     ----------------------------------------------------------------
     On phone width the desktop underline tabs were crammed beside the
     title and clipped off-screen. We restyle them as a touch-first
     segmented control: an inset track on its own full-width row beneath
     the title, with a raised brand-indigo pill on the active tab,
     comfortable 40px tap targets, momentum scroll + scroll-snap, and a
     right-edge fade hinting there's more to swipe.
     ---------------------------------------------------------------- */
  .content-header > div:first-child {
    flex-wrap: wrap;          /* let the tab strip drop to its own line */
    gap: 8px 10px !important;
    min-width: 0;
    flex: 1 1 100%;
    height: auto !important;  /* override inline height:100% */
    padding: 8px 0 10px;
  }

  .content-header h1#page-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* The strip: full-width inset track, horizontally scrollable.
     A two-sided edge fade signals "this scrolls" rather than "this is
     clipped": content dissolves into the track on whichever side has more
     to reveal. We animate the mask via a CSS var the strip can't set
     itself, so we use a symmetric fade that reads as a scroller. */
  #header-tabs {
    margin-left: 0 !important;
    gap: 2px !important;                      /* tighter so more peeks through */
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    height: auto !important;
    padding: 4px !important;
    background: #eef2f7 !important;           /* inset track */
    border-radius: 14px !important;
    box-shadow: inset 0 1px 2px rgba(15,23,42,0.07) !important;
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;       /* iOS momentum */
    scroll-snap-type: x proximity;
    scrollbar-width: none;                   /* Firefox */
    /* Symmetric edge fade — wider on the right (36px) where the next tab
       peeks in, slim on the left (14px). Strongly hints horizontal scroll. */
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 36px), transparent 100%);
            mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 36px), transparent 100%);
  }
  #header-tabs::-webkit-scrollbar {
    display: none;                           /* Chrome/Safari */
  }

  /* Each tab becomes a pill segment */
  #header-tabs button {
    flex: 0 0 auto;
    scroll-snap-align: start;
    height: 40px !important;
    min-height: 40px;
    padding: 0 13px !important;              /* compact so the next tab shows */
    border-radius: 11px !important;
    font-size: 13px;
    font-weight: 700;
    color: #64748b;
    background: transparent !important;
    transition: color .2s ease, background .25s ease, box-shadow .25s ease, transform .12s ease;
  }

  #header-tabs button:active {
    transform: scale(0.96);
  }

  /* Active segment: raised white pill with brand-indigo label */
  #header-tabs button.active {
    color: var(--accent) !important;
    font-weight: 800;
    background: #ffffff !important;
    box-shadow: 0 2px 8px rgba(15,23,42,0.10),
                0 0 0 1px rgba(99,102,241,0.10) !important;
  }

  /* Kill the desktop underline indicator on mobile - pill replaces it */
  #header-tabs button::after,
  #header-tabs button.active::after {
    display: none !important;
  }

  /* ================================================================
     MOBILE OPTIMIZATION PASS (CSS-only) — three friction fixes:
       1. Restore the top quick-action toolbar (点名/新生登记/快速开单/刷新)
       2. Comfortable 44px touch targets for in-table action buttons
       3. Cleaner card-transform readability for data tables
     Layered as overrides on the existing mobile base; no markup change.
     ================================================================ */

  /* ── 1. Restore header quick-actions as a swipeable action row ──
     Desktop hides .header-tools to save space; phones need 点名/开单/
     登记 daily. Re-show it as its own full-width horizontally-scroll
     row beneath the title — mirrors the tab-strip pattern so it reads
     as native. The live clock is dropped (noise on a phone). */
  .header-tools {
    display: flex !important;
    flex: 1 1 100%;
    width: 100%;
    order: 3;                      /* title row, tab strip, then tools */
    gap: 8px !important;
    margin-top: 2px;
    padding: 2px 0 4px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
            mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
  }
  .header-tools::-webkit-scrollbar { display: none; }

  /* Live clock is dead weight on a phone — hide it, keep the buttons. */
  #current-time { display: none !important; }

  /* Each quick-action: touch-first pill, full label kept for clarity. */
  .header-tools .header-action-btn {
    flex: 0 0 auto;
    scroll-snap-align: start;
    height: 44px;
    min-height: 44px;
    padding: 0 16px !important;
    border-radius: 12px !important;
    font-size: 13px !important;
    white-space: nowrap;
  }
  .header-tools .header-action-btn:active { transform: scale(0.97); }

  /* Reload icon button: keep it square + thumb-sized, not stretched. */
  .header-tools .btn-icon {
    flex: 0 0 auto;
    width: 44px !important;
    height: 44px !important;
    scroll-snap-align: start;
  }

  /* ── 2. Bigger tap targets inside the card-transformed tables ──
     In-row action buttons are 11px/5px on desktop — fine with a mouse,
     a miss-fest with a thumb. Bump every button that lands in a table
     cell to a 40px tall, comfortably-padded pill, and let the action
     cluster wrap full-width and left-align (the cell is right-aligned
     by the card transform, which crushes a button row). */
  .data-table td button {
    min-height: 40px !important;
    padding: 9px 16px !important;
    font-size: 13px !important;
    border-radius: 10px !important;
  }
  /* The action cell holds a flex cluster of buttons — give it room. */
  .data-table td[data-label] > div {
    justify-content: flex-end;
    gap: 8px !important;
    flex-wrap: wrap;
  }
  /* Action cell: drop the 50% label gutter so buttons get full width. */
  .data-table td:last-child {
    padding-left: 12px !important;
    padding-top: 12px !important;
    text-align: left !important;
  }
  .data-table td:last-child:before {
    position: static;
    display: block;
    width: auto;
    margin-bottom: 8px;
  }

  /* ── 3. Card-transform readability polish ──
     More breathing room between label/value, a soft divider per field,
     and a stronger header row so each card reads as a tidy record. */
  .data-table tr {
    padding: 14px !important;
    margin-bottom: 16px !important;
    box-shadow: 0 4px 14px rgba(15,23,42,0.05) !important;
    border: 1px solid #e9eef4 !important;
  }
  .data-table td {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 11px 4px !important;
    padding-left: 4px !important;
    text-align: right !important;
    border-bottom: 1px solid #f1f5f9 !important;
    min-height: 44px;
  }
  .data-table td:last-child { border-bottom: none !important; }
  .data-table td:before {
    position: static !important;
    width: auto !important;
    flex: 0 0 auto;
    padding-right: 0 !important;
    font-size: 11px;
  }
  .data-table td:first-child {
    font-size: 15px;
    font-weight: 800;
    color: #0f172a;
    padding: 12px 12px !important;
    margin-bottom: 6px;
    border-bottom: none !important;
    justify-content: flex-start;
  }

  /* ================================================================
     MOBILE FORM PASS (CSS-only) — the modals (编辑学生/开班/开单…) are
     dense desktop grids that never reflow on a phone. Fixes:
       1. Collapse every inline `1fr 1fr(…)` form grid to a single column
       2. 16px input font (kills Android/iOS tap-zoom) + roomier tap height
       3. Stack the side-by-side time-select pairs in class modals
       4. Single-column student checklist (was cramped 2-col)
     Selectors target inline-styled markup by attribute, not :has() — old
     Android webviews silently drop :has() (see css_has_webview_pitfall).
     ================================================================ */

  /* ── 1. Collapse dense two/three-column form grids ──
     These are inline `grid-template-columns: 1fr 1fr` on .form-group / plain
     divs inside modals; attribute match + !important beats the inline value. */
  .modal [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* ── 2. Bigger, tap-friendly inputs; 16px stops mobile focus-zoom ──
     Covers both class-styled inputs and the many inline-styled ones. */
  .modal input,
  .modal select,
  .modal textarea {
    font-size: 16px !important;
    padding: 12px 14px !important;
    border-radius: 12px !important;
    min-height: 48px;
    box-sizing: border-box;
  }
  .modal input[type="radio"],
  .modal input[type="checkbox"] {
    min-height: 0;                 /* don't inflate hidden/radio inputs */
  }
  .modal label {
    font-size: 13px;
  }
  /* Roomy title/close spacing on a phone-sized modal. */
  .modal h2 {
    font-size: 18px !important;
    line-height: 1.3;
  }

  /* ── 3. Stack the time-start / "-" / time-end row (add/edit class) ──
     It's an inline `display:flex` wrapper holding two selects + a dash. */
  #ac-time-start, #ac-time-end,
  #ec-time-start, #ec-time-end {
    width: 100% !important;
    flex: 1 1 100% !important;
  }
  .modal .form-group > div[style*="display:flex"],
  .modal .form-group > div[style*="display: flex"] {
    flex-wrap: wrap;
    gap: 8px !important;
  }

  /* ── 4. Student pick-lists: one column, taller scroll area ──
     #ac-student-list / #ec-student-list are inline 2-col grids. */
  #ac-student-list,
  #ec-student-list {
    grid-template-columns: 1fr !important;
    max-height: 44vh !important;
  }

  /* Sticky modal action bar so 取消/保存 stay reachable without scrolling
     to the very bottom of a long form. */
  .modal .modal-actions {
    position: sticky;
    bottom: -20px;                 /* modal has 20px mobile padding */
    background: white;
    margin: 20px -20px -20px;
    padding: 14px 20px;
    border-top: 1px solid #eef2f7;
    box-shadow: 0 -6px 18px rgba(15,23,42,0.06);
    z-index: 2;
  }
  .modal .modal-actions button {
    min-height: 48px;
    flex: 1 1 auto;                /* full-width, easy-to-hit action buttons */
  }

  /* ================================================================
     JS-BUILT INVOICE MODAL (渐进式学生账单) — this one isn't a `.modal`;
     ui-invoices.js hand-builds the overlay + a fixed-width inner card
     with inline styles, so the rules above don't reach it. Its one real
     phone breakage is the line-item row: an inline 6-column grid
     (140px 1fr 70px 100px 90px 40px ≈ 440px of fixed track) that
     overflows a 390px screen and drags the whole modal off the left
     edge. Reflow that row to a 2-column mini-grid; label the cells so
     they read stacked. Class hooks already exist — no JS change.
     ================================================================ */
  .stubill-item-row {
    grid-template-columns: 1fr 1fr !important;  /* was 140px 1fr 70px… */
    gap: 10px !important;
    row-gap: 8px !important;
    padding: 12px !important;
  }
  /* Source-type picker + the item/preset picker each span the full row. */
  .stubill-item-row > div:nth-child(1),
  .stubill-item-row > div:nth-child(2) {
    grid-column: 1 / -1;
  }
  /* Qty / unit-price / subtotal / delete share the two columns below. */
  .stubill-item-row select,
  .stubill-item-row input {
    font-size: 16px !important;                 /* no focus-zoom, bigger tap */
    padding: 11px 10px !important;
    min-height: 46px;
    box-sizing: border-box;
  }
  /* Delete (✕) cell: keep it compact, don't let it stretch a whole row. */
  .stubill-item-row > div:last-child {
    display: flex;
    justify-content: flex-end;
  }
  /* Year+month sub-picker inside the item cell already grids 2-up — fine. */

  /* Hard stop any accidental horizontal overflow from a hand-built modal:
     the JS overlays use inline `display:flex` centering; clamp their inner
     card so nothing can bleed past the viewport on a phone. */
  #student-invoice-modal-overlay > div,
  #digital-invoice-overlay > div,
  #deposit-roster-overlay > div {
    width: 95vw !important;
    max-width: 95vw !important;
  }
  /* And prevent the payment sub-grid (support inline grid-template) collapsing
     weirdly — stack method + reference on their own rows. */
  #add-stubill-payment-container {
    grid-template-columns: 1fr !important;
  }

  /* ── 5. Touch-target backstop for in-page (non-modal, non-table) controls ──
     The passes above cover modals, header actions and in-table buttons. The
     remaining thumb-misses live in the page body: the small search boxes and
     filter selects that sit in a card header (e.g. the 7px-tall 搜索学生 input),
     and standalone icon buttons. Give every such control a comfortable tap
     height + 16px font (no iOS focus-zoom). Scoped to #content-body so it can't
     touch the header/tab/modal controls that already have bespoke sizing, and
     radio/checkbox are exempted so they don't inflate.
     (Applies across the whole phone+tablet range via the 1024px breakpoint.) */
  #content-body input:not([type="radio"]):not([type="checkbox"]),
  #content-body select,
  #content-body textarea {
    min-height: 44px;
    font-size: 16px;
    box-sizing: border-box;
  }
  /* Standalone icon buttons in the page body (not the ones already sized in a
     table cell or the header toolbar). */
  #content-body .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }
}

.mobile-menu-btn {
  display: none;
}

/* Header Tabs Underline Styles */
/* ── Desktop header tabs: segmented "inset track + raised white pill" ──
   Unifies with the mobile pill strip. A subtle inset track groups the tabs;
   the active tab is a raised white pill with an indigo label. The track is
   shrinkable + horizontally scrollable with a right-edge fade that signals
   "more tabs this way", so a long bilingual row never collides with the
   right-hand toolbar. (ui-ux-pro-max: nav-state-active, scroll-behavior,
   state-clarity, elevation-consistent, layout-shift-avoid) */
/* Full-width sub-nav row that hosts the tab track on its own line below the
   header. Aligns its left edge with the header content (40px gutter). */
#header-tabs-bar {
  flex-shrink: 0;
  padding: 10px 40px;
  background: white;
  border-bottom: 1px solid var(--border);
  overflow: hidden;            /* clip the track's edge-fade cleanly */
}

#header-tabs {
  height: auto;
  display: inline-flex;        /* track is only as wide as its tabs */
  max-width: 100%;             /* but never wider than the row → then it scrolls */
  align-items: center;
  gap: 4px;
  padding: 5px !important;
  background: #eef2f7 !important;            /* inset track */
  border: none !important;
  border-radius: 14px !important;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06) !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}
#header-tabs::-webkit-scrollbar { display: none; }

#header-tabs button {
  flex: 0 0 auto;
  scroll-snap-align: start;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 16px !important;
  height: 38px;
  font-size: 13.5px;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  white-space: nowrap;
  border-radius: 10px !important;
  /* Animate color/background/shadow only — no layout-shifting transforms. */
  transition: color 0.2s ease, background 0.22s ease, box-shadow 0.22s ease;
}

#header-tabs button:hover {
  color: #1e293b !important;
  background: rgba(255, 255, 255, 0.6) !important;
  box-shadow: none !important;
  transform: none !important;
}

#header-tabs button.active,
#header-tabs button.active:hover {
  color: var(--accent) !important;
  font-weight: 800;
  background: #ffffff !important;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.10),
              0 0 0 1px rgba(99, 102, 241, 0.12) !important;
}

#header-tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Retire the old underline indicator — the pill is the active affordance. */
#header-tabs button::after,
#header-tabs button.active::after {
  display: none !important;
}

#header-tabs::-webkit-scrollbar { display: none; }

@media (prefers-reduced-motion: reduce) {
  #header-tabs button { transition: none; }
}

