:root {
  --bg: #faf9f5;
  --side: #f5f4ef;
  --hover: rgba(31, 30, 29, .06);
  --active: rgba(31, 30, 29, .09);
  --card: #ffffff;
  --pop: #ffffff;
  --line: #e8e5dc;
  --line-2: #d6d2c6;
  --text: #1f1e1d;
  --text-2: #4d4a43;
  --muted: #73706a;
  --accent: #c96442;
  --blue: #2f6fe0;
  --user: #efede6;
  --ok: #2f7d45;
  --ok-soft: #e4f0e6;
  --bad: #b8402d;
  --bad-soft: #f8e3de;
  --warn: #a8690c;
  --warn-soft: #f6ead3;
  --code: #f2f0e9;
  --shadow: 0 2px 6px rgba(0,0,0,.06), 0 12px 32px rgba(0,0,0,.10);
  --sans: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1f1e; --side: #1f1f1e; --hover: rgba(255,255,255,.05); --active: rgba(255,255,255,.08);
    --card: #262624; --pop: #2a2a28; --line: #31312f; --line-2: #42423f;
    --text: #e9e7e1; --text-2: #c9c6be; --muted: #9d9a92; --accent: #d97757; --blue: #5b9cf6;
    --user: #2d2d2b; --ok: #7cc28d; --ok-soft: #233227; --bad: #ec8b78; --bad-soft: #3d2622; --warn: #e3b25e; --warn-soft: #3a3022; --code: #191918;
    --shadow: 0 2px 6px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1f1f1e; --side: #1f1f1e; --hover: rgba(255,255,255,.05); --active: rgba(255,255,255,.08);
  --card: #262624; --pop: #2a2a28; --line: #31312f; --line-2: #42423f;
  --text: #e9e7e1; --text-2: #c9c6be; --muted: #9d9a92; --accent: #d97757; --blue: #5b9cf6;
  --user: #2d2d2b; --ok: #7cc28d; --ok-soft: #233227; --bad: #ec8b78; --bad-soft: #3d2622; --warn: #e3b25e; --warn-soft: #3a3022; --code: #191918;
  --shadow: 0 2px 6px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; flex: none; }
.hidden { display: none !important; }
a { color: var(--blue); }
.mono { font-family: var(--mono); }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 30px 26px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-mark { color: var(--accent); display: grid; place-items: center; }
.login-card h1 { margin: 2px 0 0; font: 500 24px/1.2 var(--serif); }
.login-card p { margin: 0 0 6px; color: var(--muted); }
.login-card input { padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); outline: none; }
.login-card input:focus { border-color: var(--text-2); }
.login-err { color: var(--bad); min-height: 20px; font-size: 13px; }

