/* ============================================================================
   co-op — Design System  (v2, "calm & precise", taste-pass)
   ----------------------------------------------------------------------------
   Aesthetic: calm & precise, panels floating on a tinted workspace (T3/Linear
   lineage). Palette: teal-steel PRIMARY (one accent) + brass reserved SOLELY as
   the agent-identity signal (deliberate second role, locked — not decoration).
   Fonts: Hanken Grotesk (UI + display via weight — deliberately NOT Inter/Geist) +
   Commit Mono (code). No serif accent (taste-skill bans Instrument Serif as an
   AI-tell; emphasis is same-family weight). OKLCH, light+dark via [data-theme], AA.
   Shape lock: panels 14 · controls 9 · inset 7 · pills full.
   Consumed by both mockup.html and (later) the real Web Components.
   Prod note: fonts self-hosted via include_str!; the mockup loads them from a CDN.
   ============================================================================ */

/* ---- Fonts: self-hosted (production requirement — no runtime CDN) --------- */
/* Relative URLs resolve under both the real server (/static/css/ → /static/fonts/)
   and any static preview of the static/ dir. Baked into the binary (routes_web). */
@font-face {
  font-family: "Hanken Grotesk";
  src: url("../fonts/hanken-grotesk-latin-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Hanken Grotesk";
  src: url("../fonts/hanken-grotesk-latin-500.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Hanken Grotesk";
  src: url("../fonts/hanken-grotesk-latin-600.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Hanken Grotesk";
  src: url("../fonts/hanken-grotesk-latin-700.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Commit Mono";
  src: url("../fonts/commit-mono-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Commit Mono";
  src: url("../fonts/commit-mono-700.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

/* ---- Tokens: shared ------------------------------------------------------- */
:root {
  --font-sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Commit Mono", ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  /* fixed rem scale, ratio ~1.2 (product; not fluid) */
  --text-xs: 0.75rem;    --text-sm: 0.8125rem; --text-ui: 0.875rem;
  --text-msg: 0.9375rem; --text-md: 1.0625rem; --text-lg: 1.25rem;
  --leading: 1.55; --leading-tight: 1.25;

  /* 4px spacing rhythm */
  --s1: 0.25rem; --s2: 0.5rem; --s3: 0.75rem; --s4: 1rem;
  --s5: 1.25rem; --s6: 1.5rem; --s8: 2rem;

  /* SHAPE LOCK — one radius scale, used everywhere */
  --r-panel: 14px;  --r-ctrl: 9px;  --r-inset: 7px;  --r-pill: 999px;

  /* motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-1: 120ms; --dur-2: 180ms; --dur-3: 260ms;

  /* z-index scale */
  --z-base: 1; --z-sticky: 10; --z-drawer: 500; --z-dropdown: 600;
  --z-modal: 1000; --z-toast: 1100; --z-tooltip: 1200;

  /* layout vars — driven by collapse/resize JS (persisted). canvas is the
     resizable track (drag the chat|canvas divider); rail is toggle-only. */
  --rail-w: 256px;
  --canvas-w: 620px;
  --gap: 10px;
}

/* ---- Tokens: light (default) --------------------------------------------- */
[data-theme="light"] {
  color-scheme: light;
  --app:       oklch(0.955 0.006 220);   /* tinted workspace behind the panels */
  --bg:        oklch(1 0 0);             /* panel surface (chat) */
  --surface:   oklch(0.988 0.004 220);   /* panel surface (rail/canvas chrome) */
  --surface-2: oklch(0.955 0.006 220);   /* insets, hover, code bg */
  --surface-3: oklch(0.925 0.007 220);   /* pressed */

  --border:        oklch(0.90 0.006 220);
  --border-2:      oklch(0.94 0.005 220); /* softer inner dividers */
  --border-strong: oklch(0.82 0.008 220);

  --ink:   oklch(0.24 0.012 250);
  --ink-2: oklch(0.45 0.012 250);
  --ink-3: oklch(0.52 0.012 250);

  --accent:       oklch(0.55 0.10 222);
  --accent-solid: oklch(0.50 0.11 226);
  --accent-hover: oklch(0.45 0.11 226);
  --accent-ink:   oklch(0.99 0.01 220);
  --accent-weak:  oklch(0.955 0.024 222);

  --brass:      oklch(0.55 0.09 74);
  --brass-weak: oklch(0.945 0.032 78);
  --brass-ring: oklch(0.70 0.11 78);

  --ok:   oklch(0.52 0.12 155); --ok-weak:   oklch(0.94 0.04 155);
  --warn: oklch(0.58 0.11 70);  --warn-weak: oklch(0.95 0.05 78);
  --err:  oklch(0.53 0.19 27);  --err-weak:  oklch(0.95 0.04 27);

  --shadow-1: 0 1px 2px oklch(0.2 0.03 250 / 0.05), 0 2px 6px oklch(0.2 0.03 250 / 0.05);
  --shadow-2: 0 8px 24px oklch(0.2 0.03 250 / 0.10), 0 2px 8px oklch(0.2 0.03 250 / 0.06);
}

/* ---- Tokens: dark -------------------------------------------------------- */
[data-theme="dark"] {
  color-scheme: dark;
  --app:       oklch(0.145 0.008 250);
  --bg:        oklch(0.195 0.009 250);
  --surface:   oklch(0.185 0.009 250);
  --surface-2: oklch(0.235 0.010 250);
  --surface-3: oklch(0.275 0.011 250);

  --border:        oklch(0.30 0.011 250);
  --border-2:      oklch(0.25 0.010 250);
  --border-strong: oklch(0.40 0.013 250);

  --ink:   oklch(0.955 0.004 250);
  --ink-2: oklch(0.74 0.008 250);
  --ink-3: oklch(0.62 0.009 250);

  --accent:       oklch(0.74 0.11 216);
  --accent-solid: oklch(0.70 0.12 216);
  --accent-hover: oklch(0.77 0.12 216);
  --accent-ink:   oklch(0.17 0.02 250);
  --accent-weak:  oklch(0.31 0.05 220);

  --brass:      oklch(0.80 0.10 80);
  --brass-weak: oklch(0.33 0.05 74);
  --brass-ring: oklch(0.78 0.11 78);

  --ok:   oklch(0.78 0.13 158); --ok-weak:   oklch(0.33 0.06 158);
  --warn: oklch(0.82 0.12 82);  --warn-weak: oklch(0.35 0.06 78);
  --err:  oklch(0.70 0.17 27);  --err-weak:  oklch(0.33 0.08 27);

  --shadow-1: 0 1px 2px oklch(0 0 0 / 0.35), 0 2px 8px oklch(0 0 0 / 0.30);
  --shadow-2: 0 10px 30px oklch(0 0 0 / 0.50), 0 3px 10px oklch(0 0 0 / 0.40);
}

/* ---- Reset / base -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body {
  height: 100%;
  /* Native-app feel: the nav surfaces are the fixed anchor. Disable pinch-zoom
     (pan only), kill rubber-band overscroll, and never allow the document itself
     to scroll or overflow sideways — inner panes own their own scrolling. Pinch
     therefore can't reflow the shell or expose horizontal overflow. */
  touch-action: pan-x pan-y;
  overscroll-behavior: none;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font-sans);
  font-size: var(--text-ui);
  font-optical-sizing: auto;
  line-height: var(--leading);
  color: var(--ink);
  background: var(--app);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overflow-x: hidden;
  /* Double-tap shouldn't zoom either — buttons/tabs feel instant like an app. */
  touch-action: pan-x pan-y;
}
[hidden] { display: none !important; } /* author display:* otherwise beats the UA hidden rule */
dialog:not([open]) { display: none !important; } /* author dialog display rules must not reveal closed modals */
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-inset); }
::selection { background: var(--accent-weak); }
svg { display: block; }

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: var(--r-pill); border: 3px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Shared panel material (the floating-surface look) */
.panel { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-panel); box-shadow: var(--shadow-1); }

/* ============================================================================
   Shell — panels floating on the tinted workspace, separated by --gap
   grid columns are var-driven so collapse/resize just animate the tracks.
   ============================================================================ */
.app-shell {
  display: grid;
  height: 100dvh;
  padding: var(--gap);
  gap: var(--gap);
  /* canvas is minmax(0, …) so it yields width when the viewport is too tight for
     all three tracks (between the 1080px overlay breakpoint and the ~1236px the
     three columns naturally need) instead of overflowing and colliding. */
  grid-template-columns: var(--rail-w) minmax(320px, 1fr) minmax(0, var(--canvas-w));
  grid-template-rows: 48px minmax(0, 1fr) 52px;
  grid-template-areas:
    "topbar topbar  topbar"
    "nav    stream  canvas"
    "ledger ledger  ledger";
  transition: grid-template-columns var(--dur-3) var(--ease);
}
.app-shell[data-rail="collapsed"]   { --rail-w: 0px; }
.app-shell[data-canvas="collapsed"] { --canvas-w: 0px; }

.topbar         { grid-area: topbar; }
.stream-switcher{ grid-area: nav; }
.context-stream { grid-area: stream; }
.co-op-canvas   { grid-area: canvas; }
.ledger-slider  { grid-area: ledger; }

/* a pane collapsed to 0 width shouldn't paint/overflow */
.app-shell[data-rail="collapsed"] .stream-switcher,
.app-shell[data-canvas="collapsed"] .co-op-canvas { opacity: 0; pointer-events: none; border-width: 0; }

/* ============================================================================
   Top bar (transparent strip on the workspace)
   ============================================================================ */
.topbar { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2); min-width: 0; }
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 650; letter-spacing: -0.01em; font-size: var(--text-md); min-width: 0; }
.brand__mark { width: 24px; height: 24px; border-radius: 8px; background: var(--accent-solid); color: var(--accent-ink); display: grid; place-items: center; font-size: 12px; font-weight: 700; letter-spacing: 0; }
.topbar__spacer { flex: 1 1 auto; min-width: 0; }

