/* Admin console. Colours are defined once as roles, light and dark. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --hairline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #256abf;
  --accent-text: #ffffff;
  --series-1: #2a78d6;
  --series-1-hover: #1c5cab;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --wash: rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a988f;
    --hairline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #5598e7;
    --accent-text: #0b0b0b;
    --series-1: #3987e5;
    --series-1-hover: #6da7ec;
    --wash: rgba(255, 255, 255, 0.06);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 1rem; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
section { margin-top: 2rem; }
code, .mono, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
.muted { color: var(--text-secondary); }
.small { font-size: 0.8em; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------ frame */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1.5rem;
  padding: 0.6rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.brand { font-weight: 600; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem; flex: 1; }
.topbar nav a {
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
}
.topbar nav a:hover { background: var(--wash); }
.topbar nav a.active { color: var(--text); font-weight: 600; background: var(--wash); }
.logout { display: flex; align-items: center; gap: 0.75rem; margin: 0; }
.who { color: var(--text-secondary); }

main { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }
main.narrow { max-width: 26rem; padding-top: 12vh; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin: 0;
}
.card.danger { border-color: var(--critical); }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.stack > h2, .stack > p { margin: 0; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1rem; align-items: start; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1rem; }

/* ------------------------------------------------------------------ forms */
label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 400; }
.hint { font-weight: 400; color: var(--text-secondary); font-size: 0.9em; }
input:not([type="checkbox"]), select, textarea {
  font: inherit;
  color: inherit;
  background: var(--page);
  border: 1px solid var(--axis);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  min-width: 0;
}
textarea { resize: vertical; }
button, a.button {
  font: inherit;
  cursor: pointer;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--axis);
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  text-decoration: none;
  display: inline-block;
}
button:hover, a.button:hover { background: var(--wash); }
button.primary, a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover, a.button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { border-color: var(--critical); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem 1rem; margin-bottom: 1rem; }
.filters label { font-weight: 400; color: var(--text-secondary); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem; margin: 1rem 0 0; }

.flash { border-radius: 8px; padding: 0.6rem 0.9rem; border: 1px solid var(--border); background: var(--surface); border-left: 4px solid var(--good); }
.flash.error { border-left-color: var(--critical); }
.flash.warn { border-left-color: var(--warning); }
.flash ul { margin: 0; padding-left: 1.1rem; }
.empty { color: var(--text-secondary); padding: 1rem; background: var(--surface); border: 1px dashed var(--axis); border-radius: 8px; }

/* ----------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.table-wrap.tall { max-height: 28rem; overflow-y: auto; }
table.data { border-collapse: collapse; width: 100%; }
table.data th, table.data td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--hairline); vertical-align: top; }
table.data.compact th, table.data.compact td { padding: 0.3rem 0.6rem; font-size: 0.9em; }
table.data th { color: var(--text-secondary); font-weight: 600; white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--wash); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { overflow-wrap: anywhere; min-width: 14rem; }
pre.code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  overflow: auto;
  max-height: 32rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 0.6rem 1.5rem; margin: 0; }
.facts dt { color: var(--text-secondary); font-size: 0.85em; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* Status is never colour alone: a shape and a word, the colour on the shape. */
.status { white-space: nowrap; }
.status > span { margin-right: 0.15rem; }
.status.active > span { color: var(--good); }
.status.withdrawn > span { color: var(--text-muted); }
.status.warn > span { color: var(--warning); }
.status.bad > span { color: var(--critical); }

/* ------------------------------------------------------------- stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1rem; margin-top: 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.9rem 1.1rem; }
.tile-label { color: var(--text-secondary); font-size: 0.9em; }
.tile-value { font-size: 1.75rem; font-weight: 600; line-height: 1.25; }
.tile-note { color: var(--text-secondary); font-size: 0.85em; }

/* ----------------------------------------------------------------- charts */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(24rem, 1fr)); gap: 1rem; margin-top: 0.5rem; }
.viz-title { font-weight: 600; margin-bottom: 0.5rem; }
.viz-svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-grid { stroke: var(--hairline); stroke-width: 1; }
.viz-baseline { stroke: var(--axis); stroke-width: 1; }
.viz-tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-bar { fill: var(--series-1); }
.viz-hit { fill: transparent; }
.viz-col { outline: none; }
.viz-col:hover .viz-bar, .viz-col:focus-visible .viz-bar { fill: var(--series-1-hover); }
.viz-col:hover .viz-hit, .viz-col:focus-visible .viz-hit { fill: var(--wash); }
.viz-table { margin-top: 0.5rem; }
.viz-table summary { cursor: pointer; color: var(--text-secondary); font-size: 0.9em; }
.viz-table table { margin-top: 0.5rem; max-width: 22rem; }
.viz-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  white-space: nowrap;
}
.viz-tooltip[hidden] { display: none; }
.viz-tooltip span { color: var(--text-secondary); }

/* IDs, dates and report cells stay on one line; wide tables scroll sideways. */
table.data .mono:not(.wrap), table.data td.small, .table-wrap.tall td { white-space: nowrap; }
.stack > button { align-self: flex-start; }
