/* ============================================================================
   Parley design system.
   "Black-box flight recorder for autonomous engineering." Copper = relay/record.
   Hand-written, server-rendered. Shared by the portal (base.html) + landing.
   ============================================================================ */

/* --- self-hosted fonts (no third-party CDN — infra tools don't leak requests) --- */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900;
  font-display: swap; src: url("/static/fonts/inter-var.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 100 800;
  font-display: swap; src: url("/static/fonts/jetbrains-mono-var.woff2") format("woff2");
}

/* --- tokens: DARK (default) ------------------------------------------------- */
:root {
  --bg-base: #0B0F17;
  --bg-raised: #111726;
  --bg-card: #151B2A;
  --bg-inset: #0C111B;
  --bg-hover: #1A2233;
  --bg-selected: rgba(201, 116, 58, 0.10);

  --border-subtle: #232B3D;
  --border-strong: #303B52;

  --text-primary: #F3F6FB;
  --text-secondary: #B7C2D4;
  --text-muted: #7E8AA0;
  --text-faint: #5A6478;

  --accent: #C9743A;            /* Relay Copper — relay/record semantics ONLY */
  --accent-hover: #D9854B;
  --accent-active: #B5652E;
  --accent-soft-bg: rgba(201, 116, 58, 0.12);
  --accent-soft-border: rgba(201, 116, 58, 0.32);
  --on-accent: #0B0F17;

  --success: #36C28B;  --success-soft-bg: rgba(54, 194, 139, 0.12);
  --warning: #E0B23C;  --warning-soft-bg: rgba(224, 178, 60, 0.14);
  --danger:  #F0605F;  --danger-soft-bg:  rgba(240, 96, 95, 0.12);
  --info:    #6FA8DC;

  /* Primary button = NEUTRAL high-contrast (Linear/Vercel move). Copper is NOT a generic accent —
     it is reserved for relay/record semantics only (route arrows, record rail, relay-kind dots,
     the live stream, focus ring). This keeps copper meaningful instead of decorative. */
  --btn-bg: #F3F6FB; --btn-bg-hover: #E2E8F1; --btn-fg: #0B0F17;

  --code-bg: var(--bg-inset);
  --code-fg: var(--text-secondary);

  /* type */
  --font-sans: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* spacing (4px base) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px; --s20: 80px; --s24: 96px;

  /* radius */
  --r-sm: 6px; --r-md: 9px; --r-lg: 12px; --r-pill: 999px;

  /* shadow (infra ≠ floating glass: cards lean on bg contrast, not shadow) */
  --shadow-1: 0 1px 2px rgba(3, 6, 12, 0.4);
  --shadow-2: 0 4px 16px rgba(3, 6, 12, 0.5);

  /* motion */
  --t-fast: 120ms ease;
  --t: 180ms ease;
  --t-slow: 320ms cubic-bezier(.2, .6, .2, 1);

  --wrap: 1120px;
  color-scheme: dark;
}

/* --- tokens: LIGHT (opt-in) ------------------------------------------------ */
[data-theme="light"] {
  --bg-base: #FBFBFC;
  --bg-raised: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-inset: #F3F5F9;
  --bg-hover: #F0F2F7;
  --bg-selected: rgba(201, 116, 58, 0.08);

  --border-subtle: #E4E8F0;
  --border-strong: #CDD4E1;

  --text-primary: #11161F;
  --text-secondary: #3D4757;
  --text-muted: #5C6677;
  --text-faint: #98A1B2;

  --accent: #C9743A;            /* fills */
  --accent-text: #A85A28;       /* links/labels on light need a darker tone for AA */
  --accent-hover: #B5652E;
  --accent-active: #9A4F22;
  --accent-soft-bg: rgba(201, 116, 58, 0.10);
  --accent-soft-border: rgba(201, 116, 58, 0.30);
  --on-accent: #FFFFFF;

  --success: #1F9D6B;  --success-soft-bg: rgba(31, 157, 107, 0.12);
  --warning: #9A7415;  --warning-soft-bg: rgba(224, 178, 60, 0.18);
  --danger:  #C53434;  --danger-soft-bg:  rgba(197, 52, 52, 0.10);
  --info:    #2E6DA4;
  --btn-bg: #11161F; --btn-bg-hover: #2A323F; --btn-fg: #FFFFFF;   /* ink button on light */

  --shadow-1: 0 1px 2px rgba(16, 22, 31, 0.06);
  --shadow-2: 0 6px 20px rgba(16, 22, 31, 0.10);
  color-scheme: light;
}
/* link/label copper uses the AA-safe tone in light, the base tone in dark */
:root { --accent-text: var(--accent); }