.agent-status { display: inline-flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s3); background: var(--brass-weak); color: var(--brass); border-radius: var(--r-pill); font-size: var(--text-xs); font-weight: 560; }
.agent-status .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.6s var(--ease) infinite; }

.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -7px; box-shadow: 0 0 0 2px var(--app); }
.avatar-stack .avatar:first-child { margin-left: 0; }

.icon-btn { width: 32px; height: 32px; flex: 0 0 32px; border-radius: var(--r-ctrl); display: grid; place-items: center; color: var(--ink-2); transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { transform: translateY(0.5px); }
.icon-btn[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); }

/* ============================================================================
   Avatars  (humans = round · agents = squircle brass)
   ============================================================================ */
.avatar { --sz: 26px; width: var(--sz); height: var(--sz); border-radius: 50%; display: inline-grid; place-items: center; flex: none; font-size: calc(var(--sz) * 0.42); font-weight: 620; color: #fff; background: var(--accent-solid); position: relative; }
.avatar--agent { border-radius: 34%; background: var(--brass-weak); color: var(--brass); font-weight: 700; }
.avatar[data-online]::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 2px var(--bg); }
.avatar[data-online="idle"]::after { background: var(--warn); }

/* ============================================================================
   Stream switcher (rail)
   ============================================================================ */
.stream-switcher { overflow: hidden auto; padding: var(--s3) var(--s2); display: flex; flex-direction: column; gap: 2px; transition: opacity var(--dur-2) var(--ease); }
.rail-label { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em; color: var(--ink-3); padding: var(--s3) var(--s3) var(--s2); display: flex; align-items: center; justify-content: space-between; }
.stream-item { display: flex; align-items: center; gap: var(--s2); width: 100%; text-align: left; padding: var(--s2) var(--s3); border-radius: var(--r-ctrl); color: var(--ink-2); font-size: var(--text-ui); min-height: 34px; transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.stream-item:hover { background: var(--surface-2); color: var(--ink); }
.stream-item[aria-current="true"] { background: var(--accent-weak); color: var(--ink); font-weight: 560; }
.stream-item .hash { color: var(--ink-3); font-weight: 500; }
.stream-item[aria-current="true"] .hash { color: var(--accent); }
.stream-item__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-item--archived { color: var(--ink-3); }
.rail-archive { margin-top: var(--s2); }
.rail-archive summary { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s2) var(--s3); color: var(--ink-3); font-size: var(--text-sm); border-radius: var(--r-ctrl); cursor: pointer; list-style: none; }
.rail-archive summary:hover { background: var(--surface-2); color: var(--ink-2); }
.rail-archive summary::-webkit-details-marker { display: none; }

