/* Memory design tokens: monochrome.
   Pure neutrals, no accent colour. Emphasis comes from weight, size, inversion
   and space; hue is reserved for status (success, warning, danger), always with
   an icon or label. One source for every page (marketing, docs, legal, dashboard).
   theme-init.js always sets data-theme="light" | "dark" on <html> before first
   paint; the media query below only covers the no-JS case.
   Contrast pairs are checked by tests/test_design_tokens.py. */

:root {
  --paper: #FFFFFF;
  --surface: #FAFAFA;
  --sunken: #F4F4F4;
  --raised: #FFFFFF;
  --ink: #0A0A0A;
  --ink-2: #525252;
  --ink-3: #636363;
  --line: #E5E5E5;
  --line-strong: #858585;
  --btn: #0A0A0A;
  --on-btn: #FFFFFF;
  --sweep: #FFFFFF;
  --sweep-soft: #EDEDED;
  --ok: #15703D;
  --ok-bg: #EEF6F1;
  --warn: #9C4221;
  --warn-bg: #FBF1EC;
  --risk: #B42318;
  --risk-bg: #FDEDEB;

  /* platforms are monochrome: a glyph plus the name, never a hue */
  --discord: #525252;
  --slack: #525252;
  --teams: #525252;
  /* chart series: grayscale steps, always paired with a dash or pattern cue */
  --s-1: #262626;
  --s-2: #8A8A8A;
  --s-bar: #3B82F6;
  --s-curve: #3B82F6;

  /* canvas ink (read by ledger.js and dashboard.js) */
  --gl-ink: #0A0A0A;
  --gl-mode: 0;

  --shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 12px 32px -14px rgba(0, 0, 0, .16);
  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 18px;

  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --fast: 120ms;
  --slow: 200ms;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #0A0A0A;
  --surface: #141414;
  --sunken: #0F0F0F;
  --raised: #1C1C1C;
  --ink: #F5F5F5;
  --ink-2: #A3A3A3;
  --ink-3: #8F8F8F;
  --line: #262626;
  --line-strong: #737373;
  --btn: #F5F5F5;
  --on-btn: #0A0A0A;
  --sweep: #0A0A0A;
  --sweep-soft: #262626;
  --ok: #6FCF97;
  --ok-bg: #0F2418;
  --warn: #E3A07C;
  --warn-bg: #2A1A12;
  --risk: #FF8A7A;
  --risk-bg: #331512;
  --discord: #A3A3A3;
  --slack: #A3A3A3;
  --teams: #A3A3A3;
  --s-1: #E5E5E5;
  --s-2: #737373;
  --s-bar: #737373;
  --s-curve: #F5F5F5;
  --gl-ink: #F5F5F5;
  --gl-mode: 1;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 18px 40px -18px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #0A0A0A;
    --surface: #141414;
    --sunken: #0F0F0F;
    --raised: #1C1C1C;
    --ink: #F5F5F5;
    --ink-2: #A3A3A3;
    --ink-3: #8F8F8F;
    --line: #262626;
    --line-strong: #737373;
    --btn: #F5F5F5;
    --on-btn: #0A0A0A;
    --sweep: #0A0A0A;
    --sweep-soft: #262626;
    --ok: #6FCF97;
    --ok-bg: #0F2418;
    --warn: #E3A07C;
    --warn-bg: #2A1A12;
    --risk: #FF8A7A;
    --risk-bg: #331512;
    --discord: #A3A3A3;
    --slack: #A3A3A3;
    --teams: #A3A3A3;
    --s-1: #E5E5E5;
    --s-2: #737373;
    --s-bar: #737373;
    --s-curve: #F5F5F5;
    --gl-ink: #F5F5F5;
    --gl-mode: 1;
    --shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 18px 40px -18px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img, svg, canvas { max-width: 100%; }
a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
a:hover { text-decoration-color: currentColor; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--ink); color: var(--paper); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 6px; }
/* Monospace is only for things that are literally code: commands, snippets, keys. Labels, dates and
   metadata use the sans with even-width digits (.mono is kept as a class name for those). */
