/* The hidden attribute must win over component display rules (e.g. .offline-note). */
[hidden] { display: none !important; }

:root {
  --bg: #f5f7fb;
  --card: #fff;
  --border: #e9eef5;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #4338ca;
  --primary-dark: #372aa8;
  --ok-bg: #dcfce7; --ok-text: #166534;
  --low-bg: #fef3c7; --low-text: #92400e;
  --zero-bg: #fee2e2; --zero-text: #b91c1c;
  --neg-bg: #1e293b; --neg-text: #fff;
  --danger: #b91c1c;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  overflow-x: hidden;
}

button, input, select {
  font: inherit;
  color: inherit;
}

h1, h2, h3 { margin: 0 0 6px; }

.muted { color: var(--muted); }

/* Header / tabs */

.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--card);
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-weight: 700;
  font-size: 16px;
  margin-right: 10px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 18px;
  overflow-x: auto;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 4px 2px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.tab[aria-selected="true"] {
  color: var(--primary);
  font-weight: 600;
  border-bottom-color: var(--primary);
}

.who {
  margin-left: auto;
  color: var(--muted);
  white-space: nowrap;
}

main {
  padding: 16px 20px 40px;
  max-width: 1200px;
  margin: 0 auto;
}

.view[hidden] { display: none; }

.view-loading {
  color: var(--muted);
  padding: 24px 0;
}

/* Stat cards */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.stat .v { font-size: 18px; font-weight: 700; }
.stat .l { color: var(--muted); }

/* Toolbar */

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.search {
  flex: 0 0 220px;
  background: var(--card);
  border: 1px solid #d9e0ea;
  border-radius: 8px;
  padding: 6px 10px;
}

