/* Opcoda — one system: neutral surfaces, one accent, mono only for code. */

:root {
  color-scheme: light dark;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --t-fast: 120ms; --t: 180ms; --ease: cubic-bezier(.2, .7, .2, 1);
  --sidebar: 264px; --read: 760px;

  /* light */
  --bg: #fafafa;
  --surface: #f2f2f3;
  --raised: #ffffff;
  --hover: #ebebed;
  --border: #e2e2e6;
  --border-strong: #cfcfd5;
  --text: #17171a;
  --muted: #5d5d66;
  --faint: #8a8a93;
  --primary: #17171a;
  --on-primary: #ffffff;
  --focus: #2f6feb;
  --ok: #1a7f37;
  --warn: #9a6700;
  --danger: #cf222e;
  --code-bg: #f6f6f8;
  --tok-kw: #a1460b;
  --tok-str: #1a7f37;
  --tok-num: #0b57d0;
  --tok-com: #8a8a93;
  --tok-fn: #6639ba;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .08);
  --scrim: rgba(10, 10, 12, .38);
  --segment: #ffffff;
  --lang-html: #c2410c;
  --lang-css: #1d4ed8;
  --lang-js: #a16207;
  --lang-py: #15803d;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0c0e;
    --surface: #121215;
    --raised: #18181c;
    --hover: #202025;
    --border: #26262c;
    --border-strong: #34343b;
    --text: #ececef;
    --muted: #a0a0aa;
    --faint: #707079;
    --primary: #ececef;
    --on-primary: #0c0c0e;
    --focus: #6ea2ff;
    --ok: #3fb950;
    --warn: #d29922;
    --danger: #ff7b72;
    --code-bg: #101013;
    --tok-kw: #f0a35e;
    --tok-str: #8ed49b;
    --tok-num: #8cb8ff;
    --tok-com: #6f6f78;
    --tok-fn: #c9a7ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
    --scrim: rgba(0, 0, 0, .55);
    --segment: #2a2a31;
    --lang-html: #fb923c;
    --lang-css: #7cb2ff;
    --lang-js: #f5cc4a;
    --lang-py: #5ed38a;
  }
}

:root[data-theme="light"] { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0c0e;
  --surface: #121215;
  --raised: #18181c;
  --hover: #202025;
  --border: #26262c;
  --border-strong: #34343b;
  --text: #ececef;
  --muted: #a0a0aa;
  --faint: #707079;
  --primary: #ececef;
  --on-primary: #0c0c0e;
  --focus: #6ea2ff;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #ff7b72;
  --code-bg: #101013;
  --tok-kw: #f0a35e;
  --tok-str: #8ed49b;
  --tok-num: #8cb8ff;
  --tok-com: #6f6f78;
  --tok-fn: #c9a7ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
  --scrim: rgba(0, 0, 0, .55);
  --segment: #2a2a31;
  --lang-html: #fb923c;
  --lang-css: #7cb2ff;
  --lang-js: #f5cc4a;
  --lang-py: #5ed38a;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- shared controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 40px; padding: 0 var(--s4);
  border: 1px solid transparent; border-radius: var(--r);
  font-weight: 550; font-size: 14px; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), opacity var(--t-fast), transform var(--t-fast);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { opacity: .88; }
.btn-secondary { background: var(--raised); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--hover); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .9; }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn-danger-outline:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn-sm { height: 34px; padding: 0 var(--s3); font-size: 13px; }
.btn-block { width: 100%; }
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--on-primary) transparent var(--on-primary) transparent;
  animation: spin .8s linear infinite;
}
.btn-secondary.is-loading::after { border-color: var(--text) transparent var(--text) transparent; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: var(--r);
  background: transparent; color: var(--muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.field { display: grid; gap: 6px; }
.field + .field { margin-top: var(--s4); }
.field label, .label { font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; gap: var(--s2); }
.field input[type="text"], .field input[type="password"], .field input:not([type]) {
  height: 42px; width: 100%; padding: 0 var(--s3);
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: var(--r);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.field-error { margin: 0; font-size: 13px; color: var(--danger); }
.form-error {
  margin: var(--s4) 0 0; padding: var(--s3); border-radius: var(--r);
  font-size: 14px; color: var(--danger);
  background: color-mix(in srgb, var(--danger) 9%, transparent);
}

.password-wrap { position: relative; }
.password-wrap input { padding-right: 64px !important; }
.reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  height: 30px; padding: 0 var(--s2); border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 550;
}
.reveal:hover { background: var(--hover); color: var(--text); }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 3px; gap: 3px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--border);
}
.segmented button, .segmented label {
  height: 34px; border: 0; border-radius: 7px; background: transparent;
  display: grid; place-items: center; font-size: 14px; font-weight: 550; color: var(--muted);
  transition: background var(--t-fast), color var(--t-fast);
  cursor: pointer;
}
.segmented button[aria-selected="true"], .segmented label:has(input:checked) {
  background: var(--segment); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }

input[type="range"] { width: 100%; accent-color: var(--primary); height: 24px; }
output { font-family: var(--mono); font-size: 13px; font-weight: 500; color: var(--muted); }

.avatar {
  flex: none; display: inline-grid; place-items: center; overflow: hidden;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--hover); color: var(--muted); font-size: 13px; font-weight: 650; letter-spacing: .02em;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-lg { width: 72px; height: 72px; font-size: 24px; }

.wordmark {
  display: inline-flex; align-items: center; gap: var(--s2);
  font-weight: 700; font-size: 17px; letter-spacing: -.02em; color: var(--text); text-decoration: none;
}
.wordmark img { width: 24px; height: 24px; border-radius: 6px; display: block; }
.mark-glyph { stroke: var(--bg); }
.empty code, .hint code { font-family: var(--mono); font-size: .92em; padding: 1px 5px; border-radius: 5px; background: var(--surface); border: 1px solid var(--border); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* ---------- boot ---------- */

.boot { min-height: 100%; display: grid; place-items: center; color: var(--muted); }

/* ---------- auth ---------- */

.auth {
  min-height: 100%; display: grid; place-items: center;
  padding: var(--s6) var(--s4) calc(var(--s6) + env(safe-area-inset-bottom));
}
.auth-panel { width: min(380px, 100%); }
.auth-panel .wordmark { margin-bottom: var(--s6); }
.auth h1 { margin: 0; font-size: 26px; line-height: 1.2; letter-spacing: -.02em; }
.auth-lede { margin: var(--s2) 0 var(--s5); color: var(--muted); }
.auth form { margin-top: var(--s5); }
.auth .btn-primary { margin-top: var(--s5); height: 44px; }
.auth-note { margin: var(--s5) 0 0; font-size: 13px; color: var(--faint); text-align: center; }

/* ---------- app shell ---------- */

.app { height: 100%; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.app[data-workspace="open"] { grid-template-columns: var(--sidebar) minmax(360px, 1fr) minmax(440px, 1.2fr); }

.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: var(--s3) var(--s3) calc(var(--s3) + env(safe-area-inset-bottom));
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; height: 40px; padding: 0 var(--s2); }
.new-chat { margin: var(--s4) 0 var(--s3); justify-content: flex-start; padding-left: var(--s3); }
.new-chat svg { width: 18px; height: 18px; }

.history { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }
.history-label { margin: var(--s3) var(--s2) var(--s1); font-size: 12px; font-weight: 600; color: var(--faint); }
.history ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; }
.history-empty { margin: var(--s2); font-size: 14px; color: var(--faint); }
.conv { position: relative; display: flex; align-items: center; border-radius: var(--r-sm); }
.conv a {
  flex: 1; min-width: 0; display: block; padding: var(--s2) var(--s2); padding-right: 36px;
  color: var(--muted); text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: var(--r-sm);
}
.conv:hover a, .conv a:focus-visible { background: var(--hover); color: var(--text); }
.conv[aria-current="page"] a { background: var(--hover); color: var(--text); font-weight: 550; }
.conv .conv-delete {
  position: absolute; right: 2px; width: 32px; height: 32px; opacity: 0;
}
.conv:hover .conv-delete, .conv[aria-current="page"] .conv-delete, .conv .conv-delete:focus-visible { opacity: 1; }
.conv .conv-delete svg { width: 16px; height: 16px; }

.account { position: relative; padding-top: var(--s3); border-top: 1px solid var(--border); }
.account-btn {
  width: 100%; display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2); border: 0; border-radius: var(--r); background: transparent; text-align: left;
}
.account-btn:hover, .account-btn[aria-expanded="true"] { background: var(--hover); }
.account-text { min-width: 0; display: grid; }
.account-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-username { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + var(--s1));
  padding: var(--s1); border-radius: var(--r); border: 1px solid var(--border);
  background: var(--raised); box-shadow: var(--shadow);
  animation: rise var(--t) var(--ease);
  z-index: 20;
}
.menu button {
  width: 100%; height: 38px; padding: 0 var(--s3); border: 0; border-radius: var(--r-sm);
  background: transparent; text-align: left; font-size: 14px;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }

/* ---------- chat ---------- */

.chat { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }

.chat-header {
  display: flex; align-items: center; gap: var(--s3);
  height: 56px; padding: 0 var(--s4); border-bottom: 1px solid var(--border);
}
.model-id { display: flex; align-items: baseline; gap: var(--s3); min-width: 0; }
.model-name { font-weight: 650; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status[data-state="online"] .dot { background: var(--ok); }
.status[data-state="checking"] .dot { animation: pulse 1.2s ease-in-out infinite; }
.usage { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.usage[data-low="true"] { color: var(--warn); }

.thread { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }

/* language tags */
.lang-tag {
  flex: none; display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px;
  font: 650 11px/1 var(--font); letter-spacing: .02em;
  color: var(--lang, var(--muted)); background: color-mix(in srgb, var(--lang, var(--muted)) 14%, transparent);
}
.lang-tag[data-lang="html"] { --lang: var(--lang-html); }
.lang-tag[data-lang="css"] { --lang: var(--lang-css); }
.lang-tag[data-lang="javascript"] { --lang: var(--lang-js); }
.lang-tag[data-lang="python"] { --lang: var(--lang-py); }

.empty {
  max-width: var(--read); margin: 0 auto; padding: clamp(40px, 11vh, 120px) var(--s5) var(--s6);
}
.empty h1 { margin: 0; font-size: clamp(26px, 3.4vw, 34px); letter-spacing: -.025em; line-height: 1.15; }
.empty p { margin: var(--s3) 0 var(--s5); color: var(--muted); max-width: 60ch; }
.examples { display: grid; gap: var(--s2); max-width: 620px; }
.example {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); border: 1px solid var(--border); border-radius: var(--r);
  background: var(--raised); text-align: left; color: var(--text); font-size: 14px;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.example:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface); }
.example:disabled { opacity: .5; cursor: not-allowed; }

.messages { list-style: none; margin: 0 auto; padding: var(--s5) var(--s5) var(--s4); max-width: var(--read); display: grid; gap: var(--s5); }
.msg { display: grid; gap: var(--s2); animation: rise var(--t) var(--ease); min-width: 0; }
.msg-user { justify-items: end; }
.bubble {
  max-width: min(85%, 560px); padding: 10px 14px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--border);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble-lang { margin-bottom: -2px; }
