:root {
  --bg: #f6f4ee; --surface: #ffffff; --surface-2: #efece4; --border: #e2ded3; --text: #1f1e1b; --muted: #6d6a62;
  --accent: #c96442; --accent-soft: #f6e3da; --accent-ink: #ffffff;
  --busy: #2f6fe0; --busy-soft: #e3ecfc; --wait: #b86e00; --wait-soft: #fbedd5; --ok: #1f8a4c; --ok-soft: #dff2e6;
  --err: #c9302c; --err-soft: #fbe3e2; --off: #9a978e;
  --code-bg: #f1eee6; --user-bg: #ece6da;
  --mono: "JetBrains Mono", "D2Coding", "Cascadia Mono", Consolas, ui-monospace, monospace;
  --sans: "Pretendard", system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", Roboto, sans-serif;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171613; --surface: #201f1b; --surface-2: #2a2924; --border: #36342e; --text: #ecebe5; --muted: #a29f95;
    --accent: #e07b55; --accent-soft: #3d2a21; --accent-ink: #1a0f0a;
    --busy: #78a9ff; --busy-soft: #1d2b44; --wait: #f3b04e; --wait-soft: #3a2c14; --ok: #5bd18a; --ok-soft: #173326;
    --err: #ff7b72; --err-soft: #3b1c1b; --off: #77746c;
    --code-bg: #1b1a17; --user-bg: #2e2b25;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-text-size-adjust: 100%; word-break: keep-all; overflow-wrap: anywhere; }
body { overscroll-behavior-y: contain; }
a { color: var(--accent); }
code, pre { font-family: var(--mono); font-size: 13px; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.warn { color: var(--wait); font-weight: 600; }

#app { display: flex; flex-direction: column; height: 100dvh; }
#topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border); background: var(--surface); min-height: 52px; position: relative; z-index: 2; }
.logo { border-radius: 7px; }
.top-title { font-weight: 700; font-size: 17px; flex: 1; display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
#panes { flex: 1; min-height: 0; display: flex; }
#side { width: 400px; border-right: 1px solid var(--border); overflow-y: auto; background: var(--bg); }
#main { flex: 1; min-width: 0; overflow-y: auto; }
body.wide #main.home { display: none; }

.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px; font-size: 20px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.sm { width: 32px; height: 32px; font-size: 16px; }
.conn-dot, .dot, .status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; background: var(--off); }
.ok { --c: var(--ok); } .wait { --c: var(--wait); } .busy { --c: var(--busy); } .err { --c: var(--err); } .off { --c: var(--off); }
.conn-dot, .dot, .status-dot { background: var(--c, var(--off)); }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 60%, transparent); } 50% { box-shadow: 0 0 0 5px transparent; } }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; min-height: 40px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13.5px; }
.btn.big { width: 100%; min-height: 48px; font-size: 16px; }
.btn.ok { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.btn.icon { width: 44px; padding: 0; font-size: 18px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-col { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge.wait { background: var(--wait); color: #fff; }
.badge.ok-soft { background: var(--ok-soft); color: var(--ok); }
.badge.accent-soft { background: var(--accent-soft); color: var(--accent); }
.pill { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.input { width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; font-weight: 400; min-height: 42px; }
.input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 0; }
.input.code { font-family: var(--mono); letter-spacing: .15em; text-transform: uppercase; font-size: 18px; }

/* home */
.home, #side { padding-bottom: 32px; }
.banner { margin: 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--accent-soft); display: flex; gap: 8px; align-items: center; }
.banner span { flex: 1; font-size: 13.5px; }
.group { margin: 12px; }
.sec-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 4px 8px; display: flex; gap: 6px; align-items: center; }
.seg { display: flex; gap: 4px; margin: 12px 12px 4px; background: var(--surface-2); border-radius: 10px; padding: 3px; width: fit-content; }
.seg button { border: 0; background: transparent; padding: 5px 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.machine { margin: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.machine.offline { opacity: .72; }
.machine-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.machine-name { font-weight: 700; }
.machine-meta { color: var(--muted); font-size: 12.5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--border); }
.srow:last-child { border-bottom: 0; }
.srow:hover, .srow.sel { background: var(--surface-2); }
.srow .status-dot { margin-top: 7px; }
.srow-main { flex: 1; min-width: 0; }
.srow-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow-sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.srow-preview { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty.sm { padding: 14px; font-size: 13.5px; }
.empty.big { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 15vh; }

/* pending cards */
.pend-list { display: flex; flex-direction: column; gap: 8px; }
.pcard { background: var(--surface); border: 1px solid color-mix(in srgb, var(--wait) 45%, var(--border)); border-left: 4px solid var(--wait); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.pcard.busy { opacity: .55; }
.pcard-title { font-weight: 700; }
.pcard-where { font-size: 12.5px; color: var(--muted); }
.pcard-sum { margin: 0; background: var(--code-bg); padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; word-break: break-all; max-height: 7.5em; overflow: hidden; }
.pcard-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pcard-actions .btn { flex: 1 1 auto; }
.pcard .plan { max-height: 45vh; overflow: auto; background: var(--code-bg); border-radius: 8px; padding: 4px 12px; }
.q { border-top: 1px dashed var(--border); padding-top: 8px; }
.q-head { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; }
.q-text { font-weight: 600; margin: 2px 0 8px; }
.q-opts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.opt { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 9px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.opt span { font-size: 12.5px; color: var(--muted); }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }

/* session view */
.session-view { display: flex; flex-direction: column; overflow: hidden !important; height: 100%; }
.sv-head { padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.sv-title { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.sv-scroll { flex: 1; overflow-y: auto; padding: 12px 12px 4px; -webkit-overflow-scrolling: touch; }
.load-more { display: block; margin: 0 auto 10px; }
.sv-list { display: flex; flex-direction: column; gap: 10px; max-width: 860px; margin: 0 auto; }
.sv-bottom { border-top: 1px solid var(--border); background: var(--surface); padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); max-height: 70%; overflow-y: auto; }
.sv-pending { display: flex; flex-direction: column; gap: 8px; max-width: 860px; margin: 0 auto; }
.sv-pending:not(:empty) { margin-bottom: 8px; }
.sv-hint { max-width: 860px; margin: 0 auto 6px; padding: 0 4px; }
.sv-hint:empty { display: none; }
.composer { display: flex; gap: 8px; align-items: flex-end; max-width: 860px; margin: 0 auto; flex-wrap: wrap; }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 12px; padding: 10px 12px; font: inherit; min-height: 44px; max-height: 180px; overflow-y: hidden; }
.composer textarea.scroll { overflow-y: auto; }
.composer .mode { flex: 1 0 100%; width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 10px; padding: 6px 10px; font: inherit; font-size: 13.5px; }
.sv-typing { display: flex; gap: 4px; padding: 8px 4px; max-width: 860px; margin: 0 auto; }
.sv-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.sv-typing span:nth-child(2) { animation-delay: .2s; } .sv-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.msg.user { align-self: flex-end; max-width: 88%; display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user-bg); padding: 9px 13px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; word-break: break-word; }
.msg-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.msg.asst { max-width: 100%; }
.md { word-break: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: .45em 0; }
.md h3, .md h4, .md h5, .md h6, .md h7, .md h8 { margin: .8em 0 .35em; font-size: 1.02em; }
.md h3 { font-size: 1.12em; }
.md ul, .md ol { margin: .4em 0; padding-left: 1.4em; }
.md pre.code, pre.code { background: var(--code-bg); padding: 10px 12px; border-radius: 9px; overflow-x: auto; white-space: pre; margin: .5em 0; }
.md blockquote { margin: .5em 0; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); }
.tbl { overflow-x: auto; margin: .5em 0; }
.tbl table { border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; vertical-align: top; }
.tbl th { background: var(--surface-2); }
.sys { align-self: center; font-size: 12.5px; color: var(--muted); background: var(--surface-2); padding: 3px 10px; border-radius: 999px; max-width: 95%; white-space: pre-wrap; word-break: break-word; }
.sys.err { color: var(--err); background: var(--err-soft); }

details.tgroup { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
details.tgroup > summary { list-style: none; cursor: pointer; padding: 7px 12px; display: flex; flex-wrap: wrap; column-gap: 8px; row-gap: 1px; font-size: 13px; color: var(--muted); align-items: center; }
details.tgroup > summary::-webkit-details-marker { display: none; }
details.tgroup > summary::before { content: "▸"; transition: transform .15s; }
details.tgroup[open] > summary::before { transform: rotate(90deg); }
.tg-count { font-weight: 600; white-space: nowrap; }
.tg-kinds { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.tg-last { flex-basis: 100%; padding-left: 18px; font-size: 12.5px; color: var(--text); opacity: .8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tg-last:empty { display: none; }
details.tgroup[open] > summary > .tg-last { display: none; }
.tg-last.mono, .t-sum.mono { font-family: var(--mono); font-size: 12px; }
.tg-body { padding: 0 8px 8px; display: flex; flex-direction: column; gap: 4px; }
details.tool { border-radius: 8px; background: var(--bg); }
details.tool > summary { list-style: none; cursor: pointer; padding: 6px 8px; display: flex; gap: 8px; align-items: center; font-size: 13px; }
details.tool > summary::-webkit-details-marker { display: none; }
.chip { font-family: var(--mono); font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); white-space: nowrap; }
.t-kind { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); white-space: nowrap; flex: none; }
.t-sum { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.t-state { width: 14px; text-align: center; font-weight: 700; color: var(--muted); }
.t-state.ok { color: var(--ok); } .t-state.err { color: var(--err); }
.tool-detail { padding: 2px 8px 8px; display: flex; flex-direction: column; gap: 6px; }
.tool-detail pre { margin: 0; max-height: 40vh; overflow: auto; white-space: pre-wrap; word-break: break-word; }
pre.cmd { background: var(--code-bg); padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; word-break: break-all; margin: 0; }
.path { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; }
pre.diff { background: var(--code-bg); padding: 8px 10px; border-radius: 8px; margin: 0; white-space: pre-wrap; word-break: break-word; }
pre.diff .del { color: var(--err); background: var(--err-soft); display: inline; }
pre.diff .add { color: var(--ok); background: var(--ok-soft); display: inline; }
.result.err pre { color: var(--err); }
.todos { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
.todos .completed { color: var(--muted); text-decoration: line-through; }
.todos .in_progress { font-weight: 700; }
details.think { font-size: 13px; color: var(--muted); }
details.think summary { cursor: pointer; }
.think-body { white-space: pre-wrap; padding: 6px 10px; border-left: 2px solid var(--border); margin-top: 4px; }

/* forms, settings, onboarding */
.form, .settings, .onboard { max-width: 640px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.form label, .onboard label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13.5px; }
.onboard { align-items: stretch; text-align: left; padding-top: 6vh; }
.onboard > img { align-self: center; border-radius: 20px; }
.onboard h1 { text-align: center; margin: 4px 0 0; }
.onboard > p.muted:first-of-type { text-align: center; margin-top: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; align-items: center; }
.kv:last-of-type { border-bottom: 0; }
.kv > span { color: var(--muted); min-width: 0; word-break: break-all; }
.kv > b { text-align: right; font-weight: 600; }
.pc { padding: 8px 0 12px; border-bottom: 1px solid var(--border); }
.pc:last-child { border-bottom: 0; }
.pc-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.pair-code { font-family: var(--mono); font-size: 32px; font-weight: 700; letter-spacing: .18em; text-align: center; padding: 12px; background: var(--accent-soft); color: var(--accent); border-radius: 12px; margin-top: 12px; user-select: all; }
code.sel { user-select: all; word-break: break-all; }

/* toasts & sheets */
#toasts { position: fixed; left: 0; right: 0; top: max(60px, calc(env(safe-area-inset-top) + 56px)); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 50; padding: 0 12px; }
.toast { pointer-events: auto; max-width: 520px; width: fit-content; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18); transition: opacity .3s, transform .3s; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.err { background: var(--err); color: #fff; }
.toast.warn { background: var(--wait); color: #fff; }
.toast.clickable { cursor: pointer; }
.toast.out { opacity: 0; transform: translateY(-8px); }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px; padding-bottom: max(18px, env(safe-area-inset-bottom)); max-height: 88dvh; overflow-y: auto; }
.sheet h3 { margin: 0 0 6px; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 18px; } }

/* login / setup */
.onboard .seg { margin: 4px 0; }
.onboard .pane, .sheet .form { display: flex; flex-direction: column; gap: 12px; }
.sheet .form { padding: 0; max-width: none; }
.onboard .step { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.otp-key { font-family: var(--mono); font-size: 15px; letter-spacing: .08em; word-break: break-all; user-select: all; }
.acct + .acct { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.audit { max-height: 55vh; overflow: auto; margin-top: 8px; }
.audit .kv.bad > span:first-child { color: var(--err); }

/* folders & collapsible groups */
.folder { margin: 10px 12px; background: var(--surface); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border)); border-radius: var(--radius); overflow: hidden; }
.machine-head[data-act="toggle"] { cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
.machine-head .chev { width: 14px; color: var(--muted); font-size: 12px; flex: none; }
.closed > .machine-head { border-bottom: 0; }
.srow .srow-more { flex: none; margin: -4px -8px 0 -4px; color: var(--muted); }
.input.code::placeholder { letter-spacing: normal; text-transform: none; }

/* usage (from Claude Usage Viewer) */
.ubar { border: 0; background: transparent; padding: 0; display: inline-flex; gap: 4px; cursor: pointer; flex: none; }
.uchip { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; white-space: nowrap; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.uchip.ok { --c: var(--ok); } .uchip.wait { --c: var(--wait); } .uchip.err { --c: var(--err); } .uchip.off { --c: var(--off); }
.usage { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.ulimit .ul-top { display: flex; justify-content: space-between; font-size: 13.5px; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 4px 0 2px; }
.meter > i { display: block; height: 100%; border-radius: 999px; }
.m-ok { background: var(--ok); } .m-wait { background: var(--wait); } .m-err { background: var(--err); } .m-off { background: var(--off); }
.t-ok { color: var(--ok); } .t-wait { color: var(--wait); } .t-err { color: var(--err); } .t-off { color: var(--off); }
details.pc-usage { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
details.pc-usage > summary { cursor: pointer; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
