/* Formal Engines — inference dashboard.
 *
 * Product register: the design serves the task. That sets it apart from the marketing site,
 * which carries the spectacle, and it drives four decisions the first version of this file
 * got wrong.
 *
 * 1. ONE FAMILY. Geist carries headings, labels, buttons, data. The Garamond appears once,
 *    in the wordmark, as the thread back to the brand. A display serif in a stat value or a
 *    table cell is a product-UI tell, not refinement.
 * 2. FIXED SCALE, not clamp(). Users sit at consistent DPI in a task; a heading that shrinks
 *    inside a panel looks broken rather than responsive. Responsiveness here is structural.
 * 3. THE SYSTEM'S TWO RADII: 0 for surfaces, pill for controls. The 2px rounding used before
 *    belonged to neither and read as an accident.
 * 4. THE BRASS SIGNAL RULE. Brass marks focus, live state, and the current position, never
 *    ambient decoration. The previous build used it as a coloured stripe down the side of
 *    every stat, which is decoration wearing a signal's clothes.
 *
 * Primary actions are pine, as everywhere else in the brand. Not black.
 */

:root {
  color-scheme: light;

  /* Alpine Brass, verbatim from DESIGN.md. */
  --white: oklch(1 0 0);
  --bg: oklch(0.985 0 0);
  --surface: oklch(0.955 0.005 82);
  --mineral: oklch(0.91 0.007 82);
  --line: oklch(0.82 0.009 82);
  --ink: oklch(0.19 0.012 82);
  --muted: oklch(0.43 0.014 82);
  --brass: oklch(0.61 0.125 68);
  --brass-light: oklch(0.75 0.14 68);
  --pine: oklch(0.255 0.04 145);
  --pine-deep: oklch(0.18 0.025 145);
  --on-dark: oklch(0.95 0.006 82);

  /* Semantic state. Product UI needs these named, not improvised per component. */
  --ok: oklch(0.42 0.09 150);
  --warn: oklch(0.52 0.12 70);
  --danger: oklch(0.48 0.17 27);
  --danger-soft: oklch(0.96 0.02 27);

  --font: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --display: 'Cormorant Garamond', 'EB Garamond', Garamond, 'Times New Roman', serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;

  /* Fixed rem steps at a 1.2 ratio. More type roles here than on a brand page, so
     exaggerated contrast would read as noise rather than hierarchy. */
  --t-micro: 0.75rem;
  --t-small: 0.8125rem;
  --t-body: 0.9375rem;
  --t-lead: 1.0625rem;
  --t-h3: 1.125rem;
  --t-h2: 1.375rem;
  --t-h1: 1.75rem;
  --t-figure: 2.25rem;

  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 72px;

  --pill: 999px;
  --shell: min(76rem, calc(100vw - 3rem));
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --quick: 160ms var(--ease);
  --settle: 240ms var(--ease);

  --z-sticky: 40;
  --z-overlay: 60;
  --z-toast: 80;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --white: oklch(0.215 0.018 145);
    --bg: oklch(0.175 0.022 145);
    --surface: oklch(0.235 0.02 145);
    --mineral: oklch(0.29 0.018 145);
    --line: oklch(0.36 0.018 145);
    --ink: oklch(0.96 0.006 82);
    --muted: oklch(0.78 0.014 120);
    --brass: oklch(0.78 0.13 68);
    --brass-light: oklch(0.85 0.12 68);
    --pine: oklch(0.62 0.09 150);
    --pine-deep: oklch(0.7 0.1 150);
    --on-dark: oklch(0.14 0.02 145);
    --ok: oklch(0.72 0.11 150);
    --warn: oklch(0.79 0.12 70);
    --danger: oklch(0.7 0.15 27);
    --danger-soft: oklch(0.28 0.05 27);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; font-weight: 560; letter-spacing: -0.012em; line-height: 1.2; }
h1 { font-size: var(--t-h1); }
h2 { font-size: var(--t-h2); }
h3 { font-size: var(--t-h3); font-weight: 550; }
p { margin: 0; }

a { color: var(--pine); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--pine-deep); }

/* Brass marks focus. That is the rule, and focus is the clearest case of it. */
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: 1px; }

.mono { font-family: var(--mono); font-size: 0.86em; }
.muted { color: var(--muted); }
.small { font-size: var(--t-small); }
.micro { font-size: var(--t-micro); }
.right { text-align: right; }
.hidden { display: none !important; }
.stack > * + * { margin-top: var(--s-4); }

.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;
}

