/* PDD Phone — design system v1 (Sat Oct 24).
   One file. Every page links it. No build, no fonts to download.
   Sections: 1 tokens · 2 base · 3 app frame · 4 lists and rows · 5 status · 6 chips and badges
   7 buttons · 8 segmented tabs · 9 cards · 10 banners and toasts · 11 sheets · 12 forms
   13 chat · 14 terminal and keys · 15 timeline · 16 empty states · 17 helpers */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  color-scheme: light dark;

  /* surfaces (light) */
  --bg: #f2f2f7;            /* page: iOS grouped background */
  --bg-elev: #ffffff;       /* lists, cards, sheets */
  --bg-elev-2: #f7f7fa;     /* nested, pressed rows */
  --fill: rgba(118,118,128,.12);   /* inputs, segmented track, quiet buttons */
  --fill-2: rgba(118,118,128,.07);
  --bar: rgba(249,249,251,.82);    /* nav bar and tab bar, with blur */
  --scrim: rgba(0,0,0,.32);

  /* text */
  --text: #0b0b0f;
  --text-2: #5f5f68;        /* secondary: project, branch, last line */
  --text-3: #8e8e96;        /* tertiary: ages, captions */
  --sep: rgba(60,60,67,.16);
  --sep-strong: rgba(60,60,67,.29);

  /* brand and accent */
  --brand: #0a0a23;         /* logo navy */
  --accent: #0a63f6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(10,99,246,.11);

  /* status (shape + color, never color alone) */
  --green: #1a9a48;  --green-soft: rgba(26,154,72,.12);    /* working, online, done */
  --orange: #e25f00; --orange-soft: rgba(226,95,0,.12);    /* needs you */
  --red: #d92d20;    --red-soft: rgba(217,45,32,.10);      /* stopped, failed, not delivered */
  --amber: #a86400;  --amber-soft: rgba(214,140,0,.14);    /* stale data, offline age */
  --gray: #8e8e93;   --gray-soft: rgba(142,142,147,.14);   /* idle, offline, skipped */
  --blue: var(--accent); --blue-soft: var(--accent-soft);  /* updating, current step */

  /* agent kinds: monogram tiles, not vendor logos */
  --codex: #111827;  --codex-ink: #ffffff;
  --claude: #c8643b; --claude-ink: #ffffff;

  /* terminal: dark in both themes */
  --term-bg: #0d1117;
  --term-fg: #d6dde6;
  --term-dim: #7d8794;
  --term-green: #56d364;
  --term-yellow: #e3b341;
  --term-cyan: #56c2d6;
  --term-red: #ff7b72;

  /* type scale (iOS sizes) */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --t-large: 700 32px/38px var(--font-display);   /* page title */
  --t-title: 700 22px/28px var(--font-display);   /* sheet and section hero */
  --t-title3: 600 20px/25px var(--font-display);
  --t-head: 600 17px/22px var(--font);            /* row title, buttons */
  --t-body: 400 17px/23px var(--font);
  --t-callout: 400 16px/21px var(--font);
  --t-sub: 400 15px/20px var(--font);             /* row second line */
  --t-foot: 400 13px/18px var(--font);            /* meta, section header */
  --t-cap: 500 12px/16px var(--font);             /* chips, badges */

  /* spacing: 4 pt grid */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;
  --gutter: 16px;

  /* shape */
  --r-sm: 8px; --r: 12px; --r-lg: 16px; --r-xl: 22px; --r-pill: 999px;
  --hit: 44px;                     /* smallest tap target */
  --shadow-1: 0 1px 2px rgba(0,0,0,.05), 0 1px 1px rgba(0,0,0,.03);
  --shadow-2: 0 8px 28px rgba(0,0,0,.14), 0 2px 6px rgba(0,0,0,.06);

  /* motion */
  --ease: cubic-bezier(.2,.8,.2,1);
  --fast: 160ms; --med: 280ms;

  /* safe areas */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --nav-h: 44px;
  --tab-h: 50px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --bg-elev-2: #2c2c2e;
    --fill: rgba(118,118,128,.24);
    --fill-2: rgba(118,118,128,.14);
    --bar: rgba(22,22,24,.78);
    --scrim: rgba(0,0,0,.55);
    --text: #f5f5f7;
    --text-2: #a1a1aa;
    --text-3: #6e6e76;
    --sep: rgba(84,84,88,.55);
    --sep-strong: rgba(120,120,128,.6);
    --accent: #4c8dff; --accent-ink: #ffffff; --accent-soft: rgba(76,141,255,.18);
    --green: #32d15d;  --green-soft: rgba(50,209,93,.16);
    --orange: #ff9f0a; --orange-soft: rgba(255,159,10,.17);
    --red: #ff453a;    --red-soft: rgba(255,69,58,.16);
    --amber: #ffb340;  --amber-soft: rgba(255,179,64,.15);
    --gray: #8e8e93;   --gray-soft: rgba(142,142,147,.2);
    --codex: #f5f5f7;  --codex-ink: #0b0b0f;
    --claude: #d97a52;
    --shadow-1: 0 0 0 0 transparent;  /* not "none": it is used inside shadow lists */
    --shadow-2: 0 10px 36px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --bg-elev-2: #2c2c2e;
  --fill: rgba(118,118,128,.24);
  --fill-2: rgba(118,118,128,.14);
  --bar: rgba(22,22,24,.78);
  --scrim: rgba(0,0,0,.55);
  --text: #f5f5f7;
  --text-2: #a1a1aa;
  --text-3: #6e6e76;
  --sep: rgba(84,84,88,.55);
  --sep-strong: rgba(120,120,128,.6);
  --accent: #4c8dff; --accent-ink: #ffffff; --accent-soft: rgba(76,141,255,.18);
  --green: #32d15d;  --green-soft: rgba(50,209,93,.16);
  --orange: #ff9f0a; --orange-soft: rgba(255,159,10,.17);
  --red: #ff453a;    --red-soft: rgba(255,69,58,.16);
  --amber: #ffb340;  --amber-soft: rgba(255,179,64,.15);
  --gray: #8e8e93;   --gray-soft: rgba(142,142,147,.2);
  --codex: #f5f5f7;  --codex-ink: #0b0b0f;
  --claude: #d97a52;
  --shadow-1: 0 0 0 0 transparent;  /* not "none": it is used inside shadow lists */
  --shadow-2: 0 10px 36px rgba(0,0,0,.6);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: var(--t-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
[data-when]:not([data-on]) { display: none !important; }  /* kit.js turns on the elements of the current ?state= */
svg.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 17px; height: 17px; }
svg.i.xs { width: 14px; height: 14px; stroke-width: 2.2; }
svg.i.lg { width: 28px; height: 28px; }
svg.i.xl { width: 44px; height: 44px; stroke-width: 1.6; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 3. App frame ------------------------------------------------------------- */
/* .app is the phone. On a wide screen it stays phone width, centred. */
.app {
  position: relative;
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}
@media (min-width: 600px) {
  body { background: var(--fill-2); }
  .app { box-shadow: 0 0 0 1px var(--sep), var(--shadow-2); }
}

/* top bar: back on the left, small title in the middle, actions on the right */
.nav {
  position: sticky; top: 0; z-index: 20;
  padding-top: var(--safe-t);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid transparent;
}
.nav.scrolled, .nav.solid { border-bottom-color: var(--sep); }
.nav-row {
  height: var(--nav-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 var(--s2);
}
.nav-title { font: var(--t-head); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.nav-left { display: flex; justify-content: flex-start; }
.nav-right { display: flex; justify-content: flex-end; gap: var(--s1); }
.nav-btn {
  min-width: var(--hit); height: var(--hit);
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  color: var(--accent); font: var(--t-body); padding: 0 var(--s2); border-radius: var(--r);
}
.nav-btn:active { opacity: .5; }
.nav-btn.back { padding-left: 0; }
.nav-btn.back svg { width: 26px; height: 26px; stroke-width: 2.3; }

/* large page title, scrolls with the page */
.page-head { padding: var(--s2) var(--gutter) var(--s3); }
.page-head h1 { margin: 0; font: var(--t-large); letter-spacing: -.02em; }
.page-head .sub { margin-top: 2px; font: var(--t-sub); color: var(--text-2); }
.page-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s3); }

/* page body */
.content { padding: 0 0 calc(var(--tab-h) + var(--safe-b) + var(--s10)); }
.content.no-tabbar { padding-bottom: calc(var(--safe-b) + var(--s8)); }

/* bottom tab bar */
.tabbar {
  position: fixed; z-index: 30; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(100%, 430px);
  padding: 0 var(--s2) var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep);
}
.tab {
  position: relative; height: var(--tab-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-3); font: 500 10.5px/12px var(--font);
}
.tab svg.i { width: 25px; height: 25px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab .badge { position: absolute; top: 4px; left: calc(50% + 6px); }

/* floating primary action, above the tab bar, in thumb reach */
.fab {
  position: fixed; z-index: 25;
  right: max(var(--gutter), calc(50% - 215px + var(--gutter)));
  bottom: calc(var(--tab-h) + var(--safe-b) + var(--s3));
  height: 50px; padding: 0 var(--s5) 0 var(--s4);
  display: inline-flex; align-items: center; gap: var(--s2);
  border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-ink);
  font: var(--t-head);
  box-shadow: 0 6px 20px rgba(10,99,246,.35), 0 1px 3px rgba(0,0,0,.2);
}
.fab:active { transform: scale(.97); }
/* round "+" only: for pages where a wide pill would cover content */
.fab.round { width: 56px; height: 56px; padding: 0; justify-content: center; }
.fab.round svg.i { width: 26px; height: 26px; }
.fab svg.i { stroke-width: 2.4; }

