/* huddle design system — see DESIGN.md for the rules and /design for every component in every state.
   Sections: 1 tokens · 2 base · 3 primitives · 4 layout & pages · 5 session · 6 timeline · 7 panes
   · 8 overlays · 9 responsive & accessibility. Components use tokens only, never raw values. */

/* ============================== 1. TOKENS ============================== */
:root {
  /* colour roles (light) */
  --bg: #ffffff;
  --bg-subtle: #f6f8fa;
  --bg-muted: #eff2f5;
  --bg-inset: #f6f8fa;
  --text: #1f2328;
  --muted: #59636e;
  --border: #d0d7de;
  --border-muted: #d8dee4;
  --accent: #0969da;
  --accent-emphasis: #0969da;
  --accent-soft: #ddf4ff;
  --success: #1a7f37;
  --success-emphasis: #1f883d;
  --success-soft: #dafbe1;
  --attention: #9a6700;
  --attention-soft: #fff8c5;
  --danger: #d1242f;
  --danger-emphasis: #cf222e;
  --danger-soft: #ffebe9;
  --done: #8250df;
  --done-soft: #fbefff;
  --underline: #fd8c73;
  --on-emphasis: #ffffff;
  --header-bg: #f6f8fa;
  --btn-bg: #f6f8fa;
  --btn-hover: #eff2f5;
  --btn-active: #e6eaef;
  --btn-border: rgba(31, 35, 40, 0.15);
  --code-bg: rgba(129, 139, 152, 0.12);
  --pre-bg: #f6f8fa;
  --backdrop: rgba(31, 35, 40, 0.5);
  --diff-add: #dafbe1;
  --diff-add-num: #aceebb;
  --diff-del: #ffebe9;
  --diff-del-num: #ffcecb;
  --diff-hunk: #ddf4ff;
  --sel: #fff8c5;
  --tk-kw: #cf222e;
  --tk-str: #0a3069;
  --tk-num: #0550ae;
  --tk-com: #59636e;
  --tk-type: #8250df;
  --brand-green: #3fb950;
  --brand-blue: #58a6ff;
  --brand-orange: #f0883e;

  /* type */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-2xs: 11px; --fs-xs: 12px; --fs-sm: 13px; --fs: 14px; --fs-md: 16px; --fs-lg: 20px; --fs-xl: 24px;
  --lh-tight: 1.25; --lh: 1.5; --lh-code: 20px;
  --fw: 400; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700;

  /* spacing (4-point) */
  --sp-0: 2px; --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  /* sizes */
  --ctl-xs: 24px; --ctl-sm: 28px; --ctl: 32px; --ctl-lg: 40px; --row: 30px;
  --header-h: 56px; --tabs-h: 48px; --status-h: 40px;
  --panel-w: 320px; --drawer-w: 360px; --tree-w: 280px; --read-w: 920px;

  /* shape, elevation, layers, motion */
  --r-sm: 4px; --r-md: 6px; --r-lg: 12px; --r-full: 999px;
  --shadow-sm: 0 1px 0 rgba(31, 35, 40, 0.04);
  --shadow: 0 1px 3px rgba(31, 35, 40, 0.12), 0 8px 24px rgba(66, 74, 83, 0.12);
  --shadow-lg: 0 1px 3px rgba(31, 35, 40, 0.12), 0 24px 48px rgba(66, 74, 83, 0.2);
  --z-sticky: 10; --z-raised: 3; --z-sheet: 30; --z-drawer: 31; --z-mention: 40; --z-modal: 50; --z-popover: 60; --z-toast: 100;
  --dur-fast: 80ms; --dur: 120ms; --dur-slow: 160ms; --ease: cubic-bezier(.2, 0, 0, 1);
  --focus: 0 0 0 3px var(--accent-soft);

  color-scheme: light;
}

/* colour roles (dark): the system preference unless light is forced, or when dark is chosen */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --bg-subtle: #151b23; --bg-muted: #212830; --bg-inset: #010409;
    --text: #f0f6fc; --muted: #9198a1; --border: #3d444d; --border-muted: #2f353d;
    --accent: #4493f8; --accent-emphasis: #1f6feb; --accent-soft: rgba(56, 139, 253, 0.15);
    --success: #3fb950; --success-emphasis: #238636; --success-soft: rgba(46, 160, 67, 0.15);
    --attention: #d29922; --attention-soft: rgba(187, 128, 9, 0.15);
    --danger: #f85149; --danger-emphasis: #da3633; --danger-soft: rgba(248, 81, 73, 0.1);
    --done: #ab7df8; --done-soft: rgba(171, 125, 248, 0.15);
    --header-bg: #010409; --btn-bg: #212830; --btn-hover: #262c36; --btn-active: #2a313c; --btn-border: #3d444d;
    --code-bg: rgba(101, 108, 118, 0.2); --pre-bg: #151b23; --backdrop: rgba(1, 4, 9, 0.7);
    --diff-add: rgba(46, 160, 67, 0.15); --diff-add-num: rgba(63, 185, 80, 0.3);
    --diff-del: rgba(248, 81, 73, 0.1); --diff-del-num: rgba(248, 81, 73, 0.3); --diff-hunk: rgba(56, 139, 253, 0.1);
    --sel: rgba(187, 128, 9, 0.25);
    --tk-kw: #ff7b72; --tk-str: #a5d6ff; --tk-num: #79c0ff; --tk-com: #9198a1; --tk-type: #d2a8ff;
    --shadow-sm: 0 0 transparent; --shadow: 0 0 0 1px #3d444d, 0 16px 32px rgba(1, 4, 9, 0.85);
    --shadow-lg: 0 0 0 1px #3d444d, 0 24px 48px rgba(1, 4, 9, 0.9);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --bg-subtle: #151b23; --bg-muted: #212830; --bg-inset: #010409;
  --text: #f0f6fc; --muted: #9198a1; --border: #3d444d; --border-muted: #2f353d;
  --accent: #4493f8; --accent-emphasis: #1f6feb; --accent-soft: rgba(56, 139, 253, 0.15);
  --success: #3fb950; --success-emphasis: #238636; --success-soft: rgba(46, 160, 67, 0.15);
  --attention: #d29922; --attention-soft: rgba(187, 128, 9, 0.15);
  --danger: #f85149; --danger-emphasis: #da3633; --danger-soft: rgba(248, 81, 73, 0.1);
  --done: #ab7df8; --done-soft: rgba(171, 125, 248, 0.15);
  --header-bg: #010409; --btn-bg: #212830; --btn-hover: #262c36; --btn-active: #2a313c; --btn-border: #3d444d;
  --code-bg: rgba(101, 108, 118, 0.2); --pre-bg: #151b23; --backdrop: rgba(1, 4, 9, 0.7);
  --diff-add: rgba(46, 160, 67, 0.15); --diff-add-num: rgba(63, 185, 80, 0.3);
  --diff-del: rgba(248, 81, 73, 0.1); --diff-del-num: rgba(248, 81, 73, 0.3); --diff-hunk: rgba(56, 139, 253, 0.1);
  --sel: rgba(187, 128, 9, 0.25);
  --tk-kw: #ff7b72; --tk-str: #a5d6ff; --tk-num: #79c0ff; --tk-com: #9198a1; --tk-type: #d2a8ff;
  --shadow-sm: 0 0 transparent; --shadow: 0 0 0 1px #3d444d, 0 16px 32px rgba(1, 4, 9, 0.85);
  --shadow-lg: 0 0 0 1px #3d444d, 0 24px 48px rgba(1, 4, 9, 0.9);
  color-scheme: dark;
}

/* ============================== 2. BASE ============================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--fw) var(--fs)/var(--lh) var(--sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--accent); text-decoration: none; border-radius: var(--r-sm); }
a:hover { text-decoration: underline; }
code, pre, kbd { font-family: var(--mono); font-size: var(--fs-xs); }
kbd { display: inline-block; min-width: 20px; text-align: center; border: 1px solid var(--border); border-bottom-color: var(--border-muted); box-shadow: inset 0 -1px 0 var(--border-muted); border-radius: var(--r-md); padding: 0 var(--sp-1); background: var(--bg-subtle); font-size: var(--fs-2xs); line-height: 18px; color: var(--text); }
h1, h2, h3 { margin: 0; line-height: var(--lh-tight); }
h1 { font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
h2 { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
h3 { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--muted); display: flex; align-items: center; gap: var(--sp-2); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-xs); }
.block { display: block; }
.hidden { display: none !important; }
.error { color: var(--danger); }
.spacer { flex: 1; }
.pad { padding: var(--sp-3) var(--sp-4); }
.grow { flex: 1; min-width: 0; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot img { animation: pulse 1.2s infinite; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent-emphasis); outline-offset: 2px; }
.ico { flex: none; display: inline-block; vertical-align: -3px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .3; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes flash { 0%, 40% { background: var(--attention-soft); box-shadow: 0 0 0 2px var(--attention); } }

/* ============================== 3. PRIMITIVES ============================== */

