/* ============================================================================
   Pi Remote — production stylesheet
   Derived from the exported design system (assets/app.css).
   Review-canvas chrome (.shell-*, .device*, .annot*, .spec-*, .idx-*, .screen-*)
   has been removed; token and component layers are preserved 1:1.

   Zoom policy: page zoom and pinch-zoom are disabled at three levels —
   viewport meta, `touch-action`, and a >=16px font on every text control
   (iOS force-zooms a focused input whose font is smaller than 16px).
   ========================================================================= */

/* ─── 1. design tokens ─────────────────────────────────────────────────── */
:root {
  /* dark — primary, developer-tool posture */
  --bg:        #0B0D10;
  --surface:   #15181D;
  --raised:    #1C2027;
  --border:    #23272E;
  --divider:   #1B1F25;
  --fg:        #E6E9EF;
  --muted:     #8B93A1;
  --disabled:  #5A6270;
  --accent:    #4F8CFF;
  --success:   #3FB950;
  --warning:   #D29922;
  --danger:    #F85149;
  --code-bg:   #0E1116;

  /* derived — colour-mix only, no new literals */
  --accent-soft:         color-mix(in oklch, var(--accent) 16%, transparent);
  --accent-ink:          color-mix(in oklch, var(--accent) 78%, white);
  --danger-ink:          color-mix(in oklch, var(--danger) 74%, white);
  --accent-strong:       color-mix(in oklch, var(--accent) 82%, black);
  --accent-strong-hover: color-mix(in oklch, var(--accent) 68%, black);
  --on-accent:  #FFFFFF;
  --success-soft: color-mix(in oklch, var(--success) 15%, transparent);
  --danger-soft:  color-mix(in oklch, var(--danger) 15%, transparent);
  --warning-soft: color-mix(in oklch, var(--warning) 14%, transparent);
  --danger-strong:  color-mix(in oklch, var(--danger) 80%, black);
  --danger-strong-hover: color-mix(in oklch, var(--danger) 68%, black);
  --fg-soft:    color-mix(in oklch, var(--fg) 6%, transparent);
  --fg-softer:  color-mix(in oklch, var(--fg) 4%, transparent);
  --edge:       color-mix(in oklch, var(--muted) 45%, transparent);
  --switch-off: color-mix(in oklch, var(--muted) 40%, transparent);
  --knob:       #FFFFFF;
  --ink:        #000000;
  --overlay:    color-mix(in oklch, var(--ink) 58%, transparent);
  --shadow:     0 1px 2px color-mix(in oklch, var(--ink) 40%, transparent);

  /* VS Code Dark+ syntax ramp */
  --syn-key:  #569CD6;
  --syn-str:  #CE9178;
  --syn-com:  #6A9955;
  --syn-fn:   #DCDCAA;
  --syn-type: #4EC9B0;
  --syn-num:  #B5CEA8;
  --syn-var:  #9CDCFE;

  /* type */
  --font-ui:   -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter',
               'Segoe UI', system-ui, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', ui-monospace, SFMono-Regular, Menlo,
               'Cascadia Code', monospace;

  --t-large: 34px;  --lh-large: 1.15;
  --t-title: 17px;  --lh-title: 1.3;
  --t-body:  15px;  --lh-body:  1.5;
  --t-sub:   13px;  --lh-sub:   1.45;
  --t-label: 11px;  --lh-label: 1.35;
  --t-code:  13px;  --lh-code:  1.55;
  --t-term:  12px;  --lh-term:  1.6;

  /* geometry — 4pt grid */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s7: 32px; --s8: 40px;

  --r-card: 16px;
  --r-btn: 12px;
  --r-input: 20px;
  --r-sheet: 20px;
  --r-chip: 999px;

  --gutter: 16px;
  --navbar-h: 52px;

  /* iOS home-indicator / notch insets */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* light — same semantics, re-derived */
[data-theme='light'] {
  --bg:        #FFFFFF;
  --surface:   #F6F7F9;
  --raised:    #FFFFFF;
  --border:    #E3E6EB;
  --divider:   #EDEFF3;
  --fg:        #12151A;
  --muted:     #5A6270;
  --disabled:  #9AA1AC;
  --code-bg:   #F6F7F9;
  --accent:    #2563EB;
  --success:   #1A7F37;
  --warning:   #9A6700;
  --danger:    #CF222E;

  --accent-soft:         color-mix(in oklch, var(--accent) 12%, transparent);
  --accent-ink:          color-mix(in oklch, var(--accent) 88%, black);
  --danger-ink:          color-mix(in oklch, var(--danger) 88%, black);
  --accent-strong:       var(--accent);
  --accent-strong-hover: color-mix(in oklch, var(--accent) 84%, black);
  --danger-strong:       var(--danger);
  --danger-strong-hover: color-mix(in oklch, var(--danger) 84%, black);
  --success-soft: color-mix(in oklch, var(--success) 12%, transparent);
  --danger-soft:  color-mix(in oklch, var(--danger) 10%, transparent);
  --warning-soft: color-mix(in oklch, var(--warning) 14%, transparent);
  --fg-soft:    color-mix(in oklch, var(--fg) 6%, transparent);
  --fg-softer:  color-mix(in oklch, var(--fg) 4%, transparent);
  --edge:       color-mix(in oklch, var(--muted) 45%, transparent);
  --switch-off: color-mix(in oklch, var(--muted) 35%, transparent);
  --overlay:    color-mix(in oklch, var(--ink) 34%, transparent);
  --shadow:     0 1px 2px color-mix(in oklch, var(--ink) 12%, transparent);
}

/* ─── 2. reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* zoom policy: kill double-tap-to-zoom and pinch-zoom */
  touch-action: pan-x pan-y;
  overscroll-behavior-y: none;
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* zoom policy: no callout / selection popups on chrome, no double-tap zoom */
  touch-action: pan-x pan-y;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
p { margin: 0; text-wrap: pretty; }
ul, ol { margin: 0; }
h1, h2, h3, h4 { margin: 0; }
[hidden] { display: none !important; }

/* text is selectable where it matters, but not the app chrome */
.selectable, .mda, .bubble, .term, .code-body, .diff, .think-body { user-select: text; -webkit-user-select: text; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 999px; border: 3px solid var(--bg);
}
::-webkit-scrollbar-track { background: transparent; }

/* ─── 3. app scaffold ──────────────────────────────────────────────────── */
#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

.app-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  scrollbar-width: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.app-scroll::-webkit-scrollbar { display: none; }
.pad { padding-inline: var(--gutter); }

/* nav bar */
.navbar {
  flex: none; min-height: var(--navbar-h);
  display: flex; align-items: center; gap: var(--s2);
  padding: calc(2px + var(--safe-top)) var(--s3) 2px var(--s1);
  border-bottom: 1px solid var(--divider);
  background: var(--bg);
}
.navbar-center { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.navbar-title {
  font-size: var(--t-title); font-weight: 600; letter-spacing: -0.01em;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.navbar-sub {
  font-family: var(--font-mono); font-size: var(--t-label); color: var(--muted);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.navbar-plain { padding-inline: var(--s1); }

.icon-btn {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  display: grid; place-items: center; color: var(--fg);
  touch-action: manipulation;
}
.icon-btn:hover { background: var(--fg-soft); }
.icon-btn:active { background: var(--fg-soft); }
.icon-btn[disabled] { opacity: 0.35; pointer-events: none; }

/* page head (large title) */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s3);
  padding: calc(var(--s2) + var(--safe-top)) var(--gutter) var(--s3);
}
.page-title {
  font-size: var(--t-large); font-weight: 700; line-height: var(--lh-large);
  letter-spacing: -0.022em; margin: 0;
}
.head-actions { display: flex; gap: 2px; margin-bottom: -4px; }

/* tab bar */
.tabbar {
  flex: none; display: flex; border-top: 1px solid var(--divider);
  background: color-mix(in oklch, var(--bg) 94%, transparent);
  backdrop-filter: blur(18px);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; min-height: 56px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: var(--t-label); font-weight: 500; letter-spacing: 0.01em;
  touch-action: manipulation;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }

/* ─── 4. atoms ─────────────────────────────────────────────────────────── */
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.meta { font-family: var(--font-mono); font-size: var(--t-label); color: var(--muted); }

.step-log {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.9; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.step-log .ok { color: var(--success); }

.dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block;
  background: var(--disabled);
}
.dot.idle { background: var(--disabled); }
.dot.run  { background: var(--success); animation: breathe 1.6s ease-in-out infinite; }
.dot.warn { background: var(--warning); }
.dot.err  { background: var(--danger); }
.dot.ok   { background: var(--success); }

.chip {
  position: relative; display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 11px; border-radius: var(--r-chip);
  border: 1px solid var(--border); background: var(--surface); color: var(--fg);
  font-size: 12px; font-weight: 500; white-space: nowrap;
  touch-action: manipulation;
}
.chip:hover { background: var(--raised); border-color: var(--edge); }
.chip .mono, .chip code { font-family: var(--font-mono); font-size: 11.5px; }
.chip-accent { border-color: color-mix(in oklch, var(--accent) 55%, transparent); color: var(--accent); }
.chip-muted { color: var(--muted); }
.chip-dashed { border-style: dashed; color: var(--muted); }
.chip-add { color: var(--accent); border-color: color-mix(in oklch, var(--accent) 45%, transparent); }
.chip[disabled] { opacity: 0.45; pointer-events: none; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: 6px;
  font-family: var(--font-mono); font-size: var(--t-label); font-weight: 500;
}
.badge-add { background: var(--success-soft); color: var(--success); }
.badge-del { background: var(--danger-soft); color: var(--danger-ink); }
.badge-neutral { background: var(--fg-soft); color: var(--muted); }
.badge-risk {
  border: 1px solid color-mix(in oklch, var(--danger) 60%, transparent);
  background: var(--danger-soft); color: var(--danger-ink);
  font-family: var(--font-ui); font-size: 12px; padding: 3px 9px; border-radius: 999px;
}
.badge-new { background: var(--accent-soft); color: var(--accent-ink); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: var(--s4);
}
.card-flush { padding: 0; overflow: hidden; }
.divider { height: 1px; background: var(--divider); }
.section-label {
  font-size: var(--t-label); font-weight: 500; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--muted);
}
.rule { border: 0; border-top: 1px solid var(--divider); margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 18px; border-radius: var(--r-btn);
  border: 1px solid transparent; font-size: var(--t-body); font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.06s ease;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent-strong); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong-hover); }