.search::placeholder { color: #94a3b8; }

.chip {
  background: var(--card);
  border: 1px solid #d9e0ea;
  border-radius: 14px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
}

.chip.on {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: var(--primary);
  font-weight: 600;
}

.btn {
  display: inline-block;
  text-align: center;
  border: 1px solid #d9e0ea;
  border-radius: 8px;
  padding: 7px 12px;
  background: var(--card);
  cursor: pointer;
}

.btn:hover { background: #fafbfd; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

.btn-primary:hover { background: var(--primary-dark); }

/* .primary is used standalone (not paired with .btn), so it carries its own box model. */
.primary {
  display: inline-block;
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
}

.primary:hover { background: var(--primary-dark); }

button:disabled { opacity: .55; cursor: default; }

/* Split layout: table + side panel */

.split {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

/* Rounded corners live on this wrapper, not on table.t: an overflow:hidden ancestor
   would make .t th's position:sticky stick to the wrapper's scrollport instead of the
   page, which never moves — so the header wouldn't actually stick on scroll. */
.table-wrap {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
}

table.t {
  border-collapse: collapse;
  background: var(--card);
  width: 100%;
}

.t th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 10px;
  background: #fafbfd;
  border-bottom: 1px solid #eef1f6;
  position: sticky;
  top: 49px;
}

.t td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f4f8;
}

.t tr.sel td { background: #eef2ff; }
.t tr:hover td { background: #fafbfd; }
.t tr.sel:hover td { background: #eef2ff; }

.b {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  border-radius: 12px;
  padding: 2px 8px;
  font-weight: 700;
}

.b-ok { background: var(--ok-bg); color: var(--ok-text); }
.b-low { background: var(--low-bg); color: var(--low-text); }
.b-zero { background: var(--zero-bg); color: var(--zero-text); }
.b-negative { background: var(--neg-bg); color: var(--neg-text); }

.q {
  border: 1px solid #d9e0ea;
  border-radius: 6px;
  padding: 2px 7px;
  margin-right: 4px;
  background: var(--card);
  white-space: nowrap;
  cursor: pointer;
}

.q:hover { background: #fafbfd; }

/* Side panel */

.panel {
  width: 340px;
  flex: 0 0 340px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
}

.panel .big { font-size: 30px; font-weight: 800; margin: 6px 0 2px; }

.panel .row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.panel .btn { display: block; margin-top: 6px; width: 100%; }

.hist {
  margin-top: 10px;
  border-top: 1px solid #eef1f6;
  padding-top: 8px;
  line-height: 1.9;
}

/* Cards (mobile students / money) */

.cards { display: none; flex-direction: column; gap: 8px; }

.pc {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.pc .top { display: flex; justify-content: space-between; align-items: center; }
.pc .n { font-weight: 600; }
.pc .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.pc .acts .q { text-align: center; margin-right: 0; }

/* Money tab */

.money-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.line {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
}

.line.minus span:last-child { color: var(--danger); }

.line.total {
  border-top: 1px solid #e2e8f0;
  margin-top: 4px;
  padding-top: 8px;
  font-weight: 700;
  font-size: 15px;
}

.card .warn {
  color: var(--low-text);
  background: var(--low-bg);
  border-radius: 8px;
  padding: 6px 8px;
  margin-top: 8px;
  font-size: 13px;
}

/* Full-screen overlay (mobile student panel) */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 40;
  overflow-y: auto;
  padding: 12px 16px 40px;
  display: none;
}

.overlay.open { display: block; }

body.scroll-locked { overflow: hidden; }

.offline-note { display: inline-block; margin: -4px 0 10px; }

.overlay-back {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  padding: 6px 0 12px;
  cursor: pointer;
}

/* Dialogs */

dialog.dlg {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .15);
  padding: 16px;
  width: min(340px, 90vw);
  color: var(--text);
  background: var(--card);
}

dialog.dlg::backdrop {
  background: rgba(15, 23, 42, .35);
}

dialog.dlg h3 { font-size: 16px; }

.dlg-text { color: var(--text); margin: 8px 0 12px; }

.field-row { margin-bottom: 10px; display: flex; flex-direction: column; }

.field-row label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.field,
.field-row input,
.field-row select {
  border: 1px solid #d9e0ea;
  border-radius: 8px;
  padding: 7px 9px;
  background: var(--card);
  width: 100%;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.field-hint:empty { display: none; margin-top: 0; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }

.pill {
  display: inline-block;
  border: 1px solid #d9e0ea;
  border-radius: 8px;
  padding: 5px 12px;
  background: var(--card);
  cursor: pointer;
}

.pill.on {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: var(--primary);
  font-weight: 600;
}

.pills-other { margin-top: 8px; }

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* Toasts */

#toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  max-width: 360px;
}

.toast {
  background: var(--text);
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .2);
}

.toast-error { background: var(--danger); }
.toast-success { background: var(--ok-text); }

.toast-text { flex: 1; }

.toast-action,
.toast-close {
  background: rgba(255, 255, 255, .15);
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
}

.toast-close {
  background: none;
  padding: 0 4px;
  font-size: 16px;
  line-height: 1;
}

/* Expired page */

.expired-page {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.expired-page[hidden] { display: none; }

.expired-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 360px;
  text-align: center;
}

.expired-card .btn { margin-top: 14px; }

/* Students tab extras */

.empty {
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.panel-loading {
  color: var(--muted);
  padding: 16px 0;
}

.panel .warn {
  color: var(--danger);
  margin: 6px 0;
}

.hist-line { margin-bottom: 2px; }
.hist-line.voided { text-decoration: line-through; opacity: .6; }

.big.level-ok { color: var(--ok-text); }
.big.level-low { color: var(--low-text); }
.big.level-zero { color: var(--zero-text); }
.big.level-negative { color: var(--danger); }

.overlay-body .panel-content .big { font-size: 30px; font-weight: 800; margin: 6px 0 2px; }
.overlay-body .panel-content .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.overlay-body .panel-content .btn { display: block; margin-top: 6px; width: 100%; }
.overlay-body .panel-content .hist { margin-top: 10px; border-top: 1px solid #eef1f6; padding-top: 8px; line-height: 1.9; }

/* Focus visibility */

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
.tab:focus-visible,
.chip:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Responsive: < 900px → cards, full-screen panel */

@media (max-width: 899px) {
  html, body { overflow-x: hidden; }

  main {
    padding: 12px 16px 32px;
  }

  /* Title on its own row, tabs below it, so the tabs are never squeezed behind the title. */
  .nav {
    padding: 8px 16px 0;
    gap: 2px 16px;
    flex-wrap: wrap;
  }

  .logo { flex: 1 1 auto; margin-right: 0; }

  .tabs {
    order: 3;
    flex: 1 0 100%;
    gap: 20px;
  }

  .tab { padding: 8px 2px; font-size: 15px; }

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

  table.t { display: none; }
  .cards { display: flex; }

  .split { display: block; }
  .panel { display: none; }

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

  .search { flex: 1 1 auto; }

  .primary { margin-left: 0; }
}

/* Wide screens: slightly larger text. From 1100px so the table + side panel still fit;
   the page and panel get a little wider to match, and the sticky table header follows the taller nav. */
@media (min-width: 1100px) {
  html, body { font-size: 16px; }
  main { max-width: 1320px; }
  .panel { width: 380px; flex-basis: 380px; }
  .t th { top: 52px; }
  .logo { font-size: 18px; }
  .tab { font-size: 16px; }
  .stat .v { font-size: 21px; }
  .panel .big { font-size: 34px; }
  .line.total { font-size: 17px; }
  .card .warn { font-size: 14px; }
  dialog.dlg h3 { font-size: 18px; }
  .field-row label { font-size: 14px; }
  .field-hint { font-size: 13px; }
}