/* buttons — default · primary · danger · danger-ghost · ghost · github; sizes small · default · block; states hover · active · focus · disabled · busy */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--ctl); padding: 0 var(--sp-3); border-radius: var(--r-md);
  border: 1px solid var(--btn-border); background: var(--btn-bg); color: var(--text);
  font: var(--fw-medium) var(--fs)/1 var(--sans); cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--btn-hover); text-decoration: none; }
.btn:active:not(:disabled) { background: var(--btn-active); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; opacity: .8; }
.btn .ico { vertical-align: middle; }
.btn.primary, .btn.success { background: var(--success-emphasis); border-color: var(--btn-border); color: var(--on-emphasis); }
.btn.primary:hover:not(:disabled), .btn.success:hover:not(:disabled) { background: var(--success-emphasis); filter: brightness(.94); }
.btn.primary:active:not(:disabled), .btn.success:active:not(:disabled) { filter: brightness(.88); }
.btn.danger { background: var(--danger-emphasis); border-color: transparent; color: var(--on-emphasis); }
.btn.danger:hover:not(:disabled) { background: var(--danger-emphasis); filter: brightness(.94); }
.btn.danger-ghost { color: var(--danger); }
.btn.danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover:not(:disabled) { background: var(--bg-muted); }
.btn.small { height: var(--ctl-sm); padding: 0 var(--sp-2); gap: var(--sp-1); font-size: var(--fs-xs); }
.btn.block { width: 100%; height: var(--ctl-lg); }
.btn.github { background: var(--text); color: var(--bg); border-color: transparent; height: var(--ctl-lg); font-weight: var(--fw-semibold); }
.btn.github:hover:not(:disabled) { background: var(--text); opacity: .9; }
.btn-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.btn-pair > :only-child { grid-column: 1 / -1; }
.btn-col { display: flex; flex-direction: column; gap: var(--sp-2); }
.btn-col .btn, .btn.block-sm { width: 100%; justify-content: center; }

.icon-btn { width: var(--ctl); height: var(--ctl); border-radius: var(--r-md); border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex: none; transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.icon-btn:hover { background: var(--bg-muted); color: var(--text); }
.icon-btn:active { background: var(--btn-active); }

/* fields — states focus · invalid · disabled */
input, textarea, select {
  width: 100%; min-height: var(--ctl); padding: 5px var(--sp-3); border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: var(--fs)/20px var(--sans); box-shadow: inset 0 1px 0 rgba(208, 215, 222, 0.2);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .85; }
textarea { resize: vertical; padding: var(--sp-2) var(--sp-3); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-emphasis); box-shadow: var(--focus); }
input:user-invalid, textarea:user-invalid, .field.invalid input, .field.invalid textarea { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
input:disabled, textarea:disabled, select:disabled { background: var(--bg-subtle); color: var(--muted); cursor: not-allowed; }
.select { height: var(--ctl); padding: 0 28px 0 var(--sp-3); }
.search { max-width: 280px; height: var(--ctl); }
label { display: flex; flex-direction: column; gap: var(--sp-2); font-weight: var(--fw-semibold); }
.field { display: flex; flex-direction: column; gap: var(--sp-2); font-weight: var(--fw); }
.field-label { display: flex; align-items: baseline; gap: var(--sp-2); font-weight: var(--fw-semibold); font-size: var(--fs); }
.field-label .opt { font-weight: var(--fw); font-size: var(--fs-xs); color: var(--muted); }
.field-help { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger); display: flex; align-items: center; gap: var(--sp-1); }
.input-icon { position: relative; display: flex; align-items: center; }
.input-icon > .ico { position: absolute; left: var(--sp-3); color: var(--muted); pointer-events: none; }
.input-icon > input { padding-left: 36px; }
label.toggle { flex-direction: row; align-items: center; gap: var(--sp-2); font-weight: var(--fw); font-size: var(--fs-sm); }
label.toggle input, .radio input, .check-row input { width: auto; min-height: 0; box-shadow: none; accent-color: var(--success-emphasis); }
.radio-group { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); }
.radio { flex-direction: row; align-items: flex-start; gap: var(--sp-2); font-weight: var(--fw); cursor: pointer; }
.radio input { margin-top: var(--sp-1); }
.check-row { display: flex; flex-direction: row; align-items: flex-start; gap: var(--sp-3); font-weight: var(--fw); cursor: pointer; }
.check-row input { margin-top: 3px; }
.row { display: flex; gap: var(--sp-2); align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row select { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

/* switch — off · on · read-only; the whole .switch-row is the target */
.switch { position: relative; flex: none; width: 40px; height: 24px; border-radius: var(--r-full); border: 1px solid var(--border); background: var(--bg-muted); cursor: pointer; padding: 0; transition: background var(--dur) var(--ease); }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--bg); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: left var(--dur) var(--ease); }
.switch.on { background: var(--success-emphasis); border-color: transparent; }
.switch.on .knob { left: 18px; background: var(--on-emphasis); }
.switch:disabled { cursor: not-allowed; }
.switch-row { display: flex; flex-direction: row; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); font-weight: var(--fw); cursor: pointer; border-radius: var(--r-md); }
.switch-row:hover { background: var(--bg-subtle); }
.switch-row > span { flex: 1; }
.switch-row.compact { padding: 0; }
.switch-row.compact:hover, .switch-row.readonly:hover { background: none; }
.switch-row.readonly { cursor: default; }
.switch-row.readonly .switch { opacity: .55; }
.sw-label { display: block; font-weight: var(--fw-semibold); font-size: var(--fs-sm); }

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--bg); }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-1); border: none; background: transparent; color: var(--muted); padding: 0 var(--sp-3); height: var(--ctl-sm); font: var(--fw-medium) var(--fs-xs) var(--sans); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover:not(:disabled):not(.on) { background: var(--bg-subtle); color: var(--text); }
.seg button.on { background: var(--bg-muted); color: var(--text); font-weight: var(--fw-semibold); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.seg-count { margin-left: var(--sp-1); padding: 0 6px; border-radius: var(--r-full); background: var(--bg-muted); font-size: var(--fs-2xs); }
.seg button.on .seg-count { background: var(--bg); }

/* chips, state labels, counters, badges */
.chip { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 0 var(--sp-2); height: 22px; border-radius: var(--r-full); background: var(--bg-subtle); border: 1px solid var(--border); font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--muted); white-space: nowrap; }
.chip .ico { vertical-align: middle; }
.chip.rule { font-family: var(--mono); font-size: var(--fs-2xs); }
.chip.branch { font-family: var(--mono); color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.small-chip { height: 20px; font-size: var(--fs-2xs); padding: 0 6px; }
.pill { display: inline-flex; align-items: center; gap: var(--sp-1); height: 22px; padding: 0 10px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: var(--fw-medium); background: var(--bg-muted); color: var(--muted); text-transform: capitalize; white-space: nowrap; }
.pill.working, .pill.running { background: var(--accent-emphasis); color: var(--on-emphasis); }
.pill.awaiting-approval, .pill.paused { background: var(--attention-soft); color: var(--attention); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--attention) 40%, transparent); }
.pill.failed { background: var(--danger-emphasis); color: var(--on-emphasis); }
.pill.idle { background: var(--success-emphasis); color: var(--on-emphasis); }
.pill.ended { background: var(--done); color: var(--on-emphasis); }
.pill.starting, .pill.pending { background: var(--bg-muted); color: var(--muted); }
.pill.working::before, .pill.running::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
.badge { display: inline-flex; align-items: center; gap: var(--sp-1); height: 20px; padding: 0 var(--sp-2); border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: var(--fw-medium); margin-left: var(--sp-1); background: var(--bg-muted); color: var(--muted); }
.badge.driving { background: var(--accent-soft); color: var(--accent); }
.count, .tab-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-full); background: var(--bg-muted); color: var(--text); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.tab-badge.attn, .count { background: var(--accent-emphasis); color: var(--on-emphasis); }
.dot-count { position: absolute; top: -3px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-full); background: var(--danger-emphasis); color: var(--on-emphasis); font: var(--fw-semibold) var(--fs-2xs)/18px var(--sans); text-align: center; box-shadow: 0 0 0 2px var(--header-bg); }

/* avatar — image · initials · agent · system; driving ring; presence dot */
.avatar { width: var(--size, 28px); height: var(--size, 28px); border-radius: 50%; flex: none; object-fit: cover; box-shadow: 0 0 0 1px var(--border-muted); }
.avatar.initials, .avatar.agent, .avatar.system { display: inline-flex; align-items: center; justify-content: center; color: var(--on-emphasis); font-weight: var(--fw-semibold); font-size: max(var(--fs-2xs), calc(var(--size, 28px) * .4)); letter-spacing: -.02em; }
.avatar.agent { background: var(--text); color: var(--bg); }
.avatar.agent .ico { vertical-align: 0; }
.avatar.system { background: var(--bg-muted); color: var(--muted); }
.avatar.driving { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--underline); }
.av-wrap { position: relative; display: inline-flex; flex: none; }
.presence-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); flex: none; display: inline-block; }
.presence-dot.on { background: var(--success); }
.presence-dot.ring { position: absolute; right: -1px; bottom: -1px; box-shadow: 0 0 0 2px var(--bg); }