/* bar fixed to the bottom of a page without a tab bar (composer, Start button) */
.bottom-bar {
  position: fixed; z-index: 30; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(100%, 430px);
  padding: var(--s2) var(--gutter) calc(var(--safe-b) + var(--s2));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep);
}

/* 4. Lists and rows -------------------------------------------------------- */
.section { margin: 0 0 var(--s6); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2);
  padding: 0 calc(var(--gutter) + 4px) var(--s2);
  font: 600 13px/18px var(--font); color: var(--text-2); text-transform: uppercase; letter-spacing: .03em;
}
.section-head .link { text-transform: none; letter-spacing: 0; font: var(--t-sub); color: var(--accent); }
.section-head.big { text-transform: none; letter-spacing: -.01em; font: var(--t-title3); color: var(--text); padding-top: var(--s2); }
.section-foot { padding: var(--s2) calc(var(--gutter) + 4px) 0; font: var(--t-foot); color: var(--text-2); }

/* inset grouped list */
.list {
  margin: 0 var(--gutter);
  background: var(--bg-elev);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  list-style: none; padding: 0;
}
.list > * + * { border-top: .5px solid var(--sep); }
.list.indent > * + * { border-top: 0; }
.list.indent > * + * > .row-body { border-top: .5px solid var(--sep); }