.msg-user.is-failed .bubble { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.msg-error { display: flex; align-items: center; gap: var(--s3); font-size: 13px; color: var(--danger); }
.msg-error .btn { height: 30px; }

.msg-bot { justify-items: stretch; }
.msg-author { display: flex; align-items: center; gap: var(--s2); font-size: 13px; font-weight: 600; }
.msg-author .mark { width: 20px; height: 20px; }

/* file card (assistant reply) */
.file-card { min-width: 0; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--raised); overflow: hidden; }
.file-card.is-active { border-color: var(--border-strong); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 14%, transparent); }
.file-head { display: flex; align-items: center; gap: var(--s2); min-height: 48px; padding: var(--s2) var(--s2) var(--s2) var(--s3); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.file-name { font: 600 13px var(--mono); }
.file-meta { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.file-actions { margin-left: auto; display: flex; gap: 2px; }
.file-actions .btn { height: 30px; padding: 0 10px; font-size: 12.5px; gap: 6px; }
.file-actions .btn svg { width: 14px; height: 14px; }
.file-body { position: relative; max-height: 288px; overflow: hidden; background: var(--code-bg); cursor: pointer; }
.file-body pre { margin: 0; padding: var(--s3) var(--s4); font: 12.5px/1.6 var(--mono); white-space: pre; overflow: hidden; tab-size: 4; }
.file-body.is-clipped::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 88px; pointer-events: none;
  background: linear-gradient(color-mix(in srgb, var(--code-bg) 0%, transparent), var(--code-bg) 75%);
}
.file-more { position: absolute; left: 50%; bottom: var(--s3); transform: translateX(-50%); z-index: 1; height: 30px; font-size: 12.5px; }
.verdict { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.verdict svg { width: 14px; height: 14px; }
.verdict[data-state="ok"] { color: var(--ok); }
.verdict[data-state="warn"] { color: var(--warn); }
.msg-meta { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

/* in-progress reply */
.working {
  display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4);
  border: 1px dashed var(--border-strong); border-radius: var(--r-lg); color: var(--muted); font-size: 13.5px;
}
.working .bar { flex: 1; max-width: 160px; height: 4px; border-radius: 999px; background: var(--hover); overflow: hidden; position: relative; }
.working .bar::after { content: ""; position: absolute; inset: 0; width: 40%; border-radius: inherit; background: var(--muted); animation: slide 1.4s ease-in-out infinite; }
.working time { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--faint); }
@keyframes slide { from { transform: translateX(-110%); } to { transform: translateX(260%); } }

/* syntax colors */
.tok-kw, .tok-tag, .tok-sel { color: var(--tok-kw); }
.tok-str { color: var(--tok-str); }
.tok-num, .tok-prop { color: var(--tok-num); }
.tok-com { color: var(--tok-com); font-style: italic; }
.tok-fn, .tok-attr, .tok-at { color: var(--tok-fn); }

/* composer */
.composer { padding: 0 var(--s5) calc(var(--s4) + env(safe-area-inset-bottom)); }
.composer-box {
  max-width: var(--read); margin: 0 auto;
  display: grid; gap: 4px; padding: var(--s2) var(--s2) var(--s2) var(--s3);
  background: var(--raised); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.composer-box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
.lang-picker { display: flex; flex-wrap: wrap; gap: 2px; }
.lang-picker label {
  position: relative; height: 28px; padding: 0 10px; display: inline-flex; align-items: center;
  border-radius: 7px; border: 1px solid transparent; font-size: 12.5px; font-weight: 550; color: var(--muted); cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.lang-picker label:hover { background: var(--hover); color: var(--text); }
.lang-picker label:has(input:checked) { background: var(--segment); border-color: var(--border); color: var(--text); }
.lang-picker input { position: absolute; opacity: 0; pointer-events: none; }
.lang-picker label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }
.composer-row { display: flex; align-items: flex-end; gap: var(--s2); }
.composer textarea {
  flex: 1; min-height: 40px; max-height: 220px; padding: 9px 2px; resize: none;
  border: 0; outline: 0; background: transparent; line-height: 1.45;
}
.composer textarea::placeholder { color: var(--faint); }
.send {
  flex: none; width: 40px; height: 40px; display: grid; place-items: center;
  border: 0; border-radius: var(--r); background: var(--primary); color: var(--on-primary);
  transition: opacity var(--t-fast), transform var(--t-fast);
}
.send svg { width: 18px; height: 18px; }
.send:disabled { opacity: .3; cursor: not-allowed; }
.send:active:not(:disabled) { transform: translateY(1px); }
.composer-note { max-width: var(--read); margin: var(--s2) auto 0; font-size: 12px; color: var(--faint); text-align: center; }
.composer-note[data-tone="warn"] { color: var(--warn); }

/* ---------- code workspace ---------- */

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); border-left: 1px solid var(--border); }
.ws-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  height: 56px; padding: 0 var(--s2) 0 var(--s4); background: var(--raised); border-bottom: 1px solid var(--border);
}
.ws-title { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.ws-file { font: 600 14px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-status { font-size: 12px; font-weight: 600; white-space: nowrap; }
.ws-status[data-state="ok"] { color: var(--ok); }
.ws-status[data-state="warn"] { color: var(--warn); }
.ws-actions { display: flex; align-items: center; gap: 2px; }
.ws-tabs { display: flex; gap: var(--s1); padding: 0 var(--s3); background: var(--raised); border-bottom: 1px solid var(--border); }
.ws-tabs button {
  height: 40px; padding: 0 var(--s3); margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--muted); font-size: 13px; font-weight: 600;
}
.ws-tabs button:hover { color: var(--text); }
.ws-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }
.ws-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#ws-code { overflow: auto; }

.code-view { flex: 1; display: grid; grid-template-columns: auto minmax(0, 1fr); align-content: start; background: var(--code-bg); font: 12.5px/1.65 var(--mono); }
.code-gutter { margin: 0; padding: var(--s3) var(--s3) var(--s3) var(--s4); text-align: right; color: var(--faint); user-select: none; border-right: 1px solid var(--border); white-space: pre; }
.code-lines { margin: 0; padding: var(--s3) var(--s4); overflow-x: auto; white-space: pre; tab-size: 4; color: var(--text); }