/* card, flash, empty state, skeleton, spinner, kbd lists */
.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-4); }
.card.empty { text-align: center; padding: var(--sp-7) var(--sp-4); display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.flash-note { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); border: 1px solid color-mix(in srgb, var(--accent-emphasis) 40%, transparent); background: var(--accent-soft); font-size: var(--fs-sm); }
.flash-note.warn { border-color: color-mix(in srgb, var(--attention) 40%, transparent); background: var(--attention-soft); }
.flash-note.danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--danger-soft); }
.flash-note.success { border-color: color-mix(in srgb, var(--success) 40%, transparent); background: var(--success-soft); }
.flash-note .row { width: 100%; margin-top: var(--sp-1); }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); text-align: center; padding: var(--sp-7) var(--sp-5); }
.empty-state h3 { font-size: var(--fs-lg); color: var(--text); }
.empty-state p { max-width: 420px; }
.empty-note { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3); border: 1px dashed var(--border); border-radius: var(--r-md); color: var(--muted); font-size: var(--fs-sm); }
.empty-note .ico { margin-top: var(--sp-0); }
.skeleton { height: 64px; border-radius: var(--r-lg); background: linear-gradient(90deg, var(--bg-subtle), var(--bg-muted), var(--bg-subtle)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; flex: none; }
.big-ico { color: var(--muted); }
.label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--muted); margin-bottom: var(--sp-0); }
.inline-link { display: inline-flex; align-items: center; gap: var(--sp-1); }
.inline-link .ico { vertical-align: middle; }
.status { font-size: var(--fs-xs); display: inline-flex; align-items: center; gap: var(--sp-1); white-space: nowrap; font-variant-numeric: tabular-nums; }
.status.ok { color: var(--success); }
.status.err { color: var(--danger); }
.status.wait { color: var(--attention); font-weight: var(--fw-semibold); }
.status.run { color: var(--accent); }
.diffstat { display: inline-flex; gap: var(--sp-2); font: var(--fw-semibold) var(--fs-xs) var(--mono); }
.diffstat .add { color: var(--success); }
.diffstat .del { color: var(--danger); }

/* ============================== 4. LAYOUT & PAGES ============================== */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
#app > main { flex: 1 0 auto; }

.topbar { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; gap: var(--sp-3); height: var(--header-h); padding: 0 var(--sp-4); background: var(--header-bg); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: var(--fw-semibold); font-size: var(--fs-md); color: var(--text); flex: none; }
.brand:hover { text-decoration: none; }
.palette-btn { display: inline-flex; align-items: center; gap: var(--sp-2); height: var(--ctl); padding: 0 var(--sp-2) 0 var(--sp-3); min-width: 200px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg); color: var(--muted); font: var(--fs) var(--sans); cursor: pointer; transition: border-color var(--dur-fast) var(--ease); }
.palette-btn:hover { border-color: var(--muted); }
.palette-btn .label { flex: 1; text-align: left; margin: 0; font-weight: var(--fw); font-size: var(--fs); }
.avatar-btn { display: inline-flex; align-items: center; gap: var(--sp-1); border: none; background: none; padding: var(--sp-0); color: var(--muted); cursor: pointer; border-radius: var(--r-full); }
.avatar-btn:hover { color: var(--text); }
.inbox-btn { position: relative; color: var(--text); }

/* sign-in */
.login-page { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, 1fr); background: radial-gradient(900px 500px at 10% 0%, color-mix(in srgb, var(--brand-green) 14%, transparent), transparent 60%), radial-gradient(800px 500px at 90% 100%, color-mix(in srgb, var(--brand-blue) 14%, transparent), transparent 60%), var(--bg-subtle); }
.login-hero { display: flex; flex-direction: column; justify-content: center; gap: var(--sp-5); padding: clamp(32px, 6vw, 96px); max-width: 760px; justify-self: end; width: 100%; }
.login-brand { display: flex; align-items: center; gap: var(--sp-3); font-size: 22px; font-weight: var(--fw-semibold); }
.login-hero h1 { font-size: clamp(32px, 4.2vw, 56px); line-height: 1.08; font-weight: var(--fw-bold); letter-spacing: -0.02em; }
.grad { background: linear-gradient(90deg, var(--brand-green), var(--brand-blue) 55%, var(--brand-orange)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-hero .lead { font-size: clamp(16px, 1.3vw, 19px); color: var(--muted); max-width: 560px; }
.features { list-style: none; margin: var(--sp-2) 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4) var(--sp-5); max-width: 620px; }
.features li { display: flex; gap: var(--sp-3); align-items: flex-start; }
.features .f-ico { flex: none; width: 36px; height: 36px; border-radius: var(--r-lg); display: grid; place-items: center; background: var(--bg); border: 1px solid var(--border); color: var(--accent); }
.features strong { display: block; font-size: var(--fs); }
.features li span:last-child { font-size: var(--fs-sm); color: var(--muted); }
.login-side { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: var(--sp-4); padding: clamp(24px, 5vw, 64px); background: color-mix(in srgb, var(--bg) 70%, transparent); border-left: 1px solid var(--border-muted); backdrop-filter: blur(6px); }
.login-head { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.login-head h2 { font-size: var(--fs-xl); font-weight: 300; letter-spacing: -0.01em; }
.login-head .mobile-logo { display: none; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-5); border-radius: var(--r-lg); background: var(--bg); box-shadow: var(--shadow); }
.dev-login { display: flex; flex-direction: column; gap: var(--sp-3); }
.or { color: var(--muted); font-size: var(--fs-xs); display: flex; align-items: center; gap: var(--sp-2); }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.login-foot { text-align: center; max-width: 320px; }

/* home */
.page { max-width: 1280px; margin: 0 auto; padding: var(--sp-6) clamp(16px, 3vw, 32px) var(--sp-7); }
.page.narrow { max-width: 560px; }
.home { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: var(--sp-6); align-items: start; }
.home-main { display: flex; flex-direction: column; gap: var(--sp-5); min-width: 0; }
.home-side { display: flex; flex-direction: column; gap: var(--sp-4); position: sticky; top: calc(var(--header-h) + var(--sp-6)); }
.home-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; padding-bottom: var(--sp-5); border-bottom: 1px solid var(--border-muted); }
.home-hero h1 { font-size: clamp(22px, 2.4vw, 30px); letter-spacing: -0.01em; }
.home-hero p { margin-top: var(--sp-2); }
.home-new { display: none; }
.new-session { display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-5); border-radius: var(--r-lg); }
.form-head h2 { font-size: 18px; margin-bottom: var(--sp-1); }
.more-options { border: 1px solid var(--border-muted); border-radius: var(--r-md); }
.more-options > summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); cursor: pointer; list-style: none; font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--muted); border-radius: var(--r-md); }
.more-options > summary::-webkit-details-marker { display: none; }
.more-options > summary:hover { color: var(--text); }
.more-options > summary .ico { transition: transform var(--dur) var(--ease); }
.more-options[open] > summary .ico { transform: rotate(90deg); }
.more-body { display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-1) var(--sp-3) var(--sp-4); }
.session-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.list-tools { display: flex; gap: var(--sp-2); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.search-wrap { flex: 1; max-width: 320px; }
.search-wrap .search { max-width: none; width: 100%; }
.session-rows { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--bg); }
.session-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); background: var(--bg); color: var(--text); transition: background var(--dur-fast) var(--ease); }
.session-row + .session-row { border-top: 1px solid var(--border-muted); }
.session-row:hover { background: var(--bg-subtle); text-decoration: none; }
.session-row .t { font-weight: var(--fw-semibold); font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-row:hover .t { color: var(--accent); }
.row-ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--success-soft); color: var(--success); }
.row-ico.running { background: var(--accent-soft); color: var(--accent); }
.row-ico.ended { background: var(--done-soft); color: var(--done); }
.row-ico.failed { background: var(--danger-soft); color: var(--danger); }
.row-ico.pending, .row-ico.starting { background: var(--bg-muted); color: var(--muted); }
.row-meta { display: flex; gap: var(--sp-1) var(--sp-3); flex-wrap: wrap; font-size: var(--fs-xs); color: var(--muted); margin-top: var(--sp-1); }
.row-chevron { color: var(--muted); }
.how { padding: var(--sp-5); border-radius: var(--r-lg); background: var(--bg-subtle); }
.how h3 { font-size: var(--fs); color: var(--text); margin-bottom: var(--sp-3); }
.how ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.how li { display: flex; gap: var(--sp-3); align-items: flex-start; font-size: var(--fs-sm); }
.step-n { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--bg); border: 1px solid var(--border); font-size: var(--fs-xs); font-weight: var(--fw-semibold); }

/* ============================== 5. SESSION ============================== */
body:has(.session-shell) { overflow: hidden; }
.session-shell { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); height: calc(100dvh - var(--header-h)); }
.session-shell.with-drawer { grid-template-columns: minmax(0, 1fr) var(--panel-w) var(--drawer-w); }
.stream { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }

