/* Archar board — design tokens and components.
 *
 * Plain CSS, no build step. Written mobile-first at 390 px; desktop is the same
 * components with wider gutters.
 *
 * Two rules run through all of it:
 *   - Colour is never the only signal. Every state chip carries a label, and
 *     health dots carry a glyph, so the board is readable without colour vision.
 *   - Nothing animates except streaming text and countdowns, and both stop
 *     under prefers-reduced-motion.
 */

/* ── tokens ─────────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark light;

  --bg:          #0b0e14;
  --surface-1:   #121722;
  --surface-2:   #1a2130;
  --surface-3:   #232c3d;
  --border:      #2a3446;
  --border-soft: #202839;

  --text:        #e6ebf4;
  --text-dim:    #9aa7bd;
  --text-faint:  #6b7891;

  --accent:      #6ea8fe;
  --accent-ink:  #0b1220;
  --accent-soft: #1c2b45;

  --slate:   #8b97ad;
  --indigo:  #8b93f8;
  --amber:   #e3b341;
  --emerald: #3fb950;
  --teal:    #2dd4bf;
  --rose:    #f85149;
  --zinc:    #6e7681;

  --radius:    10px;
  --radius-sm: 7px;
  --gap:       12px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --tap: 44px;               /* never smaller; thumbs are not mice */
  --measure: 68ch;
  --nav-h: 58px;

  /* Type scale. Six sizes and one display size, used by name so two screens
     cannot pick two nearly-equal sizes for the same thing. */
  --fs-xs: .74rem; --fs-sm: .84rem; --fs-md: 1rem; --fs-lg: 1.12rem;
  --fs-xl: 1.45rem; --fs-2xl: 1.8rem; --fs-display: 2.1rem;
  --lh-tight: 1.2; --lh: 1.5;

  /* Spacing scale, in 4px steps. */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-7: 32px; --s-8: 48px;

  /* Elevation. Dark surfaces get their depth from a lighter surface, so the
     shadows are soft and mostly for light mode. */
  --shadow-1: 0 1px 2px rgba(0,0,0,.25);
  --shadow-2: 0 4px 14px rgba(0,0,0,.28);
  --shadow-3: 0 12px 34px rgba(0,0,0,.35);

  /* Motion: fast for feedback, base for screens. Both stop under reduced-motion. */
  --dur-fast: 120ms; --dur: 200ms; --ease: cubic-bezier(.2,.7,.2,1);

  /* The five states a post moves through, named so a chip and a calendar dot
     and a progress bar all mean the same colour by the same word. */
  --state-ready: var(--accent);
  --state-filmed: var(--indigo);
  --state-scheduled: var(--amber);
  --state-live: var(--emerald);
  --state-skipped: var(--zinc);
}

/* Light. Once by media query, once by attribute: the style page and the
   screenshot set force a theme with data-theme on <html>. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:          #f6f8fb;
    --surface-1:   #ffffff;
    --surface-2:   #eef2f8;
    --surface-3:   #e3e9f2;
    --border:      #d3dbe7;
    --border-soft: #e2e8f0;
    --text:        #111827;
    --text-dim:    #4b5563;
    --text-faint:  #6b7280;
    --accent:      #1d4ed8;
    --accent-ink:  #ffffff;
    --accent-soft: #dbeafe;
    --slate:   #64748b;
    --indigo:  #4f46e5;
    --amber:   #b45309;
    --emerald: #047857;
    --teal:    #0f766e;
    --rose:    #b91c1c;
    --zinc:    #52525b;
    --shadow-1: 0 1px 2px rgba(16,24,40,.08);
    --shadow-2: 0 4px 14px rgba(16,24,40,.10);
    --shadow-3: 0 12px 34px rgba(16,24,40,.14);
  }
}
:root[data-theme="light"] {
  --bg:          #f6f8fb;
  --surface-1:   #ffffff;
  --surface-2:   #eef2f8;
  --surface-3:   #e3e9f2;
  --border:      #d3dbe7;
  --border-soft: #e2e8f0;
  --text:        #111827;
  --text-dim:    #4b5563;
  --text-faint:  #6b7280;
  --accent:      #1d4ed8;
  --accent-ink:  #ffffff;
  --accent-soft: #dbeafe;
  --slate:   #64748b;
  --indigo:  #4f46e5;
  --amber:   #b45309;
  --emerald: #047857;
  --teal:    #0f766e;
  --rose:    #b91c1c;
  --zinc:    #52525b;
  --shadow-1: 0 1px 2px rgba(16,24,40,.08);
  --shadow-2: 0 4px 14px rgba(16,24,40,.10);
  --shadow-3: 0 12px 34px rgba(16,24,40,.14);
}

/* ── reset ──────────────────────────────────────────────────────────────── */

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 620; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
h4 { font-size: .92rem; color: var(--text-dim); }
p  { margin: 0 0 .8em; max-width: var(--measure); }