.checks { position: sticky; bottom: 0; background: var(--raised); border-top: 1px solid var(--border); }
.checks summary { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); cursor: pointer; font-size: 13px; font-weight: 600; list-style: none; }
.checks summary::-webkit-details-marker { display: none; }
.checks summary::after { content: "Show"; margin-left: auto; font-weight: 500; color: var(--faint); }
.checks[open] summary::after { content: "Hide"; }
.checks summary svg { width: 16px; height: 16px; }
.checks ul { list-style: none; margin: 0; padding: 0 var(--s4) var(--s3); display: grid; gap: 8px; font-size: 13px; max-height: 34vh; overflow: auto; }
.checks li { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: var(--s2); }
.checks li svg { width: 16px; height: 16px; margin-top: 2px; }
.checks li small { display: block; color: var(--muted); font: 12px/1.5 var(--mono); overflow-wrap: anywhere; }
.check-ok { color: var(--ok); }
.check-bad { color: var(--warn); }

.preview-bar, .run-bar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  min-height: 48px; padding: var(--s2) var(--s3) var(--s2) var(--s4); background: var(--raised); border-bottom: 1px solid var(--border);
}
.preview-bar .btn svg, .run-bar .btn svg { width: 14px; height: 14px; }
.preview-frame { flex: 1; min-height: 0; background: #ffffff; }
.preview-frame iframe { display: block; width: 100%; height: 100%; border: 0; background: #ffffff; }
.run-status { font-size: 13px; color: var(--muted); }
.run-output {
  flex: 1; min-height: 0; margin: 0; padding: var(--s3) var(--s4); overflow: auto;
  font: 12.5px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; background: var(--code-bg); color: var(--text);
}
.run-output .stderr { color: var(--danger); }
.run-output .sys { color: var(--faint); }

/* ---------- dialogs ---------- */

.dialog {
  width: min(560px, calc(100% - 32px)); max-height: min(760px, calc(100% - 48px));
  padding: 0; border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--raised); color: var(--text); box-shadow: var(--shadow);
}
.dialog[open] { display: flex; flex-direction: column; animation: rise var(--t) var(--ease); }
.dialog::backdrop { background: var(--scrim); }
.dialog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s3) var(--s3) var(--s3) var(--s5); border-bottom: 1px solid var(--border);
}
.dialog-header h2 { margin: 0; font-size: 17px; }
.dialog-body { overflow-y: auto; padding: 0 var(--s5) var(--s5); }
.settings-section { padding: var(--s5) 0; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: 0; padding-bottom: 0; }
.settings-section h3 { margin: 0 0 var(--s4); font-size: 15px; }
.settings-section > p { margin: 0 0 var(--s4); color: var(--muted); font-size: 14px; }
.avatar-row { display: flex; align-items: center; gap: var(--s4); margin-bottom: var(--s5); }
.avatar-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: 6px; }
.row { display: flex; align-items: flex-end; gap: var(--s3); }
.row .field { flex: 1; }
.static-value { margin: 0; height: 42px; display: flex; align-items: center; color: var(--muted); font-family: var(--mono); font-size: 14px; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.saved { font-size: 13px; color: var(--ok); align-self: center; }

.dialog-small { width: min(420px, calc(100% - 32px)); }
.dialog-small .dialog-body { padding-top: var(--s5); }
.dialog-small p { margin: 0; color: var(--muted); }
.dialog-small .field { margin-top: var(--s4); }
.dialog-footer { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s5); border-top: 1px solid var(--border); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--s5) + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: var(--s3) var(--s4); border-radius: var(--r);
  background: var(--primary); color: var(--on-primary); font-size: 14px; box-shadow: var(--shadow);
  animation: rise var(--t) var(--ease); z-index: 50;
}

.only-mobile { display: none; }
.scrim { display: none; }

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .app[data-workspace="open"] { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  .workspace {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); z-index: 35;
    box-shadow: var(--shadow); animation: slide-in var(--t) var(--ease);
  }
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 860px) {
  .app, .app[data-workspace="open"] { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 30;
    transform: translateX(-100%); transition: transform var(--t) var(--ease);
    box-shadow: var(--shadow); visibility: hidden;
  }
  .app[data-drawer="open"] .sidebar { transform: none; visibility: visible; }
  .app[data-drawer="open"] .scrim { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: 25; }
  .chat-header { padding: 0 var(--s2); gap: var(--s2); }
  .conv .conv-delete { opacity: 1; }
  .workspace { width: 100vw; border-left: 0; }
}

@media (max-width: 560px) {
  .messages { padding: var(--s4) var(--s4) var(--s3); gap: var(--s4); }
  .empty { padding-inline: var(--s4); }
  .composer { padding-inline: var(--s3); }
  .bubble { max-width: 92%; }
  .usage .usage-long { display: none; }
  .file-actions .btn-label { display: none; }
  .dialog { width: 100%; max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; border: 0; margin: 0; }
  .dialog-small { height: auto; margin: auto auto 0; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .row { flex-direction: column; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