/* --- reset + base ---------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg-base); color: var(--text-primary);
  font-family: var(--font-sans); font-size: 15px; line-height: 1.55;
  font-weight: 400; letter-spacing: 0;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3 { line-height: 1.15; font-weight: 600; margin: 0 0 var(--s4); letter-spacing: -0.011em; }
h1 { font-size: 28px; }
h2 { font-size: 18px; line-height: 1.25; }
h3 { font-size: 15px; line-height: 1.3; }
p { margin: 0 0 var(--s4); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent-hover); }
strong { font-weight: 600; color: var(--text-primary); }
small { font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border-subtle); margin: var(--s6) 0; }
/* Selection must be clearly visible (the soft 12% accent tint was nearly invisible in dark mode and
   set no text color). Use a solid accent highlight with a contrasting foreground in both themes. */
::selection { background: var(--accent); color: #fff; }
::-moz-selection { background: var(--accent); color: #fff; }

/* A guidance line inside a <pre> (e.g. "cd /path/to/your-project") that is shown for context but is
   NOT copied by the copy button (see team.html copy JS). Dim it so it reads as a hint, not a command. */
pre .copy-skip { color: var(--text-faint); user-select: none; }

code, pre, .mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1, "zero" 1; }
pre {
  background: var(--bg-inset); border: 1px solid var(--border-subtle);
  border-radius: var(--r-md); padding: 12px 14px; overflow-x: auto;
  color: var(--code-fg); font-size: 13px; line-height: 1.5; tab-size: 2; margin: var(--s2) 0;
}
:not(pre) > code {
  background: var(--bg-inset); border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm); padding: 1px 5px; font-size: 12px; color: var(--text-primary);
}
code.route { color: var(--accent); border-color: var(--accent-soft-border); }  /* relay token */

.muted { color: var(--text-muted); }
.eyebrow, .overline {
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); margin: 0 0 var(--s3);
}

/* --- layout ---------------------------------------------------------------- */
header.app {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 var(--s6);
  background: color-mix(in srgb, var(--bg-raised) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}
.brand { display: inline-flex; align-items: center; gap: var(--s2);
  color: var(--text-primary); font-weight: 560; letter-spacing: -0.01em; font-size: 16px; }
.brand:hover { color: var(--text-primary); }
.brand svg { display: block; }
nav.app-nav { display: flex; align-items: center; gap: var(--s5); }
nav.app-nav a { color: var(--text-muted); font-size: 14px; position: relative; padding: 4px 0; }
nav.app-nav a:hover { color: var(--text-primary); }
nav.app-nav a.active { color: var(--text-primary); }
nav.app-nav a.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px;
  background: var(--accent); border-radius: 2px;
}
main { max-width: 820px; margin: var(--s8) auto var(--s16); padding: 0 var(--s5); }
main.wide { max-width: 1120px; }   /* matches the landing .wrap so portal + landing share one rhythm */

/* --- buttons --------------------------------------------------------------- */
.btn, button, a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid transparent; border-radius: var(--r-md);
  padding: 9px 15px; font: 540 14px/1 var(--font-sans); cursor: pointer;
  text-decoration: none; transition: background var(--t-fast), border-color var(--t-fast);
}
.btn:hover, button:hover, a.btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); }
.btn:active, button:active { transform: translateY(0.5px); }
.btn:disabled, button:disabled { background: var(--border-strong); color: var(--text-faint);
  cursor: not-allowed; }

button.ghost, a.ghost, .ghost {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  padding: 8px 14px; font: 540 14px/1 var(--font-sans); transition: all var(--t-fast);
}
button.ghost::after, a.ghost::after { display: none; }
button.ghost:hover, a.ghost:hover, .ghost:hover {
  background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent-soft-border);
}
.ghost.sm, a.ghost.sm { padding: 4px 9px; font-size: 12.5px; }

button.copy, .copy {
  background: var(--bg-inset); color: var(--text-muted);
  border: 1px solid var(--border-subtle); border-radius: var(--r-sm);
  padding: 3px 9px; font: 500 11.5px/1.4 var(--font-mono); margin: var(--s2) 0 -2px;
}
button.copy::after { display: none; }
button.copy:hover { color: var(--text-primary); background: var(--bg-hover); }

