/*
 * DM Sans + DM Mono — self-hosted to avoid CDN blocks in Mongolia.
 * Place woff2 files in a /fonts/ directory alongside this CSS file.
 * Download from:
 *   DM Sans:  https://fonts.google.com/specimen/DM+Sans  (download family)
 *   DM Mono:  https://fonts.google.com/specimen/DM+Mono  (download family)
 * Required files:
 *   DMSans-Regular.woff2, DMSans-Medium.woff2, DMSans-SemiBold.woff2,
 *   DMSans-Light.woff2, DMMono-Regular.woff2, DMMono-Medium.woff2
 *
 * Until files are deployed the system-ui / monospace fallbacks below render
 * cleanly on all platforms.
 */
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 300; font-display: swap;
  src: url('/fonts/DMSans-Light.woff2') format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/fonts/DMSans-Regular.woff2') format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('/fonts/DMSans-Medium.woff2') format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('/fonts/DMSans-SemiBold.woff2') format('woff2'); }
@font-face { font-family: 'DM Mono'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/fonts/DMMono-Regular.woff2') format('woff2'); }
@font-face { font-family: 'DM Mono'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('/fonts/DMMono-Medium.woff2') format('woff2'); }

:root {
  --bg:       #f4f6f9;
  --surface:  #ffffff;
  --border:   #e2e6ed;
  --hover:    #f0f3f8;
  --accent:   #2563eb;
  --accent2:  #059669;
  --danger:   #dc2626;
  --warn:     #d97706;
  --text:     #111827;
  --muted:    #6b7280;
  --sidebar:  210px;
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ── Login ── */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e8f0fe 0%, #f4f6f9 60%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 40px; width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.login-logo {
  width: 44px; height: 44px; background: var(--accent);
  border-radius: 10px; display: flex; align-items: center;
  justify-content: center; margin-bottom: 20px; font-size: 22px;
}
.login-title { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--muted); margin-bottom: 28px; }
.field-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.inp {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
  outline: none; margin-bottom: 14px; transition: border-color .15s;
}
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.btn-primary {
  width: 100%; padding: 11px; font-size: 14px; font-weight: 500;
  background: var(--accent); color: #fff; border: none;
  border-radius: 8px; cursor: pointer; transition: opacity .15s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.err-msg { font-size: 12px; color: var(--danger); margin-bottom: 10px; display: none; }

/* ── App shell ── */
.app-shell { display: none; min-height: 100vh; }
.app-shell.active { display: flex; }

.sidebar {
  width: var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 10;
  box-shadow: 1px 0 8px rgba(0,0,0,.04);
}
.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo-icon {
  width: 32px; height: 32px; background: var(--accent);
  border-radius: 8px; display: flex; align-items: center;
  justify-content: center; font-size: 16px; margin-bottom: 8px;
}
.sidebar-logo-text { font-size: 13px; font-weight: 600; line-height: 1.2; }
.sidebar-logo-sub  { font-size: 11px; color: var(--muted); }

.nav { flex: 1; padding: 12px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  cursor: pointer; color: var(--muted);
  font-size: 13px; font-weight: 500;
  transition: all .15s; margin-bottom: 2px;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover  { background: var(--hover); color: var(--text); }
.nav-item.active { background: rgba(37,99,235,.08); color: var(--accent); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }
.admin-info {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; margin-bottom: 6px;
}
.admin-avatar {
  width: 28px; height: 28px; background: var(--accent);
  border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 600;
  flex-shrink: 0; color: #fff;
}
.admin-name { font-size: 12px; font-weight: 500; }
.logout-btn {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  background: none; border: none; color: var(--muted);
  font-size: 12px; cursor: pointer; text-align: left;
  transition: all .15s; display: flex; align-items: center; gap: 8px;
}
.logout-btn:hover { color: var(--danger); background: rgba(220,38,38,.06); }

.main-area { margin-left: var(--sidebar); flex: 1; min-height: 100vh; }
.topbar {
  height: 52px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px;
  justify-content: space-between; position: sticky; top: 0; z-index: 5;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.page-title { font-size: 15px; font-weight: 600; }
.topbar-right { font-size: 12px; color: var(--muted); }

.content { padding: 24px; }

/* ── Pages ── */
.page { display: none; }
.page.active { display: block; }

/* ── Stat cards ── */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 8px; }
.stat-val   { font-size: 26px; font-weight: 600; font-family: 'DM Mono', monospace; line-height: 1; }
.stat-val.green  { color: var(--accent2); }
.stat-val.blue   { color: var(--accent); }
.stat-val.yellow { color: var(--warn); }
.stat-val.red    { color: var(--danger); }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ── Cards ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: #fafbfc;
}
.card-title { font-size: 13px; font-weight: 600; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 16px; text-align: left;
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; background: #fafbfc;
}
td {
  padding: 10px 16px; font-size: 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--hover); }