.session-title { flex: 1; min-width: 0; padding-left: var(--sp-3); border-left: 1px solid var(--border); }
.session-title .t { font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-title .sub { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; margin-top: 1px; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.conn.live { background: var(--success); }
.conn.offline { background: var(--danger); animation: pulse 1s infinite; }
.presence { display: flex; align-items: center; padding-left: var(--sp-2); }
.presence-item { margin-left: -4px; display: inline-flex; border: none; background: none; padding: 0; cursor: pointer; position: relative; border-radius: 50%; transition: transform var(--dur-fast) var(--ease); }
.presence-item .avatar { box-shadow: 0 0 0 2px var(--header-bg); }
.presence-item .avatar.driving { box-shadow: 0 0 0 2px var(--header-bg), 0 0 0 4px var(--underline); }
.presence-item:has(.driving) { margin-right: var(--sp-1); }
.presence-item:hover { z-index: 1; transform: translateY(-1px); }
.presence-item.typing::after { content: "…"; position: absolute; right: -4px; bottom: -6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); font-size: var(--fs-2xs); line-height: 1; padding: 1px 3px; color: var(--muted); }
.presence .more { margin-left: var(--sp-1); font-size: var(--fs-xs); color: var(--muted); }

/* tabs (underline nav) */
.tabs { display: flex; gap: var(--sp-2); padding: 0 var(--sp-4); border-bottom: 1px solid var(--border); background: var(--header-bg); flex: none; overflow-x: auto; scrollbar-width: none; }
.tab { position: relative; display: inline-flex; align-items: center; gap: var(--sp-2); border: none; background: none; color: var(--text); padding: 0 var(--sp-3); height: var(--tabs-h); font: var(--fw) var(--fs) var(--sans); cursor: pointer; white-space: nowrap; border-radius: var(--r-md); }
.tab:hover { background: var(--bg-muted); }
.tab.on { font-weight: var(--fw-semibold); }
.tab.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: var(--r-md); background: var(--underline); }
.mobile-only { display: none; }

/* filter bar */
.filter-bar { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-4); border-bottom: 1px solid var(--border-muted); background: var(--bg); flex: none; flex-wrap: wrap; }
.filter-bar .chips { display: flex; gap: var(--sp-1); flex-wrap: wrap; flex: 1; }
.filter-chip { white-space: nowrap; flex: none; border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: var(--r-md); padding: 0 var(--sp-3); height: var(--ctl-sm); font: var(--fw-medium) var(--fs-xs) var(--sans); cursor: pointer; display: inline-flex; gap: var(--sp-2); align-items: center; transition: background var(--dur-fast) var(--ease); }
.filter-chip:hover { background: var(--bg-muted); color: var(--text); }
.filter-chip .n { font-size: var(--fs-2xs); background: var(--bg-muted); border-radius: var(--r-full); padding: 0 6px; }
.filter-chip.on { background: var(--bg-muted); color: var(--text); border-color: var(--border); }
.search-toggle { display: none; }

/* stream */
.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); }
.timeline { max-width: var(--read-w); margin: 0 auto; padding: var(--sp-4) clamp(12px, 2vw, 24px) var(--sp-2); display: flex; flex-direction: column; gap: var(--sp-0); position: relative; }
.no-match { text-align: center; color: var(--muted); padding: var(--sp-7) var(--sp-4); }
.jump { position: absolute; left: 50%; transform: translateX(-50%); bottom: var(--sp-3); display: inline-flex; align-items: center; gap: var(--sp-2); border-radius: var(--r-full); padding: 6px var(--sp-4); border: 1px solid var(--border); background: var(--bg); box-shadow: var(--shadow); cursor: pointer; color: var(--accent); font: var(--fw-semibold) var(--fs-xs) var(--sans); z-index: 2; animation: rise var(--dur) var(--ease); }
.unread-divider { display: flex; align-items: center; gap: var(--sp-3); color: var(--danger); font-size: var(--fs-xs); font-weight: var(--fw-semibold); margin: var(--sp-2) 0; }
.unread-divider::before, .unread-divider::after { content: ""; flex: 1; border-top: 1px solid var(--danger); opacity: .5; }

/* status bar */
.status-bar { display: flex; align-items: center; gap: var(--sp-3); padding: 6px var(--sp-4); border-top: 1px solid var(--border); background: var(--bg-subtle); font-size: var(--fs-sm); min-height: var(--status-h); flex: none; }
.status-left { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; min-width: 0; flex: 1; }
.status-left code { background: var(--code-bg); padding: 1px 6px; border-radius: var(--r-md); max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-left.awaiting-approval, .status-left.paused { color: var(--attention); }
/* the approval prompt stays on one row: the command truncates, the button never wraps */
.status-left.awaiting-approval { flex-wrap: nowrap; }
.status-left.awaiting-approval strong { white-space: nowrap; }
.status-left.awaiting-approval code { flex: 0 1 auto; min-width: 0; }
.status-left.awaiting-approval .btn { flex: none; margin-left: auto; }
.status-left.working { color: var(--accent); }
.status-left.failed { color: var(--danger); }
.status-left.idle, .status-left.ended { color: var(--muted); }
.idle-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: none; }
.typing { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; display: flex; align-items: center; gap: var(--sp-1); }
.dots { display: inline-flex; gap: var(--sp-0); }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }

/* composer */
.composer { border-top: 1px solid var(--border); background: var(--bg); padding: var(--sp-3) var(--sp-4); flex: none; }
.composer-box { position: relative; max-width: var(--read-w); margin: 0 auto; display: flex; gap: var(--sp-2); align-items: flex-end; }
.composer-box textarea { min-height: var(--ctl-lg); max-height: 220px; resize: none; background: var(--bg-subtle); padding-top: 9px; padding-bottom: 9px; }
.composer-box textarea:focus { background: var(--bg); }
.composer-box .btn { height: var(--ctl-lg); padding: 0 var(--sp-5); }
.composer-hint { max-width: var(--read-w); margin: var(--sp-2) auto 0; font-size: var(--fs-xs); color: var(--muted); display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.composer-hint .badge { margin: 0; }
.composer-hint .keys { display: inline-flex; align-items: center; gap: var(--sp-1); }

/* panel */
.panel { border-left: 1px solid var(--border); background: var(--bg); overflow-y: auto; overflow-x: hidden; }
.panel-mobile-head { display: none; }
.panel-section { padding: var(--sp-4); border-bottom: 1px solid var(--border-muted); display: flex; flex-direction: column; gap: var(--sp-3); }
.ps-head { display: flex; align-items: center; gap: var(--sp-2); color: var(--muted); min-height: 20px; }
.ps-head h3 { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ps-meta { margin-left: auto; font-size: var(--fs-xs); color: var(--muted); display: inline-flex; align-items: center; }
.panel-section.attention { background: var(--attention-soft); border-bottom-color: color-mix(in srgb, var(--attention) 30%, transparent); }
.panel-section.attention .ps-head, .panel-section.attention h3 { color: var(--attention); }
.approval-mini { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3); background: var(--bg); border: 1px solid color-mix(in srgb, var(--attention) 35%, var(--border)); border-radius: var(--r-md); }
.approval-what { display: flex; align-items: center; gap: var(--sp-2); color: var(--text); min-width: 0; }
.approval-what code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.driver-card { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3); border: 1px solid var(--border-muted); border-radius: var(--r-md); background: var(--bg-subtle); }
.driver-name { display: flex; align-items: center; gap: var(--sp-1); }
.driver-card .small { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-0); }
.hint { line-height: var(--lh); }
.request { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-3); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent-emphasis) 30%, transparent); border-radius: var(--r-md); }
.req-who { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); }
.req-text { min-width: 0; }
.handoff-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2); }
.control-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-2); }
.control-grid .btn { width: 100%; padding: 0 var(--sp-1); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-1) var(--sp-3); margin: 0; font-size: var(--fs-xs); padding-top: var(--sp-3); border-top: 1px solid var(--border-muted); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-tag { display: inline-flex; align-items: center; gap: var(--sp-1); color: var(--accent); font-weight: var(--fw-semibold); }
.live-tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
.queue-item { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-2); background: var(--bg-subtle); }
.q-head { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); flex-wrap: wrap; }
.q-text .md p { margin: 0; }
.q-edit { display: flex; flex-direction: column; gap: var(--sp-2); }
.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.people li { display: flex; align-items: center; gap: var(--sp-3); }
.people li:not(.on) .av-wrap { opacity: .6; }
.who-col { flex: 1; min-width: 0; line-height: 1.35; font-size: var(--fs-sm); }
.who-line { display: flex; align-items: center; gap: var(--sp-2); }
.who-line .who-login { font-weight: var(--fw-semibold); }
.who-col .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary-mini { background: var(--bg-subtle); border: 1px solid var(--border-muted); border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3); }
.summary-mini .md p { margin: var(--sp-0) 0; }