.btn-secondary { border-color: var(--border); color: var(--fg); }
.btn-secondary:hover { background: var(--fg-soft); border-color: var(--edge); }
.btn-ghost { color: var(--fg); }
.btn-ghost:hover { background: var(--fg-soft); }
.btn-danger { background: var(--danger-strong); color: var(--on-accent); }
.btn-danger:hover { background: var(--danger-strong-hover); }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { background: var(--danger-soft); color: var(--danger-ink); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: var(--t-sub); border-radius: 10px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* NOTE: font-size stays >=16px on every text control. iOS Safari force-zooms
   the page when focusing an input smaller than that, and no viewport setting
   can override it. */
.input {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: var(--r-input);
  background: var(--bg); border: 1px solid var(--border); color: var(--fg);
  font-size: 16px;
}
.input::placeholder { color: var(--muted); }
.input:hover { border-color: var(--edge); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.mono { font-family: var(--font-mono); font-size: 16px; }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--t-sub); color: var(--muted); }

.switch {
  position: relative; width: 51px; height: 31px; flex: none; border-radius: 999px;
  background: var(--switch-off); transition: background 0.2s ease;
  touch-action: manipulation;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: var(--knob); box-shadow: var(--shadow);
  transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}
.switch[aria-checked='true'] { background: var(--accent); }
.switch[aria-checked='true']::after { transform: translateX(20px); }