.badge { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; font-size: var(--text-xs); font-weight: 600; line-height: 1; padding: 3px 7px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--ink-2); }
.badge--mention { background: var(--accent-solid); color: var(--accent-ink); }

.rail-person { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); font-size: var(--text-sm); color: var(--ink-2); min-height: 32px; }
.rail-person .name { flex: 1; }
.rail-person .role { font-size: var(--text-xs); color: var(--ink-3); }
.rail-btn { margin-top: var(--s1); padding: var(--s2) var(--s3); border-radius: var(--r-ctrl); color: var(--ink-2); font-size: var(--text-sm); display: flex; align-items: center; gap: var(--s2); transition: background var(--dur-1) var(--ease); }
.rail-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ============================================================================
   Context stream (chat)
   ============================================================================ */
.context-stream { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.stream-head { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s4); height: 52px; border-bottom: 1px solid var(--border-2); flex: none; }
.stream-head__title { font-size: var(--text-md); font-weight: 640; letter-spacing: -0.01em; display: flex; align-items: center; gap: var(--s2); }
.stream-head__title .hash { color: var(--ink-3); }
.stream-head__sub { font-size: var(--text-xs); color: var(--ink-3); }

/* "Catch me up" — private digest panel, anchored under the stream head */
dialog.catchup-panel { position: fixed; top: 60px; right: var(--s4); left: auto; bottom: auto; margin: 0; padding: 0; width: min(420px, 92vw); max-height: min(70vh, 560px); background: var(--bg); color: var(--ink); border: 1px solid var(--border-strong); border-radius: var(--r-panel); box-shadow: var(--shadow-2); z-index: var(--z-dropdown); overflow: hidden; display: flex; flex-direction: column; }
dialog.catchup-panel::backdrop { background: transparent; }
.catchup-panel__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border-2); flex: none; }
.catchup-panel__title { font-weight: 620; font-size: var(--text-ui); }
.catchup-panel__actions { display: flex; align-items: center; gap: var(--s1); }
.catchup-panel__body { padding: var(--s4); overflow-y: auto; font-size: var(--text-ui); color: var(--ink); line-height: var(--leading); flex: 1; min-height: 0; }
.catchup-panel__body p { margin: 0 0 var(--s3); }
.catchup-panel__body p:last-child { margin-bottom: 0; }
.catchup-panel__body ul { margin: 0 0 var(--s3); padding-left: 1.2em; }
.catchup-panel__body li { margin-bottom: var(--s1); }
.catchup-panel__body code { font-family: var(--font-mono); font-size: 0.9em; background: var(--surface-2); border-radius: 4px; padding: 1px 4px; }
.catchup-panel__body h1, .catchup-panel__body h2, .catchup-panel__body h3 { margin: 0 0 var(--s2); font-size: var(--text-md); font-weight: 640; }
.catchup-panel__loading, .catchup-panel__error { color: var(--ink-3); font-size: var(--text-ui); }
.catchup-panel__error { color: var(--err); }
.catchup-panel__foot { flex: none; padding: var(--s2) var(--s4); border-top: 1px solid var(--border-2); font-size: var(--text-xs); color: var(--ink-3); display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.catchup-panel__foot[hidden] { display: none; }
@media (max-width: 720px) {
  dialog.catchup-panel { top: 52px; right: var(--s3); left: var(--s3); width: auto; }
}

.messages { flex: 1; overflow-y: auto; padding: var(--s5) var(--s5) var(--s3); display: flex; flex-direction: column; gap: var(--s5); }
.msg { display: grid; grid-template-columns: 28px 1fr; gap: var(--s3); }
.msg .avatar { --sz: 28px; }
.msg__body { min-width: 0; padding-top: 1px; }
.msg__head { display: flex; align-items: baseline; gap: var(--s2); margin-bottom: 2px; }
.msg__author { font-weight: 620; font-size: var(--text-ui); }
.msg__author--agent { color: var(--brass); }
.msg__time { font-size: var(--text-xs); color: var(--ink-3); }
.msg__text { font-size: var(--text-msg); color: var(--ink); line-height: var(--leading); max-width: 66ch; }
.msg__text p + p { margin-top: var(--s3); }

.mention { color: var(--accent); background: var(--accent-weak); padding: 1px 6px; border-radius: var(--r-pill); font-weight: 560; font-size: 0.95em; white-space: nowrap; }
.mention--agent { color: var(--brass); background: var(--brass-weak); }

/* inline tool-status */
.tool-status { margin-top: var(--s3); max-width: 460px; display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); background: var(--surface-2); border: 1px solid var(--border-2); border-radius: var(--r-ctrl); font-size: var(--text-sm); }
.tool-status__icon { width: 16px; height: 16px; display: grid; place-items: center; color: var(--ink-3); flex: none; }
.tool-status--running .tool-status__icon { color: var(--accent); animation: spin 1s linear infinite; }
.tool-status--ok .tool-status__icon { color: var(--ok); }
.tool-status--error .tool-status__icon { color: var(--err); }
.tool-status__tool { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink); }
.tool-status__summary { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-status__spacer { flex: 1; }

/* artifact card */
.artifact-card { margin-top: var(--s3); max-width: 460px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctrl); overflow: hidden; transition: border-color var(--dur-2) var(--ease); }
.artifact-card[data-state="ready"] { border-color: var(--border-strong); }
.artifact-card__top { display: flex; align-items: center; gap: var(--s3); padding: var(--s3); }
.artifact-card__glyph { width: 32px; height: 32px; border-radius: var(--r-inset); flex: none; display: grid; place-items: center; background: var(--surface-2); color: var(--accent); }
.artifact-card__meta { min-width: 0; flex: 1; }
.artifact-card__title { font-weight: 560; font-size: var(--text-ui); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artifact-card__type { font-size: var(--text-xs); color: var(--ink-3); font-family: var(--font-mono); }
.artifact-card__progress { height: 3px; background: var(--surface-2); }
.artifact-card__bar { height: 100%; width: 0; background: var(--accent); transition: width 200ms linear; }
.artifact-card[data-state="ready"] .artifact-card__progress { display: none; }

.msg-file { margin-top: var(--s3); max-width: min(460px, 100%); display: inline-flex; align-items: center; gap: var(--s3); padding: var(--s3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctrl); color: var(--ink); }
.msg-file:hover { border-color: var(--border-strong); }
.msg-file__glyph { width: 34px; height: 34px; border-radius: var(--r-inset); flex: none; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-3); font-family: var(--font-mono); font-size: 10px; font-weight: 700; }
.msg-file__meta { min-width: 0; display: grid; gap: 2px; }
.msg-file__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 560; }
.msg-file__detail, .msg-file__caption { color: var(--ink-3); font-size: var(--text-xs); }
.msg-file__detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file--image { display: block; padding: 0; overflow: hidden; }
.msg-file__image { display: block; max-width: min(460px, 100%); max-height: 360px; object-fit: contain; background: var(--surface-2); }
.msg-file__caption { display: block; padding: var(--s2) var(--s3); }