/* ---------- wordmark: the one place the display serif appears ---------- */

.wordmark {
  font-family: var(--display);
  font-size: 1.0625rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.wordmark span { color: var(--muted); font-style: italic; }

/* ---------- chrome ---------- */

.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  width: var(--shell); margin: 0 auto;
  display: flex; align-items: center; gap: var(--s-5); min-height: 60px;
}
.topbar nav { display: flex; align-items: center; gap: var(--s-1); margin-left: auto; flex-wrap: wrap; }
/* A select in the bar is a control, not a form field: the full-width field styling makes it
   as wide as its longest option and pushes the actions onto a second row. */
.topbar select {
  width: auto; min-width: 0; margin: 0;
  padding: var(--s-2) var(--s-3);
  font-size: var(--t-small); border-radius: var(--pill);
  border: 1px solid var(--mineral); background: var(--white); color: var(--ink);
}
.topbar nav a {
  font-size: var(--t-small); color: var(--muted); text-decoration: none;
  padding: var(--s-2) var(--s-3); border-radius: var(--pill);
  transition: color var(--quick), background var(--quick);
}
.topbar nav a:hover { color: var(--ink); background: var(--surface); }
.topbar nav a[aria-current='page'] { color: var(--ink); background: var(--surface); font-weight: 550; }

main { width: var(--shell); margin: 0 auto; padding: var(--s-6) 0 var(--s-8); }

.page-head { margin-bottom: var(--s-6); }
.page-head h1 { margin-bottom: var(--s-2); }
.page-head p { color: var(--muted); max-width: 62ch; }

/* ---------- surfaces: square, hairline, flat ---------- */

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  padding: var(--s-5);
}
.panel + .panel { margin-top: var(--s-4); }
.panel__head {
  /* Wraps, because a heading and an action on one narrow row otherwise squeeze the heading
     until it breaks mid-phrase and the two collide. */
  display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-3);
  margin-bottom: var(--s-4); padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--mineral);
}
.panel__head > :first-child { margin-right: auto; }

.grid { display: grid; gap: var(--s-4); }
/* min(track, 100%), not a bare track: a fixed minimum wider than the grid itself makes the
   column overflow its container, and the content spills past the panel edge on a phone. */
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr)); }

/* ---------- readouts ---------- */

.readout { display: flex; flex-direction: column; gap: var(--s-1); }
.readout__label {
  font-size: var(--t-small); color: var(--muted); font-weight: 500;
}
.readout__value { font-size: var(--t-figure); line-height: 1.05; font-weight: 500; letter-spacing: -0.02em; }
.readout__note { font-size: var(--t-small); color: var(--muted); }
.readout--warn .readout__value { color: var(--warn); }
.readout--danger .readout__value { color: var(--danger); }

/* ---------- controls ---------- */

.btn {
  font: inherit; font-size: var(--t-small); font-weight: 550;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 38px; padding: 0 var(--s-5);
  border: 1px solid var(--pine); border-radius: var(--pill);
  background: var(--pine); color: var(--on-dark);
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--quick), border-color var(--quick), color var(--quick);
}
.btn:hover:not(:disabled) { background: var(--pine-deep); border-color: var(--pine-deep); color: var(--on-dark); }
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn--ghost:hover:not(:disabled) { background: var(--surface); border-color: var(--muted); color: var(--ink); }
.btn--danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn--small { min-height: 30px; padding: 0 var(--s-3); font-size: var(--t-micro); }
.btn--wide { width: 100%; }

.field { display: block; }
.field > span {
  display: block; font-size: var(--t-small); font-weight: 500;
  color: var(--ink); margin-bottom: var(--s-2);
}
.field__hint { display: block; font-size: var(--t-micro); color: var(--muted); margin-top: var(--s-2); }

input, select {
  font: inherit; font-size: var(--t-body); width: 100%;
  min-height: 38px; padding: 0 var(--s-3);
  border: 1px solid var(--line); border-radius: 0;
  background: var(--bg); color: var(--ink);
  transition: border-color var(--quick);
}
input::placeholder { color: var(--muted); opacity: 1; }
input:hover:not(:disabled) { border-color: var(--muted); }
input:focus { border-color: var(--brass); outline-offset: 1px; }
input:disabled { background: var(--surface); color: var(--muted); cursor: not-allowed; }
input[aria-invalid='true'] { border-color: var(--danger); }

/* Align on the top, not the bottom: one field carrying a hint is taller than its
   neighbours, and bottom-alignment pushed its label out of line with theirs. */