/* ============================== 6. TIMELINE ============================== */
.timeline::before { content: ""; position: absolute; top: 0; bottom: 0; left: calc(clamp(12px, 2vw, 24px) + 25px); width: 2px; background: var(--border-muted); }
/* every step reserves a narrow action rail on its right (pointer devices) so actions never cover content */
.item { --rail: 0px; position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: var(--sp-3); padding: 10px calc(var(--sp-3) + var(--rail)) 10px 6px; border-radius: var(--r-md); transition: background var(--dur-fast) var(--ease); }
@media (hover: hover) { .item { --rail: 36px; } }
.item.filtered { display: none; }
.item:hover { background: color-mix(in srgb, var(--bg-subtle) 70%, transparent); }
.item.selected { background: var(--accent-soft); }
.item.flash { animation: flash 1.6s; }
.item > .gutter { display: flex; justify-content: center; padding-top: var(--sp-0); position: relative; z-index: 1; }
.item .gutter-dot { width: 10px; height: 10px; margin-top: 9px; border-radius: 50%; background: var(--bg); border: 2px solid var(--border); }
.item .gutter-icon { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-muted); display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--bg); color: var(--muted); }
.gutter-icon.warn { background: var(--attention-soft); color: var(--attention); }
.gutter-icon.done { background: var(--done-soft); color: var(--done); }
.gutter-icon.tool { width: 26px; height: 26px; margin-top: 3px; background: var(--bg-subtle); border: 1px solid var(--border); }
.gutter-icon.muted-ico { width: 26px; height: 26px; margin-top: var(--sp-0); }
.item .who { display: flex; align-items: baseline; gap: var(--sp-2); margin-bottom: var(--sp-0); flex-wrap: wrap; }
.item time { font-size: var(--fs-xs); color: var(--muted); margin-left: auto; padding-left: var(--sp-2); font-variant-numeric: tabular-nums; }
.item .who .arrow, .item .who .muted { font-size: var(--fs-sm); color: var(--muted); }

/* step toolbar: a vertical stack inside the action rail, shown on hover or keyboard focus */
.item-actions { position: absolute; top: 6px; right: 6px; z-index: var(--z-raised); display: flex; flex-direction: column; gap: var(--sp-0); padding: var(--sp-0); background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }
.item:hover .item-actions, .item-actions:focus-within { opacity: 1; pointer-events: auto; }
.act-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-1); border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; padding: 0 6px; min-width: var(--ctl-sm); height: var(--ctl-sm); border-radius: var(--r-md); font-size: var(--fs-xs); }
.act-btn:hover { background: var(--bg-muted); color: var(--text); }
.react-wrap { position: relative; }
.react-picker { display: none; position: absolute; right: calc(100% + var(--sp-1)); top: calc(var(--sp-0) * -1); z-index: 5; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); padding: var(--sp-1); gap: var(--sp-0); }
.react-picker.open { display: flex; animation: pop var(--dur) var(--ease); }
.react-picker button { display: inline-flex; align-items: center; justify-content: center; border: none; background: none; width: var(--ctl); height: var(--ctl); border-radius: var(--r-md); cursor: pointer; color: var(--text); }
.react-picker button:hover { background: var(--accent-soft); color: var(--accent); }
.item-footer { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; margin-top: var(--sp-2); }
.reaction { display: inline-flex; align-items: center; gap: var(--sp-1); border: 1px solid var(--border); background: transparent; border-radius: var(--r-full); padding: 0 var(--sp-2); height: var(--ctl-xs); cursor: pointer; color: var(--text); }
.reaction:hover { background: var(--bg-muted); }
.reaction span { font-size: var(--fs-xs); color: var(--muted); }
.reaction.mine { border-color: var(--accent-emphasis); background: var(--accent-soft); }
.reaction.mine span { color: var(--accent); }
.thread-chip { display: inline-flex; align-items: center; gap: var(--sp-2); height: var(--ctl-xs); padding: 0 var(--sp-3); border-radius: var(--r-full); border: 1px solid color-mix(in srgb, var(--accent-emphasis) 40%, var(--border)); background: var(--accent-soft); color: var(--accent); font: var(--fw-medium) var(--fs-xs) var(--sans); cursor: pointer; }
.thread-chip.resolved { background: transparent; border-color: var(--border); color: var(--muted); }

/* step kinds */
.item.notice { grid-template-columns: 40px 1fr; padding: var(--sp-1) calc(var(--sp-3) + var(--rail)) var(--sp-1) 6px; color: var(--muted); font-size: var(--fs-sm); }
.item.notice::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border); justify-self: center; align-self: center; position: relative; z-index: 1; box-shadow: 0 0 0 3px var(--bg); }
.item.notice:hover { background: none; }
.item.notice > .body { display: flex; align-items: center; }
.item.notice time { margin-left: var(--sp-2); }
.item.boxed { margin: 6px 0; }
.item.boxed > .body { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-4); }
.item.boxed:hover { background: none; }
.item.boxed:hover > .body { border-color: color-mix(in srgb, var(--muted) 50%, var(--border)); }
.item.task .task-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
.item.task .meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin: var(--sp-2) 0; font-size: var(--fs-sm); color: var(--muted); }
.item.instruction .body { border: 1px solid color-mix(in srgb, var(--accent-emphasis) 35%, var(--border)); background: var(--accent-soft); border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3); }
.item.thinking details summary { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; color: var(--muted); font-size: var(--fs-sm); list-style: none; padding-top: var(--sp-1); }
.item.thinking details summary::before { content: ""; width: 5px; height: 5px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform var(--dur) var(--ease); }
.item.thinking details[open] summary::before { transform: rotate(45deg); }
.item.thinking .md { color: var(--muted); font-size: var(--fs-sm); border-left: 2px solid var(--border); padding-left: var(--sp-3); margin-top: var(--sp-2); }
.path-link { border: none; background: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; display: inline-flex; align-items: center; gap: var(--sp-2); text-align: left; max-width: 100%; }
.path-link:hover code { text-decoration: underline; }
.path-link code { color: inherit; overflow: hidden; text-overflow: ellipsis; }

/* tool call */
.tool-call { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg); overflow: hidden; }
.tool-call > summary { display: flex; align-items: center; gap: var(--sp-2); padding: 6px var(--sp-3); cursor: pointer; list-style: none; font-size: var(--fs-sm); min-height: 36px; }
.tool-call > summary::-webkit-details-marker { display: none; }
.tool-call > summary:hover { background: var(--bg-subtle); }
.tool-call[open] > summary { border-bottom: 1px solid var(--border); background: var(--bg-subtle); }
.tool-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-label code.cmd { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-label code.cmd::before { content: "$ "; color: var(--muted); }
pre.output, pre.code { margin: 0; padding: var(--sp-3) var(--sp-4); background: var(--pre-bg); overflow: auto; max-height: 440px; white-space: pre-wrap; word-break: break-word; font-size: var(--fs-xs); line-height: var(--lh-code); }
pre.output.err { color: var(--danger); }
pre.code.small { font-size: var(--fs-2xs); }
.tool-call pre.code { border-bottom: 1px solid var(--border); }

/* diff */
.diff { margin-top: var(--sp-2); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--bg); }
.diff > summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); cursor: pointer; font-size: var(--fs-xs); background: var(--bg-subtle); border-bottom: 1px solid var(--border); list-style: none; }
.diff > summary::-webkit-details-marker { display: none; }
.diff > summary::before, .change > summary::before { content: ""; flex: none; width: 6px; height: 6px; margin: 0 var(--sp-1) 0 var(--sp-0); border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); transition: transform var(--dur) var(--ease); }
.diff:not([open]) > summary { border-bottom: none; }
.diff:not([open]) > summary::before, .change:not([open]) > summary::before { transform: rotate(-45deg); }
.diff > summary .diffstat { margin-left: auto; }
.diff-scroll { overflow-x: auto; max-height: 600px; overflow-y: auto; }
.diff table { border-collapse: collapse; width: 100%; font: var(--fs-xs)/var(--lh-code) var(--mono); }
.diff td { padding: 0 10px; white-space: pre; vertical-align: top; }
.diff td.ln { width: 1%; min-width: 50px; text-align: right; color: var(--muted); user-select: none; }
.diff tr.add { background: var(--diff-add); }
.diff tr.add td.ln { background: var(--diff-add-num); }
.diff tr.add td:last-child::before { content: "+"; position: absolute; margin-left: -8px; color: var(--success); }
.diff tr.del { background: var(--diff-del); }
.diff tr.del td.ln { background: var(--diff-del-num); }
.diff tr.del td:last-child::before { content: "−"; position: absolute; margin-left: -8px; color: var(--danger); }
.diff tr.hunk td { color: var(--muted); background: var(--diff-hunk); padding-top: var(--sp-1); padding-bottom: var(--sp-1); }
.diff tr.meta td { color: var(--muted); font-style: italic; }

/* approval */
.item.approval .body { border: 1px solid color-mix(in srgb, var(--attention) 45%, var(--border)); background: var(--attention-soft); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.approval-head { display: flex; flex-direction: column; gap: var(--sp-0); }
.approval-title { display: flex; align-items: center; gap: var(--sp-2); }
.approval-title .chip { margin-left: auto; }
.item.approval pre.code { border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--border-muted); }
.approval-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: var(--sp-2); }
.verdict { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; font-size: var(--fs-sm); }
.verdict.approve { color: var(--success); }
.verdict.deny { color: var(--danger); }

