:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #f1efe8; --text: #1b1b1a; --muted: #6b6a66;
  --border: #e1e0d9; --accent: #2a78d6; --accent-bg: #e6f1fb; --parent: #2a78d6; --student: #eda100;
  --danger: #a32d2d; --danger-bg: #fcebeb; --success: #1d9e75; --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --surface: #1f1f1e; --surface-2: #2a2a28; --text: #f1f0eb; --muted: #a09f99;
    --border: #353532; --accent-bg: #0c2f52; --danger-bg: #3a1515; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { font-weight: 500; margin: 0 0 .5rem; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; } .center { text-align: center; }
.error { color: var(--danger); background: var(--danger-bg); padding: .5rem .75rem; border-radius: var(--radius); font-size: 14px; }
.brand { font-weight: 500; font-size: 18px; letter-spacing: .02em; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.container { max-width: 1040px; margin: 0 auto; padding: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.5rem; margin-top: 1rem; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.stack label, .field-row label { display: flex; flex-direction: column; gap: .25rem; font-size: 14px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.field-row.four { grid-template-columns: repeat(4, 1fr); } .field-row.five { grid-template-columns: repeat(5, 1fr); }
label.inline { flex-direction: row; align-items: center; gap: .4rem; display: inline-flex; margin-right: 1rem; color: var(--text); }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .45rem .6rem; min-height: 36px; width: 100%; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
input[readonly] { background: var(--surface-2); letter-spacing: .1em; font-family: monospace; }
input[type="radio"], input[type="checkbox"] { width: auto; min-height: 0; padding: 0; margin: 0; accent-color: var(--accent); }
[hidden] { display: none !important; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .9rem .9rem; margin: 0; }
legend { font-size: 13px; color: var(--muted); padding: 0 .3rem; }

.btn { font: inherit; font-size: 14px; padding: .45rem .9rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; gap: .3rem; }
.btn:hover { background: var(--surface-2); } .btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; } .btn.danger:hover { background: var(--danger-bg); }
.btn.tiny { padding: .2rem .5rem; font-size: 12px; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1.25rem 0 .5rem; }
.spacer { flex: 1; }

.grid-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 1rem; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.metric .lbl { font-size: 13px; color: var(--muted); } .metric .val { font-size: 24px; font-weight: 500; }
.metric.parent .val { color: var(--parent); } .metric.student .val { color: var(--student); }
.charts-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.chart-card { margin-bottom: 0; } .chart-wrap { position: relative; height: 240px; }

.semester { margin-bottom: 1.25rem; }
.semester-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.semester-head .totals { display: flex; gap: 1rem; font-size: 14px; flex-wrap: wrap; }
.totals .p { color: var(--parent); } .totals .s { color: var(--student); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-weight: 500; color: var(--muted); font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.p { color: var(--parent); } td.s { color: var(--student); }
tr.section td { color: var(--muted); font-size: 13px; padding-top: .9rem; border-bottom: none; }
.grade-input { width: 80px; min-height: 32px; padding: .25rem .5rem; text-align: center; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); }
.badge.proj { background: #faeeda; color: #633806; }
@media (prefers-color-scheme: dark) { .badge.proj { background: #412402; color: #fac775; } }
.sem-chart { position: relative; height: 180px; margin-top: .75rem; }
.name-btn { background: none; border: none; color: var(--text); font: inherit; cursor: pointer; padding: 0; text-align: left; }
.name-btn.parent:hover { color: var(--accent); text-decoration: underline; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
  padding: 1.25rem 1.5rem; width: min(560px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-actions { display: flex; gap: .5rem; margin-top: .5rem; align-items: center; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: .5rem 1rem; border-radius: var(--radius); font-size: 14px; z-index: 20; }
footer { padding: 1.5rem; }

.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; width: min(380px, 100%); }
.auth-card form { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }
.auth-card label { display: flex; flex-direction: column; gap: .25rem; font-size: 14px; color: var(--muted); }

@media (max-width: 600px) {
  .field-row, .field-row.four, .field-row.five { grid-template-columns: 1fr 1fr; }
  th.hide-sm, td.hide-sm { display: none; }
  .container { padding: .6rem; }
}

/* v3: admin page + shared bits */
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
