/* Colors mirror the app's default "cool-slate" theme tokens (oklch, natively
   supported on iOS). Keep these in sync with Alas/Resources/Themes/cool-slate.json. */
:root {
  color-scheme: dark;
  font-family: -apple-system, system-ui, sans-serif;
  --bg-0: oklch(0.22 0.018 220);
  --bg-1: oklch(0.245 0.018 220);
  --bg-2: oklch(0.275 0.020 220);
  --bg-3: oklch(0.305 0.022 220);
  --bg-4: oklch(0.345 0.024 220);
  --fg: oklch(0.94 0.012 220);
  --fg-muted: oklch(0.78 0.014 220);
  --fg-dim: oklch(0.62 0.014 220);
  --fg-faint: oklch(0.50 0.014 220);
  --accent: oklch(0.74 0.11 195);
  --line: oklch(0.32 0.020 220 / 0.6);
  --line-soft: oklch(0.32 0.020 220 / 0.35);
  --add: oklch(0.78 0.14 155);
  --del: oklch(0.72 0.16 25);
}
* { box-sizing: border-box; }
/* Fixed-height app shell: header + scrolling body + pinned footer, sized to the
   *dynamic* viewport (dvh) so it tracks iOS's collapsing toolbar instead of
   overflowing past the visible screen the way 100vh does. */
html, body { height: 100%; }
/* position:fixed locks the shell to the viewport so iOS can't scroll the
   document when the keyboard opens; JS then drives height from
   window.visualViewport so the shell tracks the keyboard exactly. The
   100dvh is the no-JS fallback. */
body { margin: 0; position: fixed; top: 0; left: 0; right: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; color: var(--fg); background: linear-gradient(180deg, var(--bg-1), var(--bg-0)) fixed; -webkit-font-smoothing: antialiased; }
main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