/* human edit (commit box) */
.commit-box { border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; margin-top: var(--sp-2); }
.commit-msg { padding: var(--sp-2) var(--sp-3); font-weight: var(--fw-semibold); background: var(--bg); }
.commit-box > .small { padding: 0 var(--sp-3) var(--sp-2); }
.commit-foot { display: flex; gap: var(--sp-3); align-items: center; padding: 6px var(--sp-3); background: var(--bg-subtle); border-top: 1px solid var(--border-muted); flex-wrap: wrap; }
.sha { color: var(--accent); background: var(--accent-soft); padding: 0 6px; border-radius: var(--r-md); }

/* summary */
.item.summary > .body { border-color: color-mix(in srgb, var(--done) 55%, var(--border)); box-shadow: inset 3px 0 0 var(--done); }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3) var(--sp-5); margin-top: var(--sp-2); }
.summary-grid section:first-child { grid-column: 1 / -1; }

/* markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: var(--sp-1) 0; }
.md ul, .md ol { margin: var(--sp-1) 0; padding-left: 2em; }
.md code { background: var(--code-bg); padding: .2em .4em; border-radius: var(--r-md); font-size: 85%; }
.md pre.code { border-radius: var(--r-md); margin: var(--sp-2) 0; }
.md pre.code code { background: none; padding: 0; font-size: var(--fs-xs); }
.md blockquote { margin: 6px 0; padding: 0 1em; border-left: .25em solid var(--border); color: var(--muted); }
.md .h { font-weight: var(--fw-semibold); margin: var(--sp-3) 0 var(--sp-1); }
.md .h1 { font-size: 18px; }
.md .h2 { font-size: var(--fs-md); }
.mention { color: var(--text); font-weight: var(--fw-semibold); }
.mention.agent { background: var(--accent-soft); color: var(--accent); border-radius: var(--r-md); padding: 0 var(--sp-1); }

/* ============================== 7. PANES: files, editor, changes, comments ============================== */
.files-view { display: grid; grid-template-columns: var(--tree-w) minmax(0, 1fr); min-height: 0; }
.tree-pane { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-3) var(--sp-3) var(--sp-1) var(--sp-4); }
.tree-filter { margin: 6px var(--sp-3) var(--sp-2); width: calc(100% - 24px); }
.tree { flex: 1; overflow: auto; padding: 0 var(--sp-2) var(--sp-3); }
.tree-meta { padding: var(--sp-2) var(--sp-4); border-top: 1px solid var(--border-muted); }
.tree-empty { padding: var(--sp-3) var(--sp-2); }
.tree-row { display: flex; align-items: center; gap: 6px; width: 100%; height: var(--row); padding: 0 var(--sp-2) 0 calc(var(--sp-2) + var(--depth, 0) * 16px); border: none; background: none; color: var(--text); border-radius: var(--r-md); font: var(--fs) var(--sans); text-align: left; cursor: pointer; white-space: nowrap; }
.tree-row:hover { background: var(--bg-muted); }
.tree-row.selected { background: var(--bg-muted); font-weight: var(--fw-semibold); box-shadow: inset 2px 0 0 var(--accent-emphasis); }
.tree-row .caret { width: 12px; color: var(--muted); flex: none; display: inline-flex; justify-content: center; }
.tree-row .node-ico { display: inline-flex; color: var(--muted); flex: none; }
.tree-row.dir .node-ico { color: var(--accent); }
.tree-row .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tree-row.ch-added .name { color: var(--success); }
.tree-row.ch-modified .name { color: var(--attention); }
.tree-row.ch-deleted .name { color: var(--danger); text-decoration: line-through; }
.tree-viewers { display: inline-flex; }
.tree-viewers .avatar { margin-left: -4px; }
.ch-badge { font: var(--fw-semibold) var(--fs-2xs) var(--mono); width: 18px; height: 18px; border-radius: var(--r-sm); display: inline-flex; align-items: center; justify-content: center; flex: none; border: 1px solid transparent; }
.ch-badge.added { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
.ch-badge.modified { background: var(--attention-soft); color: var(--attention); border-color: color-mix(in srgb, var(--attention) 40%, transparent); }
.ch-badge.deleted { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.ch-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--attention); flex: none; }
.ch-pill { font-size: var(--fs-xs); font-weight: var(--fw-medium); height: 22px; display: inline-flex; align-items: center; padding: 0 var(--sp-2); border-radius: var(--r-full); text-transform: capitalize; white-space: nowrap; }
.ch-pill.added { background: var(--success-soft); color: var(--success); }
.ch-pill.modified { background: var(--attention-soft); color: var(--attention); }
.ch-pill.deleted { background: var(--danger-soft); color: var(--danger); }

.viewer-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); padding: var(--sp-4) clamp(12px, 2vw, 24px); }
.viewer-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.mobile-back { display: none; margin: calc(var(--sp-1) * -1) 0 var(--sp-2) calc(var(--sp-2) * -1); }
.viewer-head { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md) var(--r-md) 0 0; background: var(--bg-subtle); flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: var(--sp-0); min-width: 0; overflow: hidden; }
.crumbs .sep { color: var(--muted); padding: 0 var(--sp-1); }
.crumbs span { color: var(--accent); }
.viewers { display: inline-flex; align-items: center; gap: var(--sp-1); }
.viewers .avatar + .avatar { margin-left: -8px; }
.sel-bar { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); background: var(--attention-soft); border: 1px solid var(--border); border-top: none; font-size: var(--fs-sm); flex-wrap: wrap; }
.code-scroll { flex: 1; overflow: auto; border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--r-md) var(--r-md); }
.code-scroll > .diff { margin: 0; border: none; border-radius: 0; }
.code { font: var(--fs-xs)/var(--lh-code) var(--mono); padding: var(--sp-2) 0 var(--sp-5); min-width: max-content; }
.code-row { display: flex; }
.code-row .ln { position: sticky; left: 0; flex: none; width: 64px; padding: 0 var(--sp-4) 0 0; text-align: right; color: var(--muted); background: var(--bg); border: none; border-right: 3px solid transparent; font: inherit; cursor: pointer; user-select: none; }
.code-row .ln:hover { color: var(--text); }
.code-row .lc { white-space: pre; padding: 0 var(--sp-4) 0 10px; }
.code-row.added { background: var(--diff-add); }
.code-row.added .ln { background: var(--diff-add-num); border-right-color: var(--success); }
.code-row.sel, .code-row.sel .ln { background: var(--sel); }
.code-row.sel .ln { color: var(--text); }
.tk-kw { color: var(--tk-kw); }
.tk-str { color: var(--tk-str); }
.tk-num { color: var(--tk-num); }
.tk-com { color: var(--tk-com); font-style: italic; }
.tk-type { color: var(--tk-type); }
.viewer-loading { padding: var(--sp-4); }
.viewer-empty { margin: auto; text-align: center; padding: var(--sp-7) var(--sp-5); max-width: 480px; display: flex; flex-direction: column; gap: var(--sp-2); align-items: center; }
.viewer-empty h3 { font-size: var(--fs-lg); color: var(--text); }
.quick-files { display: flex; flex-direction: column; gap: 6px; margin-top: var(--sp-3); align-items: flex-start; }

/* editor */
.editor { display: flex; flex-direction: column; min-height: 0; flex: 1; gap: var(--sp-3); }
.editor-head { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.path-row { display: flex; align-items: center; gap: 6px; min-width: 0; flex-wrap: wrap; }
.path-row code.strong { font-weight: var(--fw-semibold); font-size: var(--fs); }
.path-input { width: min(420px, 60vw); font-family: var(--mono); font-size: var(--fs-sm); }
.editor-banners { display: flex; flex-direction: column; gap: var(--sp-2); }
.editor-banners:empty { display: none; }
.editor-tabs { display: flex; align-items: center; gap: var(--sp-2); }
.editor-pane { flex: 1; min-height: 240px; display: flex; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--bg); transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.editor-pane:focus-within { border-color: var(--accent-emphasis); box-shadow: var(--focus); }
.editor-gutter { flex: none; width: 56px; overflow: hidden; padding: var(--sp-2) var(--sp-3) var(--sp-2) 0; text-align: right; font: var(--fs-xs)/var(--lh-code) var(--mono); color: var(--muted); background: var(--bg-subtle); border-right: 1px solid var(--border-muted); user-select: none; }
.editor-text { flex: 1; border: none !important; box-shadow: none !important; border-radius: 0; resize: none; padding: var(--sp-2) var(--sp-3); font: var(--fs-xs)/var(--lh-code) var(--mono); white-space: pre; overflow: auto; tab-size: 4; background: var(--bg); min-height: 0; }
.editor-preview { flex: 1; overflow: auto; min-height: 240px; }
.editor-preview .diff { margin: 0; }

/* changes */
.changes-view { overflow-y: auto; padding: var(--sp-4) clamp(12px, 2vw, 24px); gap: var(--sp-3); }
.changes-view > * { max-width: 1280px; width: 100%; margin-left: auto; margin-right: auto; }
.changes-head { display: flex; flex-direction: column; gap: var(--sp-3); }
.sync-bar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border-muted); border-radius: var(--r-md); background: var(--bg-subtle); }
.sync-state { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-sm); }
.sync-state.ok { color: var(--success); }
.sync-state.warn { color: var(--attention); font-weight: var(--fw-semibold); }
.commits { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border-muted); border-radius: var(--r-md); font-size: var(--fs-sm); overflow: hidden; }
.commits li { display: flex; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); }
.commits li + li { border-top: 1px solid var(--border-muted); }
.commits code { color: var(--accent); }
.change-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.change { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg); overflow: hidden; }
.change > summary { display: flex; align-items: center; gap: var(--sp-3); padding: 6px var(--sp-3); min-height: 44px; cursor: pointer; list-style: none; background: var(--bg-subtle); }
.change > summary::-webkit-details-marker { display: none; }
.change[open] > summary { border-bottom: 1px solid var(--border); }
.change-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-xs); font-weight: var(--fw-semibold); }
.change.deleted .change-path { text-decoration: line-through; color: var(--muted); }
.change-body .diff { margin: 0; border: none; border-radius: 0; }
.change-body .diff > summary { display: none; }

