/*
 * KTBG admin — shared design tokens + components.
 *
 * Linked by every admin surface (admin.html, enforcement.html, schools.html,
 * editor.html) so they look and behave like ONE product instead of three.
 * Page-specific rules stay in the page; anything shared belongs here.
 *
 * Contrast targets: body text >= 4.5:1 on its surface, UI boundaries and focus
 * rings >= 3:1. --line is a meaningful border; --line-soft is decorative only.
 */

:root {
  color-scheme: dark;

  --bg: #0a1424;
  --surface: #0f2036;
  --surface-2: #132a45;
  --surface-3: #16304e;
  --line: #2b4f80;
  --line-soft: #1a3355;

  --ink: #eef4ff;
  --ink-2: #b7cbe6;
  --ink-3: #8aa4c6;

  --accent: #3987e5;
  --accent-2: #2f6df0;
  --good: #45c47c;
  --warn: #e9b352;
  --bad: #ef7d7d;
  --focus: #7fb4ff;

  /* Validated categorical series (dark, surface #0f2036) — see dataviz. */
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;

  --radius: 12px;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.42);
  --bar-h: 52px;
  --font: "Trebuchet MS", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
h1, h2, h3, h4 { margin: 0; font-weight: 800; }
button, input, select, textarea { font: inherit; }
a { color: var(--accent); }

.hidden, [hidden] { display: none !important; }
.muted { color: var(--ink-3); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* Visible focus everywhere — never remove an outline without replacing it. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 300;
  background: var(--accent-2); color: #fff; padding: 9px 14px; border-radius: 0 0 10px 10px;
  text-decoration: none; font-weight: 700;
}
.skip-link:focus { top: 0; }

/* ---------------------------- top bar ---------------------------- */
header[data-admin-bar] {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  min-height: var(--bar-h); padding: 8px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0c1a30, #0a1424);
  position: sticky; top: 0; z-index: 40;
}
header[data-admin-bar] .bar-brand { font-weight: 900; font-size: 15px; white-space: nowrap; }
header[data-admin-bar] .bar-brand .dot { color: var(--good); }
header[data-admin-bar] .bar-back { text-decoration: none; color: var(--ink-2); font-weight: 700; white-space: nowrap; }
header[data-admin-bar] .bar-back:hover { color: var(--ink); }
header[data-admin-bar] .bar-spacer { margin-left: auto; }

.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); flex-shrink: 0;
}
.chip b { color: var(--ink); font-weight: 700; }
.chip.warn { border-color: #7a5f22; background: #3a2e12; color: #ffe0a8; }
.chip.bad { border-color: #7a2b3f; background: #3a1420; color: #ffd7de; }

/* ---------------------------- buttons ---------------------------- */
.btn {
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); cursor: pointer;
  font-weight: 700; white-space: nowrap;
}
.btn:hover { filter: brightness(1.14); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.good { background: #17693f; border-color: #23885a; color: #dcffec; }
/* Destructive. Defined HERE because editor.html used `btn bad` without ever
   defining it, so its two delete buttons rendered as neutral grey. */
.btn.bad { background: #5a2130; border-color: #8b3145; color: #ffd7de; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

input.text, select.text, .field input, .field select {
  padding: 8px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: #0b1c33; color: var(--ink);
}
input.text:focus, select.text:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(57,135,229,.3); }

/* Segmented control — use role="radiogroup"/role="radio" in markup. */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: #0e2038; color: var(--ink-2); padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 13px; }
.seg button[aria-checked="true"], .seg button.on { background: var(--accent-2); color: #fff; }
.seg button:focus-visible { outline-offset: -2px; }

/* ---------------------------- layout ---------------------------- */
.layout { display: flex; min-height: calc(100vh - var(--bar-h)); }
nav.side {
  width: 208px; flex: 0 0 208px; border-right: 1px solid var(--line);
  padding: 14px 10px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: var(--bar-h); height: calc(100vh - var(--bar-h)); overflow-y: auto;
}
nav.side .navlink {
  display: flex; align-items: center; gap: 10px; width: 100%; text-decoration: none;
  padding: 10px 12px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--ink-2); cursor: pointer; font-weight: 600;
  font-size: 14px; text-align: left;
}
nav.side .navlink .ico { font-size: 16px; width: 20px; text-align: center; flex: 0 0 20px; }
nav.side .navlink:hover { background: var(--surface); color: var(--ink); }
nav.side .navlink[aria-current="page"] {
  background: var(--surface-3); color: var(--ink); border-color: var(--line);
}
nav.side .badge {
  margin-left: auto; font-size: 11px; background: var(--accent-2); color: #fff;
  border-radius: 999px; padding: 0 7px; min-width: 18px; text-align: center; font-weight: 700;
}
nav.side .navgroup {
  margin: 14px 0 4px; padding: 0 12px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3);
}
nav.side .ext { margin-left: auto; font-size: 11px; color: var(--ink-3); }
main { flex: 1 1 auto; padding: 20px 24px 60px; min-width: 0; }
main:focus { outline: none; }

/* Responsive: icon rail, then a horizontal strip. */
@media (max-width: 1100px) {
  nav.side { width: 60px; flex-basis: 60px; padding: 12px 6px; }
  nav.side .navlink { justify-content: center; padding: 10px 6px; }
  nav.side .navlink span:not(.ico):not(.badge) { display: none; }
  nav.side .navgroup, nav.side .ext { display: none; }
  main { padding: 16px 14px 48px; }
}
@media (max-width: 760px) {
  .layout { display: block; }
  nav.side {
    width: auto; flex-basis: auto; height: auto; position: static;
    flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line);
  }
  nav.side .navlink { width: auto; flex: 0 0 auto; }
  header[data-admin-bar] { padding: 8px 12px; }
}

/* ---------------------------- cards, tables ---------------------------- */
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin-bottom: 12px; }