#bar { flex: 0 0 auto; z-index: 5; display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: color-mix(in oklab, var(--bg-1), transparent 6%); backdrop-filter: blur(8px); border-bottom: 0.5px solid var(--line-soft); }
#nav-title { font-size: 16px; font-weight: 600; color: var(--fg); }
#detail-title { min-width: 0; flex: 1; font-size: 15px; font-weight: 650; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Connection chip: dot + label, color driven by [data-state]. */
#status.chip { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--fg-muted); background: color-mix(in oklab, var(--bg-3) 70%, transparent); border: 0.5px solid var(--line); white-space: nowrap; }
#status.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--fg-faint); flex-shrink: 0; }
#status[data-state="ok"]::before { background: var(--add); box-shadow: 0 0 6px color-mix(in oklab, var(--add) 70%, transparent); }
#status[data-state="bad"]::before { background: var(--del); }
#status[data-state="connecting"]::before { background: oklch(0.82 0.13 90); }
/* The active view fills the shell; long content scrolls inside it, not the page. */
.view { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 12px calc(28px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }   /* !important: beats .sheet's later display:flex */

/* Sessions list */
h1 { font-size: 22px; font-weight: 700; margin: 12px 4px 10px; }
#session-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.session-row { width: 100%; color: var(--fg); font: inherit; text-align: left; display: flex; align-items: flex-start; gap: 8px; -webkit-tap-highlight-color: transparent; }
.session-open { flex: 1; min-width: 0; border: none; background: none; color: inherit; font: inherit; text-align: left; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.session-open:focus-visible { outline: 1.5px solid var(--accent); outline-offset: 2px; }
.session-row-card { padding: 12px; border: 0.5px solid var(--line); border-radius: 10px; background: color-mix(in oklab, var(--bg-2) 54%, transparent); }
.session-row-card:has(.session-open:active) { background: var(--bg-3); }
.session-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.session-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-row .status { color: var(--accent); font-size: 11px; flex-shrink: 0; white-space: nowrap; }
.session-worktree { margin-top: 6px; color: var(--fg-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-meta { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 8px; color: var(--fg-dim); font-size: 11px; line-height: 1.3; }
.session-meta span { min-width: 0; }
.meta-lines { display: inline-flex; gap: 5px; }
.meta-add { color: var(--add); }
.meta-del { color: var(--del); }
.meta-conflict { color: oklch(0.82 0.13 90); }
.session-row-minimal { justify-content: space-between; align-items: center; gap: 10px; padding: 15px 10px; border-bottom: 0.5px solid var(--line-soft); background: none; }
.session-row-minimal .session-head { flex: 1; }
.session-row-minimal:has(.session-open:active) { background: var(--bg-2); }
#back { background: none; border: none; color: var(--accent); font-size: 15px; padding: 4px 2px; margin: -4px 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.rename-btn { flex: 0 0 auto; width: 30px; height: 30px; border: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: color-mix(in oklab, var(--bg-3) 64%, transparent); color: var(--fg-muted); font-size: 15px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.rename-btn:active { background: var(--bg-4); color: var(--fg); }
#detail-rename { margin-left: -4px; }

/* Transcript: a non-scrolling column — only #messages scrolls, #drivebar pins. */
#transcript { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
#messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 2px 12px 8px; display: flex; flex-direction: column; }
.msg { margin: 5px 0; line-height: 1.5; font-size: 15px; overflow-wrap: anywhere; white-space: pre-wrap; }
.m-agent { align-self: stretch; color: var(--fg); padding: 1px 2px; }
.m-user { align-self: flex-end; max-width: 82%; padding: 9px 13px; color: var(--fg); background: linear-gradient(180deg, color-mix(in oklab, var(--accent) 32%, transparent), color-mix(in oklab, var(--accent) 20%, transparent)); border: 0.5px solid color-mix(in oklab, var(--accent) 50%, transparent); border-radius: 13px 13px 4px 13px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.m-systemNotice { align-self: center; color: var(--fg-faint); font-size: 12.5px; text-align: center; padding: 4px; }

/* Markdown-rendered prose (agent/user) */
.md { white-space: normal; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h1, .md h2, .md h3, .md h4, .md h5 { margin: 12px 0 6px; line-height: 1.3; font-weight: 700; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15.5px; } .md h4 { font-size: 14px; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md li > p { margin: 0; }
.md a { color: var(--accent); }
.md strong { font-weight: 700; } .md em { font-style: italic; }
.md code { font-family: ui-monospace, monospace; font-size: .88em; background: color-mix(in oklab, var(--bg-0) 70%, transparent); padding: 1px 5px; border-radius: 5px; }
.md pre { margin: 8px 0; padding: 10px 12px; background: color-mix(in oklab, var(--bg-0) 60%, transparent); border: 0.5px solid var(--line-soft); border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 12px; line-height: 1.45; }
.md blockquote { margin: 6px 0; padding-left: 12px; border-left: 2px solid var(--bg-4); color: var(--fg-dim); }
.md hr { border: none; border-top: 0.5px solid var(--line); margin: 10px 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 0.5px solid var(--line); padding: 5px 9px; }

/* Thinking — collapsed by default, left accent rule */
.m-thought { align-self: stretch; border-left: 1.5px solid var(--bg-4); padding-left: 11px; margin: 6px 0; }
.thought-toggle { display: block; width: 100%; border: none; background: none; color: var(--fg-faint); font: inherit; font-size: 11px; text-align: left; padding: 3px 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.thought-toggle::before { content: "•••  "; }
.m-thought.is-open .thought-toggle::before { content: "×  "; }
.m-thought .thought-body { color: var(--fg-dim); font-style: italic; font-size: 13px; line-height: 1.5; padding: 4px 0 2px; }

/* Tool call / structured card — collapsed by default */
.m-tool { align-self: stretch; color: var(--fg); background: color-mix(in oklab, var(--bg-1) 60%, transparent); border: 0.5px solid var(--line); border-radius: 8px; margin: 5px 0; overflow: hidden; }
.m-tool.is-open { border-color: var(--bg-4); }
.tool-toggle { appearance: none; -webkit-appearance: none; width: 100%; border: none; background: none; color: var(--fg); font: inherit; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 8px 10px; text-align: left; -webkit-tap-highlight-color: transparent; }
.tool-verb { flex-shrink: 0; font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--accent); }
.tool-name { color: var(--fg-muted); font-family: ui-monospace, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-preview { flex: 1; min-width: 0; color: var(--fg-faint); font-family: ui-monospace, monospace; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-status { flex-shrink: 0; margin-left: auto; font-size: 12px; font-weight: 700; }
.tool-status.ok { color: var(--add); } .tool-status.err { color: var(--del); } .tool-status.run { color: var(--fg-faint); }
.tool-chev { flex-shrink: 0; color: var(--fg-faint); font-size: 11px; transition: transform .15s; }
.m-tool.is-open .tool-chev { transform: rotate(180deg); }
.tool-body { margin: 0; padding: 9px 11px; border-top: 0.5px solid var(--line-soft); background: color-mix(in oklab, var(--bg-0) 55%, transparent); font-family: ui-monospace, monospace; font-size: 11.5px; line-height: 1.45; color: var(--fg-muted); white-space: pre; overflow-x: auto; max-height: 46vh; overflow-y: auto; }

/* Composer / drive bar */
#drivebar { flex: 0 0 auto; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in oklab, var(--bg-1), transparent 4%); backdrop-filter: blur(8px); border-top: 0.5px solid var(--line-soft); }
/* Take-over PILL: a compact, no-typing way to grab the lease. Sits above the
   always-present composer (the composer itself also auto-takes on any action). */
#takeover { display: block; margin: 0 auto 8px; padding: 7px 16px; border: 0.5px solid color-mix(in oklab, var(--accent) 55%, transparent); border-radius: 999px; background: color-mix(in oklab, var(--accent) 16%, transparent); color: var(--fg); font-size: 13px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent; }
#takeover:active { background: color-mix(in oklab, var(--accent) 24%, transparent); }
/* One rounded field; the action button docks bottom-right and the textarea
   grows above it. align-items:flex-end keeps the button pinned to the last line. */
#composer-row { display: flex; gap: 7px; align-items: flex-end; padding: 5px 5px 5px 5px; background: var(--bg-0); border: 0.5px solid var(--line); border-radius: 22px; }
#composer-row:focus-within { border-color: color-mix(in oklab, var(--accent) 60%, var(--line)); }
/* Thumbnail row above the composer — horizontal, scrollable small previews. */
#chips { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 2px 4px 8px; }
#chips .chip { position: relative; flex: 0 0 auto; }
#chips .chip img { width: 54px; height: 54px; object-fit: cover; border-radius: 9px; border: 0.5px solid var(--line); display: block; }
#chips .chip-x { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; padding: 0; border: none; border-radius: 50%; background: var(--bg-4); color: var(--fg); font-size: 11px; line-height: 18px; display: flex; align-items: center; justify-content: center; cursor: pointer; -webkit-tap-highlight-color: transparent; }
/* font-size MUST be ≥16px: iOS auto-zooms (and inflates the viewport) on focus
   of any smaller field. */
#prompt { flex: 1; min-height: 24px; max-height: 40vh; padding: 7px 0; border: none; background: none; color: var(--fg); font: inherit; font-size: 16px; line-height: 1.35; resize: none; outline: none; }
#attach.hidden + #prompt { padding-left: 9px; }   /* breathing room when the attach button is hidden */
#prompt::placeholder { color: var(--fg-faint); }
#composer-row button { flex-shrink: 0; width: 34px; height: 34px; padding: 0; border: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .08s; }
#composer-row button:active { transform: scale(0.92); }
#send { background: var(--accent); color: var(--bg-0); }
#stop { background: var(--del); color: var(--fg); }
/* Secondary icon buttons (attach, config) — muted, no fill. */
#attach, #config { background: none; color: var(--fg-dim); }
#attach:active, #config:active { color: var(--fg-muted); }

/* Config sheet (⚙) — reuses .option-btn / .is-selected for the radio lists. */
#cfg-model-section, #cfg-mode-section { margin-bottom: 14px; }
#cfg-autorun-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; margin: 6px 0; border: 1px solid var(--bg-4); border-radius: 10px; background: var(--bg-1); color: var(--fg); font-size: 15px; cursor: pointer; }
#cfg-autorun { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }

/* Pair / error gate (full screen) */
#gate { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 28px; background: linear-gradient(180deg, var(--bg-1), var(--bg-0)); }
.gate-card { text-align: center; max-width: 320px; }
.gate-icon { font-size: 38px; line-height: 1; margin-bottom: 14px; }
.gate-card h2 { font-size: 19px; font-weight: 700; margin: 0 0 10px; color: var(--fg); }
.gate-card p { font-size: 14.5px; line-height: 1.55; color: var(--fg-dim); margin: 0; }
#gate-retry { margin-top: 18px; padding: 11px 20px; border: 0.5px solid color-mix(in oklab, var(--accent) 55%, transparent); border-radius: 10px; background: color-mix(in oklab, var(--accent) 18%, transparent); color: var(--fg); font-size: 15px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent; }
#gate-retry:active { background: color-mix(in oklab, var(--accent) 26%, transparent); }

/* Bottom sheets (permission / question) */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; z-index: 10; }
.sheet-card { background: var(--bg-2); width: 100%; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); border-radius: 16px 16px 0 0; border-top: 0.5px solid var(--line); }
.sheet-card button { display: block; width: 100%; padding: 13px; margin: 7px 0; border: none; border-radius: 10px; font-size: 16px; cursor: pointer; }
.btn-allow { background: var(--add); color: var(--bg-0); } .btn-deny { background: var(--del); color: var(--fg); }
.sheet-close { background: var(--bg-4); color: var(--fg-muted); }
.sheet-title { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--fg); }
.sheet-input { width: 100%; margin: 0 0 10px; padding: 12px 13px; border: 1px solid var(--bg-4); border-radius: 10px; background: var(--bg-0); color: var(--fg); font: inherit; font-size: 16px; outline: none; }
.sheet-input:focus { border-color: color-mix(in oklab, var(--accent) 65%, var(--bg-4)); }
.question-block { margin-bottom: 16px; }
.question-prompt { margin: 0 0 8px; font-size: 14px; color: var(--fg-muted); }
.option-btn { display: block; width: 100%; padding: 12px 14px; margin: 6px 0; border: 1px solid var(--bg-4); border-radius: 10px; background: var(--bg-1); color: var(--fg); font-size: 15px; text-align: left; cursor: pointer; }
.option-btn.is-selected { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 18%, transparent); }
.btn-submit { background: var(--accent); color: var(--bg-0); font-weight: 600; }
.btn-submit:disabled { background: var(--bg-3); color: var(--fg-faint); cursor: not-allowed; opacity: .7; }