.row { display: flex; gap: var(--s-3); align-items: flex-start; flex-wrap: wrap; }
.row .field { flex: 1 1 12rem; }
.row > .btn { margin-top: 1.55rem; }
.chips { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ---------- data ---------- */

.scroll-x { overflow-x: auto; margin: 0 calc(var(--s-5) * -1); padding: 0 var(--s-5); }
table { width: 100%; border-collapse: collapse; font-size: var(--t-small); }
th {
  text-align: left; font-weight: 550; font-size: var(--t-micro); color: var(--muted);
  padding: 0 var(--s-3) var(--s-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: var(--s-3); border-bottom: 1px solid var(--mineral); vertical-align: baseline; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--quick); }
tbody tr:hover { background: var(--surface); }
th.right, td.right { text-align: right; }

.tag {
  display: inline-flex; align-items: center; gap: var(--s-1);
  font-size: var(--t-micro); font-weight: 550;
  padding: 2px var(--s-2); border: 1px solid var(--line); border-radius: var(--pill);
  color: var(--muted); white-space: nowrap;
}
.tag--ok { color: var(--ok); border-color: color-mix(in oklch, var(--ok) 40%, transparent); }
.tag--warn { color: var(--warn); border-color: color-mix(in oklch, var(--warn) 40%, transparent); }
.tag--bad { color: var(--danger); border-color: color-mix(in oklch, var(--danger) 40%, transparent); }
/* Brass as live state: the one ambient-looking use that the rule permits. */
.tag--live { color: var(--brass); border-color: var(--brass); }
.tag--live::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--brass);
  animation: pulse 2s var(--ease) infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- notices ---------- */

.notice {
  border: 1px solid var(--line); background: var(--surface);
  padding: var(--s-3) var(--s-4); font-size: var(--t-small); margin-bottom: var(--s-4);
}
.notice--ok { border-color: color-mix(in oklch, var(--ok) 40%, transparent); color: var(--ok); }
.notice--bad { border-color: color-mix(in oklch, var(--danger) 45%, transparent); background: var(--danger-soft); color: var(--danger); }

.secret {
  font-family: var(--mono); font-size: var(--t-small); word-break: break-all;
  background: var(--surface); border: 1px solid var(--line); padding: var(--s-3) var(--s-4);
}
.copy-row { display: flex; gap: var(--s-2); align-items: flex-start; }
.copy-row .secret { flex: 1; min-width: 0; }
/* A pill with a wrapped label reads as broken. Fix the control's width so the mono text
   beside it takes the remaining space instead of squeezing the button. It must not stretch
   either: on a narrow screen the URL wraps to two lines, and a stretched pill beside it
   becomes a circle. */
.copy-row .btn { flex: 0 0 auto; align-self: flex-start; }

/* ---------- loading and empty ---------- */

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--mineral) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: sweep 1.4s linear infinite;
  color: transparent !important;
  border-radius: 1px;
}
@keyframes sweep { to { background-position: -200% 0; } }

.empty { padding: var(--s-6) var(--s-4); text-align: center; }
.empty h3 { margin-bottom: var(--s-2); }
.empty p { color: var(--muted); max-width: 44ch; margin: 0 auto var(--s-4); }

/* ---------- steps ---------- */

.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.steps > li {
  counter-increment: step; position: relative;
  padding: 0 0 var(--s-5) var(--s-6); margin-left: 11px;
  border-left: 1px solid var(--line);
}
.steps > li:last-child { border-left-color: transparent; padding-bottom: 0; }
.steps > li::before {
  content: counter(step);
  position: absolute; left: -11px; top: 0;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: var(--t-micro); color: var(--muted);
}
.steps > li[data-state='active']::before { border-color: var(--brass); color: var(--brass); }
.steps > li[data-state='done']::before { content: '✓'; border-color: var(--ok); color: var(--ok); }
.steps h3 { margin-bottom: var(--s-1); }

/* ---------- sign-in ---------- */