.row {
  position: relative;
  display: flex; align-items: center; gap: var(--s3);
  min-height: var(--hit);
  padding: var(--s3) var(--gutter);
  color: var(--text);
  width: 100%; text-align: left;
}
a.row:active, button.row:active { background: var(--bg-elev-2); }
.row-lead { flex: none; display: flex; align-items: center; justify-content: center; align-self: flex-start; margin-top: 1px; }
.row-body { flex: 1; min-width: 0; }
.row-title { font: var(--t-head); display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.row-title > .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font: var(--t-sub); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row-line { font: var(--t-sub); color: var(--text-2); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-meta { font: var(--t-foot); color: var(--text-3); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-trail { flex: none; display: flex; align-items: center; gap: var(--s2); color: var(--text-3); font: var(--t-sub); }
.row-trail .chev { width: 16px; height: 16px; stroke-width: 2.4; color: var(--text-3); opacity: .7; }
.row.simple { padding-top: 11px; padding-bottom: 11px; }
.row.simple .row-title { font: var(--t-body); }
.row .value { color: var(--text-2); font: var(--t-body); }
.row.danger .row-title { color: var(--red); font: var(--t-body); }
.row.action .row-title { color: var(--accent); font: var(--t-body); }
/* stale row (machine offline): dim the content, keep the amber age readable, stop the pulse */
.row.stale .row-lead, .row.stale .row-title, .row.stale .row-line, .row.stale .row-sub { opacity: .55; }
.row.stale .dot { animation: none; }

/* icon tile at the start of a settings row */
.tile { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; background: var(--gray); }
.tile svg.i { width: 18px; height: 18px; stroke-width: 2.1; }
.tile.blue { background: var(--accent); } .tile.green { background: var(--green); }
.tile.orange { background: var(--orange); } .tile.red { background: var(--red); }

/* group header inside a list: machine, then project */
.group-head {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--gutter) var(--s1);
  font: 600 13px/18px var(--font); color: var(--text-2);
}
.group-head .count { color: var(--text-3); font-weight: 500; }

/* agent kind monogram: Cx = Codex, Cl = Claude */
.kind {
  width: 34px; height: 34px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 13px/1 var(--font); letter-spacing: -.02em;
  position: relative;
}
.kind.codex { background: var(--codex); color: var(--codex-ink); }
.kind.claude { background: var(--claude); color: var(--claude-ink); }
.kind.sm { width: 24px; height: 24px; border-radius: 7px; font-size: 10px; }
.kind.lg { width: 48px; height: 48px; border-radius: 13px; font-size: 17px; }
/* status dot pinned to the kind tile */
.kind > .dot { position: absolute; right: -3px; bottom: -3px; box-shadow: 0 0 0 2.5px var(--bg-elev); }

/* 5. Status ---------------------------------------------------------------- */
/* dot shapes: working = solid circle (pulses), needs you = solid circle + ring,
   idle = hollow ring, stopped = square, offline = hollow dashed, updating = spinner */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--gray); }