/* --- cards ----------------------------------------------------------------- */
.card {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg); padding: var(--s5); margin: var(--s4) 0; box-shadow: var(--shadow-1);
}
.card h2 { margin-bottom: var(--s4); }
.card--inset { background: var(--bg-inset); }
.card.flash {
  background: var(--success-soft-bg); border-color: var(--success);
  border-left: 3px solid var(--success); color: var(--text-primary);
}
.card.flash.danger { background: var(--danger-soft-bg); border-color: var(--danger);
  border-left-color: var(--danger); }

/* --- forms ----------------------------------------------------------------- */
label { color: var(--text-secondary); font-size: 13.5px; display: block; margin: 0 0 var(--s1); }
input, select, textarea {
  background: var(--bg-inset); border: 1px solid var(--border-strong);
  color: var(--text-primary); border-radius: var(--r-sm);
  padding: 9px 11px; font: 400 14px/1.4 var(--font-sans); width: 100%; margin: var(--s1) 0;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
select { width: auto; cursor: pointer; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent); border-width: 1.5px; outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft-bg);
}
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input[aria-invalid="true"] { border-color: var(--danger); }

/* --- tables (the core surface) + the record rail --------------------------- */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font: 600 12px/1.4 var(--font-sans); letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 7px 10px; border-bottom: 1px solid var(--border-strong);
}
tbody td {
  padding: 7px 10px; border-bottom: 1px solid var(--border-subtle);
  vertical-align: top; font-size: 13.5px; color: var(--text-secondary);
}
tbody td code, tbody td.mono { font-size: 13px; }
tbody tr:hover { background: var(--bg-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* record rail: append-only surfaces get a left hairline; newest row lit copper */
.record { border-left: 2px solid var(--border-subtle); }
.record tbody tr[data-live] { box-shadow: inset 2px 0 0 var(--accent); }

/* --- status dots ----------------------------------------------------------- */
.dot-on, .dot-off, .dot-idle, .dot-dead {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap;
}
.dot-on::before, .dot-off::before, .dot-idle::before, .dot-dead::before {
  content: ""; width: 8px; height: 8px; border-radius: var(--r-pill); flex: none;
}
.dot-on  { color: var(--success); } .dot-on::before  { background: var(--success);
  animation: breathe 1.6s ease-in-out infinite; }   /* liveness — the only ambient motion */
.dot-idle { color: var(--warning); } .dot-idle::before { background: var(--warning); }
.dot-dead { color: var(--danger); }  .dot-dead::before { background: var(--danger); }
.dot-off { color: var(--text-faint); }
.dot-off::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-faint); }

/* --- badges / trust labels ------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font: 500 11.5px/1.4 var(--font-mono); padding: 2px 8px;
  border: 1px solid var(--border-subtle); border-radius: var(--r-sm);
  background: var(--bg-inset); color: var(--text-secondary);
}
.badge--flag { background: var(--danger-soft-bg); border-color: var(--danger); color: var(--danger); }
.badge--ok { background: var(--success-soft-bg); border-color: var(--success); color: var(--success); }
.badge--warn { background: var(--warning-soft-bg); border-color: var(--warning); color: var(--warning); }
.badge--muted { color: var(--text-muted); }
/* kind badge: a leading copper dot marks "a relay happened" */
.route-arrow { color: var(--accent); font-weight: 600; }   /* the only copper glyph in a record */

/* DISTINCT token treatments so a row doesn't read as one uniform sea of pills:
   identity = <code> chip · trust = quiet tag · kind = dot+label · status = colored chip (.badge--*) */
.kind { display: inline-flex; align-items: center; gap: 6px; font: 450 12px/1 var(--font-mono);
  color: var(--text-secondary); white-space: nowrap; }
.kind::before { content: ""; width: 5px; height: 5px; border-radius: var(--r-pill);
  background: var(--text-muted); flex: none; }
.kind.relay::before { background: var(--accent); }        /* copper dot = a relay happened */
.trust { font: 450 11.5px/1.3 var(--font-mono); color: var(--text-muted); }   /* attribution, low-key */

/* --- page header (shared portal pattern) ----------------------------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4);
  flex-wrap: wrap; margin: 0 0 var(--s6); padding-bottom: var(--s4); border-bottom: 1px solid var(--border-subtle); }
.page-head .titles h1 { margin: 0 0 6px; }
.page-head .titles .meta { color: var(--text-muted); font-size: 13.5px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: var(--s2); align-items: center; }

.tabs { display: flex; gap: 2px; }
.tabs a { padding: 6px 12px; border-radius: var(--r-sm); color: var(--text-muted); font-size: 13.5px; }
.tabs a:hover { background: var(--bg-hover); color: var(--text-primary); }
.tabs a.active { background: var(--bg-card); color: var(--text-primary);
  box-shadow: inset 0 0 0 1px var(--border-strong); }

.pill { display: inline-flex; align-items: center; gap: 6px; font: 500 11.5px/1 var(--font-mono);
  padding: 3px 9px; border-radius: var(--r-pill); border: 1px solid var(--border-subtle);
  background: var(--bg-inset); color: var(--text-secondary); }
/* 'pro' / append-only etc. — a touch more present, but NOT copper (copper = relay/record only) */
.pill.accent { border-color: var(--border-strong); color: var(--text-primary); }

