:root {
  --navy: #14254a;
  --navy-2: #1f3566;
  --gold: #c9962b;
  --gold-soft: #fbf3e2;
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #1b2030;
  --muted: #667085;
  --line: #e3e6ee;
  --green: #1f7a4d;   --green-bg: #e6f4ec;
  --amber: #a45d00;   --amber-bg: #fff1dc;
  --red: #b42318;     --red-bg: #fde8e7;
  --blue: #1d4f9c;    --blue-bg: #e7effb;
  --grey: #5b6474;    --grey-bg: #eef0f4;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; }
[hidden] { display: none !important; }
h2 { font-size: 16px; margin: 0 0 4px; }
.muted { color: var(--muted); margin: 0; font-size: 13px; }

/* ---------- brand / topbar ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; letter-spacing: .08em; }
.brand small { color: var(--muted); font-size: 12px; }
.brand-logo { width: 34px; height: auto; display: block; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--navy); color: var(--gold);
  display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 20px; padding: 10px 20px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button { border: 0; background: none; padding: 9px 14px; border-radius: 8px; cursor: pointer;
  font: inherit; color: var(--muted); font-weight: 600; }
.tabs button:hover { background: var(--bg); }
.tabs button.active { background: var(--navy); color: #fff; }
.top-actions { display: flex; gap: 8px; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* ---------- buttons ---------- */
a.btn { text-decoration: none; display: inline-block; }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px;
  border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c5cad6; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger.ghost { background: none; color: var(--red); border-color: transparent; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.link { border: 0; background: none; color: var(--blue); cursor: pointer; font: inherit; padding: 0 4px; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 100%); }
.login-card { background: var(--card); padding: 28px; border-radius: 14px; width: 100%; max-width: 360px;
  display: grid; gap: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.warn .value { color: var(--amber); }
.kpi.bad .value { color: var(--red); }
.kpi.click { cursor: pointer; }
.kpi.click:hover { border-color: var(--gold); }

/* ---------- panels / tables ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  background: #fafbfc; position: sticky; top: 0; }
tbody tr:hover { background: #fafbfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { color: var(--muted); font-size: 12px; }
td.actions { white-space: nowrap; text-align: right; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.active { background: var(--green-bg); color: var(--green); }
.chip.expiring_soon { background: var(--amber-bg); color: var(--amber); }
.chip.expired { background: var(--red-bg); color: var(--red); }
.chip.upcoming { background: var(--blue-bg); color: var(--blue); }
.chip.inactive { background: var(--grey-bg); color: var(--grey); }
.chip.renewed { background: var(--gold-soft); color: #8a6417; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px;
  font: inherit; font-size: 13px; cursor: pointer; font-weight: 600; color: var(--muted); }
.chips button.active { background: var(--navy); color: #fff; border-color: var(--navy); }
input[type=search] { min-width: 280px; }
.filter-note { background: var(--gold-soft); border: 1px solid #ecd8a8; padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; }

/* ---------- forms ---------- */
label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfd4de; border-radius: 8px;
  background: #fff; color: var(--text); width: 100%; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.span2 { grid-column: span 2; }
.row { display: flex; gap: 8px; }
.form-error { background: var(--red-bg); color: var(--red); padding: 9px 12px; border-radius: 8px; margin: 12px 0 0; font-weight: 600; }
.quick-period { font-size: 13px; color: var(--muted); margin-top: -4px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.active-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 10px; margin: 0; }

.school-picker { position: relative; }
.dropdown { position: absolute; left: 0; right: 0; top: 100%; z-index: 3; margin: 4px 0 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
  max-height: 260px; overflow-y: auto; font-weight: 400; }
.dropdown li { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.dropdown li:hover, .dropdown li.hl { background: var(--bg); }
.dropdown li .sub { color: var(--muted); font-size: 12px; }
.dropdown li .warn { color: var(--amber); font-size: 12px; font-weight: 600; }
.chosen { background: var(--bg); border-radius: 8px; padding: 8px 10px; font-weight: 400; display: flex; justify-content: space-between; gap: 8px; }
.chosen .warn { color: var(--amber); font-weight: 600; font-size: 12px; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  box-shadow: 0 30px 80px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog form { padding: 22px; }
dialog h2 { margin-bottom: 16px; font-size: 18px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.spacer { flex: 1; }
#confirm-dialog { width: min(420px, calc(100vw - 32px)); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff;
  padding: 10px 18px; border-radius: 8px; font-weight: 600; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.toast.err { background: var(--red); }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; overflow-x: auto; }
  .top-actions { margin-left: auto; }
  .top-actions .btn { padding: 7px 10px; }
  main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  input[type=search] { min-width: 0; width: 100%; }
  .toolbar-right { width: 100%; }
}

/* ---------- donor & school pages ---------- */
.name-link { color: inherit; text-decoration: none; }
.name-link:hover { color: var(--navy-2); text-decoration: underline; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--blue); text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; }
.detail-head h1 { margin: 0 0 4px; font-size: 24px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.prog-chips { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.period-line { margin: 10px 0 0; font-size: 13.5px; }
.kpi .value.small { font-size: 20px; }
.section-title { margin: 22px 0 10px; font-size: 16px; }
.window-toggle { margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.school-card { display: grid; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s; }
.school-card:hover { border-color: var(--gold); box-shadow: 0 6px 18px rgba(20,37,74,.08); }
.school-card .sub { color: var(--muted); font-size: 12.5px; }
.sc-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.sc-period { font-size: 13px; font-weight: 600; }
.sc-stats { display: flex; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.sc-stats b { color: var(--text); }
.sc-open { color: var(--blue); font-weight: 600; font-size: 13px; }

.visit { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.visit-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.visit-head .sub { color: var(--muted); font-size: 12.5px; }
.visit-reports { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
table.obs { margin-top: 10px; font-size: 13px; }
table.obs th, table.obs td { padding: 6px 10px; }
.band { font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.band.strong { background: var(--green-bg); color: var(--green); }
.band.developing { background: var(--amber-bg); color: var(--amber); }
.band.needs_support { background: var(--red-bg); color: var(--red); }
.thumbs { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.thumb { width: 84px; height: 84px; border-radius: 8px; border: 1px solid var(--line); padding: 0; overflow: hidden;
  background: var(--bg); cursor: pointer; display: grid; place-items: center; font: inherit; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.video { background: var(--navy); color: #fff; font-size: 22px; line-height: 1; gap: 2px; align-content: center; }
.thumb.video small { font-size: 11px; }
.thumb.more { font-weight: 700; font-size: 15px; color: var(--navy); }
.thumb.broken img { display: none; }
.thumb.broken::after { content: "Photo"; font-size: 12px; }

dialog.viewer { width: min(1000px, calc(100vw - 24px)); background: #0d1424; color: #fff; padding: 16px; }
.viewer-close { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: #fff; font-size: 20px; cursor: pointer; }
#viewer-body { display: grid; place-items: center; min-height: 300px; }
#viewer-body img, #viewer-body video { max-width: 100%; max-height: 72vh; border-radius: 6px; }
.viewer-nav { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.viewer-nav span { color: #c9d1e4; font-size: 13px; }