.entry { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
.entry__pitch, .entry__form { padding: var(--s-7) var(--s-5); }
.entry__pitch {
  background: var(--pine); color: var(--on-dark);
  display: flex; flex-direction: column; justify-content: center; gap: var(--s-5);
}
.entry__pitch .wordmark, .entry__pitch h1 { color: var(--on-dark); }
.entry__pitch .wordmark span { color: color-mix(in oklch, var(--on-dark) 62%, transparent); }
.entry__pitch h1 { font-size: 2rem; max-width: 18ch; text-wrap: balance; }
.entry__pitch p { color: color-mix(in oklch, var(--on-dark) 80%, transparent); max-width: 46ch; }
.entry__inner { width: min(30rem, 100%); margin: 0 auto; }
.entry__form { display: flex; flex-direction: column; justify-content: center; }
.entry__foot { margin-top: var(--s-5); font-size: var(--t-small); color: var(--muted); }

/* The live rate table on the sign-in page: the reason to sign up, shown rather than claimed. */
.rates { width: 100%; border-collapse: collapse; font-size: var(--t-small); }
.rates th {
  color: color-mix(in oklch, var(--on-dark) 62%, transparent);
  border-bottom-color: color-mix(in oklch, var(--on-dark) 25%, transparent);
}
.rates td {
  border-bottom-color: color-mix(in oklch, var(--on-dark) 14%, transparent);
  padding: var(--s-2) var(--s-3);
}
.rates tbody tr:hover { background: color-mix(in oklch, var(--on-dark) 7%, transparent); }
.rates .was { color: color-mix(in oklch, var(--on-dark) 55%, transparent); text-decoration: line-through; }
.rates .now { color: var(--brass-light); font-weight: 550; }

.ladder { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.ladder__step {
  flex: 1 1 6rem; padding: var(--s-3);
  border: 1px solid color-mix(in oklch, var(--on-dark) 22%, transparent);
}
.ladder__step b { display: block; font-size: var(--t-h2); font-weight: 500; letter-spacing: -0.02em; }
.ladder__step span { font-size: var(--t-micro); color: color-mix(in oklch, var(--on-dark) 66%, transparent); }
.ladder__step[data-current='true'] { border-color: var(--brass); }
.ladder__step[data-current='true'] b { color: var(--brass-light); }

@media (min-width: 60rem) {
  .entry { grid-template-columns: 1.05fr 1fr; }
  /* The operator gate has no pitch panel beside it, so it must not sit in a half-width
     column with the other half blank. */
  .entry--solo { grid-template-columns: 1fr; }
  .entry__pitch { padding: var(--s-8) var(--s-7); }
  .entry__form { padding: var(--s-8) var(--s-7); }
  .entry__pitch h1 { font-size: 2.5rem; }
}

/* ---------- misc ---------- */

.spinner {
  width: 0.85em; height: 0.85em; display: inline-block; vertical-align: -0.1em;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite; opacity: 0.7;
}
@keyframes spin { to { transform: rotate(360deg); } }

.divider { height: 1px; background: var(--line); border: 0; margin: var(--s-5) 0; }

@media (max-width: 48rem) {
  :root { --shell: calc(100vw - 2rem); }
  .topbar__inner { flex-wrap: wrap; padding: var(--s-3) 0; min-height: 0; }
  .topbar nav { margin-left: 0; width: 100%; }
  .readout__value { font-size: 1.75rem; }
  main { padding-top: var(--s-5); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .skeleton { animation: none; background: var(--surface); }
}

/* ---------- the operator's manage sheet ---------- */

/* A native dialog, because the accounts table sits inside an overflow container and anything
   positioned inside it would be clipped at the edge. */
dialog {
  width: min(46rem, calc(100% - 2rem));
  padding: var(--s-6);
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--white);
  color: var(--ink);
}
dialog::backdrop { background: color-mix(in oklch, var(--ink) 45%, transparent); }
dialog h2 { margin: 0 0 var(--s-1); }
dialog h3 { margin: 0 0 var(--s-2); font-size: 1rem; }

.sheet__close-form { float: right; margin: 0 0 var(--s-2) var(--s-3); }
.sheet__block {
  margin-top: var(--s-5);
  padding-top: var(--s-5);
  border-top: 1px solid var(--mineral);
}

/* The row action lives in a column of its own so the money columns stay aligned. */
.postpaid-panel .ops-filter { min-height: 44px; margin-block: var(--s-2); }
.postpaid-panel .btn, .postpaid-panel .field input { min-height: 44px; }
.postpaid-panel > .btn { margin-top: var(--s-4); }
.postpaid-panel .row > .btn { margin-top: var(--s-2); }
.postpaid-panel .field__hint { font-size: var(--t-small); }
.postpaid-panel #postpaid-position { color: var(--ink); margin-top: var(--s-5); }
.postpaid-panel #postpaid-history { overflow-wrap: anywhere; }
@media (max-width: 48rem) {
  .postpaid-panel .field__hint { font-size: var(--t-body); }
}
td.row-action { text-align: right; white-space: nowrap; }
