:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg: #101218; --rail: #12151d; --pane: #171a23; --card: #1b1f2a;
  --field: #11151d; --hover: #242938; --line: #303543; --faint: #272b38;
  --text: #f1f1f7; --muted: #a8afc3; --primary: #c7b5ff; --accent-bg: #322a45;
  --green: #95dfbd; --amber: #f3c584; --red: #ffacb8; --radius: .8rem;
  --reading: 49rem;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
button,input,select,textarea { font: inherit; color: inherit; }
button,.btn {
  display: inline-flex; gap: .45rem; align-items: center; justify-content: center;
  min-height: 2.55rem; padding: .52rem .9rem; border: 1px solid var(--line); border-radius: .62rem;
  background: var(--card); color: var(--text); cursor: pointer; text-decoration: none;
  font-size: .89rem; font-weight: 560; line-height: 1.35;
}
button:hover,.btn:hover { background: var(--hover); border-color: #52586b; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: #211831; font-weight: 660; }
button.primary:hover { background: #dacdff; }
button.subtle { background: transparent; border-color: transparent; color: var(--muted); }
button.subtle:hover { background: var(--hover); color: var(--text); }
.square { width: 2.48rem; height: 2.48rem; min-height: 0; padding: 0; font-size: 1.3rem; }
input,select,textarea {
  width: 100%; min-width: 0; min-height: 2.7rem; border: 1px solid var(--line); border-radius: .58rem;
  background: var(--field); padding: .6rem .75rem; line-height: 1.45;
}
input::placeholder,textarea::placeholder { color: #949caf; }
textarea { resize: vertical; }
select { appearance: none; padding-right: 2rem; text-overflow: ellipsis;
  background-image: linear-gradient(45deg,transparent 49%,var(--muted) 50%),linear-gradient(135deg,var(--muted) 49%,transparent 50%);
  background-position: calc(100% - 1.1rem) center,calc(100% - .8rem) center; background-size:.31rem .31rem; background-repeat:no-repeat; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1,h2,h3,p { margin: 0; }
h1 { font-size: clamp(1.65rem,3vw,2.3rem); line-height:1.12; letter-spacing:-.045em; }
h2 { font-size:1.18rem; letter-spacing:-.024em; line-height:1.35; overflow-wrap:anywhere; }
h3 { font-size:1rem; letter-spacing:-.012em; line-height:1.4; }
label { display:grid; gap:.42rem; min-width:0; color:var(--muted); font-size:.9rem; }
a { color:var(--primary); }
pre,code,kbd { font-family:"IBM Plex Mono",ui-monospace,Consolas,monospace; }
pre { margin:0; white-space:pre-wrap; overflow-wrap:anywhere; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
.brand { display:flex; align-items:center; gap:.72rem; }
.brand-mark { flex:none; width:2.28rem; aspect-ratio:1; border-radius:.72rem; position:relative;
  background:linear-gradient(145deg,#e0d5ff,#ae92f4); box-shadow:0 2px 8px #09071455; }
.brand-mark::before,.brand-mark::after { content:""; position:absolute; width:34%; height:36%; border:2px solid #392458; border-radius:16%; transform:skewY(-14deg); }
.brand-mark::before { left:21%; top:37%; }
.brand-mark::after { left:36%; top:23%; background:#d1bafb; }
.wordmark { font-size:1.04rem; font-weight:720; letter-spacing:-.045em; line-height:1.14; }
.wordmark b { display:block; font-weight:490; font-size:.81rem; letter-spacing:.035em; color:var(--muted); }
.glyph { display:inline-block; width:1.15rem; height:1.15rem; position:relative; flex:none; color:inherit; }
.glyph::before,.glyph::after { content:""; position:absolute; }
.glyph-chats::before { inset:1px 0 4px; border:1.6px solid; border-radius:4px; }
.glyph-chats::after { left:3px; bottom:1px; width:5px; height:5px; border-left:1.6px solid; transform:skewY(-35deg); }
.glyph-runs::before { inset:2px auto 2px 4px; width:10px; border-left:1.6px solid; border-bottom:1.6px solid; border-radius:0 0 0 3px; }
.glyph-runs::after { width:5px; height:5px; border-radius:50%; background:currentColor; left:2px; top:1px; box-shadow:10px 12px 0 currentColor,10px 4px 0 currentColor; }
.glyph-mcp::before { width:9px; height:9px; border:1.6px solid; transform:rotate(45deg); border-radius:2px; left:4px; top:3px; }
.glyph-mcp::after { width:3px; height:3px; border-radius:50%; background:currentColor; left:0; top:8px; box-shadow:16px 0 currentColor; }
.glyph-devices::before { inset:2px 0 5px; border:1.6px solid; border-radius:3px; }
.glyph-devices::after { left:30%; right:30%; bottom:2px; border-top:2px solid; }
.glyph-search::before { width:9px; height:9px; border:1.6px solid; border-radius:50%; left:2px; top:2px; }
.glyph-search::after { width:7px; height:2px; background:currentColor; transform:rotate(45deg); left:11px; top:13px; }
.gate { min-height:100svh; display:grid; place-items:center; padding:1.2rem;
  background:radial-gradient(ellipse at 20% 16%,#2a243f 0,transparent 49%),radial-gradient(ellipse at 80% 86%,#172b31,transparent 48%),var(--bg); }
.auth-card { width:min(100%,26.5rem); padding:clamp(1.35rem,5vw,2.35rem); border:1px solid #44404f; border-radius:1.3rem; background:#191b25; box-shadow:0 1.5rem 5rem #090a1266; }
.auth-card h1 { margin:2.1rem 0 1.4rem; }
.auth-card form,.form { display:grid; gap:1rem; }
.feedback { margin-top:.55rem; color:var(--red); font-size:.9rem; line-height:1.5; }
.feedback:empty { display:none; }
.app { display:grid; grid-template-columns:11.5rem minmax(0,1fr); height:100dvh; min-height:0; }
.workspace-nav { display:flex; flex-direction:column; gap:2.55rem; background:var(--rail); border-right:1px solid var(--faint); padding:1.5rem .7rem .85rem; }
.workspace-nav .brand { padding:0 .45rem; }
.workspace-nav nav { display:grid; gap:.32rem; }
.workspace-nav nav button { justify-content:start; gap:.8rem; width:100%; background:transparent; border-color:transparent; color:var(--muted); min-height:2.85rem; }
.workspace-nav nav button:hover { background:var(--card); }
.workspace-nav nav button[aria-current] { color:#e5d7ff; background:var(--accent-bg); border-color:#493c5b; }
.rail-foot { margin-top:auto; border-top:1px solid var(--faint); padding-top:.8rem; display:grid; }
.rail-foot button { justify-content:start; background:transparent; border:0; color:var(--muted); }
.network-dot { width:.5rem; height:.5rem; border-radius:50%; background:#828799; }
.network-dot.connected { background:var(--green); }
#mobile-logout { display:none; }
main { min-height:0; min-width:0; overflow:auto; }
.chat-page { height:100%; display:grid; grid-template-columns:clamp(15rem,21vw,20rem) minmax(0,1fr); }
.session-pane { display:flex; flex-direction:column; min-height:0; background:var(--pane); border-right:1px solid var(--faint); }
.pane-head { padding:1.3rem 1rem .9rem; display:grid; gap:.65rem; }
.pane-title,.page-title,.run-summary,.dialog-head { display:flex; align-items:center; justify-content:space-between; gap:.85rem; }
.pane-title { margin-bottom:.65rem; }
.pane-title h1 { font-size:1.5rem; }
.pane-title .square { background:#292338; border-color:#493d60; color:var(--primary); }
.search-field,.device-field { position:relative; }
.search-field .glyph,.device-field .glyph { position:absolute; left:.7rem; top:50%; transform:translateY(-50%); color:var(--muted); pointer-events:none; }
.search-field input,.device-field select { padding-left:2.35rem; font-size:.875rem; }
.session-list { flex:1; overflow:auto; padding:0 .65rem .9rem; }
.project-group { padding:1rem .55rem .45rem; color:var(--muted); font-size:.8rem; font-weight:650; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
.session-list button { display:grid; gap:.34rem; justify-content:stretch; width:100%; padding:.7rem .65rem; text-align:left; background:transparent; border:1px solid transparent; }
.session-list button:hover { background:var(--card); }
.session-list button[aria-current] { background:#282739; border-color:#413b52; box-shadow:inset 2px 0 var(--primary); }
.session-list button span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.session-list small { color:var(--muted); font-size:.79rem; font-weight:450; }
.more { align-self:center; margin:.3rem .65rem .7rem; }
.chat,.chat-body { height:100%; min-width:0; min-height:0; }
.chat-body { display:grid; grid-template-rows:auto minmax(0,1fr) auto; }
.chat { background:radial-gradient(ellipse at 85% -20%,#212031 0,transparent 55%),var(--bg); }
.empty { min-height:100%; display:flex; gap:.8rem; align-items:center; justify-content:center; flex-direction:column; text-align:center; color:var(--muted); padding:1.4rem; }
.empty-mark { width:3.55rem; margin-bottom:.6rem; border-radius:1.1rem; transform:rotate(-5deg); }
.empty strong { font-size:1.55rem; color:var(--text); letter-spacing:-.04em; }
.empty button { margin-top:.25rem; }
.chat-head { border-bottom:1px solid var(--faint); padding:1.1rem clamp(1rem,3vw,2.5rem); display:flex; justify-content:space-between; align-items:center; gap:.8rem; }
.chat-heading { min-width:0; }
.chat-heading h2 { font-size:clamp(1.05rem,1.65vw,1.45rem); display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.chat-heading p { color:var(--muted); font-size:.81rem; margin:.2rem 0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#chat-status { display:inline-flex; align-items:center; gap:.4rem; font-size:.81rem; color:var(--muted); }
#chat-status::before { content:""; width:.42rem; height:.42rem; border-radius:50%; background:#9095a8; }
#chat-status[data-phase=working] { color:var(--primary); }
#chat-status[data-phase=working]::before { background:var(--primary); animation:pulse 1s ease-in-out infinite alternate; }
#chat-status[data-phase=waiting]::before { background:var(--amber); }
@keyframes pulse { to { opacity:.35; } }
@media (prefers-reduced-motion:reduce) { #chat-status[data-phase=working]::before { animation:none; } }
.chat-actions,.composer-actions,.button-row { display:flex; align-items:center; gap:.45rem; flex-wrap:wrap; }
.chat-actions { justify-content:end; }
.mobile-back { display:none; }
.chat-scroller { min-height:0; overflow:auto; padding:1.25rem clamp(1rem,3vw,3rem) .8rem; scrollbar-gutter:stable; }
.messages,.child-group { max-width:var(--reading); margin:0 auto; }
.messages { display:grid; gap:1.9rem; padding:.4rem 0 1rem; }
.message { display:grid; min-width:0; gap:.64rem; }
.message.user { width:fit-content; max-width:92%; justify-self:end; background:#282436; border:1px solid #44384f; border-radius:1rem 1rem .35rem 1rem; padding:.85rem 1rem; }
.message-title { display:flex; align-items:center; flex-wrap:wrap; column-gap:.55rem; row-gap:.2rem; color:var(--muted); font-size:.81rem; }
.message-title strong { color:var(--text); font-size:.91rem; }
.assistant .message-title strong::before { content:""; display:inline-block; width:.8rem; height:.8rem; margin-right:.5rem; vertical-align:-.03rem; background:var(--primary); border-radius:.22rem; transform:rotate(-12deg); }
.message-title time { margin-left:auto; font-variant-numeric:tabular-nums; }
.answer { display:grid; gap:.5rem; min-width:0; }
.message-text { white-space:pre-wrap; overflow-wrap:anywhere; line-height:1.66; }
.answer code { background:#2e273a; color:#e4cdff; padding:.03em .32em; border-radius:.3rem; font-size:.91em; }
.code-block,.turn-history,.child-group { border:1px solid var(--line); border-radius:.65rem; background:#151922; }
.code-block { min-width:0; overflow:hidden; }
.code-head { display:flex; align-items:center; justify-content:space-between; padding:.2rem .7rem; background:#202431; color:var(--muted); font-size:.82rem; }
.code-head button,.copy-turn { min-height:1.9rem; font-size:.8rem; }
.copy-turn { justify-self:start; }
.code-block pre { padding:.8rem; white-space:pre; overflow:auto; font-size:.87rem; line-height:1.6; }
details summary { cursor:pointer; }
.turn-history summary,.child-group summary { padding:.6rem .85rem; font-size:.88rem; color:#c8c4d9; }
summary::marker { color:#aa97cd; }
.turn-step { border-top:1px solid var(--faint); padding-left:.65rem; }
.turn-step pre { max-height:20rem; overflow:auto; margin:.3rem .7rem .7rem; background:var(--field); padding:.65rem; font-size:.86rem; line-height:1.5; }
.child-group { margin-bottom:1.1rem; }
.children { display:flex; flex-wrap:wrap; padding:.3rem .55rem .55rem; gap:.25rem; }
.chat-foot { min-width:0; padding:0 clamp(.8rem,3vw,2.5rem) .85rem; }
.jump-wrap { position:relative; margin:auto; max-width:var(--reading); }
#jump-last { position:absolute; right:0; bottom:.2rem; background:var(--raised,var(--card)); border:1px solid var(--line); color:var(--text); box-shadow:0 .35rem .8rem #08090f77; }
.composer { max-width:var(--reading); margin:auto; padding:.5rem; border:1px solid #454353; background:var(--card); border-radius:1rem; }
.composer:focus-within { border-color:#9b85bd; }
.composer textarea { resize:vertical; max-height:27vh; min-height:3.4rem; border:0; background:transparent; }
.composer textarea:focus-visible { outline:0; }
.composer-actions { flex-wrap:nowrap; }
.composer-actions #chat-model { min-width:0; max-width:65%; display:block; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; margin-right:auto; font-size:.82rem; }
.key-hint { color:var(--muted); font-size:.75rem; white-space:nowrap; }
kbd { font-size:.73rem; }
.permissions { display:grid; gap:.4rem; max-height:25vh; overflow:auto; max-width:var(--reading); margin:0 auto .5rem; }
.approval { border:1px solid #604a38; background:#28211c; padding:.7rem; border-radius:.6rem; display:grid; gap:.55rem; }
.approval pre { color:var(--amber); font-size:.86rem; }
.content-page { max-width:78rem; margin:auto; padding:clamp(1.4rem,4vw,3.6rem); }
.page-title { padding-bottom:1.35rem; border-bottom:1px solid var(--line); margin-bottom:1.3rem; }
.data-list,.run-list { display:grid; gap:.85rem; }
.data-row,.run-card { padding:1.1rem 1.2rem; background:var(--pane); border:1px solid var(--line); border-radius:var(--radius); }
.data-row { display:flex; align-items:center; justify-content:space-between; gap:.75rem 1rem; flex-wrap:wrap; }
.row-identity { display:flex; gap:.85rem; align-items:center; min-width:0; }
.row-identity > .glyph { box-sizing:content-box; border:11px solid #272638; border-radius:.7rem; background:#272638; color:var(--primary); }
.data-row p,.meta,.fine { color:var(--muted); font-size:.86rem; line-height:1.5; overflow-wrap:anywhere; }
.data-row p { margin-top:.2rem; }
.inline-form { display:grid; grid-template-columns:minmax(10rem,16rem) minmax(0,1fr) auto; align-items:end; gap:.85rem; margin-bottom:1.3rem; }
.filter-bar { display:flex; flex-wrap:wrap; gap:.4rem; margin:0 0 1.25rem; }
.filter-bar button { border-radius:2rem; min-height:2.25rem; background:transparent; color:var(--muted); }
.filter-bar button[aria-pressed=true] { background:var(--accent-bg); color:#e1d1ff; border-color:#574668; }
.run-card { display:grid; gap:.9rem; }
.run-summary { align-items:start; }
.run-summary .meta { margin-top:.3rem; }
.run-progress { display:flex; align-items:center; gap:.7rem; color:var(--muted); font-size:.83rem; }
.run-progress progress { width:min(11rem,40%); height:.42rem; border:0; border-radius:1rem; background:var(--line); color:var(--primary); }
progress::-webkit-progress-bar { background:var(--line); border-radius:1rem; }
progress::-webkit-progress-value { background:var(--primary); border-radius:1rem; }
progress::-moz-progress-bar { background:var(--primary); border-radius:1rem; }
.step-list { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,13rem),1fr)); gap:.6rem; }
.step { display:grid; align-content:start; gap:.5rem; min-width:0; border:1px solid var(--faint); border-radius:.65rem; background:var(--field); padding:.85rem; }
.step[data-status=running],.step[data-status=sending] { border-color:#6c5436; }
.step[data-status=failed] { border-color:#754552; }
.step-task,.step-output { font-size:.88rem; line-height:1.55; white-space:pre-wrap; overflow-wrap:anywhere; }
.step-task { color:var(--muted); max-height:8rem; overflow:auto; }
.step-output { margin:.4rem 0; max-height:17rem; overflow:auto; }
.step summary { color:var(--primary); font-size:.86rem; }
.pill { display:inline-flex; align-items:center; width:fit-content; white-space:nowrap; padding:.2rem .65rem; border:1px solid var(--line); border-radius:2rem; font-size:.8rem; color:var(--muted); }
.pill.done,.pill.online,.pill.connected { color:var(--green); background:#1a2b25; border-color:#335246; }
.pill.running,.pill.sending,.pill.pending,.pill.stopping,.pill.needs_auth { color:var(--amber); background:#30271e; border-color:#5a4835; }
.pill.failed { color:var(--red); background:#341f2a; border-color:#61404c; }
dialog { width:min(39rem,calc(100% - 1.6rem)); max-height:90dvh; color:var(--text); background:var(--pane); border:1px solid #474958; border-radius:1.1rem; padding:1.3rem; box-shadow:0 1.5rem 6rem #06080d88; }
dialog::backdrop { background:#080a12be; backdrop-filter:blur(4px); }
.dialog-head { margin-bottom:1.1rem; }
.form-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.8rem; }
.form details { border:1px solid var(--line); border-radius:.6rem; padding:.75rem; }
.form summary { font-weight:620; }
.form details > div { margin-top:.75rem; }
.checks { display:flex; flex-wrap:wrap; gap:.35rem .55rem; margin-top:.45rem; }
.checks label { display:flex; align-items:center; overflow-wrap:anywhere; }
.checks input { width:1rem; min-height:0; accent-color:var(--primary); }
.command { padding:.75rem; background:var(--field); border:1px solid var(--line); border-radius:.55rem; }
#toast { position:fixed; bottom:1rem; right:1rem; max-width:min(calc(100vw - 2rem),30rem); padding:.75rem 1rem; border:1px solid #494659; border-radius:.75rem; background:#2b2938; box-shadow:0 .5rem 2rem #08091199; z-index:3; overflow-wrap:anywhere; }
@media (min-width:761px) and (max-width:1100px) {
  .app { grid-template-columns:5.8rem minmax(0,1fr); }
  .workspace-nav { align-items:center; padding-inline:.3rem; }
  .workspace-nav .wordmark,.rail-foot #rail-devices { display:none; }
  .workspace-nav nav button { flex-direction:column; justify-content:center; gap:.35rem; min-height:3.7rem; padding:.4rem; font-size:.76rem; }
  .workspace-nav nav { width:100%; }
}
@media (max-width:760px) {
  .app { grid-template-columns:minmax(0,1fr); grid-template-rows:minmax(0,1fr) auto; }
  main { grid-row:1; }
  .workspace-nav { grid-row:2; padding:.23rem .35rem max(.23rem,env(safe-area-inset-bottom)); border:0; border-top:1px solid var(--line); z-index:1; }
  .workspace-nav .brand,.rail-foot { display:none; }
  .workspace-nav nav { grid-template-columns:repeat(4,minmax(0,1fr)); gap:.15rem; }
  .workspace-nav nav button { flex-direction:column; justify-content:center; gap:.15rem; min-height:2.95rem; font-size:.77rem; padding:.26rem .1rem; }
  .workspace-nav nav button[aria-current] { background:#292434; border-color:transparent; }
  .chat-page { display:block; }
  .chat-page:not(.mobile-open) .chat,.chat-page.mobile-open .session-pane { display:none; }
  .session-pane { height:100%; border:0; }
  .mobile-back { display:inline-flex; margin:0 0 .2rem -.6rem; min-height:2rem; }
  .chat-head { padding:.4rem .8rem .65rem; }
  .chat-actions { max-width:7.3rem; }
  .chat-actions button { padding:.45rem .55rem; font-size:.82rem; }
  .chat-scroller { padding:.9rem .85rem .35rem; }
  .chat-foot { padding:0 .5rem .45rem; }
  .composer textarea { min-height:2.75rem; }
  .composer-actions #chat-model { max-width:55%; }
  .key-hint { display:none; }
  .pane-head { padding:1rem .85rem .55rem; }
  .pane-title h1 { font-size:1.85rem; }
  .session-list button { min-height:3.35rem; }
  .content-page { padding:1.25rem .85rem 2rem; }
  .page-title { flex-wrap:wrap; }
  .inline-form,.form-grid { grid-template-columns:1fr; }
  .step-list { grid-template-columns:1fr; }
  .data-row,.run-card { padding:.9rem; }
  #mobile-logout { display:inline-flex; margin-top:1rem; }
  #toast { bottom:calc(4.2rem + env(safe-area-inset-bottom)); }
}
.message-text { white-space:normal; }
.message-text p,.message-text li { white-space:pre-wrap; }
.message-text > * + * { margin-top:.6rem; }
.message-text h3 { font-size:1.08rem; margin-block-start:.85rem; }
.message-text h3:first-child { margin-top:0; }
.message-text ul,.message-text ol { margin-block-end:0; padding-inline-start:1.55rem; }
.message-text ul:first-child,.message-text ol:first-child { margin-top:0; }
.message-text li + li { margin-top:.25rem; }
.message-text li::marker { color:var(--primary); }
