:root {
  --green: #1f6f4a;
  --green-light: #e5f3eb;
  --red: #b3261e;
  --red-light: #fbe9e7;
  --ink: #1d2320;
  --muted: #5f6b65;
  --line: #dde3df;
  --bg: #f5f7f6;
  --card: #fff;
  --gold: #f2b705;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; min-height: 40px;
}
button:hover { border-color: #b9c4be; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--green); color: #fff; border-color: var(--green); }
button.big { min-height: 52px; font-size: 1.1rem; font-weight: 600; }
button.small { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
button.danger { color: var(--red); }
button.link { border: none; background: none; color: var(--green); text-decoration: underline; padding: 0; min-height: 0; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: #fff; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid #9fd3b5; outline-offset: 1px; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--green); color: #fff;
  padding-top: max(12px, env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 1.15rem; }
.class-title { font-weight: 500; opacity: .9; text-align: right; }

.center-card { max-width: 420px; margin: 48px auto; padding: 32px 24px; background: var(--card);
  border-radius: var(--radius); text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.center-card h1 { margin-top: 0; }

/* Tabs */
.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.tab { flex: 1; border: none; border-radius: 0; background: none; padding: 12px 4px; min-height: 48px;
  border-bottom: 3px solid transparent; color: var(--muted); font-weight: 600; }
.tab.active { color: var(--green); border-bottom-color: var(--green); }

.panel { max-width: 960px; margin: 0 auto; padding: 16px; }
.box { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.box h2 { margin: 0 0 8px; font-size: 1.15rem; }
.box textarea { margin: 8px 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-between select { width: auto; }

/* Bank */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px;
  padding-bottom: 260px; }
.card { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px; min-height: 72px;
  border: 2px solid var(--line); border-radius: var(--radius); background: #fff; text-align: left; }
.card-name { font-weight: 600; overflow-wrap: anywhere; }
.card-bal { color: var(--green); font-variant-numeric: tabular-nums; }
.card.neg .card-bal { color: var(--red); }
.card.selected { border-color: var(--green); background: var(--green-light); box-shadow: inset 0 0 0 1px var(--green); }
.card.selected .card-name::before { content: "✓ "; color: var(--green); }

.action-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: #fff;
  border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.08);
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: grid; gap: 8px; max-width: 960px; margin: 0 auto; }
body:not([data-tab="bank"]) .action-bar { display: none; }
.action-bar:not(.ready) .action-row:last-child button { opacity: .5; }
.sel-count { font-weight: 600; }
.chips { display: flex; gap: 6px; overflow-x: auto; }
.chip { border-radius: 999px; min-height: 36px; padding: 4px 14px; flex: none; }
.action-row { display: flex; gap: 8px; }
.action-row #amount { flex: 0 0 120px; }
.action-row button { flex: 1; }
button.deposit { background: var(--green); color: #fff; border-color: var(--green); }
button.withdraw { background: var(--red); color: #fff; border-color: var(--red); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plus { color: var(--green); }
.minus { color: var(--red); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tag { background: #eef1ef; border-radius: 4px; padding: 1px 6px; font-size: .75rem; color: var(--muted); }
details.more { position: relative; }
details.more summary { list-style: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
details.more summary::-webkit-details-marker { display: none; }
details.more .menu { position: absolute; right: 0; top: 110%; z-index: 4; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; display: grid; gap: 4px; min-width: 170px; box-shadow: 0 4px 16px rgba(0,0,0,.12); }

/* Settings form */
#settings-form label { display: block; margin-bottom: 12px; font-weight: 500; }
#settings-form label input { margin-top: 4px; }
#settings-form input.short { max-width: 100px; display: block; }
#settings-form label.check { display: flex; align-items: center; gap: 8px; }
#settings-form label.check input { width: auto; margin: 0; }
#import-file { margin: 8px 0 12px; }

/* Toast + busy */
.toast { position: fixed; left: 50%; top: 16px; transform: translate(-50%, -150%); background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 10px; z-index: 50; max-width: 92vw; transition: transform .25s; }
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--red); }
body.busy { cursor: progress; }
body.busy button { pointer-events: none; }

/* Student page */
.student-main { max-width: 520px; margin: 0 auto; padding: 16px; }
.balance-card { background: linear-gradient(135deg, var(--green), #2c8c61); color: #fff; border-radius: 18px;
  padding: 28px 20px; text-align: center; margin-bottom: 16px; box-shadow: 0 6px 20px rgba(31,111,74,.25); }
.student-name { font-size: 1.3rem; font-weight: 700; }
.balance-label { opacity: .9; margin-top: 6px; }
.balance { font-size: 3.4rem; font-weight: 800; margin: 6px 0; font-variant-numeric: tabular-nums; }
.balance.neg { color: #ffd2cc; }
.balance-card .muted { color: rgba(255,255,255,.8); }
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: none; }
.history .amt { font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-width: 600px) {
  .panel { padding: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
  .card { padding: 10px; min-height: 64px; }
  .actions { flex-direction: column; align-items: stretch; }
}

/* Class picker + teachers */
.class-picker { width: auto; max-width: 60vw; background: rgba(255,255,255,.15); color: #fff;
  border: 1px solid rgba(255,255,255,.4); font-weight: 600; padding: 6px 10px; }
.class-picker option { color: var(--ink); }
.teacher-list { list-style: none; padding: 0; margin: 8px 0 12px; }
.teacher-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
@media (max-width: 480px) {
  body:has(#app:not([hidden])) .brand span { display: none; }
  .class-picker { max-width: 78vw; }
}
.error-text { color: var(--red); font-weight: 600; }