code, kbd, pre { font-family: var(--mono); }
.mono { font-variant-numeric: tabular-nums; }
:not(pre) > code {
  font-size: .88em;
  background: var(--sunken);
  box-shadow: inset 0 0 0 1px var(--line);
  border-radius: 5px;
  padding: .05em .35em;
}
/* search matches: bold with a 1px underline, no fill */
mark { background: none; color: inherit; font-weight: 700; text-decoration: underline 1px; text-underline-offset: 3px; }
/* "new" marker: a small filled dot in the text colour */
.new-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; vertical-align: .15em; }
.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: 12px; top: -48px; z-index: 100;
  padding: 10px 14px; border-radius: var(--radius-s);
  background: var(--btn); color: var(--on-btn); text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 12px; }
.eyebrow {
  font-family: var(--sans); font-size: 12px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3);
}

/* ---------- brand mark ---------- */
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 18px; letter-spacing: -.02em; text-decoration: none; color: var(--ink);
}
.brand svg { width: 28px; height: 28px; flex: none; }

/* ---------- signature buttons ---------- */
.btn {
  --bg: var(--btn); --fg: var(--on-btn);
  position: relative; isolation: isolate; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 44px; padding: 0 20px; border: 0; border-radius: 999px;
  background: var(--bg); color: var(--fg);
  font: 600 15px/1 var(--sans); text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: transform var(--fast) var(--ease), color .18s;
}
.btn:has(kbd) { padding-right: 7px; }
/* On hover the opposite fill sweeps across and the button inverts: paper fill,
   ink label, 1px ink border. Pressing lowers it 1px. */
.btn::before {
  content: ""; position: absolute; inset: -2px -12px; z-index: -1;
  background: var(--sweep); transform: translateX(-104%) skewX(-18deg);
  transition: transform .32s var(--ease);
}
.btn:hover::before, .btn:focus-visible::before { transform: translateX(0) skewX(-18deg); }
.btn:hover, .btn:focus-visible { color: var(--btn); box-shadow: inset 0 0 0 1px var(--btn); }
.btn:active { transform: translateY(1px); }
.btn kbd {
  display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 8px;
  border-radius: 999px; font: 500 11.5px var(--sans);
  background: color-mix(in srgb, currentColor 14%, transparent);
}
.btn.ghost { --bg: transparent; --fg: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn.ghost::before { background: var(--sweep-soft); }
.btn.ghost:hover, .btn.ghost:focus-visible { color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.btn.quiet { --bg: transparent; --fg: var(--ink-2); padding: 0 12px; }
.btn.quiet::before { background: var(--sunken); }
.btn.quiet:hover, .btn.quiet:focus-visible { color: var(--ink); box-shadow: none; }
.btn.danger { --bg: transparent; --fg: var(--risk); box-shadow: inset 0 0 0 1px var(--risk); }
.btn.danger::before { background: var(--risk-bg); }
.btn.danger:hover, .btn.danger:focus-visible { color: var(--risk); box-shadow: inset 0 0 0 1px var(--risk); }
/* Clean edges on hover. The outline is redrawn on ::after, above the sweep, so it's never half-covered
   mid-sweep; and once the sweep has finished, the button's own fill switches to the sweep color so no
   sliver of the old fill shows through the anti-aliased rounded edge. Leaving hover switches it back at once. */
.btn { --fill: var(--sweep); }
.btn.ghost { --fill: var(--sweep-soft); }
.btn.quiet { --fill: var(--sunken); }
.btn.danger { --fill: var(--risk-bg); }
.btn::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inherit; pointer-events: none; }
.btn:hover, .btn:focus-visible { background-color: var(--fill); transition: transform var(--fast) var(--ease), color .18s, background-color 0s .32s; }
.btn[disabled]:hover, .btn[aria-disabled="true"]:hover { background-color: var(--bg); color: var(--fg); box-shadow: none; }
.btn.ghost[disabled]:hover, .btn.ghost[aria-disabled="true"]:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn.small { min-height: 36px; font-size: 14px; padding: 0 14px; }
.btn.small:has(kbd) { padding-right: 5px; }
.btn.small kbd { height: 26px; min-width: 26px; }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn[disabled]::before, .btn[aria-disabled="true"]::before { display: none; }
@media (max-width: 640px) { .btn.small { min-height: 44px; } }

/* ---------- theme toggle (radio fieldset driven by theme.js) ---------- */
.theme-toggle {
  display: inline-flex; gap: 2px; margin: 0; padding: 3px; border: 0; border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--line); min-width: 0;
}
.theme-toggle .theme-choice { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.theme-option {
  width: 30px; height: 30px; border-radius: 999px; display: grid; place-items: center;
  color: var(--ink-3); cursor: pointer;
}
.theme-option svg { width: 15px; height: 15px; }
.theme-option:hover { color: var(--ink); }
.theme-choice:checked + .theme-option {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12), inset 0 0 0 1px var(--line);
}
.theme-choice:focus-visible + .theme-option { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- provenance stamp & platform chips ---------- */
.stamp {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  font: 11.5px/1.5 var(--sans); color: var(--ink-3);
}
/* Platform badge: the platform's official mark plus its name (files in static/img/brands). */
.plat { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-2); }
.plat::before {
  content: ""; width: 14px; height: 14px; flex: none;
  background: var(--brand, radial-gradient(circle, var(--ink-3) 35%, transparent 38%)) center / contain no-repeat;
}
.plat.discord { --brand: url("../img/brands/discord.svg"); }
.plat.slack { --brand: url("../img/brands/slack.svg"); }
.plat.teams { --brand: url("../img/brands/teams.svg"); }
.plat.google { --brand: url("../img/brands/google.svg"); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 11.5px var(--sans); padding: 2px 9px; border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--ink-2); white-space: nowrap;
}
.pill.strong { background: var(--ink); color: var(--paper); box-shadow: none; }
.pill.ok { background: var(--ok-bg); color: var(--ok); box-shadow: none; }
.pill.risk { background: var(--risk-bg); color: var(--risk); box-shadow: none; }
.pill.warn { background: var(--warn-bg); color: var(--warn); box-shadow: none; }