/* buttons — controls radius, tactile :active */
.btn { display: inline-flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r-ctrl); font-size: var(--text-sm); font-weight: 560; border: 1px solid var(--border-strong); background: var(--bg); color: var(--ink); transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease); }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent-solid); color: var(--accent-ink); border-color: transparent; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--sm { padding: var(--s1) var(--s2); font-size: var(--text-xs); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.typing { display: flex; align-items: center; gap: var(--s2); color: var(--ink-3); font-size: var(--text-sm); }
.typing__dots { display: inline-flex; gap: 3px; }
.typing__dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: bounce 1.2s var(--ease) infinite; }
.typing__dots i:nth-child(2) { animation-delay: 0.15s; }
.typing__dots i:nth-child(3) { animation-delay: 0.3s; }

/* composer */
.composer { position: relative; padding: var(--s2) var(--s4) var(--s4); flex: none; }
.composer__box { display: flex; align-items: flex-end; gap: var(--s2); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-panel); padding: var(--s2); transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease); }
.composer__box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.composer__input { flex: 1; border: none; outline: none; resize: none; background: none; color: var(--ink); font: inherit; font-size: var(--text-msg); padding: var(--s1) 0; max-height: 140px; }
.composer__input::placeholder { color: var(--ink-3); }
.composer__attach { flex: none; margin-bottom: 1px; }
.composer__attach:disabled { opacity: .45; pointer-events: none; }
.composer__send { width: 34px; height: 34px; border-radius: var(--r-inset); background: var(--accent-solid); color: var(--accent-ink); display: grid; place-items: center; flex: none; transition: background var(--dur-1) var(--ease), transform var(--dur-1) var(--ease); }
.composer__send:hover { background: var(--accent-hover); }
.composer__send:active { transform: translateY(1px); }
.composer__uploads { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }
.composer__uploads:empty { display: none; }
.upload-chip { max-width: min(260px, 100%); display: inline-flex; align-items: center; gap: var(--s2); padding: 4px 8px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--text-xs); color: var(--ink-2); }
.upload-chip__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-chip__status { flex: none; color: var(--ink-3); }
.upload-chip--pending .upload-chip__status { color: var(--accent); }
.upload-chip--ok { background: var(--ok-weak); border-color: transparent; color: var(--ok); }
.upload-chip--ok .upload-chip__status { color: var(--ok); }
.upload-chip--error { background: var(--err-weak); border-color: transparent; color: var(--err); }
.upload-chip--error .upload-chip__status { color: var(--err); }
.composer__hint { margin-top: var(--s2); font-size: var(--text-xs); color: var(--ink-3); }
.composer__hint--warn { color: var(--warn); }
.composer[data-flash] .composer__box { border-color: var(--warn); animation: composer-shake var(--dur-3) var(--ease); }
.composer__hint kbd { font-family: var(--font-mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: 0.9em; }

/* @-mention popover */
.mention-menu { position: absolute; left: var(--s4); right: var(--s4); bottom: calc(100% - var(--s1)); z-index: var(--z-dropdown); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-ctrl); box-shadow: var(--shadow-2); padding: var(--s1); max-height: 180px; overflow-y: auto; }
.mention-menu__opt { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r-inset); font-size: var(--text-sm); color: var(--ink-2); cursor: pointer; }
.mention-menu__opt:hover { background: var(--surface-2); color: var(--ink); }
.mention-menu__opt[aria-selected="true"] { background: var(--accent-weak); color: var(--ink); }

@keyframes composer-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .composer[data-flash] .composer__box { animation: none; }
}

/* ============================================================================
   co-op canvas
   ============================================================================ */
.co-op-canvas { position: relative; display: flex; flex-direction: column; min-height: 0; overflow: hidden; transition: opacity var(--dur-2) var(--ease); }
.canvas__tabs { position: relative; display: flex; align-items: center; gap: 2px; padding: var(--s2) var(--s2) 0; border-bottom: 1px solid var(--border-2); flex: none; overflow-x: auto; scrollbar-width: thin; }
.canvas__new { width: 28px; height: 28px; flex: none; align-self: center; }
.canvas-tab { display: inline-flex; align-items: stretch; min-width: 0; max-width: 260px; flex: 0 1 auto; border-radius: var(--r-inset) var(--r-inset) 0 0; }
.canvas-tab--dragging { opacity: 0.45; }
.canvas-tab[data-pinned] .canvas-tab__ctl:first-of-type { color: var(--brass); background: var(--brass-weak); }
.canvas-tab[data-attention] { box-shadow: inset 0 2px 0 var(--brass); }
.viewport-tab { min-width: 0; display: inline-flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s2) var(--s2) var(--s3); border-radius: var(--r-inset) 0 0 0; color: var(--ink-2); font-size: var(--text-sm); border: 1px solid transparent; border-bottom: none; transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.viewport-tab:hover { background: var(--surface-2); color: var(--ink); }
.viewport-tab[aria-selected="true"] { background: var(--bg); color: var(--ink); border-color: var(--border-2); position: relative; }
.viewport-tab[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--bg); }
.viewport-tab__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewport-tab .kind { font-size: var(--text-xs); color: var(--ink-3); font-family: var(--font-mono); }
.viewport-tab .tab-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }
.viewport-tab .tab-dot[data-state="running"] { background: var(--warn); }
.viewport-tab .tab-dot[data-state="waiting_input"] { background: var(--brass); }
.viewport-tab .tab-dot[data-state="error"] { background: var(--err); }
.viewport-tab .tab-dot[data-state="stale"] { background: var(--ink-3); }
.canvas-tab__badge { max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-3); font-size: var(--text-xs); }
.canvas-tab__ctl { width: 24px; min-width: 24px; flex: 0 0 24px; display: grid; place-items: center; color: var(--ink-3); border-top: 1px solid transparent; border-bottom: none; }
.canvas-tab__ctl:hover { color: var(--ink); background: var(--surface-2); }
.canvas-tab:has(.viewport-tab[aria-selected="true"]) .canvas-tab__ctl { background: var(--bg); border-top-color: var(--border-2); }
.canvas-tab:has(.viewport-tab[aria-selected="true"]) .canvas-tab__ctl:last-child { border-right: 1px solid var(--border-2); border-radius: 0 var(--r-inset) 0 0; }