:focus-visible {
  outline: 2px solid var(--accent);
  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;
}

/* ── layout ─────────────────────────────────────────────────────────────── */

#app { min-height: 100vh; display: flex; flex-direction: column; }

.shell { flex: 1; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--gap);
  padding: 10px 14px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
  min-height: 52px;
}
.topbar h1 { margin: 0; font-size: 1.1rem; }
.topbar .spacer { flex: 1; }
.topbar .meta { color: var(--text-dim); font-size: .82rem; }

.main {
  flex: 1;
  padding: 14px 14px calc(var(--nav-h) + 24px);
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  animation: screen-in var(--dur) var(--ease) both;
}
@keyframes screen-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.stack   { display: flex; flex-direction: column; gap: var(--gap); }
.stack-s { display: flex; flex-direction: column; gap: 6px; }
.row     { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-tight { display: flex; align-items: center; gap: 5px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grow    { flex: 1; min-width: 0; }

.section-title {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 0 8px;
  font-size: .74rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-faint);
}
.section-title::after {
  content: ""; flex: 1; height: 1px; background: var(--border-soft);
}

/* ── nav ────────────────────────────────────────────────────────────────── */

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex;
  background: color-mix(in srgb, var(--surface-1) 96%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav a {
  flex: 1;
  min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px 2px;
  color: var(--text-faint); font-size: .68rem; font-weight: 560;
  text-decoration: none; position: relative;
}
.nav a[aria-current="page"] { color: var(--accent); }
.nav a[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 22%; right: 22%;
  height: 2px; background: var(--accent); border-radius: 0 0 2px 2px;
}
.nav .icon { flex-shrink: 0; }
.nav .badge {
  position: absolute; top: 4px; left: 50%; margin-left: 4px;
  background: var(--accent); color: var(--accent-ink);
  font-size: .62rem; font-weight: 800; line-height: 1;
  padding: 2px 5px; border-radius: 9px; min-width: 16px; text-align: center;
}
/* Inside the More sheet the items are full-width rows with the icon above the
   label, so the number sits in the row's top-right corner, inside its border. */
.nav .popover a { position: relative; }
.nav .popover .badge { top: 10px; left: auto; right: 12px; margin: 0; font-size: .72rem; }

/* ── cards ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px;
}
.card.tight   { padding: 10px 12px; }
.card.raised  { background: var(--surface-2); }
.card.accent  { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.card.quiet   { background: transparent; border-style: dashed; color: var(--text-dim); }
.card.danger  { border-color: color-mix(in srgb, var(--rose) 45%, var(--border)); }

.card-link { display: block; color: inherit; text-decoration: none; }
.card-link:hover { text-decoration: none; border-color: var(--accent); }
.card-link:hover .title { color: var(--accent); }

.title    { font-weight: 620; }
.subtitle { color: var(--text-dim); font-size: .87rem; }
.tiny     { font-size: .76rem; color: var(--text-faint); }
.dim      { color: var(--text-dim); }
.mono     { font-family: var(--mono); font-size: .84em; }
.nowrap   { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2  {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── chips ──────────────────────────────────────────────────────────────── */

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px;
  font-size: .72rem; font-weight: 620; line-height: 1.5;
  background: var(--surface-3); color: var(--text-dim);
  border: 1px solid transparent; white-space: nowrap;
}
.chip .glyph { font-size: .8em; }
.chip .icon { width: 12px; height: 12px; }

.chip[data-tone="slate"]   { color: var(--slate);   background: color-mix(in srgb, var(--slate) 15%, transparent); }
.chip[data-tone="indigo"]  { color: var(--indigo);  background: color-mix(in srgb, var(--indigo) 15%, transparent); }
.chip[data-tone="amber"]   { color: var(--amber);   background: color-mix(in srgb, var(--amber) 15%, transparent); }
.chip[data-tone="emerald"] { color: var(--emerald); background: color-mix(in srgb, var(--emerald) 15%, transparent); }
.chip[data-tone="teal"]    { color: var(--teal);    background: color-mix(in srgb, var(--teal) 15%, transparent); }
.chip[data-tone="rose"]    { color: var(--rose);    background: color-mix(in srgb, var(--rose) 15%, transparent); }
.chip[data-tone="zinc"]    { color: var(--zinc);    background: color-mix(in srgb, var(--zinc) 15%, transparent); }
.chip[data-tone="accent"]  { color: var(--accent);  background: var(--accent-soft); }

.dot { font-size: .7em; line-height: 1; }

/* ── buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 15px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font-size: .9rem; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-3); text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.btn.primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 85%, white);
}
.btn.ghost   { background: transparent; }
.btn.danger  { border-color: color-mix(in srgb, var(--rose) 50%, var(--border)); color: var(--rose); }
.btn.small   { min-height: 34px; padding: 0 10px; font-size: .8rem; font-weight: 560; }
.btn.wide    { width: 100%; }
.btn-row     { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row.stretch .btn { flex: 1; }

/* ── forms ──────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .8rem; font-weight: 600; color: var(--text-dim); }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], select, textarea {
  width: 100%; min-height: var(--tap);
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text);
}
textarea { min-height: 140px; resize: vertical; line-height: 1.55; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
::placeholder { color: var(--text-faint); }

.tabs {
  display: flex; gap: 3px; overflow-x: auto;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none; -ms-overflow-style: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  min-height: 42px; padding: 0 12px;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-dim); font-size: .87rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  min-height: 34px; padding: 0 11px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-dim); font-size: .8rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.filters button[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}

/* ── empty states ───────────────────────────────────────────────────────── */

.empty {
  padding: 22px 16px; text-align: center;
  border: 1px dashed var(--border); border-radius: var(--radius);
  color: var(--text-dim);
}
.empty .headline { font-weight: 620; color: var(--text); margin-bottom: 4px; }
.empty p { margin: 0 auto; max-width: 46ch; font-size: .88rem; }

/* ── skeletons: same height as the real thing, so nothing jumps ─────────── */

.skeleton {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 50%,
                              var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
  border-radius: var(--radius);
}
.skeleton.line { height: 12px; border-radius: 4px; margin: 7px 0; }
.skeleton.card-h { height: 108px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── the packet review screen ───────────────────────────────────────────── */

.draft {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  white-space: pre-wrap;
  line-height: 1.65;
  font-size: .95rem;
  overflow-wrap: anywhere;
}

/* The underline is the whole mechanism: reasoning attached to the phrase it
 * explains, one tap away, never a wall of text above the artifact. */
.annotated {
  border-bottom: 2px dotted var(--accent);
  cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0;
  padding: 0 1px; color: inherit; font: inherit; text-align: left;
}
.annotated:hover { background: var(--accent-soft); }
.annotated[aria-expanded="true"] { background: var(--accent-soft); }

.popover {
  position: fixed; z-index: 60; left: 12px; right: 12px;
  background: var(--surface-3);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 13px;
  box-shadow: 0 12px 34px rgb(0 0 0 / .45);
  max-height: 62vh; overflow-y: auto;
}
.popover .quote {
  font-style: italic; color: var(--text-dim);
  border-left: 2px solid var(--accent); padding-left: 9px; margin-bottom: 9px;
}

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgb(0 0 0 / .55);
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .87rem; }
.kv dt { color: var(--text-faint); white-space: nowrap; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ── fact rows ──────────────────────────────────────────────────────────── */

.fact {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 9px 2px; border-bottom: 1px solid var(--border-soft);
  width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0;
  text-align: left; cursor: pointer; color: inherit;
}
.fact:last-child { border-bottom: none; }
.fact .cat {
  flex: 0 0 74px; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint);
  padding-top: 2px;
}
.fact .body { flex: 1; min-width: 0; }
.fact .detail { margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--border); }

