:root {
  --bg: #ffffff;
  --side: #f7f7f8;
  --raised: #ffffff;
  --sunken: #f3f3f5;
  --hover: #ededf0;
  --border: #e5e5e9;
  --border-strong: #d0d0d6;
  --text: #18181b;
  --muted: #6c6c75;
  --faint: #a1a1aa;
  --accent: #18181b;
  --accent-text: #ffffff;
  --bubble: #f1f1f4;
  --code: #f4f4f6;
  /* commands in Ghostty's colors: Tomorrow here, its default Tomorrow Night in the dark (yellow darkened to read on white) */
  --sh-cmd: #718c00;
  --sh-kw: #8959a8;
  --sh-flag: #4271ae;
  --sh-str: #a67c00;
  --sh-var: #3e999f;
  --sh-op: #c82829;
  --sh-comment: #8e908c;
  --working: #d97706;
  --blocked: #dc2626;
  --ok: #16a34a;
  --idle: #a1a1aa;
  --link: #2563eb;
  --focus: #2563eb;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.14), 0 2px 6px rgba(0, 0, 0, 0.06);
  color-scheme: light;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* the system's theme, unless this browser picked one in 设置 (html[data-theme]) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg: #18181a;
  --side: #121214;
  --raised: #212124;
  --sunken: #1d1d20;
  --hover: #2a2a2e;
  --border: #2d2d32;
  --border-strong: #3d3d44;
  --text: #ececef;
  --muted: #9d9da6;
  --faint: #6b6b74;
  --accent: #ececef;
  --accent-text: #18181b;
  --bubble: #2a2a2e;
  --code: #242428;
  --sh-cmd: #b5bd68;
  --sh-kw: #b294bb;
  --sh-flag: #81a2be;
  --sh-str: #f0c674;
  --sh-var: #8abeb7;
  --sh-op: #cc6666;
  --sh-comment: #969896;
  --working: #f59e0b;
  --blocked: #f87171;
  --ok: #4ade80;
  --idle: #6b6b73;
  --link: #60a5fa;
  --focus: #60a5fa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #18181a;
  --side: #121214;
  --raised: #212124;
  --sunken: #1d1d20;
  --hover: #2a2a2e;
  --border: #2d2d32;
  --border-strong: #3d3d44;
  --text: #ececef;
  --muted: #9d9da6;
  --faint: #6b6b74;
  --accent: #ececef;
  --accent-text: #18181b;
  --bubble: #2a2a2e;
  --code: #242428;
  --sh-cmd: #b5bd68;
  --sh-kw: #b294bb;
  --sh-flag: #81a2be;
  --sh-str: #f0c674;
  --sh-var: #8abeb7;
  --sh-op: #cc6666;
  --sh-comment: #969896;
  --working: #f59e0b;
  --blocked: #f87171;
  --ok: #4ade80;
  --idle: #6b6b73;
  --link: #60a5fa;
  --focus: #60a5fa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
/* the app owns the viewport: the page itself never scrolls, so phone browsers keep their toolbars and the composer stays put */
html:has(.shell) { overflow: hidden; overscroll-behavior: none; }
body { background: var(--bg); color: var(--text); font: 14px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
pre, code { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.boot { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; height: 100dvh; padding: 24px; color: var(--muted); text-align: center; }
.boot-mark { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 650; color: var(--text); letter-spacing: -0.01em; }
.boot-mark img { width: 26px; height: 26px; }
.boot-bar { position: relative; width: 120px; height: 3px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.boot-bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 40%; border-radius: inherit; background: var(--faint); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
.boot-error { margin: 0; max-width: 420px; overflow-wrap: anywhere; }

/* ---------- loading placeholders ---------- */
.sk { --sk-a: var(--sunken); --sk-b: var(--hover); display: block; height: 10px; border-radius: 6px; background: linear-gradient(90deg, var(--sk-a) 30%, var(--sk-b) 50%, var(--sk-a) 70%); background-size: 300% 100%; animation: shimmer 1.4s ease-in-out infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.sk-list { padding: 6px 6px 0; }
.side .sk { --sk-a: var(--hover); --sk-b: var(--border); }
.sk-group { padding: 8px 6px 6px; }
.sk-head { height: 9px; }
.sk-item { display: flex; gap: 9px; align-items: flex-start; padding: 9px 8px; }
.sk-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 2px; }
.sk-lines { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.sk-sub { height: 8px; }
.sk-title { height: 14px; margin: 3px 0 7px; }
.sk-conv { padding-top: 28px; }
.sk-turn { display: flex; flex-direction: column; gap: 11px; margin-bottom: 40px; }
.sk-ask { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.sk-bubble { height: 38px; border-radius: 18px; }
.page-loading { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 8px 0; }
.conv-inner.enter { animation: appear 0.18s ease-out; }
@keyframes appear { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sk, .boot-bar::after, .conv-inner { animation: none !important; } }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.grow { flex: 1; }
.ico { flex: none; display: inline-block; vertical-align: -0.18em; }
kbd { font: 11px/1.5 var(--mono); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--muted); background: var(--sunken); white-space: nowrap; }

/* ---------- shell ---------- */
.shell { position: fixed; inset: 0; display: grid; grid-template-columns: 296px minmax(0, 1fr); }
.side { background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; container: conversation / inline-size; --rail-width: clamp(150px, 14cqw, 200px); --reading-shift: clamp(0px, calc((100cqw - 900px) / 2), 48px); }
.scrim { display: none; }

.side-head { display: flex; align-items: center; gap: 8px; padding: 12px 10px 6px 16px; }
.brand { font-weight: 650; font-size: 15px; flex: 1; display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
.brand img { width: 20px; height: 20px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--raised); border-radius: 8px; padding: 5px 12px; line-height: 1.35; white-space: nowrap; transition: background-color 0.12s, border-color 0.12s, opacity 0.12s; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: 0.86; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.4; cursor: default; }
.btn.primary:disabled { opacity: 0.25; }
.btn.small { padding: 3px 10px; font-size: 12.5px; }
.btn.danger { background: var(--blocked); border-color: var(--blocked); color: #fff; }
.btn.danger:hover { opacity: 0.88; }
.btn.danger-outline { color: var(--blocked); }
.btn.danger-outline:hover { background: color-mix(in srgb, var(--blocked) 10%, var(--raised)); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: 0; background: transparent; padding: 4px 8px; border-radius: 7px; color: var(--muted); transition: background-color 0.12s, color 0.12s; }
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--hover); color: var(--text); }
.icon-btn.only { width: 32px; height: 32px; padding: 0; flex: none; }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

.side-tools { padding: 6px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.search-wrap { position: relative; display: flex; align-items: center; color: var(--faint); }
.search-wrap > .ico { position: absolute; left: 10px; pointer-events: none; }
.search { width: 100%; border: 1px solid var(--border); background: var(--raised); border-radius: 9px; padding: 6px 52px 6px 32px; outline: none; transition: border-color 0.12s; }
.search:focus { border-color: var(--border-strong); }
.search::-webkit-search-cancel-button { display: none; }
.kbd { position: absolute; right: 6px; border: 1px solid var(--border); border-bottom-width: 2px; background: var(--sunken); border-radius: 5px; padding: 0 5px; font: 11px/1.5 var(--mono); color: var(--muted); }
.kbd:hover { color: var(--text); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 1px 10px; font-size: 12px; color: var(--muted); transition: background-color 0.12s, color 0.12s; }
.chip:hover { color: var(--text); }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.archived-chip { margin-left: auto; }
.side-list { flex: 1; overflow-y: auto; padding: 0 8px 16px; overscroll-behavior: contain; }
.side-foot { border-top: 1px solid var(--border); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 2px; font-size: 12.5px; color: var(--muted); }
.side-action { width: 34px; height: 34px; padding: 0; }
.side-action.on { color: var(--text); background: var(--hover); }
.account { display: inline-flex; align-items: center; gap: 8px; max-width: 170px; border: 0; background: transparent; border-radius: 8px; padding: 4px 8px 4px 4px; color: var(--text); }
.account:hover, .account[aria-expanded="true"] { background: var(--hover); }
.account > .ico { color: var(--faint); transform: rotate(180deg); }
.account-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.avatar { flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 11.5px; font-weight: 650; }

/* ---------- menus ---------- */
.menu-wrap { position: relative; display: inline-flex; }
.menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 45; min-width: 184px; padding: 4px; display: flex; flex-direction: column; background: var(--raised); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow); animation: pop 0.1s ease-out; }
.menu.up { top: auto; bottom: calc(100% + 6px); left: 0; right: auto; }
@keyframes pop { from { opacity: 0; transform: translateY(-3px); } }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 7px 10px; border-radius: 7px; text-align: left; font-size: 13px; color: var(--text); white-space: nowrap; }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item > .ico { color: var(--muted); }
.menu-item.danger, .menu-item.danger > .ico { color: var(--blocked); }
.menu-item[aria-disabled="true"] { opacity: 0.4; cursor: default; }
.menu-item[aria-disabled="true"]:hover { background: transparent; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.ico-gap { width: 16px; flex: none; }

/* ---------- utility pages ---------- */
.page { width: 100%; max-width: 1040px; margin: 0 auto; padding: 28px 24px 40px; }
.page .field input, .page .field select, .page .field textarea { background: var(--bg); }
.settings-page { max-width: 720px; }
.settings-section { padding: 20px 0; border-bottom: 1px solid var(--border); }
.settings-section:first-child { padding-top: 4px; }
.settings-section:last-child { border-bottom: 0; }
.settings-section h2 { font-size: 14px; font-weight: 600; margin: 0 0 12px; }
.settings-section h3 { font-size: 13px; font-weight: 600; margin: 18px 0 10px; }
.settings-section .note { margin-top: 8px; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--sunken); border: 1px solid var(--border); }
.seg { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; color: var(--muted); font-size: 13px; }
.seg:hover { color: var(--text); }
.seg.on { background: var(--raised); color: var(--text); box-shadow: var(--shadow-sm); }
.shortcuts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; margin: 0; align-items: baseline; }
.shortcuts dd { margin: 0; color: var(--muted); font-size: 13px; }
.account-me { display: flex; align-items: center; gap: 10px; margin: 0; }
.account-me .note { margin: 0; }
.account-list, .account-form { max-width: 440px; }
.account-row { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.schedule-toolbar, .schedule-title, .schedule-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.schedule-toolbar { justify-content: space-between; margin-bottom: 14px; }
.schedule-toolbar .note { flex: 1; min-width: 200px; margin: 0; }
.schedule-list { display: grid; gap: 12px; }
.schedule-card { border: 1px solid var(--border); background: var(--raised); border-radius: 12px; padding: 14px 16px; overflow-wrap: anywhere; }
.schedule-title { justify-content: space-between; }
.schedule-title strong { min-width: 0; }
.schedule-prompt { margin: 8px 0; white-space: pre-wrap; font-size: 13px; max-height: 100px; overflow: auto; padding: 8px 10px; border-radius: 8px; background: var(--sunken); }
.schedule-actions { margin-top: 12px; gap: 6px; }
.schedule-link { color: var(--link); margin-left: 10px; }
.schedule-link:hover { text-decoration: underline; }
.schedule-history { font-size: 12px; color: var(--muted); margin-top: 8px; }
.schedule-history summary { cursor: pointer; }
.schedules-page.editing { max-width: none; padding: 0; }
.schedule-rules { margin-top: 16px; border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; background: var(--side); }
.schedule-rules-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.schedule-rules-head h2 { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 600; margin: 0; }
.schedule-rules-head h2 .ico { color: var(--muted); }
.schedule-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); white-space: nowrap; }
a.schedule-badge:hover { color: var(--text); }
.schedule-mark { color: var(--muted); margin-right: 4px; }
.subagent-mark { display: inline-block; margin-right: 5px; padding: 0 5px; border: 1px solid var(--border); border-radius: 4px; font-size: 10.5px; line-height: 15px; color: var(--muted); vertical-align: 1px; }
.schedule-rule-fields { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.schedule-rule-fields .field { flex: 1 1 140px; min-width: 0; margin: 0; }
.schedule-rule-fields .schedule-at { flex-basis: 240px; }
.schedule-rule-fields input, .schedule-rule-fields select { min-width: 0; }
.schedule-save-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.schedule-save-row > .note { margin: 0; }
.schedule-rules .err:empty { display: none; }

/* ---------- the session list ---------- */
.group { margin-top: 6px; }
.group-head { display: flex; align-items: center; gap: 6px; width: 100%; min-height: 30px; border: 0; background: transparent; padding: 5px 6px; border-radius: 7px; text-align: left; color: var(--muted); font-size: 12.5px; }
.group-head:hover { background: var(--hover); }
.group-row { display: flex; align-items: center; gap: 2px; }
.group-row .group-head { flex: 1; min-width: 0; }
.group-new { display: grid; place-items: center; flex: none; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--faint); opacity: 0; transition: opacity 0.12s; }
.group-row:hover .group-new, .group-new:focus-visible { opacity: 1; }
.group-new:hover { background: var(--hover); color: var(--text); }
.group-name { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; color: var(--faint); }
.chev { flex: none; display: inline-grid; place-items: center; transition: transform 0.15s; }
.group-head .chev { width: 12px; height: 12px; color: var(--faint); }
.group.closed .chev { transform: rotate(-90deg); }
.group.closed .group-items { display: none; }
.group-items { margin-left: 12px; padding-left: 6px; border-left: 1px solid var(--border); }