.mono { font-family: 'DM Mono', monospace; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 500;
}
.badge-green  { background: rgba(5,150,105,.1);   color: var(--accent2); }
.badge-blue   { background: rgba(37,99,235,.1);    color: var(--accent); }
.badge-yellow { background: rgba(217,119,6,.1);    color: var(--warn); }
.badge-red    { background: rgba(220,38,38,.1);    color: var(--danger); }
.badge-gray   { background: rgba(107,114,128,.12); color: var(--muted); }

/* ── Filters ── */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.filter-inp {
  padding: 7px 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); font-size: 13px; outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
}
.filter-inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.08); }

/* ── Search wrap: input + clear btn + scan btn in one row ── */
.search-row {
  display: flex; align-items: center; gap: 8px;
  flex: 2; min-width: 280px; max-width: 50%;
}
.search-wrap {
  position: relative; display: flex; align-items: center;
  flex: 1; min-width: 0;
}
.search-wrap .filter-inp {
  width: 100%; padding-right: 28px;
}
.clear-btn {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 14px; line-height: 1;
  padding: 2px 3px; border-radius: 3px;
  display: none; flex-shrink: 0;
}
.clear-btn:hover { color: var(--text); background: var(--hover); }
.search-wrap.has-value .clear-btn { display: block; }
.scan-btn {
  flex-shrink: 0;
  height: 33px; width: 38px;
  display: none; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
  border: none; border-radius: 7px;
  font-size: 16px; cursor: pointer;
  transition: background .15s;
}
.scan-btn:hover { background: #1450a0; }
.filter-btn {
  padding: 7px 14px; border-radius: 7px;
  border: 1px solid var(--accent); color: var(--accent);
  background: rgba(37,99,235,.06);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s;
}
.filter-btn:hover { background: rgba(37,99,235,.12); }

/* ── Pagination ── */
.pagination {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted); background: #fafbfc;
}
.pg-btn {
  padding: 5px 12px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; font-size: 12px; transition: all .15s;
}
.pg-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: rgba(37,99,235,.04); }
.pg-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Class summary bars ── */
.class-row {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: grid; grid-template-columns: 140px 1fr auto;
  align-items: center; gap: 16px;
}
.class-row:last-child { border-bottom: none; }
.class-name { font-size: 13px; font-weight: 500; }
.class-bar-wrap { position: relative; height: 6px; background: var(--border); border-radius: 3px; }
.class-bar { height: 100%; border-radius: 3px; background: var(--accent); transition: width .4s ease; }
.class-bar.warn { background: var(--warn); }
.class-meta { font-size: 12px; color: var(--muted); text-align: right; min-width: 120px; }

/* ── Loading / empty ── */
.loading-row td { text-align: center; color: var(--muted); padding: 40px !important; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }

/* ── Hamburger button (hidden on desktop) ── */
.hamburger {
  display: none;
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px; width: 36px; height: 36px;
  background: none; border: none; cursor: pointer; padding: 4px;
  border-radius: 8px; flex-shrink: 0;
  transition: background .15s;
}
.hamburger:hover { background: var(--hover); }
.hamburger span {
  display: block; width: 20px; height: 2px;
  background: var(--text); border-radius: 2px;
  transition: all .2s;
}