.canvas__toolbar { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border-2); flex: none; }
.url-chip { display: inline-flex; align-items: center; gap: var(--s2); font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-2); background: var(--surface-2); border-radius: var(--r-pill); padding: 3px var(--s3); }
.url-chip .live { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }

.canvas__stage { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.canvas__stage[data-mode="split"] { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1px; background: var(--border-2); }
.canvas__pane-wrap { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.canvas__pane-wrap[data-side="left"] { grid-column: 1; }
.canvas__pane-wrap[data-side="right"] { grid-column: 2; }
.canvas__pane-wrap[data-active="true"] .canvas__toolbar { box-shadow: inset 0 2px 0 var(--accent); }
.canvas__pane { flex: 1; min-height: 0; background: var(--bg); position: relative; border-radius: 0 0 var(--r-panel) var(--r-panel); overflow: hidden; }
.canvas__pane iframe { width: 100%; height: 100%; border: none; background: #fff; display: block; }

.code-view { height: 100%; overflow: auto; padding: var(--s4) var(--s5); font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.7; color: var(--ink); tab-size: 2; }
.code-view .ln { color: var(--ink-3); user-select: none; display: inline-block; width: 2.5ch; margin-right: var(--s3); text-align: right; }
.tok-kw { color: var(--accent); } .tok-str { color: var(--ok); } .tok-com { color: var(--ink-3); font-style: italic; } .tok-fn { color: var(--brass); }
.editor-pane { height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.editor-pane__text { flex: 1; min-height: 0; width: 100%; resize: none; border: 0; outline: 0; padding: var(--s4) var(--s5); background: var(--bg); color: var(--ink); font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.65; tab-size: 2; }
.editor-pane__text[readonly] { color: var(--ink-2); background: var(--surface); }
.editor-pane__footer { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: var(--s2); padding: var(--s2) var(--s3); border-top: 1px solid var(--border-2); background: var(--surface); }
.editor-pane__status { margin-right: auto; color: var(--ink-3); font-size: var(--text-xs); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.asset-pane { height: 100%; display: grid; place-items: center; background: radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 22px 22px; }
.asset-pane img { max-width: 90%; max-height: 90%; object-fit: contain; }
.run-pane { height: 100%; display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.run-pane__head { flex: none; display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border-2); }
.run-pane__command { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-output { flex: 1; min-height: 0; overflow: auto; margin: 0; padding: var(--s4); font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.55; color: var(--ink); white-space: pre-wrap; word-break: break-word; }

/* New-pane dropdown (W9) — anchored under the "New pane" button. */
.new-pane-menu { position: absolute; top: 100%; left: var(--s2); z-index: var(--z-dropdown); margin-top: var(--s1); min-width: 168px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-ctrl); box-shadow: var(--shadow-2); padding: var(--s1); display: flex; flex-direction: column; }
.new-pane-menu__item { text-align: left; padding: var(--s2) var(--s3); border-radius: var(--r-inset); font-size: var(--text-sm); color: var(--ink-2); }
.new-pane-menu__item:hover, .new-pane-menu__item:focus-visible { background: var(--surface-2); color: var(--ink); }

/* Browser pane (W7) — URL bar + iframe + blocked-frame fallback. */
.browser-pane { height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.browser-pane__bar { flex: none; display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border-2); background: var(--surface); }
.browser-pane__url { flex: 1; min-width: 0; padding: 5px var(--s3); border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--bg); color: var(--ink); font-family: var(--font-mono); font-size: var(--text-xs); }
.browser-pane__frame { flex: 1; min-height: 0; position: relative; }
.browser-pane__frame iframe { width: 100%; height: 100%; border: none; background: #fff; display: block; }
.browser-pane__blocked { height: 100%; display: grid; place-items: center; gap: var(--s3); text-align: center; padding: var(--s5); color: var(--ink-2); }
.browser-pane__blocked a { color: var(--accent); }

/* Line-mode terminal (W8 fallback — no vendorable xterm build, no sandboxed PTY
   yet; see co-op-canvas.js module docs). */
.terminal-pane { height: 100%; min-height: 0; display: flex; flex-direction: column; background: #17181b; color: #d8dae0; }
.terminal-pane__label { flex: none; padding: var(--s1) var(--s3); font-size: var(--text-xs); color: var(--ink-3); background: var(--surface); border-bottom: 1px solid var(--border-2); }
.terminal-pane__scrollback { flex: 1; min-height: 0; overflow: auto; margin: 0; padding: var(--s3) var(--s4); font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.terminal-pane__input-row { flex: none; display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s4); border-top: 1px solid #2a2c31; }
.terminal-pane__prompt { color: #7ee787; font-family: var(--font-mono); }
.terminal-pane__input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; color: inherit; font-family: var(--font-mono); font-size: var(--text-sm); }
/* Standard 16-color ANSI foregrounds — a terminal's palette is a protocol
   convention, not a co-op brand token, so these are literal rather than mapped
   onto --accent/--ok/--err. */
.ansi-bold { font-weight: 700; }
.ansi-fg-30 { color: #6b7280; } .ansi-fg-90 { color: #9aa1ac; }
.ansi-fg-31 { color: #f07178; } .ansi-fg-91 { color: #ff8b92; }
.ansi-fg-32 { color: #7ee787; } .ansi-fg-92 { color: #9dffb0; }
.ansi-fg-33 { color: #e5c07b; } .ansi-fg-93 { color: #ffe08a; }
.ansi-fg-34 { color: #7aa2f7; } .ansi-fg-94 { color: #9ec2ff; }
.ansi-fg-35 { color: #c792ea; } .ansi-fg-95 { color: #e0b0ff; }
.ansi-fg-36 { color: #56d4dd; } .ansi-fg-96 { color: #8be9e6; }
.ansi-fg-37 { color: #d8dae0; } .ansi-fg-97 { color: #ffffff; }

/* drag-resize handle on the canvas's left edge (the chat|canvas divider) */
.resize-handle { position: absolute; left: 0; top: 0; bottom: 0; width: 10px; cursor: col-resize; z-index: var(--z-sticky); display: grid; place-items: center; }
.resize-handle::before { content: ""; width: 3px; height: 44px; border-radius: var(--r-pill); background: var(--border-strong); opacity: 0; transition: opacity var(--dur-1) var(--ease); }
.resize-handle:hover::before, .app-shell[data-resizing] .resize-handle::before { opacity: 1; }
.app-shell[data-resizing] { cursor: col-resize; user-select: none; }
.app-shell[data-resizing] .app-shell, .app-shell[data-resizing] * { transition: none !important; }

/* ============================================================================
   Ledger slider (Time Machine)
   ============================================================================ */
/* position:relative anchors the absolute peek banner/ticks. It lives on the base
   rule (not source-after the media queries) so the mobile `position: fixed`
   overlay still wins — otherwise the ledger stays in grid flow on mobile,
   referencing a grid-area absent from the phone template, and spawns implicit
   columns that squeeze the chat/composer to ~half width. */
.ledger-slider { position: relative; display: flex; align-items: center; gap: var(--s4); padding: 0 var(--s4); }
.ledger__label { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--text-sm); color: var(--ink-2); font-weight: 560; flex: none; }
.ledger__track { flex: 1; height: 28px; position: relative; display: flex; align-items: center; }
.ledger__line { position: absolute; inset: auto 0; height: 2px; background: var(--border-strong); border-radius: var(--r-pill); }
.ledger__fill { position: absolute; left: 0; height: 2px; background: var(--accent); border-radius: var(--r-pill); }
.tick { position: absolute; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; background: var(--ink-3); cursor: pointer; transition: transform var(--dur-1) var(--ease); }
.tick--event { width: 8px; height: 8px; }
.tick--commit { width: 13px; height: 13px; background: var(--accent); border: 2px solid var(--bg); }
.tick--invalid { background: var(--surface-3); }
.tick:hover { transform: translate(-50%, -50%) scale(1.35); }
.tick--now { width: 3px; height: 20px; border-radius: 2px; background: var(--brass); transform: translate(-50%, -50%); }
.ledger__actions { display: flex; gap: var(--s2); flex: none; }

/* ============================================================================
   Mobile — bottom tab bar + drawers (hidden on desktop)
   ============================================================================ */
.mobilebar, .drawer-scrim { display: none; }

/* ============================================================================
   Animations
   ============================================================================ */
@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes drawer-in { from { transform: translateX(-100%); } to { transform: translateX(0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ============================================================================
   Responsive
   ---------------------------------------------------------------------------- */
/* Tablet: canvas becomes an overlay drawer, not an inline column.
   A drawer RESTS CLOSED: visibility here is its own axis (data-canvas="open"),
   not the desktop collapse flag — keying it to "not collapsed" (the default)
   left the drawer sitting over chat+rail across the whole 721–1080 range, and
   over the phone timeline view (no mview rule selects the canvas there).
   opacity stays 1 so it slides out rather than fades. */
@media (max-width: 1080px) {
  .app-shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); grid-template-areas: "topbar topbar" "nav stream" "ledger ledger"; }
  .co-op-canvas { position: fixed; inset: 56px var(--gap) 64px auto; width: min(560px, 84vw); z-index: var(--z-drawer); box-shadow: var(--shadow-2); transform: translateX(calc(100% + var(--gap) * 2)); transition: transform var(--dur-3) var(--ease); pointer-events: none; }
  .app-shell[data-canvas="open"] .co-op-canvas { transform: translateX(0); pointer-events: auto; }
  .resize-handle { display: none; }
}

/* Mobile: one pane at a time, bottom tab bar switches views, rail is a drawer */
@media (max-width: 720px) {
  body { overflow: hidden; }
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 48px minmax(0, 1fr) 56px;
    grid-template-areas: "topbar" "stream" "mobilebar";
    padding: max(var(--gap), env(safe-area-inset-top)) max(var(--gap), env(safe-area-inset-right)) env(safe-area-inset-bottom) max(var(--gap), env(safe-area-inset-left));
    max-width: 100vw; overflow: hidden;
  }
  /* declutter + prevent overflow on phone */
  .topbar { overflow: hidden; gap: var(--s2); padding: 0; }
  .brand { white-space: nowrap; flex: 0 1 auto; overflow: hidden; }
  .brand__mark { flex: 0 0 24px; }
  .topbar > .badge, .agent-status { display: none; }
  .messages { overflow-x: hidden; padding: var(--s4) var(--s4) var(--s2); }
  .msg, .msg__body { min-width: 0; }
  .tool-status, .artifact-card { max-width: 100%; }
  .composer { padding: var(--s2) var(--s4) var(--s4); }
  .stream-switcher { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: var(--z-drawer); background: var(--bg); border: 1px solid var(--border); border-radius: 0 var(--r-panel) var(--r-panel) 0; box-shadow: var(--shadow-2); transform: translateX(-102%); transition: transform var(--dur-3) var(--ease); opacity: 1; pointer-events: auto; }
  .app-shell[data-drawer="open"] .stream-switcher { transform: translateX(0); }
  .app-shell[data-drawer="open"] .drawer-scrim { display: block; position: fixed; inset: 0; background: oklch(0 0 0 / 0.4); z-index: calc(var(--z-drawer) - 1); }

  .context-stream { grid-area: stream; }
  .co-op-canvas { position: fixed; inset: 48px var(--gap) 56px var(--gap); width: auto; z-index: var(--z-drawer); }
  .canvas__stage[data-mode="split"] { display: flex; background: var(--bg); }
  .canvas__stage[data-mode="split"] .canvas__pane-wrap:not([data-active="true"]) { display: none; }

  /* which pane shows is driven by data-mview */
  .app-shell[data-mview="chat"]   .co-op-canvas { transform: translateY(calc(100% + 80px)); pointer-events: none; }
  .app-shell[data-mview="canvas"] .co-op-canvas { transform: translateY(0); pointer-events: auto; opacity: 1; }

  .ledger-slider { position: fixed; inset: auto var(--gap) 64px var(--gap); z-index: var(--z-drawer); background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-panel); box-shadow: var(--shadow-2); height: 52px; transform: translateY(calc(100% + 80px)); transition: transform var(--dur-3) var(--ease); }
  .app-shell[data-mview="timeline"] .ledger-slider { transform: translateY(0); }

  /* bottom tab bar */
  .mobilebar { grid-area: mobilebar; display: flex; align-items: stretch; justify-content: space-around; gap: var(--s1); background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-panel); box-shadow: var(--shadow-1); margin-bottom: var(--gap); }
  .mtab { flex: 1; display: grid; place-items: center; gap: 2px; padding: var(--s1); color: var(--ink-3); font-size: 10px; font-weight: 560; border-radius: var(--r-ctrl); }
  .mtab[aria-current="true"] { color: var(--accent); }
  .mtab svg { width: 20px; height: 20px; }
}
@media (min-width: 721px) { .mobilebar, .drawer-scrim { display: none !important; } }

/* ============================================================================
   App-shell states & component chrome (additive — tokens only, shape-locked)
   ============================================================================ */
/* responsive visibility helpers (hamburger vs rail/canvas toggles) */
.mobile-only { display: none; }
@media (max-width: 720px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: grid; }
}

/* optimistic (unacknowledged) messages */
.msg[data-pending] { opacity: 0.55; }
.msg[data-pending="stalled"] .msg__time { color: var(--warn); }

/* first-visit join dialog (native <dialog> on the tinted workspace) */
dialog.join-dialog { margin: auto; padding: var(--s6); width: min(360px, 90vw); color: var(--ink); }
.join-dialog::backdrop { background: oklch(0 0 0 / 0.4); }
.join-dialog__form { display: flex; flex-direction: column; gap: var(--s4); }
.join-dialog__lead { color: var(--ink-2); font-size: var(--text-ui); }
.join-dialog__input { font: inherit; font-size: var(--text-msg); color: var(--ink); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-ctrl); padding: var(--s2) var(--s3); }
.join-dialog__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.join-dialog__go { justify-content: center; }

/* auth gate additions (claim / login / invite screens share the join dialog) */
.join-dialog__error { min-height: 1.2em; margin: 0; color: var(--err); font-size: var(--text-sm); }
.join-dialog__error:empty { display: none; }
.join-dialog__hint { margin: 0; color: var(--ink-3); font-size: var(--text-sm); }
.join-dialog__hint a { color: var(--accent); }
.join-dialog__copy, .join-dialog__guest { justify-content: center; }
.login-code { display: block; padding: var(--s3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-inset); font-family: var(--font-mono); font-size: var(--text-md); letter-spacing: 0.08em; text-align: center; user-select: all; }
.login-code-input { font-family: var(--font-mono); letter-spacing: 0.06em; text-align: center; }
.invite-role { align-self: center; }

/* ---- Settings surface (dense two-pane dialog) ----------------------------- */
/* `height` (not just `max-height`) gives the flex column a DEFINITE main size so
   the `flex: 1; min-height: 0` grid below resolves to a real height. Older WebKit
   (Safari) collapses a min-height:0 flex child to zero when the flex container's
   height is indefinite — which showed the panel as a bare header, nav+body gone. */
dialog.settings { margin: auto; padding: 0; width: min(720px, 94vw); height: min(560px, 88vh); color: var(--ink); display: flex; flex-direction: column; overflow: hidden; }
dialog.settings::backdrop { background: oklch(0 0 0 / 0.4); }
.settings__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-width: 0; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border-2); }
.settings__title { font-weight: 600; font-size: var(--text-ui); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings__close { margin-left: auto; }
.settings__grid { display: grid; grid-template-columns: 168px 1fr; flex: 1; min-height: 0; }
.settings__nav { display: flex; flex-direction: column; gap: 2px; padding: var(--s3); border-right: 1px solid var(--border-2); background: var(--surface); overflow-y: auto; }
.settings__nav-item { font: inherit; font-size: var(--text-ui); color: var(--ink-2); text-align: left; background: none; border: none; border-radius: var(--r-inset); padding: var(--s2) var(--s3); cursor: pointer; }
.settings__nav-item:hover { background: var(--surface-2); }
.settings__nav-item[aria-current="true"] { background: var(--accent-weak); color: var(--ink); font-weight: 560; }
.settings__body { padding: var(--s4); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s3); }
.settings__heading { margin: 0 0 var(--s2); font-size: var(--text-md); font-weight: 600; }
.settings__subheading { margin: var(--s3) 0 0; font-size: var(--text-ui); font-weight: 600; color: var(--ink-2); }
.settings__row { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s2) 0; border-bottom: 1px solid var(--border-2); }
.settings__row:last-child { border-bottom: none; }
.settings__row-label { font-size: var(--text-ui); min-width: 0; }
.settings__row-hint { color: var(--ink-3); font-size: var(--text-sm); margin-top: 2px; }
.settings__row-control { display: flex; align-items: center; gap: var(--s2); flex-shrink: 0; }
.settings__row-control--badge-stack { display: grid; justify-items: end; gap: var(--s1); min-width: 0; max-width: min(220px, 45%); flex-shrink: 1; }
.settings__row-control--badge-stack .badge { line-height: 1.2; text-align: right; }
.settings__member-id { display: flex; align-items: center; gap: var(--s2); }
.settings__input { font: inherit; font-size: var(--text-ui); color: var(--ink); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-ctrl); padding: var(--s1) var(--s2); width: 180px; }
.settings__input--sm { width: 90px; }
.settings__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.settings__select { font: inherit; font-size: var(--text-sm); color: var(--ink); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-ctrl); padding: var(--s1) var(--s2); }
.settings__textarea { font: inherit; font-size: var(--text-ui); color: var(--ink); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-ctrl); padding: var(--s2); width: 100%; min-height: 84px; resize: vertical; }
.settings__textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.settings__textarea:disabled { color: var(--ink-2); background: var(--surface-2); resize: none; }
.settings__hue { accent-color: var(--accent); width: 160px; }
.settings__check { display: inline-flex; align-items: center; gap: var(--s1); font-size: var(--text-sm); color: var(--ink-2); }
.settings__danger { color: var(--err); border-color: var(--err-weak); }
.settings__danger:hover { background: var(--err-weak); }
.settings__blocked { color: var(--warn); background: var(--warn-weak); }

/* backing-repo chip in the stream head */
.repo-chip { display: inline-flex; align-items: center; gap: var(--s1); font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 2px var(--s2); cursor: pointer; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.repo-chip:hover { background: var(--surface-3); }
.repo-chip[data-dirty="1"]::after { content: ""; width: 6px; height: 6px; border-radius: var(--r-pill); background: var(--warn); flex-shrink: 0; }
@media (max-width: 720px) { .repo-chip { max-width: 120px; } }

/* empty-stream "what next" card */
.empty-state { align-self: center; margin: auto; max-width: 380px; text-align: center; padding: var(--s6); background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r-panel); }
.empty-state__head { font-weight: 600; font-size: var(--text-md); margin-bottom: var(--s2); }
.empty-state__lead { color: var(--ink-2); font-size: var(--text-ui); margin: 0 0 var(--s4); }
.empty-state__actions { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: center; }

/* rail hint rows (e.g. zero-agent state) */
.rail-person--hint { font: inherit; font-size: var(--text-sm); color: var(--ink-3); background: none; border: none; cursor: pointer; text-align: left; padding: var(--s1) var(--s2); border-radius: var(--r-inset); }
.rail-person--hint:hover { background: var(--surface-2); color: var(--ink-2); }

/* interactive rail rows — agents mention the composer on click */
.rail-person--btn { font: inherit; width: 100%; background: none; border: none; cursor: pointer; text-align: left; border-radius: var(--r-inset); transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.rail-person--btn:hover { background: var(--surface-2); color: var(--ink); }
.settings__note { color: var(--ink-2); font-size: var(--text-ui); background: var(--surface-2); border-radius: var(--r-inset); padding: var(--s3); }
.settings__error { color: var(--err); font-size: var(--text-ui); }
.settings__invite-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); padding-top: var(--s2); }
.settings__invite-link { display: flex; flex-direction: column; gap: var(--s2); }
.settings__invite-url { font-size: var(--text-xs); text-align: left; word-break: break-all; user-select: all; }
.repo-browser { width: min(560px, 94vw); }
.repo-browser__path { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); word-break: break-all; }
.repo-browser__roots { display: flex; flex-wrap: wrap; gap: var(--s2); }
.repo-browser__list { min-height: 160px; max-height: min(46vh, 360px); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s1); border: 1px solid var(--border-2); border-radius: var(--r-inset); padding: var(--s1); background: var(--surface); }
.repo-browser__row { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s1) var(--s2); text-align: left; padding: var(--s2); border-radius: var(--r-inset); }
.repo-browser__row:hover { background: var(--surface-2); }
.repo-browser__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 560; }
.repo-browser__hint { grid-column: 1 / -1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); }