/* comments drawer */
.drawer { border-left: 1px solid var(--border); background: var(--bg); overflow-y: auto; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.anchor-preview { display: block; margin: var(--sp-3) var(--sp-4) var(--sp-1); padding: var(--sp-2) var(--sp-3); border-left: 3px solid var(--accent-emphasis); background: var(--bg-subtle); border-radius: 0 var(--r-md) var(--r-md) 0; color: var(--muted); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.thread { margin: var(--sp-3) var(--sp-4); padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); display: flex; flex-direction: column; gap: var(--sp-3); }
.thread.resolved { opacity: .65; }
.comment { display: grid; grid-template-columns: 24px 1fr; gap: var(--sp-2); }
.comment .who { display: flex; gap: var(--sp-2); align-items: baseline; font-size: var(--fs-sm); }
.comment time { font-size: var(--fs-xs); color: var(--muted); }
.comment-form { position: relative; display: flex; flex-direction: column; gap: var(--sp-2); align-items: flex-end; }
.new-thread-box { margin: var(--sp-3) var(--sp-4) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }

/* ============================== 8. OVERLAYS ============================== */
.popover { position: fixed; z-index: var(--z-popover); min-width: 240px; max-width: min(420px, calc(100vw - 16px)); overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 6px; animation: pop var(--dur) var(--ease); }
.popover.inbox { width: 400px; }
.popover.user-menu { width: 300px; }
.menu-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) 10px; }
.inbox-head { flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); }
.menu-sep { height: 1px; background: var(--border-muted); margin: 6px -6px; }
.menu-block { padding: 6px 10px; display: flex; flex-direction: column; gap: var(--sp-2); }
.menu-label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: var(--sp-3); width: 100%; padding: 0 10px; height: calc(var(--row) + 4px); border: none; background: none; color: var(--text); border-radius: var(--r-md); font: var(--fs) var(--sans); cursor: pointer; text-align: left; }
.menu-item:hover, .menu-item:focus-visible { background: var(--bg-muted); outline: none; }
.menu-item .ico { color: var(--muted); }
.theme-seg { width: 100%; }
.theme-seg button { flex: 1; }
.inbox-list { display: flex; flex-direction: column; gap: var(--sp-0); max-height: 60vh; overflow: auto; }
.inbox-item { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) 10px; border-radius: var(--r-md); border: none; background: none; color: var(--text); font: var(--fs)/1.4 var(--sans); text-align: left; width: 100%; }
.inbox-item.act { background: var(--bg-subtle); }
.inbox-item.link { cursor: pointer; }
.inbox-item.link:hover { background: var(--bg-muted); }
.inbox-item .grow { display: flex; flex-direction: column; gap: 6px; }
.inbox-ico { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; background: var(--bg-muted); color: var(--muted); }
.inbox-ico.warn { background: var(--attention-soft); color: var(--attention); }
.inbox-ico.accent { background: var(--accent-soft); color: var(--accent); }
.inbox-ico.danger { background: var(--danger-soft); color: var(--danger); }
.inbox-code { background: var(--code-bg); padding: var(--sp-0) 6px; border-radius: var(--r-md); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px var(--sp-4); text-align: center; color: var(--success); }
.inbox-empty strong { color: var(--text); }

.modal-backdrop { position: fixed; inset: 0; z-index: var(--z-modal); background: var(--backdrop); display: grid; place-items: center; padding: var(--sp-4); animation: fade var(--dur) var(--ease); }
.modal-backdrop.top { align-items: start; padding-top: 12vh; }
.modal { width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--bg); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); border: 1px solid var(--border); animation: pop var(--dur-slow) var(--ease); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); border-bottom: 1px solid var(--border-muted); }
.modal-head h2 { font-size: var(--fs); }
.modal-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4); border-top: 1px solid var(--border-muted); }

.palette { width: min(640px, 100%); background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); overflow: hidden; animation: pop var(--dur) var(--ease); }
.palette-top { display: flex; align-items: center; gap: var(--sp-3); padding: 0 14px; border-bottom: 1px solid var(--border-muted); color: var(--muted); }
.palette-input { border: none !important; box-shadow: none !important; height: 52px; font-size: var(--fs-md); padding: 0; background: transparent; }
.palette-list { max-height: min(420px, 55vh); overflow: auto; padding: 6px; }
.palette-group { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--muted); padding: 10px 10px var(--sp-1); }
.palette-item { display: flex; align-items: center; gap: var(--sp-3); width: 100%; height: calc(var(--row) + 8px); padding: 0 10px; border: none; background: none; color: var(--text); font: var(--fs) var(--sans); border-radius: var(--r-md); cursor: pointer; text-align: left; }
.palette-item .ico { color: var(--muted); }
.palette-item .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item.on { background: var(--accent-soft); }
.palette-item.on .ico { color: var(--accent); }
.palette-empty { padding: var(--sp-5); text-align: center; }

.mention-menu { position: absolute; left: 0; bottom: calc(100% + 6px); z-index: var(--z-mention); min-width: 260px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); padding: var(--sp-1); }
.comment-form .mention-menu { bottom: auto; top: calc(100% - 30px); }
.mention-item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; height: calc(var(--row) + 4px); padding: 0 var(--sp-2); border: none; background: none; color: var(--text); border-radius: var(--r-md); font: var(--fs-sm) var(--sans); cursor: pointer; text-align: left; }
.mention-item .small { margin-left: auto; }
.mention-item.on { background: var(--accent-soft); }

.shortcuts { border-collapse: collapse; width: 100%; }
.shortcuts td { padding: var(--sp-2) var(--sp-1); border-bottom: 1px solid var(--border-muted); }
.shortcuts td:first-child { white-space: nowrap; width: 40%; }
.shortcuts kbd + kbd { margin-left: var(--sp-1); }

#toasts { position: fixed; bottom: var(--sp-4); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--sp-2); z-index: var(--z-toast); pointer-events: none; }
.toast { pointer-events: auto; padding: 10px var(--sp-4); border-radius: var(--r-md); background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: var(--fs-sm); max-width: min(520px, calc(100vw - 32px)); animation: rise var(--dur) var(--ease); transition: opacity .3s, transform .3s; }
.toast.error { background: var(--danger-emphasis); color: var(--on-emphasis); }
.toast.success { background: var(--success-emphasis); color: var(--on-emphasis); }
.toast.leaving { opacity: 0; transform: translateY(6px); }