.btn { border: 1px solid var(--line-2); background: var(--card); padding: 7px 14px; border-radius: 9px; font-weight: 500; font-size: 13.5px; transition: background .12s, transform .1s; }
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: .9; background: var(--text); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.icon-btn { width: 30px; height: 30px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 7px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* layout */
.app { display: flex; height: 100dvh; }
.sidebar { width: 260px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; font-size: 13px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; position: relative; }
.only-mobile { display: none; }
.scrim { display: none; }

.sb-head { height: 8px; }
.sb-nav { padding: 4px 8px; display: flex; flex-direction: column; gap: 1px; }
.nav-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 7px; border: 0; background: transparent; color: var(--text-2); text-align: left; width: 100%; }
.nav-row:hover { background: var(--hover); color: var(--text); }
.nav-row svg { color: var(--muted); }
.search-row input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 0; color: var(--text); }
.search-row input::placeholder { color: var(--text-2); }
.search-row:focus-within input::placeholder { color: var(--muted); }
.sb-list { flex: 1; overflow-y: auto; padding: 6px 8px 12px; min-height: 0; }
.sb-group { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); padding: 14px 8px 4px; border: 0; background: transparent; width: 100%; text-align: left; }
.sb-group svg { width: 12px; height: 12px; transition: transform .15s; }
.sb-group.collapsed svg { transform: rotate(-90deg); }
.sb-group:hover { color: var(--text-2); }
.sb-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 7px; color: var(--text-2); position: relative; }
.sb-item:hover { background: var(--hover); color: var(--text); }
.sb-item.active { background: var(--active); color: var(--text); }
.sb-item .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-item .tm { font-size: 11.5px; color: var(--muted); flex: none; }
.dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.dot.running { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot.requires_action { background: var(--blue); }
.dot.external { background: var(--ok); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.sb-empty { color: var(--muted); padding: 12px 8px; }

.sb-foot { position: relative; padding: 8px; border-top: 1px solid var(--line); }
.acct { display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: transparent; padding: 6px; border-radius: 8px; text-align: left; }
.acct:hover { background: var(--hover); }
.avatar { width: 22px; height: 22px; border-radius: 50%; background: #6c5ce7; color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 11px; flex: none; text-transform: uppercase; }
.acct-text { display: flex; align-items: baseline; gap: 6px; min-width: 0; flex: 1; }
.acct-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-plan { font-size: 12px; color: var(--muted); white-space: nowrap; }
.acct-chev { color: var(--muted); width: 14px; height: 14px; }

/* popovers */
.pop { position: absolute; background: var(--pop); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; z-index: 40; display: flex; flex-direction: column; min-width: 220px; font-size: 13.5px; }
.pop-head { font-size: 12px; color: var(--muted); padding: 6px 10px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-item { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 7px 10px; border-radius: 7px; text-align: left; width: 100%; }
.pop-item:hover, .pop-item.kb { background: var(--hover); }
.pop-item .pi-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pop-item .pi-t { flex: 1; min-width: 0; }
.pop-item .pi-d { font-size: 12px; color: var(--muted); }
.pop-item .pi-r { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; flex: none; }
.pop-item .pi-r svg { width: 14px; height: 14px; }
.pop-item .chk { color: var(--blue); width: 16px; height: 16px; }
.pop-item .num { width: 12px; text-align: right; color: var(--muted); font-size: 12px; }
.pop-item.danger { color: var(--bad); }
.pop-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.pop-label { font-size: 12px; color: var(--muted); padding: 6px 10px 2px; }
.pop-note { font-size: 12.5px; color: var(--muted); padding: 6px 10px 8px; line-height: 1.45; max-width: 320px; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--hover); color: var(--muted); margin-left: 6px; white-space: nowrap; }
.badge.warn { background: var(--warn-soft); color: var(--warn); display: inline-flex; align-items: center; gap: 3px; }
.badge.warn svg { width: 11px; height: 11px; }

/* topbar */
.topbar { display: flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 42px; position: relative; }
.tb-title { display: flex; align-items: center; gap: 4px; border: 0; background: transparent; padding: 4px 8px; border-radius: 7px; min-width: 0; color: var(--text-2); font-size: 13px; }
.tb-title:hover { background: var(--hover); color: var(--text); }
.tb-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.tb-chev { width: 14px; height: 14px; color: var(--muted); }
.more-menu { top: 40px; left: 12px; }
.conn { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); margin-left: auto; margin-right: 6px; }
.conn.ok { background: var(--ok); opacity: .7; }
.conn.bad { background: var(--bad); }

/* thread */
.scroller { flex: 1; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.thread { max-width: 720px; margin: 0 auto; padding: 0 24px; }
.thread:first-of-type { padding-top: 16px; }
.spacer { height: 28px; }
.banner { max-width: 672px; margin: 10px auto 0; padding: 8px 12px; border-radius: 9px; background: var(--warn-soft); color: var(--text-2); font-size: 13px; }

.it { margin: 10px 0; }
.it.user { display: flex; justify-content: flex-end; margin: 26px 0 18px; }
.bubble { background: var(--user); padding: 8px 13px; border-radius: 10px; max-width: 78%; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.cmd-chip { display: inline-flex; gap: 6px; align-items: center; font-family: var(--mono); font-size: 12.5px; background: var(--user); padding: 5px 10px; border-radius: 8px; color: var(--text-2); }
.local-out { font-family: var(--mono); font-size: 12px; color: var(--text-2); background: var(--code); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; overflow-x: auto; }

.prose { font-size: 14.5px; line-height: 1.62; overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: .6em 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-weight: 600; line-height: 1.35; margin: 1.1em 0 .45em; }
.prose h1 { font-size: 1.3em; } .prose h2 { font-size: 1.15em; } .prose h3, .prose h4 { font-size: 1em; }
.prose ul, .prose ol { padding-left: 1.5em; margin: .5em 0; }
.prose li { margin: .2em 0; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 600; }
.prose code { font-family: var(--mono); font-size: .86em; background: var(--code); padding: .12em .38em; border-radius: 5px; }
.prose pre { position: relative; background: var(--code); border: 1px solid var(--line); border-radius: 9px; padding: 11px 13px; overflow-x: auto; font-size: 12.5px; line-height: 1.5; }
.prose pre code { background: none; padding: 0; font-size: inherit; }
.prose pre .hljs { background: transparent; padding: 0; }
.prose blockquote { border-left: 2px solid var(--line-2); margin: .7em 0; padding: 0 0 0 .9em; color: var(--text-2); }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 13px; margin: .7em 0; }
.prose th, .prose td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.prose th { background: var(--hover); font-weight: 600; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.copy-btn { position: absolute; top: 6px; right: 6px; opacity: 0; border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 2px 7px; font: 11.5px var(--sans); color: var(--text-2); transition: opacity .15s; }
.prose pre:hover .copy-btn, .copy-btn:focus { opacity: 1; }
@media (hover: none) { .copy-btn { opacity: .85; } }
.caret::after { content: ""; display: inline-block; width: 7px; height: 7px; background: var(--text-2); margin-left: 4px; border-radius: 50%; vertical-align: middle; animation: pulse 1s infinite; }

/* activity groups: "Ran 5 commands ›" */
.grp > summary, .row > summary, .think > summary { list-style: none; cursor: pointer; user-select: none; }
.grp > summary::-webkit-details-marker, .row > summary::-webkit-details-marker, .think > summary::-webkit-details-marker { display: none; }
.grp > summary { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; padding: 2px 0; max-width: 100%; }
.grp > summary:hover { color: var(--text-2); }
.grp > summary .gs { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp > summary .chev { width: 13px; height: 13px; transition: transform .15s; flex: none; }
.grp[open] > summary .chev { transform: rotate(90deg); }
.grp .err-n { color: var(--bad); }
.dstat { font-family: var(--mono); font-size: 12px; flex: none; }
.dstat .a { color: var(--ok); } .dstat .d { color: var(--bad); margin-left: 5px; }
.spin { width: 12px; height: 12px; border: 1.5px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.grp-body { margin: 6px 0 4px; padding-left: 12px; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.row > summary { display: flex; align-items: center; gap: 8px; padding: 3px 6px; margin-left: -6px; border-radius: 6px; font-size: 13px; color: var(--text-2); }
.row > summary:hover { background: var(--hover); }
.row .ri { color: var(--muted); display: flex; }
.row .ri svg { width: 14px; height: 14px; }
.row .rn { flex: none; font-weight: 500; }
.row .ra { color: var(--muted); font-family: var(--mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.row .rs { flex: none; display: flex; align-items: center; gap: 6px; font-size: 12px; }
.row .rs .ok { color: var(--ok); } .row .rs .err { color: var(--bad); }
.row .rs svg { width: 13px; height: 13px; }
.tool-body { margin: 4px 0 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); padding: 9px 11px; display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; }
.tool-body .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pre { font-family: var(--mono); font-size: 12px; line-height: 1.5; background: var(--code); border-radius: 7px; padding: 7px 9px; white-space: pre-wrap; word-break: break-word; max-height: 340px; overflow: auto; margin: 0; }
.pre.err { color: var(--bad); }
.diff { font-family: var(--mono); font-size: 12px; line-height: 1.5; border-radius: 7px; overflow: auto; max-height: 400px; background: var(--code); }
.diff div { white-space: pre-wrap; word-break: break-word; padding: 0 9px; }
.diff .add { background: var(--ok-soft); color: var(--ok); }
.diff .del { background: var(--bad-soft); color: var(--bad); }
.diff .ctxl { color: var(--muted); }
.think > summary { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; padding: 2px 0; }
.think > summary .chev { width: 13px; height: 13px; transition: transform .15s; }
.think[open] > summary .chev { transform: rotate(90deg); }
.think .th-body { color: var(--muted); font-size: 13px; white-space: pre-wrap; padding: 4px 0 4px 12px; border-left: 1px solid var(--line); margin: 4px 0; }
.sub-log { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-2); }
.sub-log div { display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sys-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 22px 0; }
.sys-line::before, .sys-line::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.err-box { border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); background: var(--bad-soft); color: var(--bad); border-radius: 9px; padding: 9px 12px; font-size: 13px; white-space: pre-wrap; }
.working { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin: 14px 0; }
.working .spark { color: var(--accent); width: 15px; height: 15px; animation: spin 3s linear infinite; }
.working .el { color: var(--muted); opacity: .8; }

/* composer */
.composer-wrap { padding: 0 20px calc(8px + env(safe-area-inset-bottom)); position: relative; }
.composer-wrap > * { max-width: 672px; margin-left: auto; margin-right: auto; }
.composer { position: relative; background: var(--card); border: 1px solid var(--line-2); border-radius: 14px; padding: 6px 6px 6px 6px; transition: border-color .15s; }
.composer:focus-within { border-color: var(--muted); }
.cp-main { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; max-height: 40vh; min-height: 24px; line-height: 1.5; font-size: 14px; padding: 4px 4px; }
.composer textarea::placeholder { color: var(--muted); }
.cp-icon { width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; flex: none; }
.cp-icon:hover { background: var(--hover); color: var(--text); }
.cp-icon.send:not(:disabled) { color: var(--text-2); }
.cp-icon:disabled { opacity: .35; cursor: default; background: transparent; }
.cp-icon.stop { color: var(--text); }
.cp-under { display: flex; align-items: center; gap: 10px; padding: 5px 2px 0; min-height: 28px; }
.cp-controls { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.ctl { border: 0; background: transparent; padding: 3px 7px; border-radius: 6px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.ctl:hover, .ctl.open { background: var(--hover); color: var(--text); }
.ctl-dim { color: var(--muted); }
.ring { border: 0; background: transparent; padding: 3px; border-radius: 6px; display: grid; place-items: center; }
.ring:hover { background: var(--hover); }
.ring svg { width: 16px; height: 16px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line-2); stroke-width: 2.4; }
.ring-fg { fill: none; stroke: var(--blue); stroke-width: 2.4; stroke-linecap: round; stroke-dasharray: 47.12; stroke-dashoffset: 47.12; transition: stroke-dashoffset .3s; }
.ring.warn .ring-fg { stroke: var(--warn); } .ring.bad .ring-fg { stroke: var(--bad); }
.ctl-menu { bottom: 40px; right: max(20px, calc((100% - 672px) / 2)); min-width: 260px; max-height: 70vh; overflow-y: auto; }
.limit-note { font-size: 12px; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.limit-note.warn { color: var(--warn); } .limit-note.bad { color: var(--bad); }
.limit-note a { cursor: pointer; color: inherit; text-decoration: underline; }

.slash { left: 0; right: 0; bottom: calc(100% + 6px); max-height: 280px; overflow-y: auto; }
.slash .pop-item .sn { font-family: var(--mono); font-size: 12.5px; flex: none; }
.slash .pop-item .sd { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.queue { display: flex; flex-direction: column; gap: 5px; }
.queue:not(:empty) { margin-bottom: 7px; }
.qi { display: flex; gap: 8px; align-items: flex-start; background: var(--card); border: 1px dashed var(--line-2); border-radius: 10px; padding: 6px 6px 6px 11px; font-size: 13px; }
.qi .qt { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 90px; overflow: auto; padding-top: 3px; }
.qi .ql { font-size: 11px; color: var(--muted); flex: none; padding-top: 4px; }
.qi textarea { flex: 1; min-height: 38px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--bg); padding: 5px 7px; outline: none; resize: vertical; }
.qi .icon-btn { width: 26px; height: 26px; }
.qi .icon-btn svg { width: 14px; height: 14px; }

.todos { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 7px 12px; font-size: 13px; margin-bottom: 7px; }
.todos summary { cursor: pointer; display: flex; gap: 8px; align-items: center; color: var(--muted); list-style: none; font-size: 12.5px; }
.todos summary::-webkit-details-marker { display: none; }
.todos .todo-list { padding-top: 4px; }
.todo { display: flex; gap: 8px; align-items: flex-start; padding: 2px 0; color: var(--text-2); }
.todo .box { width: 14px; height: 14px; border: 1.5px solid var(--line-2); border-radius: 50%; flex: none; margin-top: 3px; display: grid; place-items: center; }
.todo.completed { color: var(--muted); }
.todo.completed .box { background: var(--muted); border-color: var(--muted); color: var(--card); }
.todo.completed .box svg { width: 9px; height: 9px; }
.todo.in_progress { color: var(--text); }
.todo.in_progress .box { border-color: var(--text-2); border-top-color: transparent; animation: spin 1s linear infinite; }

/* permission prompts (docked above the composer) */
.perms:not(:empty) { margin-bottom: 8px; }
.perm { border: 1px solid var(--line-2); background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; display: flex; flex-direction: column; gap: 9px; max-height: 55vh; overflow-y: auto; }
.perm + .perm { margin-top: 8px; }
.perm-title { font-weight: 600; font-size: 13.5px; }
.perm-desc { color: var(--text-2); font-size: 13px; }
.perm-opts { display: flex; flex-direction: column; gap: 2px; }
.perm-opt { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; text-align: left; padding: 7px 9px; border-radius: 8px; font-size: 13.5px; width: 100%; }
.perm-opt:hover, .perm-opt:focus-visible { background: var(--hover); outline: none; }
.perm-opt .num { width: 14px; color: var(--muted); font-size: 12px; text-align: right; flex: none; }
.perm-opt.primary { background: var(--hover); }
.perm textarea { width: 100%; resize: vertical; min-height: 36px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg); padding: 7px 9px; outline: none; font-size: 13px; }
.perm textarea:focus { border-color: var(--muted); }
.q { display: flex; flex-direction: column; gap: 5px; }
.q-chip { align-self: flex-start; font-size: 11px; background: var(--hover); color: var(--text-2); padding: 1px 7px; border-radius: 5px; }
.q-text { font-weight: 500; }
.q-opt { display: flex; gap: 9px; align-items: flex-start; border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; cursor: pointer; }
.q-opt:hover { background: var(--hover); }
.q-opt.sel { border-color: var(--blue); }
.q-opt input { margin-top: 3px; accent-color: var(--blue); }
.q-opt .ol { font-weight: 500; }
.q-opt .od { font-size: 12.5px; color: var(--muted); }
.q-opt pre { font-size: 11.5px; margin: 5px 0 0; }
.q-other { border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; background: var(--bg); outline: none; }
.plan-box { max-height: 38vh; overflow: auto; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: var(--bg); }

/* usage */
.usage-mini { padding: 4px 10px 8px; display: flex; flex-direction: column; gap: 9px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.usage-mini:empty { display: none; }
.ubar { display: flex; flex-direction: column; gap: 5px; }
.ubar-h { display: flex; align-items: baseline; gap: 10px; font-size: 13px; }
.ubar-h b { font-weight: 500; }
.ubar-h .rs { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.ubar-h .pc { color: var(--text-2); font-size: 12px; min-width: 30px; text-align: right; }
.ubar-track { height: 4px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.ubar-fill { height: 100%; border-radius: 4px; background: var(--blue); transition: width .4s ease; }
.ubar-fill.warn { background: var(--warn); } .ubar-fill.bad { background: var(--bad); }
.usage-pop .pop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12.5px; }
.usage-pop .see-all { border: 0; background: transparent; color: var(--text); font-size: 12.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 5px; }
.usage-pop .see-all:hover { background: var(--hover); }
.usage-pop .see-all svg { width: 13px; height: 13px; }
.usage-pop .ubars { padding: 4px 10px 10px; display: flex; flex-direction: column; gap: 12px; min-width: 300px; }
.usage-pop .ctxline { border-top: 1px solid var(--line); padding: 8px 10px 6px; font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 80; padding: 16px; }
.modal-card { width: min(500px, 100%); max-height: 86vh; overflow-y: auto; background: var(--bg); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow); padding: 16px 20px 20px; }
.modal-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-h h3 { margin: 0; font-size: 17px; font-weight: 600; }
.usage-body { display: flex; flex-direction: column; gap: 20px; }
.usage-sec h4 { margin: 0 0 10px; font-size: 12px; color: var(--muted); font-weight: 500; }
.usage-sec .ubar + .ubar { margin-top: 14px; }
.usage-plan { display: flex; align-items: center; gap: 12px; }
.usage-plan .avatar { width: 34px; height: 34px; font-size: 14px; }
.usage-plan .pn { font-weight: 600; } .usage-plan .pe { font-size: 12.5px; color: var(--muted); }
.brk { display: flex; justify-content: space-between; font-size: 13px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.brk span:last-child { color: var(--muted); }

/* new session */
.new-view { max-width: 620px; margin: 0 auto; padding: 16vh 24px 20px; }
.nv-hello { display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--accent); margin-bottom: 26px; }
.nv-hello h2 { color: var(--text); font: 400 30px/1.2 var(--serif); margin: 0; }
.nv-folder { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 10px; background: var(--card); color: var(--muted); }
.nv-folder select { flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 0; outline: none; color: var(--text); font-size: 13.5px; }
.nv-folder select option { background: var(--pop); color: var(--text); }
.nv-input { width: 100%; margin-top: 8px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--card); outline: none; font-size: 13.5px; }

.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 9px; font-size: 13px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

/* mobile */
@media (max-width: 820px) {
  .only-mobile { display: grid; }
  .sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(84vw, 300px); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); font-size: 14px; }
  .sb-head { height: auto; padding: calc(6px + env(safe-area-inset-top)) 8px 0; display: flex; justify-content: flex-end; }
  .app.sb-open .sidebar { transform: none; }
  .app.sb-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .topbar { padding: calc(6px + env(safe-area-inset-top)) 8px 6px; }
  .thread { padding: 0 16px; }
  .composer-wrap { padding: 0 10px calc(6px + env(safe-area-inset-bottom)); }
  .prose { font-size: 15px; }
  .bubble { max-width: 88%; font-size: 15px; }
  .composer textarea { font-size: 16px; }
  .ctl-menu { right: 10px; left: 10px; min-width: 0; }
  .new-view { padding-top: 8vh; }
  .nv-hello h2 { font-size: 26px; }
  .tb-name { max-width: 70vw; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