/* list row — 44pt minimum */
.lr {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 44px; padding: 10px var(--gutter); text-align: left; width: 100%;
  touch-action: manipulation;
}
button.lr:hover, a.lr:hover { background: var(--fg-softer); }
.lr-body { flex: 1; min-width: 0; }
.lr-title {
  font-size: var(--t-body); font-weight: 500;
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.lr-sub {
  font-size: 12px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.lr-tail { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.lr-group {
  font-size: var(--t-sub); font-weight: 600; color: var(--muted);
  padding: 14px var(--gutter) 6px;
}
.sticky { position: sticky; top: 0; z-index: 3; background: var(--bg); }

/* banners */
.banner {
  display: flex; align-items: center; gap: var(--s2);
  padding: 10px var(--gutter); font-size: var(--t-sub); line-height: 1.4;
  border-bottom: 1px solid var(--border);
}
.banner-warn { background: var(--warning-soft); color: var(--warning); }
.banner-info { background: var(--accent-soft); color: var(--accent-ink); }
.banner-danger { background: var(--danger-soft); color: var(--danger-ink); }
.banner b { font-weight: 600; }
.banner svg { flex: none; }

/* empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s3); text-align: center; padding: 72px var(--s7) var(--s6); flex: 1;
}
.empty h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.empty p { font-size: var(--t-body); color: var(--muted); max-width: 26ch; }
.empty-art { color: var(--muted); opacity: 0.75; margin-bottom: var(--s2); }

/* skeleton shimmer for first paint */
.skel {
  background: linear-gradient(90deg, var(--surface) 25%, var(--raised) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}

/* ─── 5. conversation stream ───────────────────────────────────────────── */
.stream { display: flex; flex-direction: column; gap: var(--s5); padding: var(--s4) 0 var(--s6); }

/* one assistant message: thinking + prose + tool cards stacked */
.msg-assistant { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }

.msg-user { align-self: flex-end; max-width: 78%; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble {
  background: var(--raised); border-radius: var(--r-card) var(--r-card) 6px var(--r-card);
  padding: 10px 13px; font-size: var(--t-body); line-height: 1.52; color: var(--fg);
  white-space: pre-wrap; word-break: break-word;
}
.msg-time { font-size: var(--t-label); color: var(--muted); }
.thumbs { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.thumb {
  width: 88px; height: 88px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }

.mda { font-size: var(--t-body); line-height: 1.62; color: var(--fg); min-width: 0; }
.mda > * + * { margin-top: 10px; }
.mda strong { font-weight: 600; }
.mda h1, .mda h2, .mda h3 { font-size: var(--t-title); font-weight: 600; }
.mda ol, .mda ul { padding-left: 20px; }
.mda li { margin-bottom: 5px; }
.mda li::marker { color: var(--muted); }
.ic {
  font-family: var(--font-mono); font-size: var(--t-code);
  background: var(--fg-soft); border-radius: 5px; padding: 1px 5px;
}
.msg-actions { display: flex; gap: 2px; margin-top: 8px; margin-left: -8px; }
.msg-actions button {
  min-height: 34px; padding: 0 8px; border-radius: 8px;
  font-size: var(--t-sub); color: var(--muted); display: inline-flex; align-items: center; gap: 5px;
  touch-action: manipulation;
}
.msg-actions button:hover { color: var(--fg); background: var(--fg-soft); }
.clamp-8 {
  display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden;
}

.code {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
}
.code-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 8px 5px 12px; border-bottom: 1px solid var(--border);
}
.code-lang {
  font-family: var(--font-mono); font-size: var(--t-label); font-weight: 500;
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted);
}
.code-copy {
  min-width: 30px; min-height: 30px; border-radius: 7px; display: grid; place-items: center;
  color: var(--muted); touch-action: manipulation;
}
.code-copy:hover { color: var(--fg); background: var(--fg-soft); }
.code-body {
  overflow-x: auto; padding: 10px 12px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: var(--lh-code);
  white-space: pre; color: var(--fg);
  -webkit-overflow-scrolling: touch;
}
.code-body::-webkit-scrollbar { height: 6px; }
.code-body::-webkit-scrollbar-thumb { border: 0; background: var(--border); }

/* thinking */
.think { display: flex; flex-direction: column; min-width: 0; }
.think-sum {
  display: flex; align-items: center; gap: var(--s2); width: 100%;
  min-height: 44px; color: var(--muted); font-size: var(--t-sub);
  touch-action: manipulation;
}
.think-sum:hover { color: var(--fg); }
.think-body {
  margin-top: 4px; padding: 2px 0 2px 12px;
  border-left: 2px solid var(--border);
  background: var(--fg-softer);
  font-size: var(--t-sub); font-style: italic; line-height: 1.6; color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
}
.think-lead {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); animation: breathe 1.4s ease-in-out infinite;
}

/* tool card */
.tool {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-btn); overflow: hidden;
}
.tool-sum {
  display: flex; align-items: center; gap: var(--s2); width: 100%;
  min-height: 44px; padding: 0 12px; text-align: left; color: var(--fg);
  touch-action: manipulation;
}
.tool-sum:hover { background: var(--fg-softer); }
.tool-glyph { flex: none; color: var(--muted); }
.tool-status { flex: none; width: 18px; display: grid; place-items: center; }
.tool-name {
  font-family: var(--font-mono); font-size: var(--t-code); font-weight: 500;
  color: var(--fg); flex: none;
}
.tool-arg {
  font-family: var(--font-mono); font-size: var(--t-code); color: var(--muted);
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-body { padding: 0 12px 12px; }
.tool-spin {
  width: 14px; height: 14px; flex: none; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}
.tool-progress { height: 2px; background: var(--border); position: relative; overflow: hidden; }
.tool-progress::after {
  content: ''; position: absolute; inset: 0; width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: slide 1.4s ease-in-out infinite;
}
.tool-done-bar { height: 2px; background: var(--success); }
.tool-fail-bar { height: 2px; background: var(--danger); }
.batch-note {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 2px 2px;
}
.stack-tools { display: flex; flex-direction: column; gap: var(--s2); }

/* terminal */
.term {
  background: var(--bg); border-left: 3px solid var(--edge); border-radius: 8px;
  padding: 10px 12px; max-height: 240px; overflow: auto;
  font-family: var(--font-mono); font-size: var(--t-term); line-height: var(--lh-term);
  white-space: pre-wrap; word-break: break-word; color: var(--fg);
  -webkit-overflow-scrolling: touch;
}
.term::-webkit-scrollbar { width: 6px; }
.term::-webkit-scrollbar-thumb { border: 0; background: var(--border); }
.term .ok { color: var(--success); }
.term .no { color: var(--danger); }
.term .dim { color: var(--muted); }
.caret {
  display: inline-block; width: 7px; height: 13px; vertical-align: -2px;
  background: var(--fg); animation: blink 1s steps(1) infinite;
}

/* diff */
.diff {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px;
  overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: var(--lh-code);
  -webkit-overflow-scrolling: touch;
}
.diff::-webkit-scrollbar { height: 6px; }
.diff::-webkit-scrollbar-thumb { border: 0; background: var(--border); }
.dl { display: flex; min-width: max-content; position: relative; }
.dl .ln {
  width: 36px; flex: none; text-align: right; padding-right: 8px;
  font-size: var(--t-label); color: var(--disabled); user-select: none;
}
.dl .pf { width: 16px; flex: none; color: var(--muted); }
.dl .tx { white-space: pre; padding-right: 14px; }
.dl.add { background: var(--success-soft); }
.dl.add .pf { color: var(--success); }
.dl.del { background: var(--danger-soft); }
.dl.del .pf { color: var(--danger-ink); }
.dl.mod::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--warning);
}
.dl-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: var(--t-label); color: var(--muted); font-family: var(--font-mono);
}
.tk { color: var(--fg); }
.tk-k { color: var(--syn-key); }
.tk-s { color: var(--syn-str); }
.tk-c { color: var(--syn-com); }
.tk-f { color: var(--syn-fn); }
.tk-t { color: var(--syn-type); }
.tk-n { color: var(--syn-num); }
.tk-v { color: var(--syn-var); }