.table-scroll {
  overflow: auto; border: 1px solid var(--line); border-radius: var(--radius);
  max-height: calc(100vh - var(--bar-h) - 220px);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; vertical-align: middle; }
thead th {
  position: sticky; top: 0; background: #0c1a30; color: var(--ink-3);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; z-index: 1;
}
tbody tr:hover td { background: rgba(30, 58, 95, 0.28); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill { padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.pill.rejected { background: #4a1420; color: #ff9caa; }
.pill.dup { background: #43401a; color: #ecd96a; }
.pill.cap { background: #4a3410; color: #ffc46a; }
.pill.multi { background: #3a2a52; color: #d6b3ff; }
.pill.bot { background: #143a44; color: #7fe3ff; }
.pill.ok { background: #17402b; color: #8fe3ac; }
.pill.plain { background: var(--surface-2); color: var(--ink-2); }

.banner { padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; border: 1px solid; }
.banner.info { background: #0e2a44; border-color: #24558a; color: #cfe6ff; }
.banner.warn { background: #3a2e12; border-color: #7a5f22; color: #ffe0a8; }
.banner.bad { background: #3a1420; border-color: #8b3145; color: #ffd7de; }

/* ---------------------------- toast + status ---------------------------- */
#admin-activity {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: #14304e; border: 1px solid var(--line); color: var(--ink);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px;
  max-width: min(560px, 92vw); pointer-events: auto;
}
.toast.good { border-color: #23885a; background: #10331f; }
.toast.bad { border-color: #8b3145; background: #3a1420; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: admin-rise .18s ease-out; }
}
@keyframes admin-rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------------------------- danger dialog ---------------------------- */
.dlg-backdrop {
  position: fixed; inset: 0; z-index: 250; background: rgba(4, 10, 20, .72);
  display: grid; place-items: center; padding: 24px;
}
.dlg {
  width: min(520px, 96vw); background: var(--surface); border: 1px solid #8b3145;
  border-radius: 14px; box-shadow: var(--shadow); padding: 20px;
}
.dlg h3 { font-size: 17px; margin-bottom: 8px; }
.dlg p { color: var(--ink-2); margin: 0 0 14px; }
.dlg .dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.dlg input.text { width: 100%; }

/* ---------------------------------------------------------------------------
   Shared sign-in card. enforcement.html and schools.html keep their own #auth
   block, but admin-shell.js upgrades it to look and read exactly like the hub's
   gate — one product, one sign-in, not three different login boxes.
   --------------------------------------------------------------------------- */
#auth.admin-gate {
  max-width: 480px; margin: 10vh auto; padding: 26px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
#auth.admin-gate .admin-gate-head h2 { font-size: 21px; margin-bottom: 6px; }
#auth.admin-gate .admin-gate-head p { color: var(--ink-2); margin: 0 0 14px; font-size: 13px; }
#auth.admin-gate input { width: 100%; }
#auth.admin-gate .err { min-height: 1.2em; color: var(--bad); font-size: 13px; }

/* Per-column filters on the Runs & Enforcement table (ported from the retired
   standalone enforcement monitor). */
.runs-filter-row th { padding: 4px 8px 8px; background: var(--panel, #0a1424); }
.runs-col-filter {
  width: 100%; min-width: 64px; padding: 4px 6px; font-size: 11px;
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); border-radius: 6px;
  color: inherit; color-scheme: dark;
}
.runs-col-filter:focus { border-color: #2f6df0; outline: none; }
.runs-col-filter.active { border-color: #f0a83a; }

/* Ported schools-approvals fragments (from the retired schools.html). */
.sc-dupe {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #2a1a08;
  border: 1px solid #7a4a1e;
  color: #ffcfa0;
  font-size: 13px;
  line-height: 1.5;
}

.sc-dupe ul { margin: 6px 0 0; padding-left: 18px; }
.sc-dupe b { color: #fff; }

.sc-suggest {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.sc-suggest-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 5px 0;
}