/* ---------- surfaces ---------- */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px var(--line); padding: 18px 20px; min-width: 0;
}
.meter { height: 6px; border-radius: 3px; background: var(--sunken); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--ink); }
.meter.ok > i { background: var(--ok); }
.meter.warn > i { background: var(--warn); }
.meter.risk > i { background: var(--risk); }

/* ---------- the Ledger (ledger.js) ---------- */
.ledger-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ledger-lane {
  position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font: 11.5px var(--sans); color: var(--ink-2); white-space: nowrap; pointer-events: none; overflow: hidden;
}
.ledger-lane.faint { color: var(--ink-3); }
.ledger-lane small { font-size: 10.5px; color: var(--ink-3); box-shadow: inset 0 0 0 1px var(--line); border-radius: 999px; padding: 0 6px; }
.ledger-lane .plat { gap: 0; }
.ledger-lane .plat::before { width: 12px; height: 12px; }
/* one line per lane: the name shrinks with an ellipsis; a note sits on its own line below */
.ledger-lane { flex-wrap: nowrap; }
.ledger-lane:has(.lane-break) { flex-wrap: wrap; }
.ledger-lane > span:not(.plat) { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ledger-lane .lane-break { flex-basis: 100%; height: 0; }
.ledger-now { position: absolute; left: 0; top: 0; font: 10.5px var(--sans); color: var(--ink-3); pointer-events: none; }

/* ---------- form controls ---------- */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .select {
  min-height: 44px; width: 100%; padding: 0 12px; border: 0; border-radius: 10px;
  background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong);
}
.input::placeholder { color: var(--ink-3); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23858585' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 14px;
}
.input:focus-visible, .select:focus-visible { outline-offset: 0; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: inset 0 0 0 1px var(--line); background: var(--surface); }
.table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--sunken); position: sticky; top: 0; }
.table tr:last-child td { border-bottom: 0; }
.table .n { text-align: right; }

/* ---------- motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}