/* ── messages / workroom ────────────────────────────────────────────────── */

.msg { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.msg .who { font-size: .74rem; color: var(--text-faint); }
.msg .bubble {
  padding: 10px 12px; border-radius: var(--radius);
  overflow-wrap: anywhere; line-height: 1.55;
}
.msg.agent  .bubble {
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}
.msg.human  { align-items: flex-end; }
.msg.human  .bubble { background: var(--surface-3); max-width: 88%; }
.msg.system { align-items: center; }
.msg.system .bubble {
  background: none; color: var(--text-faint); font-size: .8rem;
  text-align: center; padding: 3px;
}
.msg .bubble > :first-child { margin-top: 0; }
.msg .bubble > :last-child  { margin-bottom: 0; }

.composer {
  position: sticky; bottom: 0;
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 0;
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.composer textarea { min-height: var(--tap); max-height: 40vh; }

.streaming::after {
  content: "▍"; color: var(--accent);
  animation: blink 1.05s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* ── sparklines / metrics ───────────────────────────────────────────────── */

.spark { display: block; width: 100%; height: 34px; overflow: visible; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.spark .area { fill: var(--accent); opacity: .13; }
.spark .kill { stroke: var(--rose); stroke-width: 1; stroke-dasharray: 3 3; }

.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); }

.gate { display: flex; gap: 3px; }
.gate i {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--surface-3); border: 1px solid var(--border);
}
.gate i.on { background: var(--emerald); border-color: var(--emerald); }

/* ── toast ──────────────────────────────────────────────────────────────── */

.toasts {
  position: fixed; left: 12px; right: 12px; z-index: 70;
  bottom: calc(var(--nav-h) + 14px);
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 13px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .4);
  font-size: .88rem;
}
.toast.error { border-color: var(--rose); }
.toast .grow { min-width: 0; }

