/*
 * The back office's look (#961): a plain internal tool in the brand's tokens
 * (shared/design/tokens.json, `theme.scheme`, as web/app/src/styles/tokens.css
 * resolves them, and the accent «Neón»), dark by default and light where the
 * device asks for it. A counting desk: quiet surfaces in steps of one grey,
 * figures aligned, and the accent only on what matters, the latest bucket of
 * a chart and a screen's one primary action. Saira, the brand's face, sets
 * the brand, the headings and the big figures; the system font the rest;
 * ids and technical figures are monospace and muted. Spacing on a 4px scale.
 */
@font-face {
  font-family: 'Saira';
  src: url(/static/saira.woff2?v=0ab784bd9fcd6b2c) format('woff2');
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #0b0c0d;
  --surface-1: #141617;
  --surface-2: #1c1f20;
  --line: rgba(251, 249, 247, 0.08);
  --line-strong: rgba(251, 249, 247, 0.16);
  --text: #fbf9f7;
  --text-2: #babebc;
  --text-3: #878c8b;
  --accent: #45f94f;
  --accent-text: #45f94f;
  --on-accent: #0b0c0d;
  --negative: #ff6159;
  --negative-soft: rgba(255, 97, 89, 0.12);
  --chart-mark: #3a3e3f;
  --chart-line: #6f7473;
  --r-control: 10px;
  --r-card: 16px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Saira', var(--font);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f3f1;
    --surface-1: #fff;
    --surface-2: #e9e9e6;
    --line: rgba(11, 12, 13, 0.09);
    --line-strong: rgba(11, 12, 13, 0.18);
    --text: #0b0c0d;
    --text-2: #3f4344;
    --text-3: #666b6c;
    --accent: #1fb52b;
    --accent-text: #0e7a19;
    --negative: #c62f28;
    --negative-soft: rgba(198, 47, 40, 0.1);
    --chart-mark: #c9cbc8;
    --chart-line: #9a9f9e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}

/* Links read as text; the underline comes on hover and focus. */
a { color: inherit; text-decoration: none; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover, a:focus-visible { text-decoration-line: underline; }
a.back { color: var(--text-2); font-size: 14px; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* One heading rhythm: a section's heading 32 below what comes before and 12
   over its own content; every block of content leaves 16 under it. */
h1, h2, h3 { font-family: var(--display); font-weight: 500; }
h1 { margin: 0 0 12px; font-size: 28px; line-height: 1.2; }
h2 { margin: 32px 0 12px; font-size: 20px; line-height: 1.3; }
h3 { margin: 0 0 8px; font-size: 16px; line-height: 1.4; }
p { margin: 0 0 16px; }
.muted { color: var(--text-3); }
.error { padding: 8px 12px; border-radius: var(--r-control); background: var(--negative-soft); color: var(--negative); }

/* Ids and technical figures, like a chip's serial number. */
.id, .mono { color: var(--text-3); font-family: var(--mono); font-size: 13px; }
a.id:hover, a.id:focus-visible { color: var(--text); }

/* The header: the brand, the sections and who is signed in. */
.top {
  display: grid;
  grid-template-columns: auto 1fr minmax(0, auto);
  grid-template-areas: 'brand nav me';
  align-items: center;
  gap: 8px 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
}
.brand { grid-area: brand; font: 500 17px/1 var(--display); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand span { margin-left: 4px; color: var(--text-3); font-weight: 400; }
.top nav { grid-area: nav; min-width: 0; }
.top nav ul { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; }
.top nav a, .subnav a, .quick a {
  display: block;
  padding: 6px 12px;
  border-radius: var(--r-control);
  color: var(--text-2);
  white-space: nowrap;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.top nav a:hover, .subnav a:hover, .quick a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.top nav a[aria-current='page'], .subnav a[aria-current='page'] { background: var(--surface-2); color: var(--text); font-weight: 500; }
.me { grid-area: me; display: flex; align-items: center; justify-content: end; gap: 4px; min-width: 0; color: var(--text-2); font-size: 14px; }
.me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me form { margin: 0; }

main { max-width: 1200px; margin: 0 auto; padding: 32px 24px 64px; }
.bare main { display: grid; min-height: 100vh; place-items: center; padding: 24px; }

/* Controls: a button is quiet by default; .primary is a screen's one main
   action, .danger one that cannot be taken back lightly. */
.button, button {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface-2);
  color: var(--text);
  font: 500 14px/1.4 var(--font);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease), transform 120ms var(--ease);
}
.button:hover, button:hover { border-color: var(--line-strong); text-decoration: none; }
.button:active, button:active { transform: scale(0.98); }
.primary { border-color: transparent; background: var(--accent); color: var(--on-accent); }
.primary:hover { border-color: transparent; }
.danger { border-color: transparent; background: var(--negative-soft); color: var(--negative); }
.danger:hover { border-color: var(--negative); }
button.quiet { padding: 6px 12px; border-color: transparent; background: none; color: var(--text-2); font-weight: 400; }
button.quiet:hover { background: var(--surface-2); color: var(--text); }
input, select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  background: var(--surface-1);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
input[type='checkbox'] { margin: 0 8px 0 0; vertical-align: -2px; accent-color: var(--accent-text); }

.card { margin: 0 0 16px; padding: 20px 24px; border-radius: var(--r-card); background: var(--surface-1); }
.narrow { width: min(400px, 100%); margin: 0; }
.narrow .button { width: 100%; }
.stack { display: grid; gap: 8px; margin: 0; }
.stack > * { margin: 0; }
.stack button { justify-self: start; margin-top: 4px; }
.stack label { color: var(--text-3); font-size: 13px; }
.narrow .stack { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }

/* The player's actions: one card each, at natural width. */
.actions { display: grid; gap: 12px; }
.actions .card { margin: 0; }
.actions .card > h3 { margin-bottom: 8px; }
.actions .card > p { margin-bottom: 12px; }
summary { cursor: pointer; list-style-position: outside; }
summary h3 { display: inline; margin: 0; }
details[open] > summary { margin-bottom: 12px; }

/* Tables */
.table-wrap { margin: 0 0 16px; overflow-x: auto; border-radius: var(--r-card); background: var(--surface-1); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
caption { padding: 12px 16px; color: var(--text-3); font-size: 13px; text-align: left; }
th, td { padding: 8px 16px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
td { height: 40px; }
th { color: var(--text-3); font-size: 13px; font-weight: 500; }
.num { text-align: right; white-space: nowrap; }
.empty { margin: 0 0 16px; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 0 0 16px; font-size: 14px; }

/* The period a screen covers, and any other filter form. */
.period { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin: 0 0 16px; }
.period label { display: grid; gap: 4px; color: var(--text-3); font-size: 13px; }
.period input, .period select { color: var(--text); font-size: 14px; }

/* A screen's headline figures: a row across the page. */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 12px; margin: 0 0 16px; }
.figures div { display: grid; align-content: space-between; padding: 16px 20px; border-radius: var(--r-card); background: var(--surface-1); }
.figures dt { color: var(--text-3); font-size: 13px; }
.figures dd { margin: 4px 0 0; font: 500 28px/1.2 var(--display); font-variant-numeric: tabular-nums; }

/* A record's facts, label beside value, in a card. */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 32px; font-variant-numeric: tabular-nums; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.facts .mono { font-size: 14px; }
.input { margin: 0 0 16px; padding: 16px 20px; border-radius: var(--r-card); background: var(--surface-1); white-space: pre-wrap; }

/* Charts: neutral marks, the accent on the latest bucket. Their colours
   follow the theme. */
.chart { margin: 0 0 16px; padding: 16px; border-radius: var(--r-card); background: var(--surface-1); }
.chart svg { display: block; width: 100%; height: auto; }
.chart-grid { stroke: var(--line); }
.chart-label { fill: var(--text-3); font: 11px var(--mono); }
.chart-empty { fill: var(--text-3); font: 14px var(--font); }
.chart-bar { fill: var(--chart-mark); transition: fill 150ms var(--ease); }
.chart-bar:hover { fill: var(--chart-line); }
.chart-bar.chart-latest, .chart-bar.chart-latest:hover { fill: var(--accent); }
.chart-line { fill: none; stroke: var(--chart-line); stroke-width: 1.5; stroke-linejoin: round; }
.chart-point { fill: var(--chart-line); }
.chart-point.chart-latest { fill: var(--accent); }
.chart-title { margin: 0 0 8px; color: var(--text-2); font: 500 14px/1.4 var(--font); }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(440px, 100%), 1fr)); gap: 16px; margin: 0 0 16px; align-items: start; }
.charts .chart { margin: 0; }

/* The AI section (#963): its own menu, the common periods, breakdowns side
   by side and a failed interpretation's input. */
.subnav { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 24px; }
.quick { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 8px; font-size: 13px; }
.quick a { padding: 4px 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; margin: 0 0 16px; align-items: start; }
.grid > * { margin: 0; }

/* The usage screen (#964). */
.note { font-size: 13px; }

/* htmx's request indicator, styled here instead of by htmx (includeIndicatorStyles: false). */
.htmx-indicator { opacity: 0; transition: opacity 200ms var(--ease); }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* A phone: the brand and who is signed in on one row, the sections under
   them, scrolling sideways when they do not fit. */
@media (max-width: 640px) {
  .top {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: 'brand me' 'nav nav';
    padding: 12px 16px 8px;
  }
  .top nav { margin: 0 -16px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
  .top nav::-webkit-scrollbar { display: none; }
  main { padding: 24px 16px 48px; }
  h1 { font-size: 24px; }
  .card { padding: 16px; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