/* ── Sidebar overlay backdrop ── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 9;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* col-hide-desktop: only visible on mobile (used for class name embedded in student cell) */
.col-hide-desktop { display: none; }
/* txn-mobile-student: student name shown inside date cell on mobile only */
.txn-mobile-student { display: none; }

/* ── Transaction breakdown grid ── */
.txn-bd-row-grid {
  display: grid;
  grid-template-columns: 2fr 0.7fr 1fr 1fr;
  gap: 6px;
  padding: 6px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}
.txn-bd-row-grid:last-child { border-bottom: none; }
.txn-bd-header {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 4px 0 5px;
  font-weight: 600;
}
.txn-bd-qty   { text-align: center; color: var(--muted); }
.txn-bd-price { text-align: right; color: var(--danger); }
.txn-bd-total { text-align: right; font-weight: 600; }
.txn-bd-time  { display: none; }   /* ЦАГ column removed globally */

/* ── Responsive ── */
@media (max-width: 768px) {

  /* Show hamburger, hide sidebar by default */
  .hamburger { display: flex; }
  .col-hide-desktop { display: inline; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 20;
    width: 230px;
  }
  .sidebar.open { transform: translateX(0); }

  /* Main area takes full width */
  .main-area { margin-left: 0; }

  /* Topbar */
  .topbar { padding: 0 12px; gap: 10px; }
  .page-title { font-size: 14px; }

  /* Content padding */
  .content { padding: 14px 10px; }

  /* Stats grid — 2 columns on mobile */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stat-val { font-size: 20px !important; }

  /* Today row — stack vertically */
  #page-dashboard > div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Hide col-hide-mobile globally on mobile */
  .col-hide-mobile { display: none !important; }

  /* ── Dashboard recent transactions:
     hide ID (col 3) and Үлдэгдэл (col 6) ── */
  .tbl-dashboard-txn thead th:nth-child(3),
  .tbl-dashboard-txn thead th:nth-child(6) { display: none; }


  /* ── Card-style layout for Topups and Transactions tables ── */
  .tbl-topups,
  .tbl-transactions { border-collapse: separate; border-spacing: 0 10px; width: 100%; }

  /* Make tbody a block so tr widths are unconstrained */
  .tbl-topups tbody,
  .tbl-transactions tbody { display: block; width: 100%; }

  /* Hide thead */
  .tbl-topups thead,
  .tbl-transactions thead { display: none; }

  /* Each <tr> becomes a card — matches Figma: white bg, dark border, 15px radius */
  .tbl-topups tbody tr,
  .tbl-transactions tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 15px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
  }

  /* All cells: label on top, bold value below */
  .tbl-topups tbody td,
  .tbl-transactions tbody td {
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    white-space: normal;
    word-break: break-word;
    box-sizing: border-box;
  }

  /* Label pseudo-element */
  .tbl-topups tbody td::before,
  .tbl-transactions tbody td::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 4px;
  }

  /* ── TOPUPS card layout ──────────────────── */
  /* Row 1: Date spans full width */
  .tbl-topups tbody td[data-label="Огноо"] {
    grid-column: 1 / -1;
    border-bottom: 1px solid var(--border);
  }
  /* Row 2: Student (left) + Анги (right) */
  .tbl-topups tbody td[data-label="Сурагч"] { grid-column: 1; }
  .tbl-topups tbody td[data-label="Анги"]   { grid-column: 2; display: flex; }
  /* Row 3: Status (left) + Paid date (right) */
  .tbl-topups tbody td[data-label="Төлөв"]        { grid-column: 1; }
  .tbl-topups tbody td[data-label="Төлсөн огноо"] { grid-column: 2; }
  /* Row 4: Amount spans full width */
  .tbl-topups tbody td[data-label="Дүн"] {
    grid-column: 1 / -1;
    color: var(--accent2);
    font-size: 16px;
    border-top: 1px solid var(--border);
  }
  /* Row 5: Merged reference numbers — full width, stacked vertically, compact */
  .tbl-topups tbody td[data-label="Дугаарууд"] {
    grid-column: 1 / -1;
    font-size: 12px;
    border-bottom: none;
    flex-direction: column;
    gap: 5px;
  }
  .tbl-topups tbody td[data-label="Дугаарууд"]::before { display: none; }

  /* ── TRANSACTIONS card layout — matches Figma design ───────────── */
  /* Hide Сурагч and Анги cells — no student info per design spec */
  .tbl-transactions tbody td[data-label="Сурагч"],
  .tbl-transactions tbody td[data-label="Анги"].col-hide-mobile { display: none !important; }

  /* Row 2: Amount (left) + Balance (right) — inline label: value style */
  .tbl-transactions tbody td[data-label="Дүн"] {
    grid-column: 1;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 400;
    color: var(--text);
    padding: 12px 16px;
  }
  .tbl-transactions tbody td[data-label="Дүн"]::before {
    display: inline;
    margin-bottom: 0;
    font-size: 12px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--muted);
    white-space: nowrap;
  }
  .tbl-transactions tbody td[data-label="Дүн"] .txn-mobile-val {
    font-weight: 700;
    font-size: 14px;
    color: var(--danger);
  }

  /* ҮЛДЭГДЭЛ — right column, right-aligned */
  .tbl-transactions tbody td[data-label="Үлдэгдэл"] {
    grid-column: 2;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    text-align: right;
    gap: 4px;
    font-size: 13px;
    font-weight: 400;
    color: var(--text);
    padding: 12px 16px;
  }
  .tbl-transactions tbody td[data-label="Үлдэгдэл"]::before {
    display: inline;
    margin-bottom: 0;
    font-size: 12px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--muted);
    white-space: nowrap;
  }
  .tbl-transactions tbody td[data-label="Үлдэгдэл"] .txn-mobile-val {
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
  }

  /* Row 3: ДЭЛГЭРЭНГҮЙ — full width, stacked vertically */
  .tbl-transactions tbody td[data-label="Дэлгэрэнгүй"] {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    border-bottom: none;
    font-size: 13px;
    font-weight: 400;
    flex-direction: column !important;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 16px 14px;
    border-top: none;
    overflow: visible !important;
  }
  .tbl-transactions tbody td[data-label="Дэлгэрэнгүй"]::before {
    display: none !important;
  }
  /* Breakdown grid — mobile size adjustments (4-col layout inherited from global) */
  .txn-bd-row-grid {
    gap: 4px !important;
    padding: 7px 2px !important;
    font-size: 11px !important;
  }
  .txn-bd-row-grid > span {
    padding: 0 2px;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Breakdown div — full width */
  .tbl-transactions tbody td[data-label="Дэлгэрэнгүй"] > div[id] {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }
  /* Each breakdown row — full width */
  .tbl-transactions tbody td[data-label="Дэлгэрэнгүй"] .txn-bd-row-grid {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  /* ── Transactions card header: date left, student right — same row ── */
  .tbl-transactions tbody td[data-label="Огноо"] {
    grid-column: 1 / -1;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 700;
    padding: 12px 16px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .tbl-transactions tbody td[data-label="Огноо"]::before { display: none; }
  /* Student name sits right-aligned in the date row */
  .txn-mobile-student {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    margin-top: 0;
    text-align: right;
  }

  /* Date filter label wrappers — stack cleanly on mobile */
  .filters > div { width: 100%; }
  .filter-inp { width: 100%; font-size: 14px; }
  .filter-btn { width: 100%; text-align: center; }

  /* Class summary bars */
  .class-row { grid-template-columns: 90px 1fr auto; gap: 8px; }
  .class-meta { min-width: 70px; font-size: 11px; }

  /* Cards */
  .card { border-radius: 10px; margin-bottom: 14px; }
  .card-header { flex-wrap: wrap; gap: 8px; }

  /* Detail overlay — full screen on mobile */
  #detail-overlay {
    width: 100% !important;
    top: 0 !important;
    border-radius: 0 !important;
  }

  /* Modal boxes */
  .modal-box { width: 96vw !important; max-width: none !important; padding: 24px 16px !important; }
  .modal-grid { grid-template-columns: 1fr !important; }

  /* Product page */
  .product-row {
    grid-template-columns: 1fr 70px 32px 60px !important;
    padding: 8px 12px 8px 24px !important;
  }
  .prod-header-row {
    grid-template-columns: 1fr 70px 32px 60px !important;
    padding: 7px 12px 7px 24px !important;
  }
  .product-row .product-cat-badge { display: none; }
  .prod-header-row span:nth-child(3) { display: none; }

  /* Pagination */
  .pagination { padding: 10px 12px; }

  /* Table wrap for non-card tables */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  td, th { padding: 9px 12px; font-size: 12px; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr 1fr !important; }
  .stat-val { font-size: 18px !important; }
  .content { padding: 10px 8px; }
}


/* ── Responsive ── */
@media (max-width: 768px) {

  /* Show hamburger, hide sidebar by default */
  .hamburger { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 20;
    width: 230px;
  }
  .sidebar.open { transform: translateX(0); }

  /* Main area takes full width */
  .main-area { margin-left: 0; }

  /* Topbar */
  .topbar { padding: 0 16px; gap: 12px; }
  .page-title { font-size: 14px; }

  /* Content padding */
  .content { padding: 16px 12px; }

  /* Stats grid — 2 columns on mobile */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stat-val { font-size: 20px !important; }

  /* Today row — stack vertically */
  #page-dashboard > div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Tables — horizontal scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  td, th { white-space: nowrap; padding: 9px 12px; font-size: 12px; }

  /* Filters — stack vertically on mobile */
  .filters { flex-direction: column; gap: 8px; padding: 12px; }
  .filter-inp { width: 100%; font-size: 14px; box-sizing: border-box; }
  .filter-btn { width: 100%; text-align: center; }
  /* Search row stays horizontal — never stacks */
  .search-row { flex-direction: row !important; width: 100%; max-width: 100%; min-width: 0; }
  .search-wrap { flex: 1; min-width: 0; }
  .search-wrap input.filter-inp { width: 100%; }
  /* Scan button — visible and sized on mobile only */
  .scan-btn { display: flex; height: 37px; width: 42px; font-size: 17px; }

  /* Class summary bars — adjust grid */
  .class-row { grid-template-columns: 100px 1fr auto; gap: 10px; }
  .class-meta { min-width: 80px; font-size: 11px; }

  /* Cards */
  .card { border-radius: 10px; margin-bottom: 14px; }
  .card-header { flex-wrap: wrap; gap: 8px; }

  /* Detail overlay — full screen on mobile */
  #detail-overlay {
    width: 100% !important;
    top: 0 !important;
    border-radius: 0 !important;
  }

  /* Modal boxes */
  .modal-box { width: 96vw !important; max-width: none !important; padding: 24px 20px !important; }
  .modal-grid { grid-template-columns: 1fr !important; }

  /* Product page grid */
  .product-row {
    grid-template-columns: 1fr 70px 32px 60px !important;
    padding: 8px 12px 8px 24px !important;
  }
  .prod-header-row {
    grid-template-columns: 1fr 70px 32px 60px !important;
    padding: 7px 12px 7px 24px !important;
  }
  /* Hide category badge column on mobile — redundant inside category section */
  .product-row .product-cat-badge { display: none; }
  .prod-header-row span:nth-child(3) { display: none; }

  /* Pagination */
  .pagination { padding: 10px 12px; }

  /* Student detail overlay header image */
  #overlay-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  #overlay-photo { width: 72px !important; height: 72px !important; border-radius: 12px !important; }

  /* CSV import button row */
  #csv-import-row { flex-direction: column !important; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr 1fr !important; }
  .stat-val { font-size: 18px !important; }
  td, th { font-size: 11px; padding: 8px 10px; }
  .content { padding: 12px 8px; }
}