.dot.working { background: var(--green); animation: pulse 2s var(--ease) infinite; }
.dot.needs { background: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft); }
.kind > .dot.needs { box-shadow: 0 0 0 2.5px var(--bg-elev); }
.dot.idle { background: transparent; border: 2px solid var(--gray); }
.dot.stopped { background: var(--red); border-radius: 2.5px; }
.dot.offline { background: transparent; border: 2px dashed var(--gray); }
.dot.online { background: var(--green); }
.dot.updating { background: transparent; border: 2px solid var(--accent); border-right-color: transparent; animation: spin .9s linear infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* status label: dot + word */
.status { display: inline-flex; align-items: center; gap: 6px; font: 600 13px/18px var(--font); white-space: nowrap; }
.status.working { color: var(--green); }
.status.needs { color: var(--orange); }
.status.idle { color: var(--text-2); }
.status.stopped { color: var(--red); }
.status.offline { color: var(--text-2); }
.status.updating { color: var(--accent); }
.status.online { color: var(--green); }

/* age: "2 s ago". Stale age is amber with a clock. */
.age { font: var(--t-foot); color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.age.stale { color: var(--amber); display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }

/* 6. Chips and badges ------------------------------------------------------ */
.chips { display: flex; gap: var(--s2); padding: 0 var(--gutter); overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 32px; padding: 0 var(--s3);
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-pill);
  background: var(--fill); color: var(--text);
  font: 500 14px/1 var(--font); white-space: nowrap;
}
.chip[aria-pressed="true"], .chip.on { background: var(--text); color: var(--bg-elev); }
.chip .n { color: var(--text-3); font-weight: 500; }
.chip.on .n, .chip[aria-pressed="true"] .n { color: inherit; opacity: .6; }
/* small tags inside rows */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 7px; border-radius: 6px;
  font: var(--t-cap); white-space: nowrap;
  background: var(--fill); color: var(--text-2);
}
.tag.mono { font-family: var(--mono); font-size: 11.5px; font-weight: 500; }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.orange { background: var(--orange-soft); color: var(--orange); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.blue { background: var(--accent-soft); color: var(--accent); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
/* count badge */
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--red); color: #fff; font: 700 11.5px/1 var(--font);
}
.badge.orange { background: var(--orange); }
.badge.quiet { background: var(--fill); color: var(--text-2); }