@media (max-width: 720px) {
  dialog.settings { width: 100dvw; max-width: none; height: 100dvh; max-height: none; border-radius: 0; }
  .settings__head { padding: max(var(--s3), env(safe-area-inset-top)) max(var(--s4), env(safe-area-inset-right)) var(--s3) max(var(--s4), env(safe-area-inset-left)); }
  .settings__grid { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .settings__nav { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border-2); }
  .settings__nav-item { white-space: nowrap; }
  .settings__body { padding-bottom: max(var(--s4), env(safe-area-inset-bottom)); }
  .settings__row { flex-wrap: wrap; }
}

/* quiet empty state used by panes awaiting their milestone */
.pane-empty { flex: 1; min-height: 0; display: grid; place-items: center; color: var(--ink-3); font-size: var(--text-sm); text-align: center; padding: var(--s6); }
.pane-empty svg { margin: 0 auto var(--s3); opacity: 0.6; }

/* ---- Time Machine (real scrubber) ---------------------------------------- */
/* .ledger-slider is position:relative via its base rule (kept there so the mobile
   `position: fixed` overlay wins the cascade). */
.ledger__ticks { display: contents; } /* ticks position against .ledger__track */
.ledger__track:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: var(--r-inset); }

/* rollback / fork markers — the branch story beats */
.tick--branch { width: 11px; height: 11px; background: var(--bg); border: 2px solid var(--warn); }

