:root {
  color-scheme: dark;
  font: 16px/1.55 system-ui, sans-serif;
  --bg: #11120f; --panel: #222320; --border: #272824;
  --text: #e7e7e2; --muted: #93948d; --accent: #d7d8cd;
  --row-hover: #ffffff04; --row-selected: #ffffff04;
  --code-bg: #191a17; --code-output: #c6c8bf;
  --success: #a7b79d; --error: #df9e92;
  --syntax-comment: #939b8c; --syntax-keyword: #c4acd1;
  --syntax-string: #b2c69e; --syntax-number: #d4b58b;
  --syntax-title: #b5c6d5; --syntax-type: #a9c5bd;
  --syntax-variable: #d5c6b1; --syntax-meta: #acae9e;
  --diff-context: #b5b7ae; --diff-added: #b2c69e;
  --diff-added-bg: #a7b79d12; --diff-removed-bg: #df9e9212;
  --diff-mark-bg: #ffffff12;
  --diff-added-mark-bg: #a7b79d2b; --diff-removed-mark-bg: #df9e922b;
  --dialog-backdrop: #0009;
}
/* theme.js, a blocking head script, resolves the preference (including "system") into data-theme before CSS. */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f5f0; --panel: #edeae2; --border: #d3d0c7;
  --text: #292b25; --muted: #626459; --accent: #424b38;
  --row-hover: #eeece5; --row-selected: #e7e4db;
  --code-bg: #efede6; --code-output: #45483f;
  --success: #426034; --error: #9a362c;
  --syntax-comment: #60675b; --syntax-keyword: #704285;
  --syntax-string: #3e622c; --syntax-number: #79521f;
  --syntax-title: #365d7d; --syntax-type: #2e635b;
  --syntax-variable: #65523a; --syntax-meta: #61634f;
  --diff-context: #575b50; --diff-added: #3e622c;
  --diff-added-bg: #e6eddc; --diff-removed-bg: #f5e5df;
  --diff-mark-bg: #dbd7cb;
  --diff-added-mark-bg: #d2dfbf; --diff-removed-mark-bg: #ebccc1;
  --dialog-backdrop: #292b2566;
}
* { box-sizing: border-box; }
body { margin: 0; position: relative; top: var(--viewport-top, 0px); height: var(--viewport-height, 100dvh); overflow: hidden; display: flex; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, textarea, select { font: inherit; }
button, select, input, textarea { color: inherit; background: var(--panel); border: 1px solid var(--border); border-radius: 5px; }
button { cursor: pointer; padding: .45rem .8rem; }
button:hover:not(:disabled) { background: var(--panel); }
button:disabled { cursor: default; opacity: .4; }
input, select { padding: .45rem; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
textarea { padding: .65rem; resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
small, .connection { color: var(--muted); }
.icon-button { display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; min-width: 44px; min-height: 44px; padding: .25rem; color: var(--muted); }
/* Lucide icons are inline SVGs; center them as boxes, not as text glyphs on a baseline. */
button svg { display: block; flex-shrink: 0; }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#theme-toggle { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; height: 44px; padding: 6px; }
#theme-toggle:hover, #theme-toggle:focus-visible { color: var(--text); background: var(--panel); }
#theme-toggle svg { display: none; width: 18px; height: 18px; flex-shrink: 0; }
/* Preference icons describe the setting, not the currently resolved theme. */
html:not([data-theme-preference="light"]):not([data-theme-preference="dark"]) #theme-toggle .theme-system-icon,
html[data-theme-preference="light"] #theme-toggle .theme-light-icon,
html[data-theme-preference="dark"] #theme-toggle .theme-dark-icon { display: block; }
.connection { font-size: .7rem; }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#side-panel { flex: 0 0 var(--side-panel-width, min(520px, 40vw)); min-width: 0; display: flex; flex-direction: column; border-left: 1px solid var(--border); background: var(--bg); }
#side-panel-resize { position: relative; z-index: 2; flex: 0 0 0; cursor: col-resize; touch-action: none; }
#side-panel-resize::before { content: ""; position: absolute; top: 0; bottom: 0; left: -4px; width: 8px; }
#side-panel-resize::after { content: ""; position: absolute; top: 50%; left: -2px; width: 4px; height: 32px; margin-top: -16px; border-radius: 2px; background: var(--muted); opacity: .5; }
#side-panel-resize:focus-visible { outline: 0; }
#side-panel-resize:hover::before, #side-panel-resize:focus-visible::before, #side-panel-resize.dragging::before { background: linear-gradient(to right, transparent 3px, var(--accent) 3px, var(--accent) 5px, transparent 5px); }
#side-panel-resize:hover::after, #side-panel-resize:focus-visible::after, #side-panel-resize.dragging::after { background: var(--accent); opacity: 1; }
body:has(> #side-panel[hidden]) > #side-panel-resize { display: none; }
body.side-panel-resizing { cursor: col-resize; user-select: none; }
@media (max-width: 1099px) {
  #side-panel { position: fixed; inset: 0; z-index: 6; border-left: 0; }
  #side-panel-resize { display: none; }
}
/* Shared top bar (title bar and workspace header): same height and icon-button positions,
   so an overlaying panel puts Refresh/Close exactly where the panel toggle and ⋯ were. */
.bar { display: flex; align-items: center; gap: .5rem; padding: .25rem 1rem .25rem 1.25rem; min-height: 3.5rem; border-bottom: 1px solid var(--border); }
.bar-gap { flex: 1; }
/* The sheets the title bar and status line open: a field or list under the header, then the actions. */
.sheet-body { padding: .4rem 1.25rem max(1rem, env(safe-area-inset-bottom)); }
.sheet-body > input, .sheet-body > textarea { display: block; width: 100%; font-size: .9rem; }
.sheet-body > textarea { min-height: 6rem; max-height: calc(var(--viewport-height, 100dvh) * .5); }
.sheet-body > [readonly] { color: var(--muted); }
.sheet-body > .failed { margin: .4rem 0 0; font-size: .85rem; }
.sheet-actions { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .6rem; }
.sheet-actions small { font-size: .75rem; }
.sheet-actions button { flex: 0 0 auto; min-height: 36px; padding: .3rem .9rem; font-size: .85rem; margin-left: auto; }
code { font: .8rem/1.6 ui-monospace, monospace; }
:not(pre) > code { background: var(--panel); padding: .1rem .3rem; border-radius: 3px; }
pre { position: relative; background: var(--code-bg); border: 1px solid var(--border); border-radius: 0; padding: .8rem; overflow-x: auto; white-space: pre; }
details { margin: .7rem 0; }
summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.tool-spinner { border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: tool-spin 800ms linear infinite; }
@keyframes tool-spin { to { transform: rotate(360deg); } }

/* Theme-aware syntax palette for server-highlighted code (src/lib/highlight.ts: .tool-code, .tool-diff), wherever a plugin draws it. */
.tool-code .hljs-comment, .tool-code .hljs-quote { color: var(--syntax-comment); font-style: italic; }
.tool-code .hljs-keyword, .tool-code .hljs-selector-tag,
.tool-code .hljs-literal, .tool-code .hljs-doctag { color: var(--syntax-keyword); }
.tool-code .hljs-string, .tool-code .hljs-regexp,
.tool-code .hljs-addition { color: var(--syntax-string); }
.tool-code .hljs-number, .tool-code .hljs-symbol,
.tool-code .hljs-bullet { color: var(--syntax-number); }
.tool-code .hljs-title, .tool-code .hljs-section,
.tool-code .hljs-selector-id, .tool-code .hljs-selector-class { color: var(--syntax-title); }
.tool-code .hljs-type, .tool-code .hljs-built_in,
.tool-code .hljs-attribute, .tool-code .hljs-attr { color: var(--syntax-type); }
.tool-code .hljs-variable, .tool-code .hljs-template-variable,
.tool-code .hljs-params { color: var(--syntax-variable); }
.tool-code .hljs-meta { color: var(--syntax-meta); }
.tool-code .hljs-deletion { color: var(--error); }
.tool-code .hljs-subst { color: var(--text); }
.tool-code .hljs-emphasis { font-style: italic; }
.tool-code .hljs-strong { font-weight: 700; }

/* Block-level diff rows keep inline line numbers and horizontal scrolling. */
pre.tool-diff { padding: .6rem 0; }
pre.tool-diff > code { display: block; width: max-content; min-width: 100%; background: transparent; padding: 0; }
.tool-diff .diff-line { display: block; min-height: 1.6em; padding: 0 .8rem; }
.tool-diff .diff-context { color: var(--diff-context); }
.tool-diff .diff-added { color: var(--diff-added); background: var(--diff-added-bg); }
.tool-diff .diff-removed { color: var(--error); background: var(--diff-removed-bg); }
.tool-diff mark { color: inherit; background: var(--diff-mark-bg); border-radius: 2px; }
.tool-diff .diff-added mark { background: var(--diff-added-mark-bg); }
.tool-diff .diff-removed mark { background: var(--diff-removed-mark-bg); }
.failed, #error { color: var(--error); white-space: pre-line; }
#pine-update, #pine-storage { margin: 0; padding: .5rem 1rem; border-bottom: 1px solid var(--border); background: var(--panel); font-size: .85rem; }
#pine-update button { margin-left: .5rem; padding: .2rem .6rem; }
.notice, .usage, .empty { color: var(--muted); font-size: .85rem; }
.empty { padding: 1rem; }
@media (prefers-reduced-motion: reduce) {
  .tool-spinner, dialog.sheet[open], dialog.sheet[open].closing { animation: none; }
}
#error { margin: .4rem 1.25rem; font-size: .85rem; }
dialog { color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; width: min(520px, calc(100% - 2rem)); max-height: 85dvh; padding: 1.3rem; }
dialog::backdrop { background: var(--dialog-backdrop); }
dialog h2 { margin-top: 0; font-size: 1.2rem; }
dialog label { display: block; margin-bottom: .8rem; font-size: .85rem; }
dialog input, dialog select, dialog textarea { display: block; width: 100%; margin-top: .2rem; }
dialog p { color: var(--muted); font-size: .8rem; }
dialog footer { display: flex; justify-content: flex-end; gap: .5rem; }
#dialog { width: min(640px, calc(100% - 2rem)); }
/* Bottom sheet: slides up from the composer edge; only its model list scrolls. */
dialog.sheet { margin: auto auto 0; width: min(640px, 100%); max-width: 100%; padding: 0; border-bottom: 0; border-radius: 12px 12px 0 0; overflow: hidden; }
dialog.sheet[open] { animation: sheet-up 220ms cubic-bezier(.22, 1, .36, 1); }
@keyframes sheet-up { from { transform: translateY(100%); } }
dialog.sheet[open].closing { animation: sheet-down 180ms cubic-bezier(.4, 0, 1, 1) forwards; }
@keyframes sheet-down { to { transform: translateY(100%); } }
.sheet-form { display: flex; flex-direction: column; max-height: min(80dvh, 720px); }
/* A sheet follows the visible viewport, so it shrinks with the keyboard open. */
#sheet { max-height: calc(var(--viewport-height, 100dvh) - 1rem); }
.sheet-form > * { flex-shrink: 0; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .4rem .5rem 0 1.25rem; }
.sheet-header h2 { margin: 0; font-size: 1rem; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; }
.dialog-header h2 { margin-bottom: .4rem; }
.dialog-header button { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: .25rem; border: 0; background: transparent; color: var(--muted); }
@media (max-width: 720px) {
  .bar { padding: .2rem .7rem .2rem 1rem; min-height: 3.25rem; }
}