/* 7. Buttons --------------------------------------------------------------- */
.btn {
  height: 44px; padding: 0 var(--s4);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  border-radius: var(--r);
  font: var(--t-head); white-space: nowrap;
  background: var(--fill); color: var(--accent);
  transition: transform var(--fast) var(--ease), opacity var(--fast);
}
.btn:active:not(:disabled) { transform: scale(.98); opacity: .85; }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.tinted { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: none; padding: 0 var(--s2); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.danger.solid { background: var(--red); color: #fff; }
.btn.go { background: var(--green); color: #fff; }
.btn.neutral { background: var(--fill); color: var(--text); }
.btn.sm { height: 34px; padding: 0 var(--s3); font: 600 15px/1 var(--font); border-radius: 10px; }
.btn.lg { height: 52px; font-size: 17px; border-radius: 14px; }
.btn.block { display: flex; width: 100%; }
.btn-row { display: flex; gap: var(--s2); }
.btn-row > .btn { flex: 1; }
.btn-stack { display: grid; gap: var(--s2); }
/* pending (waiting for the machine's ack) */
.btn.pending { pointer-events: none; opacity: .8; }
/* acked (the machine confirmed): clear, not faded like a disabled button */
.btn.done, .btn.done:disabled { opacity: 1; background: var(--green-soft); color: var(--green); }
.btn.pending::before { content: ""; width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }

/* big answer buttons for agent questions and permission prompts */
.answers { display: grid; gap: var(--s2); }
.answer {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 54px; padding: var(--s3) var(--s4);
  border-radius: 14px; text-align: left;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--sep-strong);
  font: var(--t-head);
}
.answer:active { background: var(--bg-elev-2); }
.answer .key {
  flex: none; width: 26px; height: 26px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--fill); color: var(--text-2); font: 600 13px/1 var(--mono);
}
.answer .what { flex: 1; min-width: 0; }
.answer .what small { display: block; font: var(--t-foot); color: var(--text-2); margin-top: 2px; }
.answer.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.answer.primary .key { background: rgba(255,255,255,.22); color: #fff; }
.answer.primary .what small { color: rgba(255,255,255,.8); }
.answer.deny { color: var(--red); }
.answer.chosen { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

/* 8. Segmented tabs -------------------------------------------------------- */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 2px; margin: 0 var(--gutter);
  background: var(--fill); border-radius: 10px;
}
.seg > button {
  height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 14px/1 var(--font); color: var(--text);
}
.seg > button[aria-selected="true"] { background: var(--bg-elev); box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 .5px rgba(0,0,0,.04); }
:root[data-theme="dark"] .seg > button[aria-selected="true"] { background: #636366; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg > button[aria-selected="true"] { background: #636366; } }

/* 9. Cards ----------------------------------------------------------------- */
.card {
  margin: 0 var(--gutter);
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  padding: var(--s4);
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: var(--s3); }
.card-head { display: flex; align-items: center; gap: var(--s3); }
.card-title { font: var(--t-head); }
.card-sub { font: var(--t-foot); color: var(--text-2); }
.card-body { margin-top: var(--s3); font: var(--t-callout); }
.card-actions { margin-top: var(--s4); }
/* "Needs you" card: orange edge */
.card.needs { box-shadow: inset 4px 0 0 var(--orange), var(--shadow-1); padding-left: calc(var(--s4) + 4px); }
.card.quote { background: var(--fill-2); box-shadow: none; padding: var(--s3); border-radius: var(--r); font: var(--t-sub); }
.mono-block {
  font: 13.5px/19px var(--mono); padding: var(--s3); border-radius: var(--r-sm);
  background: var(--fill-2); color: var(--text); overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}

/* horizontal strip of small cards (runs strip on Home) */
.strip { display: flex; gap: var(--s3); padding: 0 var(--gutter); overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip > * { scroll-snap-align: start; flex: none; width: 260px; margin: 0; }
.mini {
  display: block; background: var(--bg-elev); border-radius: var(--r-lg); padding: var(--s3) var(--s4);
  color: var(--text); box-shadow: var(--shadow-1);
}
.mini:active { background: var(--bg-elev-2); }

/* step progress: a row of small segments */
.steps-bar { display: flex; gap: 3px; margin-top: var(--s2); }
.steps-bar i { flex: 1; height: 4px; border-radius: 2px; background: var(--fill); }
.steps-bar i.done { background: var(--green); }
.steps-bar i.now { background: var(--accent); }
.steps-bar i.wait { background: var(--orange); }
.steps-bar i.skip { background: var(--gray-soft); }
.steps-bar i.fail { background: var(--red); }

/* 10. Banners and toasts --------------------------------------------------- */
.banner {
  margin: 0 var(--gutter) var(--s3);
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r);
  font: var(--t-sub);
  background: var(--fill); color: var(--text);
}
.banner > svg.i { margin-top: 0; width: 20px; height: 20px; }
.banner .b-body { flex: 1; min-width: 0; }
.banner .b-title { font-weight: 600; }
.banner .b-text { color: var(--text-2); margin-top: 1px; }
.banner .b-action { flex: none; align-self: center; }
.banner.info { background: var(--accent-soft); } .banner.info > svg.i { color: var(--accent); }
.banner.warn { background: var(--amber-soft); } .banner.warn > svg.i { color: var(--amber); }
.banner.error { background: var(--red-soft); } .banner.error > svg.i { color: var(--red); }
.banner.ok { background: var(--green-soft); } .banner.ok > svg.i { color: var(--green); }
.banner.needs { background: var(--orange-soft); } .banner.needs > svg.i { color: var(--orange); }
/* slim one-line banner pinned under the nav bar */
.banner.slim { margin: 0; border-radius: 0; padding: 8px var(--gutter); align-items: center; font: 500 14px/19px var(--font); }
.banner.slim > svg.i { width: 17px; height: 17px; }
.spin { width: 16px; height: 16px; flex: none; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }

.toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 76px);
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(min(100vw, 430px) - 2 * var(--gutter));
  display: flex; align-items: center; gap: var(--s2);
  padding: 11px var(--s4); border-radius: var(--r-pill);
  background: rgba(30,30,32,.94); color: #fff; font: 500 15px/20px var(--font);
  box-shadow: var(--shadow-2);
  transition: opacity var(--med) var(--ease), transform var(--med) var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast svg.i { width: 18px; height: 18px; color: var(--green); }

/* delivery receipt under a sent message or a decision */
.receipt { display: inline-flex; align-items: center; gap: 4px; font: var(--t-foot); color: var(--text-3); }
.receipt.sending { color: var(--text-3); }
.receipt.delivered { color: var(--green); }
.receipt.failed { color: var(--red); font-weight: 600; }

/* 11. Sheets --------------------------------------------------------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity var(--med) var(--ease);
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  width: min(100%, 430px); max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--s2) 0 calc(var(--safe-b) + var(--s5));
  transform: translateY(100%); transition: transform var(--med) var(--ease);
  box-shadow: var(--shadow-2);
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet .grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--sep-strong); margin: 0 auto var(--s2); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s2) var(--gutter) var(--s3); }
.sheet-head h2 { margin: 0; font: var(--t-title3); }
.sheet-body { padding: 0 var(--gutter); }
.sheet .list, .sheet .card, .sheet .banner { margin-left: 0; margin-right: 0; }
.sheet-close { width: 30px; height: 30px; border-radius: 50%; background: var(--fill); color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; }
.sheet-close svg.i { width: 16px; height: 16px; stroke-width: 2.6; }

/* 12. Forms ---------------------------------------------------------------- */
.field { display: block; margin: 0 var(--gutter); }
.field > span { display: block; font: var(--t-foot); color: var(--text-2); margin: 0 4px 6px; }
.input, .textarea {
  width: 100%; border: 0; outline: none;
  background: var(--bg-elev); color: var(--text);
  border-radius: var(--r); padding: 12px 14px; font: var(--t-body);
  box-shadow: var(--shadow-1);
}
.textarea { min-height: 120px; resize: none; line-height: 23px; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .textarea:focus { box-shadow: 0 0 0 2px var(--accent); }
.search { position: relative; margin: 0 var(--gutter); }
.search .input { background: var(--fill); box-shadow: none; padding-left: 36px; height: 38px; border-radius: 10px; font: var(--t-body); }
.search svg.i { position: absolute; left: 10px; top: 10px; width: 18px; height: 18px; color: var(--text-3); }

/* iOS switch */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--fill); transition: background var(--fast); }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2); transition: transform var(--med) var(--ease); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }

/* radio rows (pick one) */
.pick { display: flex; align-items: center; gap: var(--s3); }
.pick .tick { width: 22px; height: 22px; color: var(--accent); visibility: hidden; }
.pick[aria-checked="true"] .tick { visibility: visible; }

/* option cards (big choice, for New agent) */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin: 0 var(--gutter); }
.choice {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2);
  padding: var(--s4); border-radius: var(--r-lg); text-align: left;
  background: var(--bg-elev); box-shadow: var(--shadow-1); border: 1.5px solid transparent;
}
.choice[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.choice .c-title { font: var(--t-head); }
.choice .c-sub { font: var(--t-foot); color: var(--text-2); }

/* message composer */
.composer { display: flex; align-items: flex-end; gap: var(--s2); }
.composer .textarea {
  flex: 1; min-height: 40px; max-height: 140px; padding: 9px 14px;
  border-radius: 20px; background: var(--bg-elev); box-shadow: 0 0 0 .5px var(--sep-strong);
  font: var(--t-body); line-height: 22px;
}
.send {
  flex: none; width: 36px; height: 36px; margin-bottom: 2px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
}
.send:disabled { background: var(--fill); color: var(--text-3); }
.send svg.i { width: 20px; height: 20px; stroke-width: 2.6; }

/* 13. Chat ----------------------------------------------------------------- */
.chat { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s3) var(--gutter); }
.day { align-self: center; font: 600 12px/16px var(--font); color: var(--text-3); padding: var(--s2) 0; }
.msg { max-width: 86%; font: var(--t-callout); line-height: 22px; word-wrap: break-word; }
.msg.user {
  align-self: flex-end; background: var(--accent); color: #fff;
  padding: 9px 14px; border-radius: 20px 20px 6px 20px;
}
.msg.agent { align-self: flex-start; max-width: 100%; color: var(--text); }
.msg.agent p { margin: 0 0 8px; }
.msg.agent p:last-child { margin-bottom: 0; }
code, .msg code, .row code, .card code, .banner code { font: 0.88em/1.4 var(--mono); background: var(--fill); padding: 1px 5px; border-radius: 5px; }
.msg .who { display: flex; align-items: center; gap: 6px; font: 600 12px/16px var(--font); color: var(--text-3); margin-bottom: 4px; }
.msg-meta { font: var(--t-foot); color: var(--text-3); align-self: flex-end; margin-top: -6px; }
.term code, .mono-block code, pre code { background: none; padding: 0; font: inherit; }
/* collapsed tool steps */
.tools {
  align-self: stretch; border-radius: var(--r);
  background: var(--fill-2); font: var(--t-sub); color: var(--text-2);
}
.tools > summary {
  list-style: none; display: flex; align-items: center; gap: var(--s2);
  min-height: 40px; padding: 8px var(--s3); cursor: pointer;
}
.tools > summary::-webkit-details-marker { display: none; }
.tools > summary .chev { margin-left: auto; width: 16px; height: 16px; transition: transform var(--fast); }
.tools[open] > summary .chev { transform: rotate(90deg); }
.tools ul { list-style: none; margin: 0; padding: 0 var(--s3) var(--s3); display: grid; gap: 6px; }
.tools li { display: flex; gap: var(--s2); align-items: baseline; font: 13px/18px var(--mono); color: var(--text-2); }
.tools li .ok { color: var(--green); } .tools li .bad { color: var(--red); }
/* question / permission card inside the chat */
.ask {
  align-self: stretch; border-radius: var(--r-lg); padding: var(--s4);
  background: var(--orange-soft);
}
.ask-head { display: flex; align-items: center; gap: var(--s2); font: 700 13px/18px var(--font); color: var(--orange); text-transform: uppercase; letter-spacing: .03em; }
.ask-q { font: var(--t-head); margin: var(--s2) 0 var(--s3); }