/* system notice */
.sys-note {
  display: flex; align-items: center; justify-content: center; gap: var(--s2);
  font-size: 12px; color: var(--muted); text-align: center;
}
.sys-note::before, .sys-note::after {
  content: ''; height: 1px; flex: 1; background: var(--divider);
}

/* ─── 6. composer ──────────────────────────────────────────────────────── */
/* attachment previews above the composer */
.composer-atts {
  display: flex; gap: 8px; padding: 10px var(--gutter) 0;
  overflow-x: auto; scrollbar-width: none;
}
.composer-atts::-webkit-scrollbar { display: none; }
.att {
  position: relative; width: 64px; height: 64px; flex: none;
  border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: var(--bg);
}
.att img { width: 100%; height: 100%; object-fit: cover; }
.att-del {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: color-mix(in oklch, var(--ink) 66%, transparent);
  color: #fff; display: grid; place-items: center;
  font-size: 14px; line-height: 1; padding: 0;
  touch-action: manipulation;
}
.att-del:hover { background: var(--danger-strong); }

.composer { flex: none; border-top: 1px solid var(--border); background: var(--surface);
  padding-bottom: var(--safe-bottom);
}
.queue { display: flex; align-items: center; gap: var(--s2); padding: 10px var(--gutter) 0; }
.queue-chips { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.queue-chips::-webkit-scrollbar { display: none; }
.queue-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px 0 11px;
  border-radius: var(--r-chip); border: 1px dashed color-mix(in oklch, var(--accent) 50%, transparent);
  color: var(--accent-ink); background: var(--accent-soft); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.queue-chip button {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  color: var(--accent-ink); touch-action: manipulation;
}
.queue-chip button:hover { background: color-mix(in oklch, var(--accent) 24%, transparent); }
.queue-hint { font-size: var(--t-label); color: var(--muted); flex: none; }

.composer-tools {
  display: flex; align-items: center; gap: 6px; height: 36px;
  padding: 3px var(--gutter) 0; overflow-x: auto; scrollbar-width: none;
}
.composer-tools::-webkit-scrollbar { display: none; }

.composer-box {
  display: flex; align-items: flex-end; gap: var(--s2);
  margin: 2px var(--gutter) 0; padding: 6px 6px 6px 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-input);
}
.composer-box:focus-within { border-color: var(--accent); }
.composer-box textarea {
  flex: 1; min-width: 0; border: 0; background: none; resize: none;
  padding: 7px 0; max-height: 132px; min-height: 30px;
  font-family: var(--font-ui); font-size: 16px; line-height: 1.45; color: var(--fg);
  -webkit-appearance: none;
}
.composer-box textarea::placeholder { color: var(--muted); }
.composer-box textarea:focus { outline: none; }
.clip-btn {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  color: var(--muted); flex: none; touch-action: manipulation;
}
.clip-btn:hover { color: var(--fg); background: var(--fg-soft); }
.send-btn, .stop-btn {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border-radius: 50%; color: var(--on-accent); touch-action: manipulation;
}
.send-btn { background: var(--accent-strong); }
.send-btn:hover { background: var(--accent-strong-hover); }
.send-btn[disabled] { opacity: 0.4; pointer-events: none; }
.stop-btn { background: var(--danger-strong); border-radius: 11px; }
.stop-btn:hover { background: var(--danger-strong-hover); }
.composer-hint { text-align: center; font-size: var(--t-label); color: var(--muted); padding: 6px 0 10px; }
.composer-off { opacity: 0.5; }
.composer-off textarea { pointer-events: none; }