/* ============================== 10. STYLE GUIDE (/design) ============================== */
.ds-page { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--sp-6); max-width: 1440px; margin: 0 auto; padding: var(--sp-6) clamp(16px, 3vw, 32px) var(--sp-7); }
.ds-crumb { padding-left: var(--sp-3); border-left: 1px solid var(--border); white-space: nowrap; }
.topbar .theme-seg { width: auto; flex: none; }
.ds-nav { position: sticky; top: calc(var(--header-h) + var(--sp-6)); align-self: start; display: flex; flex-direction: column; gap: var(--sp-0); }
.ds-nav a { color: var(--text); padding: 6px var(--sp-3); border-radius: var(--r-md); font-size: var(--fs-sm); }
.ds-nav a:hover { background: var(--bg-muted); text-decoration: none; }
.ds-content { display: flex; flex-direction: column; gap: var(--sp-7); min-width: 0; }
.ds-hero h1 { font-size: clamp(24px, 3vw, 32px); margin-bottom: var(--sp-2); }
.ds-section { display: flex; flex-direction: column; gap: var(--sp-4); scroll-margin-top: calc(var(--header-h) + var(--sp-4)); }
.ds-section > header { display: flex; flex-direction: column; gap: var(--sp-1); padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border-muted); }
.ds-section > header h2 { font-size: var(--fs-lg); }
.ds-section h3 { margin-top: var(--sp-2); text-transform: uppercase; letter-spacing: .06em; }
.ds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--sp-4); }
.ds-two { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.ds-specimen { margin: 0; border: 1px solid var(--border); border-radius: var(--r-lg); overflow: visible; display: flex; flex-direction: column; }
.ds-stage { padding: var(--sp-5) var(--sp-4); flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg); border-radius: var(--r-lg) var(--r-lg) 0 0; min-height: 96px; }
.ds-specimen figcaption { padding: var(--sp-2) var(--sp-3); font-size: var(--fs-xs); color: var(--muted); border-top: 1px solid var(--border-muted); background: var(--bg-subtle); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.ds-w { width: 100%; }
.ds-stack { display: flex; flex-direction: column; gap: var(--sp-2); }
.ds-align-end { align-items: flex-end; }
.ds-frame { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--bg); }
.ds-panel { border-left: none; max-height: none; }
.ds-timeline { max-width: none; padding: var(--sp-6) var(--sp-4) var(--sp-4); }
.ds-show-actions .item-actions { opacity: 1; pointer-events: auto; transform: none; }
.ds-static { position: relative !important; animation: none !important; inset: auto; transform: none; width: 100%; max-width: 100%; }
.ds-tabs { border: 1px solid var(--border); border-radius: var(--r-md); width: 100%; }
.ds-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--sp-2); }
.ds-swatch { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2); border: 1px solid var(--border-muted); border-radius: var(--r-md); }
.chip-color { width: 28px; height: 28px; border-radius: var(--r-md); box-shadow: inset 0 0 0 1px var(--border); flex: none; }
.ds-type, .ds-space { display: flex; flex-direction: column; gap: var(--sp-2); }
.ds-type-row, .ds-space-row { display: grid; grid-template-columns: 100px 1fr; align-items: center; gap: var(--sp-3); }
.ds-bar { height: 12px; background: var(--accent-emphasis); border-radius: var(--r-sm); }
.ds-size { display: flex; align-items: center; padding: 0 var(--sp-3); border: 1px dashed var(--accent-emphasis); border-radius: var(--r-md); background: var(--accent-soft); }
.ds-radius { width: 120px; height: 72px; display: grid; place-items: center; border: 1px solid var(--border); background: var(--bg); }
.ds-icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--sp-2); }
.ds-icon { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-1); border: 1px solid var(--border-muted); border-radius: var(--r-md); color: var(--text); }
.ds-icon code { font-size: var(--fs-2xs); color: var(--muted); }
@media (max-width: 1024px) { .ds-page { grid-template-columns: 1fr; } .ds-nav { position: static; flex-direction: row; flex-wrap: wrap; } .ds-two { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .ds-grid { grid-template-columns: 1fr; } }

/* ============================== 9. RESPONSIVE & ACCESSIBILITY ============================== */
@media (min-width: 1600px) { :root { --panel-w: 360px; --drawer-w: 400px; --tree-w: 320px; --read-w: 1040px; } }
@media (min-width: 2000px) {
  :root { --panel-w: 400px; --drawer-w: 440px; --tree-w: 360px; --read-w: 1180px; --lh-code: 21px; }
  body { font-size: 15px; }
  .code, .diff table, .editor-text, .editor-gutter { font-size: var(--fs-sm); }
}
@media (min-width: 2600px) { :root { --panel-w: 440px; --tree-w: 400px; --read-w: 1320px; } }
@media (min-width: 1800px) {
  .login-page { grid-template-columns: minmax(0, 1.3fr) minmax(480px, 1fr); }
  .login-card { max-width: 400px; }
}
@media (max-width: 1280px) {
  :root { --panel-w: 300px; --tree-w: 240px; }
  .session-shell.with-drawer { grid-template-columns: minmax(0, 1fr) var(--drawer-w); }
  .session-shell.with-drawer .panel { display: none; }
}
@media (max-width: 1100px) {
  .palette-btn { min-width: 0; }
  .palette-btn .label, .palette-btn kbd { display: none; }
}
@media (max-width: 1024px) {
  .home { grid-template-columns: 1fr; }
  .home-side { position: static; }
  .home-new { display: inline-flex; }
  .session-shell, .session-shell.with-drawer { grid-template-columns: minmax(0, 1fr); }
  .panel { display: none; }
  .mobile-only { display: inline-flex; }
  .session-shell.show-panel .panel { display: block; position: fixed; inset: var(--header-h) 0 0 auto; width: min(380px, 100vw); z-index: var(--z-sheet); border-left: 1px solid var(--border); box-shadow: var(--shadow); animation: fade var(--dur-slow) var(--ease); }
  .panel-mobile-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 1; }
  .drawer { position: fixed; inset: var(--header-h) 0 0 auto; width: min(420px, 100vw); z-index: var(--z-drawer); box-shadow: var(--shadow); }
}
@media (max-width: 960px) {
  .login-page { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-hero { justify-self: center; padding: 40px var(--sp-5) var(--sp-2); gap: var(--sp-4); text-align: center; align-items: center; }
  .login-hero .lead { margin: 0 auto; }
  .login-side { border-left: none; background: none; backdrop-filter: none; padding: var(--sp-4) var(--sp-4) 40px; justify-content: flex-start; }
  .features { text-align: left; }
}
@media (max-width: 768px) {
  .popover.inbox, .popover.user-menu { left: var(--sp-2) !important; right: var(--sp-2) !important; width: auto; max-width: none; }
  .presence, .brand-name, .session-title .sub .muted, .session-title .sub .chip { display: none; }
  .topbar { gap: var(--sp-2); padding: 0 var(--sp-3); }
  .session-title { padding-left: var(--sp-2); }
  .item, .item.boxed { padding-right: calc(var(--sp-1) + var(--rail)); grid-template-columns: 32px minmax(0, 1fr); gap: var(--sp-2); }
  .timeline::before { left: calc(clamp(12px, 2vw, 24px) + 21px); }
  .summary-grid, .grid2 { grid-template-columns: 1fr; }
  .approval-actions { grid-template-columns: 1fr 1fr; }
  .approval-actions .note { grid-column: 1 / -1; }
  .status-left code { max-width: 22ch; }
  .composer-hint, .status-bar .typing { display: none; }
  /* files: the list and the open file are two screens */
  .files-view { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .tree-pane { border-right: none; }
  .files-view.has-file .tree-pane { display: none; }
  .files-view:not(.has-file) .viewer-pane { display: none; }
  .mobile-back { display: flex; }
  .viewer-pane { padding: var(--sp-3); }
  /* timeline search collapses behind an icon; chips scroll with a fade */
  .filter-bar { flex-wrap: nowrap; }
  .filter-bar .chips { flex: 1; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-right: var(--sp-5); -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
  .search-toggle { display: inline-flex; flex: none; }
  .filter-bar .search { display: none; }
  .filter-bar.searching { flex-wrap: wrap; }
  .filter-bar.searching .search { display: block; flex: 1 1 100%; max-width: none; order: 3; }
  .search-wrap { flex: 1 1 100%; max-width: none; }
  /* editor: path on its own line, the two actions share a row */
  .editor-head { display: grid; grid-template-columns: 1fr 1fr; }
  .editor-head .path-row { grid-column: 1 / -1; }
  .editor-head .spacer { display: none; }
}
@media (max-width: 600px) {
  .login-brand { display: none; }
  .login-head .mobile-logo { display: block; }
  .login-page { grid-template-rows: auto auto; }
  .login-hero { order: 2; padding: var(--sp-2) 20px 40px; }
  .login-side { order: 1; padding-top: var(--sp-7); }
  .features { grid-template-columns: 1fr; }
  .login-hero h1 { font-size: 28px; }
}
@media (max-width: 480px) {
  .tab { padding: 0 6px; font-size: var(--fs-sm); }
  .item.boxed > .body { padding: var(--sp-3); }
  .composer-box .btn { padding: 0 var(--sp-4); }
  .drawer, .session-shell.show-panel .panel { width: 100vw; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { border-radius: var(--r-lg) var(--r-lg) 0 0; animation: rise var(--dur-slow) var(--ease); }
}
/* touch: every control grows to a comfortable tap size; 16px fields avoid iOS zoom */
@media (pointer: coarse) {
  :root { --ctl-xs: 36px; --ctl-sm: 36px; --ctl: 40px; --ctl-lg: 44px; --row: 40px; }
  input, select, textarea, .search, .palette-input { font-size: var(--fs-md); }
  .editor-text, .editor-gutter { font-size: var(--fs-md); line-height: 24px; }
  .switch { width: 52px; height: 32px; }
  .switch .knob { width: 26px; height: 26px; }
  .switch.on .knob { left: 22px; }
  .icon-btn, .avatar-btn, .palette-btn { min-height: var(--ctl); }
  .avatar-btn { min-width: var(--ctl); }
  .btn.small { font-size: var(--fs-sm); }
}
/* no hover: tapping a step reveals its toolbar inline */
@media (hover: none) {
  .item-actions { display: none; position: static; grid-column: 2; justify-self: start; opacity: 1; pointer-events: auto; transform: none; box-shadow: none; margin-top: var(--sp-1); }
  .item.touch-active { background: var(--bg-subtle); }
  .item.touch-active .item-actions { display: flex; }
  .item.notice .item-actions { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