/* the peek cursor — a hollow accent ring riding the playhead */
.tick--cursor { width: 15px; height: 15px; background: var(--bg); border: 2px solid var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); z-index: var(--z-sticky); }

/* ticks after the peek cursor are the future-that-may-be-archived */
.tick[data-future] { opacity: 0.35; }

/* floating peek banner above the strip — right-anchored over the Peek/Restore
   actions it belongs to, so it never overlaps the chat composer/hints (which sit
   centre-left, just above the full-width ledger strip). */
.ledger__banner { position: absolute; bottom: calc(100% + 8px); right: 0; max-width: calc(100% - var(--s4)); display: flex; align-items: center; gap: var(--s3); background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-pill); box-shadow: var(--shadow-2); padding: var(--s2) var(--s4); font-size: var(--text-sm); color: var(--ink-2); white-space: nowrap; z-index: var(--z-dropdown); }
.ledger__banner span { overflow: hidden; text-overflow: ellipsis; }

.ledger__confirm-actions { display: flex; gap: var(--s2); justify-content: flex-end; }

/* chat messages newer than the peeked moment dim out */
.msg[data-future] { opacity: 0.35; }

/* a live agent turn: growing text with a quiet accent caret */
.msg--streaming .msg__text::after { content: "▍"; color: var(--accent); animation: pulse 1.1s var(--ease) infinite; }

/* cowork plan-approval card */
.approval { margin-top: var(--s3); max-width: 460px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-ctrl); overflow: hidden; }
.approval__head { padding: var(--s3); font-weight: 560; font-size: var(--text-ui); border-bottom: 1px solid var(--border-2); }
.approval__plan { padding: var(--s3); margin: 0; font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.6; color: var(--ink-2); white-space: pre-wrap; max-height: 220px; overflow: auto; }
.approval__actions { display: flex; gap: var(--s2); justify-content: flex-end; padding: var(--s2) var(--s3) var(--s3); }
.approval[data-decided="approved"] .approval__head { color: var(--ok); }
.approval[data-decided="rejected"] .approval__head { color: var(--ink-3); }
.approval[data-decided] .approval__plan { opacity: 0.6; }