/* ─── 7. sheets, scrim, menus ──────────────────────────────────────────── */
.layer { position: absolute; inset: 0; z-index: 30; }
.layer[hidden] { display: none; }
.scrim { position: absolute; inset: 0; background: var(--overlay); animation: fade 0.2s ease both; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  border-top: 1px solid var(--border);
  box-shadow: 0 -18px 40px color-mix(in oklch, var(--ink) 34%, transparent);
  animation: rise-sheet 0.28s cubic-bezier(0.32, 0.72, 0, 1) both;
  max-height: 88%; display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
.sheet-grip { width: 36px; height: 5px; border-radius: 999px; background: var(--border); margin: 8px auto 0; flex: none; }
.sheet-head { padding: 12px var(--gutter) 0; flex: none; }
.sheet-title { font-size: var(--t-title); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.sheet-sub { font-size: var(--t-sub); color: var(--muted); margin-top: 3px; line-height: 1.5; }
.sheet-body { padding: 16px var(--gutter) 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-actions { padding: 14px var(--gutter) 22px; display: flex; flex-direction: column; gap: var(--s2); flex: none; }

.menu {
  position: absolute; top: calc(50px + var(--safe-top)); right: 12px; z-index: 20; min-width: 208px;
  background: var(--raised); border: 1px solid var(--border); border-radius: 14px;
  padding: 5px; box-shadow: 0 16px 36px color-mix(in oklch, var(--ink) 46%, transparent);
  animation: pop 0.16s cubic-bezier(0.32, 0.72, 0, 1) both;
}
.menu[hidden] { display: none; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 40px; padding: 0 10px; border-radius: 9px;
  font-size: var(--t-body); color: var(--fg); text-align: left;
  touch-action: manipulation;
}
.menu-item:hover { background: var(--fg-soft); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); color: var(--danger-ink); }
.menu-sep { height: 1px; background: var(--divider); margin: 4px 6px; }

/* swipe actions */
.swipe { position: relative; overflow: hidden; }
.swipe-actions { position: absolute; inset: 0 0 0 auto; display: flex; align-items: stretch; }
.swipe-actions button {
  width: 76px; display: grid; place-items: center; font-size: var(--t-sub); font-weight: 500;
  color: var(--fg); background: var(--raised); touch-action: manipulation;
}
.swipe-actions .s-fork { background: var(--accent-strong); color: var(--on-accent); }
.swipe-actions .s-del { background: var(--danger-strong); color: var(--on-accent); }
.swipe-pane { position: relative; background: var(--bg); transition: transform 0.24s cubic-bezier(0.32, 0.72, 0, 1); }
.swipe.open .swipe-pane { transform: translateX(-152px); }

/* ─── 8. misc ──────────────────────────────────────────────────────────── */
.tile {
  width: 28px; height: 28px; flex: none; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; color: var(--muted);
}
.tile svg { width: 15px; height: 15px; }
.mark { width: 14px; flex: none; display: grid; place-items: center; }
.chev { flex: none; color: var(--muted); }
.sess-row { min-height: 76px; align-items: center; }

.fab {
  position: absolute; right: 16px; bottom: calc(96px + var(--safe-bottom)); z-index: 12;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent-strong); color: var(--on-accent);
  display: grid; place-items: center;
  box-shadow: 0 8px 22px color-mix(in oklch, var(--accent) 40%, transparent);
  animation: rise 0.24s cubic-bezier(0.32, 0.72, 0, 1) both;
  touch-action: manipulation;
}
.fab:hover { background: var(--accent-strong-hover); }
.fab[disabled] { opacity: 0.4; pointer-events: none; }

.stat-row {
  display: flex; align-items: center; gap: 6px;
  padding: 0 var(--gutter) 10px; font-size: 12px; color: var(--muted);
}
.stat-row b { color: var(--fg); font-weight: 500; }

.ring {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  background: conic-gradient(var(--accent) var(--p, 42%), var(--border) 0);
  mask: radial-gradient(circle, transparent 6px, black 6.6px);
  -webkit-mask: radial-gradient(circle, transparent 6px, black 6.6px);
}

.provider-tile {
  width: 28px; height: 28px; flex: none; border-radius: 8px;
  border: 1px solid var(--border); background: var(--raised);
  display: grid; place-items: center; color: var(--fg);
}
.provider-tile svg { width: 16px; height: 16px; }
.provider-tile .mono-glyph { font-family: var(--font-mono); font-size: 12px; font-weight: 500; }

.qr-card {
  display: flex; flex-direction: column; gap: var(--s2); align-items: flex-start;
  padding: var(--s4); border-radius: var(--r-card); border: 1px solid var(--border);
  background: var(--surface); text-align: left; flex: 1;
  touch-action: manipulation;
}
.qr-card.accent { border-color: color-mix(in oklch, var(--accent) 55%, transparent); background: var(--accent-soft); }
.qr-card:hover { border-color: var(--edge); }
.qr-card h3 { font-size: var(--t-body); font-weight: 600; margin: 0; }
.qr-card p { font-size: 12px; color: var(--muted); line-height: 1.45; }

.viewfinder {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  background: var(--bg); display: grid; place-items: center;
}
.vf-frame { position: relative; width: 232px; height: 232px; }
.vf-corner { position: absolute; width: 34px; height: 34px; border: 2px solid var(--fg); }
.vf-corner.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
.vf-corner.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 10px 0 0; }
.vf-corner.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }
.vf-corner.br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 10px 0; }
.vf-scan {
  position: absolute; left: 6px; right: 6px; height: 2px; top: 50%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scan 2.4s ease-in-out infinite;
}