.banner {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--amber) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent);
  color: var(--text); font-size: .86rem;
}
.banner.error {
  background: color-mix(in srgb, var(--rose) 13%, transparent);
  border-color: color-mix(in srgb, var(--rose) 40%, transparent);
}
/* Something finished and needs no action. Amber is the default because most
   banners are asking for something; this one is only ever reporting. */
.banner.ok {
  background: color-mix(in srgb, var(--emerald) 13%, transparent);
  border-color: color-mix(in srgb, var(--emerald) 40%, transparent);
}

/* A server refusal is a to-do list, not an error. It is rendered as one. */
.missing { margin: 6px 0 0; padding-left: 18px; font-size: .86rem; }
.missing li { margin: 3px 0; }

/* ── login ──────────────────────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 22px;
}
.login { width: 100%; max-width: 340px; }
.login .brand { text-align: center; margin-bottom: 18px; }
.login .brand .name { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.login .brand .tag  { color: var(--text-dim); font-size: .85rem; }

/* ── desktop ────────────────────────────────────────────────────────────── */

@media (min-width: 820px) {
  :root { --nav-h: 0px; }

  .shell { flex-direction: row; }

  .nav {
    position: sticky; top: 0; left: 0; right: auto; bottom: auto;
    flex-direction: column; align-self: flex-start;
    width: 186px; height: 100vh; padding: 14px 10px;
    border-top: none; border-right: 1px solid var(--border);
    gap: 2px; flex-shrink: 0;
  }
  .nav a {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start;
    gap: 10px; padding: 0 12px; min-height: 42px;
    border-radius: var(--radius-sm); font-size: .9rem;
  }
  .nav a[aria-current="page"] { background: var(--accent-soft); }
  .nav a[aria-current="page"]::before { display: none; }
  .nav .icon { width: 18px; height: 18px; }
  .nav .badge { position: static; margin: 0 0 0 auto; }

  .shell > .col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .main { padding: 20px 26px 40px; }
  .toasts { left: auto; right: 20px; bottom: 20px; width: 380px; }
  .popover { left: auto; width: 400px; }
  .pipeline-columns {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr));
    gap: 14px; align-items: start;
  }
}

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

@media print { .nav, .composer, .toasts, .btn { display: none !important; } }