.item { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 1px 7px; align-items: baseline; padding: 7px 8px; border-radius: 8px; margin: 1px 0; }
.item:hover { background: var(--hover); }
.item.sel { background: var(--raised); box-shadow: 0 0 0 1px var(--border), var(--shadow-sm); }
.item .dot { align-self: center; grid-row: 1; }
.item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { font-size: 11.5px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.item-sub { grid-column: 2 / -1; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* pin, archive / take out of the archive: over the item's right end while it is hovered */
.item-row { position: relative; }
.item-row:hover .item:not(.sel) { background: var(--hover); }
.item-row:hover .item-time, .item-row:focus-within .item-time { visibility: hidden; }
.item-row:hover .item-title, .item-row:focus-within .item-title { margin-right: 28px; }
.item-row.two:hover .item-title, .item-row.two:focus-within .item-title { margin-right: 56px; }
.item-acts { position: absolute; right: 6px; top: 5px; display: flex; gap: 2px; opacity: 0; }
.item-row:hover .item-acts, .item-acts:focus-within, .item-acts.busy { opacity: 1; }
.item-act { width: 26px; height: 26px; display: grid; place-items: center; border: 0; border-radius: 6px; padding: 0; background: transparent; color: var(--muted); }
.item-act:hover { background: var(--border); color: var(--text); }
@media (hover: none) {
  .item-acts { opacity: 1; }
  .item-time { visibility: hidden; }
  .item-row .item-title { margin-right: 28px; }
  .item-row.two .item-title { margin-right: 56px; }
  .group-new { opacity: 1; }
}
/* 置顶: not a project, so no rule down its items */
.group.pinned .group-items { margin-left: 0; padding-left: 0; border-left: 0; }
.more { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 4px 8px 4px 27px; }
.more:hover { color: var(--text); }
.empty { color: var(--muted); padding: 24px 12px; text-align: center; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); display: inline-block; flex: none; }
.dot.working { background: var(--working); animation: pulse 1.4s ease-in-out infinite; }
.dot.blocked, .dot.failed { background: var(--blocked); }
.dot.done, .dot.idle.live { background: var(--ok); }
.dot.interrupted, .dot.unknown { background: transparent; box-shadow: inset 0 0 0 1.5px var(--idle); }
.dot.live:not(.working):not(.failed) { box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 30%, transparent); }
.dot.blocked.live { box-shadow: 0 0 0 2px color-mix(in srgb, var(--blocked) 28%, transparent); }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .dot.working { animation: none; } }