.timeline { position: relative; }
.tl-rail { position: absolute; left: 26px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.tl-row { display: flex; gap: var(--s3); padding: 0 0 var(--s5); position: relative; }
.tl-gutter { width: 54px; flex: none; position: relative; display: flex; justify-content: center; }
.tl-node {
  width: 10px; height: 10px; border-radius: 50%; background: var(--bg);
  border: 2px solid var(--muted); margin-top: 18px; position: relative; z-index: 2;
}
.tl-node.cur { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.tl-card {
  flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-btn); padding: 10px 12px;
}
.tl-card.cur { border-color: color-mix(in oklch, var(--accent) 50%, transparent); }
.tl-meta { display: flex; align-items: center; gap: var(--s2); margin-bottom: 6px; }
.tl-text {
  font-size: var(--t-sub); line-height: 1.5; color: var(--fg);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tl-foot {
  display: flex; align-items: center; gap: var(--s2); margin-top: 8px;
  font-family: var(--font-mono); font-size: var(--t-label); color: var(--muted);
}

/* ─── 9. gateway-specific ──────────────────────────────────────────────── */
.toast-host {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + var(--safe-bottom)); z-index: 60;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(92vw, 420px);
}
.toast {
  background: var(--raised); border: 1px solid var(--border); color: var(--fg);
  border-radius: 12px; padding: 10px 14px; font-size: var(--t-sub);
  box-shadow: 0 10px 30px color-mix(in oklch, var(--ink) 46%, transparent);
  animation: rise 0.2s cubic-bezier(0.32, 0.72, 0, 1) both;
  max-width: 100%; word-break: break-word;
}
.toast.err { border-color: color-mix(in oklch, var(--danger) 55%, transparent); color: var(--danger-ink); }
.toast.ok { border-color: color-mix(in oklch, var(--success) 55%, transparent); }

.screen-center {
  flex: 1; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: var(--s4); padding: var(--s6);
}

.group { padding-bottom: var(--s6); }
.group-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); overflow: hidden; margin-inline: var(--gutter);
}
.group-body > * + * { border-top: 1px solid var(--divider); }

/* long-press / double-tap suppression on controls */
.no-zoom { touch-action: manipulation; }

/* ─── 10. keyframes ───────────────────────────────────────────────────── */
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rise-sheet { from { transform: translateY(100%); } to { transform: none; } }
@keyframes scan { 0%, 100% { transform: translateY(-104px); } 50% { transform: translateY(104px); } }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.anim-rise { animation: rise 0.18s cubic-bezier(0.32, 0.72, 0, 1) both; }

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

/* tablets and up: keep the conversation readable instead of stretching */
@media (min-width: 720px) {
  #app { max-width: 720px; margin-inline: auto; border-inline: 1px solid var(--border); }
  .stream { padding-inline: var(--s3); }
}