/* --- control-panel panel (team page = a console, not a card stack) --------- */
.panel { background: var(--bg-card); border: 1px solid var(--border-subtle); border-radius: var(--r-lg);
  margin-bottom: var(--s4); overflow: hidden; }
.panel > .panel-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: 12px var(--s5); border-bottom: 1px solid var(--border-subtle); background: var(--bg-raised); }
.panel > .panel-h h2 { margin: 0; font-size: 14px; }
.panel > .panel-h .h-meta { font: 500 11.5px/1 var(--font-mono); color: var(--text-muted); }
.panel > .panel-b { padding: var(--s5); }
.panel.inset > .panel-b { background: var(--bg-inset); }
.panel--quiet > .panel-h { background: transparent; }

/* --- data-log frame (history = a continuous log surface) ------------------- */
.logframe { border: 1px solid var(--border-subtle); border-radius: var(--r-lg); overflow: hidden; background: var(--bg-card); }
.logframe .toolbar, .readout .toolbar { display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); flex-wrap: wrap; padding: 9px var(--s4); border-bottom: 1px solid var(--border-subtle); }
.logframe table { font-size: 13px; }
.logframe tbody td { padding: 6px var(--s4); }
.logframe thead th { padding: 8px var(--s4); }
.logframe .scroll, .readout .scroll { overflow-x: auto; }

/* --- black-box readout (timeline = a recorder readout, darker/terminal) ---- */
.readout { border: 1px solid var(--border-subtle); border-radius: var(--r-lg); overflow: hidden; background: var(--bg-inset); }
.readout .toolbar { background: var(--bg-base); }
.readout table { font-family: var(--font-mono); font-size: 12.5px; }
.readout tbody td { padding: 6px var(--s4); color: var(--text-secondary); border-bottom-color: var(--border-subtle); }
.readout thead th { padding: 8px var(--s4); background: var(--bg-base); }
.readout tbody tr:hover { background: var(--bg-card); }
.readout .seq { color: var(--accent); font-variant-numeric: tabular-nums; }   /* copper seq = record id */
.readout .when { color: var(--text-muted); }

/* team rail = compact secondary utility panels (not equal-weight cards) */
.grid-2.sidebar > * { min-width: 0; }   /* let columns shrink — content can't blow out the track */
.sticky-rail .card { background: var(--bg-inset); padding: var(--s4); min-width: 0; }
.sticky-rail .card h2 { font-size: 13px; margin-bottom: var(--s3); }
.sticky-rail .card pre { font-size: 12px; }
.sticky-rail .card code { word-break: break-all; }   /* tokens/ids wrap instead of overflowing */

/* compact stacked tile-list for narrow-rail rows (invites, telegram links) —
   a 3-4 column table doesn't fit a 340px rail, so each row becomes a wrapping tile */
.rail-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.rail-item { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 9px; background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm); font-size: 12.5px; min-width: 0; }
.rail-item-main { display: flex; align-items: center; gap: 5px 8px; flex-wrap: wrap; min-width: 0; }
.rail-item-main code { font-size: 11.5px; }
.rail-item form, .rail-item .ghost.sm { flex: none; }

/* --- utilities ------------------------------------------------------------- */
.row { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 var(--s6); }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: var(--s6); }
@media (min-width: 1024px) { .grid-2.sidebar { grid-template-columns: 1fr 340px; align-items: start; } }
.sticky-rail { position: sticky; top: 76px; }

/* --- universal focus ring (copper = the active connection; never removed) --- */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible,
summary:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--accent-soft-bg); border-radius: var(--r-sm);
}

details > summary { cursor: pointer; color: var(--text-muted); }
details > summary:hover { color: var(--text-secondary); }

/* --- keyframes ------------------------------------------------------------- */
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes railpulse { from { box-shadow: inset 2px 0 0 var(--accent-hover); } }
@keyframes recordin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- guards ---------------------------------------------------------------- */
@media (hover: none) {  /* no sticky-hover on touch */
  tbody tr:hover { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .btn::after, a.btn::after { transition: none; }
}