/* ---------- main ---------- */
.top { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 9px 12px 9px 18px; border-bottom: 1px solid var(--border); background: var(--bg); }
.menu-btn { display: none !important; }
.top-main { flex: 1; min-width: 0; }
.top-title { font-weight: 600; font-size: 15px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.share-button { margin: 0 2px; }
.share-button > .ico { color: var(--muted); }
.share-page { min-height: 100dvh; --reading-shift: 0px; }
.share-page .share-content { padding-top: 28px; padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
.share-page > .rail { position: fixed; top: 24px; right: 12px; width: clamp(140px, 12vw, 180px); max-height: min(60dvh, 480px); }
@media (max-width: 1279px) { .share-page > .rail { top: 25dvh; } }
.share-title { margin: 0 0 24px; font-size: 20px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.share-unavailable { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.share-unavailable h1 { font-size: 20px; margin: 0; }
.share-result { padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--side); margin: 12px 0; }
.share-result .field { margin-bottom: 8px; }
.share-result input { font-family: var(--mono); font-size: 12px; }
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 0 8px 0 7px; font-size: 12px; line-height: 20px; background: var(--sunken); color: var(--text); }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; display: inline-block; }
.crumb:hover { color: var(--text); }
.handoff-link { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.handoff-link:hover { color: var(--text); }

.mid { flex: 1; display: flex; min-height: 0; }
.conv { flex: 1; min-width: 0; overflow-y: auto; overscroll-behavior: contain; }

/* The outline floats in the spare space; it never changes the conversation's width or position. */
.mid { position: relative; }
.rail { position: absolute; top: 10px; right: 14px; z-index: 5; width: var(--rail-width); min-width: 150px; max-height: min(52%, 380px); display: flex; flex-direction: column; background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.rail:empty { display: none; }
.rail.folded { width: auto; min-width: 0; max-height: none; border-radius: 999px; box-shadow: var(--shadow-sm); background: var(--raised); }
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%; border: 0; background: transparent; text-align: left; padding: 7px 10px 5px 12px; font-size: 12px; color: var(--muted); }
.rail.folded .rail-head { padding: 5px 11px; font-variant-numeric: tabular-nums; }
button.rail-head:hover { color: var(--text); }
.rail-head .ico:last-child:not(:first-child) { transform: rotate(180deg); }
.rail-label { flex: 1; }
.rail.folded .rail-label { flex: none; }
.rail-filter { margin: 0 8px 6px; border: 1px solid var(--border); background: var(--raised); border-radius: 7px; padding: 3px 8px; outline: none; font-size: 12.5px; color: var(--text); }
.rail-filter:focus { border-color: var(--muted); }
.rail-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 8px; overscroll-behavior: contain; }
.rail-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 6px; align-items: baseline; width: 100%; border: 0; border-left: 2px solid transparent; background: transparent; text-align: left; padding: 5px 8px; border-radius: 0 6px 6px 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.rail-item:hover, .rail-item:focus-visible { background: var(--hover); color: var(--text); }
.rail-item.on { border-left-color: var(--accent); color: var(--text); background: var(--sunken); }
.rail-item .outline-time { display: none; }
.rail-item .outline-text { display: block; white-space: nowrap; text-overflow: ellipsis; }
.top-line { display: flex; align-items: center; gap: 10px; min-width: 0; margin-top: 2px; }
.top-line > .top-meta { flex: 1; min-width: 0; margin-top: 0; }
/* A session's subagents, in the header in place of its state: a pill that opens into tabs for them all. */
.family { position: relative; z-index: 20; flex: none; }
.family:empty { display: none; }
.family-pill { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; padding: 0 9px 0 6px; font-size: 12px; line-height: 20px; background: var(--sunken); color: var(--text); font-variant-numeric: tabular-nums; }
.family-pill:hover, .family.open .family-pill, .family.hover .family-pill { background: var(--hover); }
.family-count { color: var(--muted); }
.family-dots { display: inline-flex; align-items: center; gap: 4px; padding: 0 3px; }
.family-dots .dot { width: 7px; height: 7px; }
.family-dots .dot.here { outline: 1.5px solid var(--muted); outline-offset: 1.5px; }
.family-pop { position: absolute; top: 100%; left: 0; padding-top: 6px; visibility: hidden; opacity: 0; transform: translateY(-4px); transition: opacity 0.12s, transform 0.12s, visibility 0s 0.12s; }
.family.open .family-pop, .family.hover .family-pop, .family:has(:focus-visible) .family-pop { visibility: visible; opacity: 1; transform: none; transition-delay: 0s; }
.family-list { position: relative; width: 248px; max-height: min(60dvh, 420px); overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 1px; padding: 6px; background: var(--raised); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.family-tab { display: grid; grid-template-columns: 8px minmax(0, 1fr); gap: 1px 8px; align-items: baseline; padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.family-tab:hover, .family-tab:focus-visible { background: var(--hover); }
.family-tab.on { background: var(--sunken); }
.family-tab .dot { align-self: center; }
.family-tab.deep { margin-left: 14px; }
.family-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.family-sub { grid-column: 2; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.family-label { padding: 10px 8px 4px; font-size: 11.5px; color: var(--faint); }
@media (prefers-reduced-motion: reduce) { .family-pop { transition: none !important; transform: none; } }
/* Center both reading and writing, with the same small left bias only when there is spare room. */
.conv-inner, .composer-inner { transform: translateX(calc(0px - var(--reading-shift))); }
.conv-inner { max-width: 900px; margin: 0 auto; padding: 14px 16px 28px; }
.newpage { max-width: 760px; margin: 0 auto; padding: min(14vh, 120px) 20px calc(40px + env(safe-area-inset-bottom)); }
.newpage h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 16px; text-align: center; }
.proj-row { display: flex; justify-content: center; align-items: center; gap: 6px; margin-bottom: 14px; }
.proj-dir { display: flex; align-items: center; gap: 6px; color: var(--muted); min-width: 0; max-width: min(520px, 100%); }
.proj-branch { flex-shrink: 0; font-size: 12.5px; color: var(--muted); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj { border: 1px solid var(--border); background: var(--raised); border-radius: 999px; padding: 5px 12px; min-width: 0; max-width: 100%; outline: none; cursor: pointer; }
.proj:hover, .proj:focus { border-color: var(--muted); }
.proj-input { display: block; width: 100%; border: 1px solid var(--border); background: var(--raised); border-radius: 10px; padding: 7px 12px; margin: -4px 0 12px; outline: none; font-family: var(--mono); font-size: 12.5px; }
.proj-input:focus { border-color: var(--muted); }
.note.proj-notice { margin: -4px 0 12px; }
.recent { margin-top: 28px; }
.recent-head { font-size: 12.5px; color: var(--muted); margin: 0 0 6px 8px; }
.lightbox { display: grid; place-items: center; }
.modal.wide.image-modal { width: calc(100vw - 32px); max-width: 1600px; max-height: calc(100dvh - 32px); }
.image-modal .modal-head > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox img, .lightbox video { display: block; max-width: 100%; max-height: calc(100dvh - 170px); object-fit: contain; border-radius: 8px; }
.placeholder { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 24px; }
.placeholder h2 { color: var(--text); font-weight: 600; margin: 0 0 6px; font-size: 18px; }
.earlier { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 28px; margin: 4px 0 18px; font-size: 12.5px; color: var(--muted); }

.turn { margin-bottom: 26px; scroll-margin-top: 12px; }
.turn.flash .q-time { animation: flash 1.6s ease-out; }
.turn.flash .prompt { animation: ring 1.6s ease-out; }
@keyframes ring { 0%, 30% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--working) 45%, transparent); } }
@keyframes flash { 0%, 30% { color: var(--text); background: color-mix(in srgb, var(--working) 22%, transparent); } 100% { background: transparent; } }
.pending { margin-bottom: 18px; }
.pending .prompt { opacity: 0.75; }
.pending-state { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 100%; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.pending-state .icon-btn { padding: 0 6px; }
.pending-state time { font-size: 11px; opacity: 0.8; }
.pending.unconfirmed .pending-state { color: var(--blocked); }
.pending-detail { max-width: min(100%, 440px); margin-top: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 12.5px; color: var(--muted); }
.pending-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.usage.high { color: var(--working); }
.ctx-branch { display: inline-flex; align-items: center; gap: 4px; }
.limits { border: 0; background: transparent; padding: 0; color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
.limits:hover { color: var(--text); }
.limits.high { color: var(--working); }
.tasks-chip { border: 0; background: transparent; padding: 0; color: var(--working); text-decoration: underline dotted; text-underline-offset: 3px; }
.limits-agent + .limits-agent { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 10px; }
.limits-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.limits-head b { color: var(--text); font-size: 14px; }
.limit-row { display: grid; grid-template-columns: 6.5em minmax(0, 1fr) 6em 9.5em; gap: 10px; align-items: center; padding: 3px 0; }
.limit-bar { height: 8px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.limit-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--ok); }
.limit-row.warn .limit-bar > span { background: var(--working); }
.limit-row.full .limit-bar > span { background: var(--blocked); }
.limit-pct { text-align: left; font-variant-numeric: tabular-nums; }
.limit-reset { font-size: 12px; color: var(--muted); white-space: nowrap; }
.outline-n { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12px; }
.outline-text { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.outline-time { color: var(--faint); font-size: 12px; white-space: nowrap; }
.outline-empty { padding: 12px; text-align: center; }
.offscreen { position: fixed; left: -9999px; top: 0; }
.q { display: flex; flex-direction: column; align-items: flex-end; }
.q-time { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; margin: 0 6px 4px; padding: 0 4px; border-radius: 4px; }
.q-row { display: flex; align-items: flex-end; justify-content: flex-end; gap: 2px; width: 100%; }
.q-row .prompt { margin-left: 0; }
.q-tools { flex: none; opacity: 0; transition: opacity 0.12s; }
.q:hover .q-tools, .q-tools:focus-within { opacity: 1; }
@media (hover: none) { .q-tools { opacity: 0.5; } }
.copy { width: 28px; height: 28px; padding: 0; }
.turn-foot .copy { width: 24px; height: 24px; margin-left: -5px; }
.q-expand { font-size: 12px; padding: 2px 8px; margin-top: 2px; }
.q-atts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-bottom: 6px; max-width: 85%; }
.image-preview { border: 1px solid var(--border); background: var(--sunken); padding: 0; border-radius: 10px; overflow: hidden; line-height: 0; cursor: zoom-in; }
.image-preview:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
.image-preview img { display: block; object-fit: contain; }
.att-preview { border: 0; border-radius: 6px; }
.msg-img { max-width: 100%; vertical-align: middle; }
.msg-img img { max-width: 100%; max-height: 320px; }
.q-img img { max-width: 240px; max-height: 180px; display: block; object-fit: contain; }
.video-preview { display: block; max-width: 100%; line-height: 0; }
.video-preview video { display: block; max-width: 100%; border-radius: 10px; border: 1px solid var(--border); background: #000; }
.video-preview.msg-img video { width: 480px; max-height: 360px; }
.video-preview.q-img video { width: 240px; max-height: 180px; }
.video-thumb { position: relative; cursor: pointer; }
.video-thumb video { display: block; width: 56px; height: 56px; object-fit: cover; border-radius: 9px; }
.video-play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.6)); }
.video-play .ico { fill: currentColor; }
.att-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; background: var(--raised); max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-chip > .ico { color: var(--muted); }
.prompt { margin-left: auto; max-width: 85%; width: fit-content; background: var(--bubble); border-radius: 18px; padding: 9px 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.prompt.clamped { max-height: 16em; overflow: hidden; -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent); mask-image: linear-gradient(180deg, #000 70%, transparent); }
.notice { font-size: 12.5px; color: var(--muted); border: 1px dashed var(--border); border-radius: 10px; padding: 6px 12px; margin: 0 0 4px auto; width: fit-content; max-width: 85%; }

.msg { margin: 12px 0; overflow-wrap: anywhere; line-height: 1.7; }
.msg > :first-child { margin-top: 0; }
.msg > :last-child { margin-bottom: 0; }
.msg p { margin: 0.5em 0; white-space: pre-wrap; }
.msg h1, .msg h2, .msg h3, .msg h4, .msg h5, .msg h6 { font-size: 15px; margin: 1em 0 0.4em; }
.msg h1, .msg h2 { font-size: 16px; }
.msg ul, .msg ol { margin: 0.4em 0; padding-left: 1.4em; }
.msg li { margin: 0.15em 0; }
.msg blockquote { margin: 0.5em 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.msg code { background: var(--code); border-radius: 4px; padding: 0.05em 0.35em; }
.msg pre { background: var(--code); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.msg pre code { background: transparent; padding: 0; }
.msg a { color: var(--link); }
.msg a:hover { text-decoration: underline; }
.file-resource { display: inline-flex; align-items: baseline; max-width: 100%; vertical-align: middle; }
.file-meta { display: inline-flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.file-size { color: var(--muted); font-size: 12px; white-space: nowrap; }
.file-resource.with-image { flex-direction: column; align-items: flex-start; gap: 5px; margin: 6px 0; }
.file-resource.unavailable { gap: 6px; flex-wrap: wrap; color: var(--muted); }
.output-images { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px; }
.msg table { border-collapse: collapse; margin: 0.6em 0; display: block; overflow-x: auto; }
.msg th, .msg td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }

/* folded, a run of tool calls is one quiet line; open, a card */
.tools { margin: 6px 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--raised); }
.tools-head { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: var(--sunken); padding: 6px 10px; text-align: left; color: var(--muted); font-size: 12.5px; }
.tools-head:hover { color: var(--text); }
.tools.closed { border-color: transparent; background: transparent; margin-left: -8px; width: fit-content; max-width: calc(100% + 8px); }
.tools.closed .tools-head { background: transparent; padding: 3px 8px; border-radius: 7px; }
.tools.closed .tools-head:hover { background: var(--hover); }
.tools.closed .chev { transform: rotate(-90deg); }
.tools.closed .tools-body { display: none; }
.tools.closed .tools-sum { flex: 0 1 auto; }
.tools-sum { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fail { color: var(--blocked); }
.tools-body { border-top: 1px solid var(--border); }
.tools-thumbs { display: flex; gap: 6px; margin: 6px 0 6px 24px; overflow: hidden; }
.tools-thumbs.open { flex-wrap: wrap; }
.tool-thumb { flex: none; width: 48px; height: 48px; border-radius: 7px; }
.tool-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-more { border: 1px solid var(--border); background: var(--sunken); color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.thumb-more:hover { background: var(--hover); color: var(--text); }
.tools-thumbs.open .thumb-more { width: auto; padding: 0 10px; }

.step { border-top: 1px solid var(--border); }
.step:first-child { border-top: 0; }
.step-line { display: grid; grid-template-columns: 18px auto minmax(0, 1fr) auto auto; gap: 8px; align-items: baseline; width: 100%; border: 0; background: transparent; padding: 5px 10px; text-align: left; font-size: 12.5px; }
.step-line:hover { background: var(--hover); }
.step-icon { display: grid; place-items: center; align-self: center; color: var(--faint); }
.step.error .step-icon { color: var(--blocked); }
.step.running .step-icon { color: var(--working); }
.step-name { font-weight: 600; white-space: nowrap; }
.step-input { font-family: var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-time { color: var(--faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.step-detail { padding: 2px 10px 10px 36px; display: none; }
.step.open .step-detail { display: block; }
.step-detail pre { margin: 6px 0 0; background: var(--code); border-radius: 6px; padding: 8px 10px; max-height: 420px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.step-detail .label { font-size: 11.5px; color: var(--faint); margin-top: 8px; }
.step-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.step-img { max-width: 100%; }
.step-img img { max-width: min(100%, 560px); max-height: 360px; }
/* a command's input, highlighted the way shells highlight what is typed */
.sh-cmd { color: var(--sh-cmd); }
.sh-kw { color: var(--sh-kw); }
.sh-flag { color: var(--sh-flag); }
.sh-str { color: var(--sh-str); }
.sh-var { color: var(--sh-var); }
.sh-op { color: var(--sh-op); }
.sh-comment { color: var(--sh-comment); }
.sublink { display: inline-flex; align-items: center; gap: 2px; color: var(--link); font-size: 12px; white-space: nowrap; }
.sublink:hover { text-decoration: underline; }
.task-badge { margin-left: 6px; font-weight: 400; font-size: 11.5px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; }
.task-badge.running, .task-state.running { color: var(--working); border-color: color-mix(in srgb, var(--working) 45%, var(--border)); }
.task-badge.done, .task-state.done { color: var(--ok); }
.task-badge.failed, .task-state.failed { color: var(--blocked); border-color: color-mix(in srgb, var(--blocked) 45%, var(--border)); }

.tasks-notice { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); border: 1px dashed color-mix(in srgb, var(--working) 45%, var(--border)); border-radius: 10px; padding: 7px 12px; margin: 4px 0 12px; }
.tasks-notice[hidden] { display: none; }
.tasks-notice > span:nth-child(2) { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.task-row + .task-row { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 10px; }
.task-head { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.task-state { flex: none; font-size: 12px; color: var(--muted); }
.task-kind { flex: none; font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 5px; }
.task-title { min-width: 0; font-family: var(--mono); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-meta { font-size: 12px; color: var(--faint); margin-top: 2px; font-variant-numeric: tabular-nums; }
.task-summary { font-size: 12.5px; margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 8.5em; overflow: auto; }
.task-actions { display: flex; gap: 6px; margin-top: 6px; }
.task-output { margin: 6px 0 0; background: var(--code); border-radius: 6px; padding: 8px 10px; max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }

.spin { display: inline-block; width: 10px; height: 10px; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.turn-foot { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 8px; }
.turn-foot .aborted { color: var(--blocked); }
.turn-foot .running { color: var(--working); }
.turn-error { margin-top: 12px; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--blocked) 35%, var(--border)); border-left: 3px solid var(--blocked); border-radius: 8px; background: color-mix(in srgb, var(--blocked) 5%, var(--bg)); overflow-wrap: anywhere; }
.turn-error strong { display: block; color: var(--blocked); margin-bottom: 4px; }
.turn-error-message { white-space: pre-wrap; }
.turn-error-code { margin-top: 4px; color: var(--muted); font: 12px var(--mono); }
.turn-retry { margin-top: 12px; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--blocked) 35%, var(--border)); border-radius: 8px; background: color-mix(in srgb, var(--blocked) 5%, var(--bg)); overflow-wrap: anywhere; }
.turn-retry strong { display: flex; align-items: center; gap: 6px; color: var(--blocked); margin-bottom: 4px; }
.retry-detail { margin: 6px 0; color: var(--muted); white-space: pre-wrap; font: 12px var(--mono); }
.files { margin-top: 4px; font-size: 12px; color: var(--muted); }
.files summary { cursor: pointer; }
.files ul { margin: 4px 0 0; padding-left: 18px; font-family: var(--mono); }

/* ---------- questions ---------- */
.ask-icon { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--blocked); color: #fff; font-size: 12px; font-weight: 600; flex: none; }
.ask { border: 1px solid color-mix(in srgb, var(--blocked) 45%, var(--border)); border-radius: 14px; background: var(--raised); padding: 10px 12px; margin-bottom: 8px; max-height: 55vh; overflow-y: auto; }
.ask-head { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.ask-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ask-step { font-size: 12px; border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; color: var(--muted); }
.ask-step.done { color: var(--ok); }
.ask-step.now { border-color: var(--text); color: var(--text); }
.ask-detail { margin: 8px 0 0; padding: 7px 9px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); font: 12px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 30vh; overflow-y: auto; }
.ask-left { color: var(--blocked); }
.ask-q { margin: 8px 0; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.ask-opts { display: flex; flex-direction: column; gap: 6px; }
.ask-opt { display: flex; align-items: flex-start; gap: 10px; width: 100%; text-align: left; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); padding: 7px 10px; }
.ask-opt:hover { background: var(--hover); }
.ask-opt.on { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.ask-mark { flex: none; width: 14px; height: 14px; margin-top: 3px; border: 1.5px solid var(--faint); border-radius: 50%; }
.ask-opt[role="checkbox"] .ask-mark { border-radius: 4px; }
.ask-opt.on .ask-mark { border-color: var(--text); background: var(--text); box-shadow: inset 0 0 0 2.5px var(--bg); }
.ask-label { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.ask-desc { font-size: 12.5px; color: var(--muted); }
.ask-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.ask-foot .grow { flex: 1; }
.ask-other { flex: 1 1 220px; min-width: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 5px 9px; outline: none; }
.ask-other:focus { border-color: var(--muted); }
.asked { margin: 10px 0; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.asked-head { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.asked-head .step-time { margin-left: auto; }
.asked-row { margin-top: 6px; overflow-wrap: anywhere; }
.asked-q { color: var(--muted); font-size: 13px; }
.asked-a { font-weight: 600; }
.asked-a::before { content: "→ "; color: var(--faint); font-weight: 400; }
.asked-a.none { font-weight: 400; color: var(--faint); }
.asked-note { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- composer ---------- */
.composer:empty { display: none; }
.composer { position: relative; z-index: 6; padding: 4px 16px calc(18px + env(safe-area-inset-bottom)); background: var(--bg); }
/* the conversation fades out under the composer instead of meeting it at an edge */
.composer::before { content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 24px; background: linear-gradient(to bottom, transparent, var(--bg)); pointer-events: none; }
.composer-inner { max-width: 868px; margin: 0 auto; }
.ctx { display: flex; gap: 4px 12px; align-items: center; padding: 0 8px 6px; font-size: 12px; color: var(--muted); min-width: 0; }
.ctx > * { flex: none; max-width: 100%; }
.ctx .context-dir { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box { border: 1px solid var(--border); border-radius: 16px; background: var(--raised); padding: 10px 10px 8px 14px; box-shadow: var(--shadow-sm); transition: border-color 0.12s, box-shadow 0.12s; }
.box:focus-within { border-color: var(--border-strong); }
.box.drop { border-color: var(--link); box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 20%, transparent); }
.box.big textarea { min-height: 96px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 8px; }
.atts.empty { display: none; }
.att { position: relative; border: 1px solid var(--border); border-radius: 10px; background: var(--sunken); min-height: 56px; display: flex; align-items: center; }
.att img { width: 56px; height: 56px; object-fit: cover; border-radius: 9px; display: block; }
.att-name { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 0 26px 0 10px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-name > .ico { color: var(--muted); }
.att.busy img, .att.busy .att-name { opacity: 0.45; }
.att.bad { border-color: var(--blocked); }
.att-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text); pointer-events: none; }
.att-x { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border); background: var(--raised); color: var(--muted); padding: 0; display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.att-x:hover { color: var(--text); }
.attach-btn { margin-left: -6px; }
.pick { border: 1px solid transparent; background: var(--sunken); border-radius: 999px; padding: 3px 8px; font-size: 12.5px; color: var(--muted); max-width: 200px; outline: none; cursor: pointer; }
.pick:hover, .pick:focus-visible { border-color: var(--border); color: var(--text); }
.box textarea { width: 100%; border: 0; outline: none; resize: none; background: transparent; min-height: 26px; max-height: 40vh; display: block; padding: 2px 0; line-height: 1.6; }
.box textarea::placeholder { color: var(--faint); }
.box-row { display: flex; align-items: center; gap: 8px 10px; margin-top: 6px; flex-wrap: wrap; }
.send-btn { width: 32px; height: 32px; padding: 0; border-radius: 50%; }
.stop-btn { color: var(--blocked); border-color: color-mix(in srgb, var(--blocked) 35%, var(--border)); }
.stop-btn:hover { background: color-mix(in srgb, var(--blocked) 10%, var(--raised)); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.check.big { font-size: 13.5px; color: var(--text); }
.note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.note.warn { color: var(--blocked); }
.jump-latest { display: none; }
.cleanup-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 4px 0 14px; font-size: 13px; }
.cleanup-bar .seg { padding: 4px 10px; }
.cleanup-group + .cleanup-group { margin-top: 16px; }
.cleanup-head { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.cleanup-group > .note { margin: 2px 0 8px 24px; }
.cleanup-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 10px; max-height: 40vh; overflow-y: auto; }
.cleanup-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1px 8px; align-items: baseline; padding: 7px 10px; cursor: pointer; }
.cleanup-row + .cleanup-row { border-top: 1px solid var(--border); }
.cleanup-row:hover { background: var(--hover); }
.cleanup-row:has(input:not(:checked)) .cleanup-title { color: var(--muted); }
.cleanup-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cleanup-sub { grid-column: 2; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- the quick switcher ---------- */
.palette-back { position: fixed; inset: 0; z-index: 70; display: flex; justify-content: center; align-items: flex-start; padding: min(12vh, 120px) 16px 16px; background: rgba(0, 0, 0, 0.28); }
.palette { width: min(620px, 100%); max-height: min(70dvh, 560px); display: flex; flex-direction: column; overflow: hidden; background: var(--raised); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); animation: pop 0.12s ease-out; }
.palette-search { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--faint); }
.palette-input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 15px; color: var(--text); }
.palette-input::placeholder { color: var(--faint); }
.palette-list { overflow-y: auto; padding: 4px 6px 6px; overscroll-behavior: contain; }
.palette-group { font-size: 11.5px; color: var(--faint); padding: 8px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; text-align: left; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.palette-item > .ico { color: var(--muted); }
.palette-item.on { background: var(--hover); }
.palette-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.palette-label, .palette-hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-hint { font-size: 12px; color: var(--muted); }
.palette-empty { padding: 28px 12px; text-align: center; color: var(--muted); }

/* ---------- dialogs, toasts, login ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--bg); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); width: min(640px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; animation: pop 0.12s ease-out; }
.modal.wide { width: min(1000px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px 6px 20px; font-weight: 600; }
.modal-body { padding: 4px 20px 16px; overflow: auto; }
.modal-body > div > p:first-child { margin-top: 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 20px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field input, .field select, .field textarea { border: 1px solid var(--border); background: var(--raised); border-radius: 8px; padding: 7px 10px; outline: none; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--border-strong); }
.field .pick { max-width: none; }
.field textarea { min-height: 120px; resize: vertical; }
.handoff-context { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; text-align: center; margin: -6px 0 14px; }
.screen { background: #0e0e10; color: #e4e4e7; border-radius: 10px; padding: 12px; overflow: auto; white-space: pre; font-size: 12px; line-height: 1.35; margin: 0; max-height: 65dvh; }
.err { color: var(--blocked); font-size: 13px; min-height: 1.2em; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 80; max-width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 9px 14px; box-shadow: var(--shadow); font-size: 13px; animation: pop 0.15s ease-out; pointer-events: auto; }
.toast.bad { background: var(--blocked); color: #fff; }

.login { display: grid; place-items: center; height: 100dvh; padding: 16px; background: var(--side); }
.login form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; border: 1px solid var(--border); border-radius: 16px; background: var(--bg); box-shadow: var(--shadow-sm); }
.login h1 { font-size: 20px; margin: 0 0 6px; display: flex; align-items: center; gap: 10px; }
.login h1 img { width: 28px; height: 28px; }
.login input { border: 1px solid var(--border); background: var(--raised); border-radius: 10px; padding: 10px 12px; outline: none; }
.login input:focus { border-color: var(--border-strong); }
.login .btn { padding: 9px; }
.login .err:empty { display: none; }

/* ---------- narrow screens ---------- */
@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .main { position: relative; overflow: hidden; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform 0.18s; }
  .shell.nav .side { transform: none; box-shadow: var(--shadow); }
  .shell.nav .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.3); z-index: 30; }
  .menu-btn { display: inline-flex !important; }
  .top { min-height: 52px; padding: 6px 6px 6px 4px; gap: 4px; }
  .top-meta { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
  .top-meta > * { flex: none; }
  .share-button { width: 32px; height: 32px; padding: 0; border-color: transparent; background: transparent; }
  .share-button .btn-label { display: none; }
  .conv-inner { padding: 14px 16px calc(28px + var(--composer-height, 0px)); }
  .composer { position: absolute; inset: auto 0 0; z-index: 10; padding: 6px 12px calc(14px + env(safe-area-inset-bottom)); opacity: var(--composer-reveal, 1); transform: translateY(calc((1 - var(--composer-reveal, 1)) * 100%)); transition: opacity 0.12s linear, transform 0.12s ease-out; }
  .composer[inert] { pointer-events: none; }
  .jump-latest { display: block; position: absolute; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 11; border-radius: 999px; padding: 8px 14px; min-height: 40px; box-shadow: var(--shadow); font-size: 12.5px; }
  .rail { top: 8px; right: 10px; }
  .modal-back { padding: 8px; }
  .modal-head { padding: 10px 8px 4px 16px; }
  .modal-body { padding: 4px 16px 12px; }
  .modal-foot { padding: 8px 16px 12px; }
  .palette-back { padding-top: 10px; }
  .screen { font-size: 10.5px; padding: 8px; max-height: 70dvh; }
  .prompt { max-width: 92%; }
  .newpage { padding-top: 32px; }
  .page { padding: 18px 16px 32px; }
  .schedule-save-row > .note { flex-basis: 100%; }
  .ctx { flex-wrap: wrap; row-gap: 2px; }
  .ctx .usage { white-space: normal; }
  .pick { max-width: 120px; }
  .q-img img { max-width: 160px; max-height: 140px; }
  .step-time { display: none; }
  .step-line { grid-template-columns: 18px auto minmax(0, 1fr) auto; }
  .limit-row { grid-template-columns: 5em minmax(0, 1fr) 6em; }
  .limit-reset { grid-column: 2 / -1; margin-top: -4px; }
  .toasts { left: 16px; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom)); align-items: center; max-width: none; }
}

@media (max-width: 800px) and (prefers-reduced-motion: reduce) {
  .composer { transform: none; transition: none; }
}

/* skills: the @ list in message boxes, and their settings */
.skill-pop { position: fixed; z-index: 60; max-height: 280px; overflow-y: auto; padding: 4px; display: flex; flex-direction: column; background: var(--raised); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow); animation: pop 0.1s ease-out; }
.skill-option { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; border: 0; background: transparent; padding: 7px 10px; border-radius: 7px; text-align: left; font-size: 13px; color: var(--text); }
.skill-option span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }
.skill-option.on, .skill-option:hover { background: var(--hover); }
.skill-list { max-width: 720px; }
.skill-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.skill-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.settings-section .skill-info .note { margin: 0; }
.skill-actions { display: flex; gap: 8px; flex-shrink: 0; }
.skill-form { padding-top: 12px; }
.skill-content { min-height: 280px; font-size: 12.5px; line-height: 1.5; resize: vertical; }
.settings-section > .btn { margin-top: 12px; }