/* 14. Terminal and quick keys ---------------------------------------------- */
.term {
  margin: 0 var(--gutter);
  background: var(--term-bg); color: var(--term-fg);
  border-radius: var(--r);
  font: 12.5px/17px var(--mono);
  padding: var(--s3); overflow: auto; white-space: pre;
  min-height: 320px;
  -webkit-overflow-scrolling: touch;
}
.term .d { color: var(--term-dim); } .term .g { color: var(--term-green); }
.term .y { color: var(--term-yellow); } .term .c { color: var(--term-cyan); } .term .r { color: var(--term-red); }
.term .b { font-weight: 700; }
.term .cursor { display: inline-block; width: 7px; height: 14px; background: var(--term-fg); vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.keys { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 0 0 var(--s2); }
.keys::-webkit-scrollbar { display: none; }
.key {
  flex: none; min-width: 44px; height: 44px; padding: 0 12px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  background: var(--bg-elev); color: var(--text); font: 600 14px/1 var(--mono);
  box-shadow: 0 1px 0 var(--sep-strong), 0 0 0 .5px var(--sep);
}
.key:active { background: var(--fill); transform: translateY(1px); }
.key.danger { color: var(--red); }
.key.wide { min-width: 64px; }

/* 15. Timeline (run steps) ------------------------------------------------- */
.timeline { list-style: none; margin: 0 var(--gutter); padding: 0; }
.tl { position: relative; display: flex; gap: var(--s3); padding-bottom: var(--s4); }
.tl::before { content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--sep-strong); }
.tl:last-child::before { display: none; }
.tl.done::before { background: var(--green); }
.tl-mark {
  flex: none; width: 28px; height: 28px; border-radius: 50%; z-index: 1;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg); border: 2px solid var(--sep-strong); color: var(--text-3);
}
.tl-mark svg.i { width: 15px; height: 15px; stroke-width: 3; }
.tl.done .tl-mark { background: var(--green); border-color: var(--green); color: #fff; }
.tl.now .tl-mark { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.tl.now .tl-mark::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s infinite; }
.tl.wait .tl-mark { border-color: var(--orange); background: var(--orange); color: #fff; }
.tl.skip .tl-mark { border-style: dashed; }
.tl.fail .tl-mark { background: var(--red); border-color: var(--red); color: #fff; }
.tl-body { flex: 1; min-width: 0; padding-top: 3px; }
.tl-title { font: var(--t-head); display: flex; align-items: center; gap: var(--s2); }
.tl.next .tl-title, .tl.skip .tl-title { color: var(--text-2); font-weight: 500; }
.tl-sub { font: var(--t-foot); color: var(--text-2); margin-top: 2px; }
.tl-card { margin-top: var(--s3); background: var(--bg-elev); border-radius: var(--r); padding: var(--s3) var(--s4); box-shadow: var(--shadow-1); }

/* 16. Empty states --------------------------------------------------------- */
.empty { text-align: center; padding: var(--s10) var(--s8); color: var(--text-2); }
.empty .e-icon { width: 64px; height: 64px; margin: 0 auto var(--s4); border-radius: 18px; display: flex; align-items: center; justify-content: center; background: var(--fill); color: var(--text-3); }
.empty h3 { margin: 0 0 6px; font: var(--t-title3); color: var(--text); }
.empty p { margin: 0 auto var(--s5); font: var(--t-sub); max-width: 280px; }

/* skeleton line while the first answer comes in (never longer than ~1 s) */
.skel { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--fill) 0%, var(--fill-2) 50%, var(--fill) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* bigger tap area than the visible shape (44 px rule) */
.send, .btn.sm { position: relative; }
.send::after, .btn.sm::after { content: ""; position: absolute; inset: -5px; }

/* 17. Helpers -------------------------------------------------------------- */
.mono { font-family: var(--mono); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font: var(--t-foot); }
.center { text-align: center; }
.row-gap { display: flex; align-items: center; gap: var(--s2); }
.spacer { flex: 1; }
.mt1 { margin-top: var(--s1); } .mt2 { margin-top: var(--s2); } .mt3 { margin-top: var(--s3); } .mt4 { margin-top: var(--s4); } .mt6 { margin-top: var(--s6); }
.mb2 { margin-bottom: var(--s2); } .mb3 { margin-bottom: var(--s3); } .mb4 { margin-bottom: var(--s4); } .mb6 { margin-bottom: var(--s6); }
.px { padding-left: var(--gutter); padding-right: var(--gutter); }
.sep-dot::before { content: "·"; margin: 0 4px; color: var(--text-3); }
.logo { width: 28px; height: 28px; flex: none; }
.ok-text { color: var(--green); } .warn-text { color: var(--amber); } .err-text { color: var(--red); } .needs-text { color: var(--orange); }

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

/* Step 3 fleet previews. Shared navigation, usage and filter controls. */
.tab { min-width: 0; min-height: 44px; }
.tabbar .tab { color: var(--text-2); }
.tabbar .tab[aria-current="page"] { color: var(--accent); }
.fleet-fields { display: grid; gap: var(--s3); margin: 0 var(--gutter) var(--s4); }
.fleet-fields label { display: grid; gap: 6px; font: var(--t-foot); color: var(--text-2); min-width: 0; }
.fleet-fields input, .fleet-fields select, .setting-select { width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--sep-strong); border-radius: var(--r); background: var(--bg-elev); color: var(--text); font: var(--t-sub); }
.fleet-filters { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.fleet-fields input[type="search"] { -webkit-appearance: none; }
.usage-card { margin: 0 var(--gutter); padding: var(--s4); background: var(--bg-elev); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.usage-item + .usage-item { margin-top: var(--s4); }
.usage-label { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; font: var(--t-sub); }
.usage-item progress { display: block; width: 100%; height: 7px; margin: 9px 0 6px; border: 0; border-radius: 7px; overflow: hidden; background: var(--fill); accent-color: var(--green); }
.usage-item progress::-webkit-progress-bar { background: var(--fill); border-radius: 7px; }
.usage-item progress::-webkit-progress-value { background: var(--green); border-radius: 7px; }
.usage-item progress::-moz-progress-bar { background: var(--green); }
.usage-detail { font: var(--t-foot); color: var(--text-2); }
.fleet-note { font: var(--t-foot); color: var(--text-2); margin: var(--s3) var(--gutter); }
.setting-field { display: block; padding: var(--s3) var(--s4); font: var(--t-sub); }
.setting-field > span { display: block; margin-bottom: 7px; font: var(--t-head); }
.setting-field small { display: block; margin-top: 7px; font: var(--t-foot); color: var(--text-2); }
.setting-field .setting-select { background: var(--fill-2); }
.fleet-result { margin: 10px 0 0; font: var(--t-foot); color: var(--text-2); }
.fleet-link { display: inline-flex; align-items: center; min-height: 44px; gap: 6px; }
.nq code { white-space: normal; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto !important; } }
