:root {
  --bg: #0f1115; --panel: #151a23; --panel-2: #1d2432; --border: #2a3245;
  --text: #e7ebf3; --muted: #8b94a8; --accent: #4f74e8; --accent-2: #3b5bdb;
  --user-bubble: #2b3a5c; --err: #ff7b72; --ok: #3fb950;
  --white: #fff; --code-bg: #0b0e14; --row-stripe: rgba(255, 255, 255, 0.03);
  --quote-bg: rgba(124, 156, 255, 0.06); --danger: #b33;
  --overlay: rgba(0, 0, 0, 0.55); --shadow: rgba(0, 0, 0, 0.5);
  --hover: rgba(255, 255, 255, 0.06); --hover-strong: rgba(255, 255, 255, 0.10);
  --accent-soft: rgba(79, 116, 232, 0.16); --gradient-top:#353f50;
}
[data-theme="light"] {
  --bg: #f4f6fb; --panel: #ffffff; --panel-2: #eef1f8; --border: #d7dcea;
  --text: #1c2333; --muted: #5b6478; --accent: #444; --accent-2: #000;
  --user-bubble: #cfe0ee; --err: #d1242f; --ok: #1a7f37;
  --white: #fff; --code-bg: #f0f2f8; --row-stripe: rgba(20, 30, 60, 0.04);
  --quote-bg: rgba(59, 91, 219, 0.08); --danger: #c62828;
  --overlay: rgba(30, 35, 50, 0.4); --shadow: rgba(30, 40, 70, 0.25);
  --hover: rgba(20, 30, 60, 0.05); --hover-strong: rgba(20, 30, 60, 0.09);
  --accent-soft: rgba(79, 116, 232, 0.12); --gradient-top:aliceblue;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* font: 15px/1.55  Frutiger, Roboto, sans-serif; */
  background: var(--bg); color: var(--text);
}
button { font: inherit; cursor: pointer; }
#app { display: flex; height: 100%; }

/* sidebar */
#sidebar {
  width: 64px; background: linear-gradient(180deg, var(--gradient-top) 0%, var(--panel) 30%);
  display: flex; flex-direction: column;
  transition: width 0.18s ease; overflow: hidden;
}
#sidebar.open { width: 264px; }
#sidebar-top { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
#sidebar-top > svg {
	margin:2px;
	margin-bottom:20px;
}
#sidebar.open #sidebar-top { 
	flex-direction: row; 
	justify-content: space-between;
	padding:10px;
}
#new-chat {
  width:35px;
  margin:2px;
  height: 35px;
  padding: 10px; background: var(--accent-2); color: var(--white);  
  border-radius: 40px;
  display: flex; align-items: center; justify-content: center;
}
#new-chat:hover { background: var(--accent); }
#new-chat .nc-icon { font-size: 20px; font-weight: 700; line-height: 1; }
#new-chat .nc-label { display: none; margin-top:-2px}
/* in expanded mode the big button is replaced by the "+" in the Chats pane head */
#sidebar.open #new-chat { display: none; }
#new-chat-head {
  background: transparent; color: var(--text); border: none; border-radius: 3px;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
}
#new-chat-head:hover { background: var(--panel-2); }

/* search bar (chats + workspaces) */
#search-bar {
  display: none; flex-direction: column; gap: 6px;
  padding: 0 10px 8px;
}
#sidebar.open #search-bar { display: flex; }
#search-input {
  width: 100%; padding: 7px 10px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 5px;
  font: inherit; font-size: 13px; outline: none;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--muted); }
/* scope toggle — flat buttons; the selected one is bold + accent */
#search-scope { display: flex; gap: 2px; }
.search-scope-btn {
  flex: 1; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 12px; font-weight: 400;
  padding: 6px 8px; transition: color 0.12s ease;
}
.search-scope-btn:hover { color: var(--text); }
.search-scope-btn.active { color: var(--accent); font-weight: 700; }
#search-results {
  flex: 0 1 auto; min-height: 0; overflow-y: auto;
  padding: 0 8px 8px; border-top: 1px solid var(--border);
}
.search-empty { color: var(--muted); font-size: 13px; padding: 10px 4px; }
.search-group-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); padding: 8px 4px 4px;
}
.search-item {
  display: block; width: 100%; text-align: left; padding: 7px 8px;
  background: none; border: none; border-radius: 5px; color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer;
}
.search-item:hover { background: var(--hover); }
.search-item .si-title { font-weight: 600; display: block; margin-bottom: 2px; }
.search-item .si-title .si-badge {
  font-weight: 400; font-size: 11px; color: var(--muted);
  margin-left: 6px; text-transform: none;
}
.search-item .si-snippet {
  color: var(--muted); font-size: 12px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.search-item .si-path { color: var(--accent); font-size: 11px; font-family: ui-monospace, monospace; }

/* collapsible panes (Chats + Workspaces) — heading toggles the body.
   No grid: the expanded pane grows to fill the sidebar (flex-grow) and its
   body grows to fill the pane; the collapsed pane shrinks to just its heading.
   Both are animated with a flex-grow transition. */
.pane {
  display: flex; flex-direction: column; min-height: 0;
  flex: 0 1 auto;
  transition: flex-grow 0.22s ease;
}
.pane:not(.collapsed) { flex-grow: 1; }
.pane-body {
  flex: 0 1 0; min-height: 0; overflow: hidden;
  transition: flex-grow 0.22s ease;
}
.pane:not(.collapsed) .pane-body { flex-grow: 1; }
.pane-head {
  display: none; align-items: center; gap: 6px; padding: 8px 10px;
  cursor: pointer; user-select: none; color: var(--muted);
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
#sidebar.open .pane-head { display: flex; }
.pane-head:hover { color: var(--text); }
.pane-caret { display: inline-flex; align-items: center; justify-content: center; transition: transform 0.15s ease; }
.pane-caret svg { display: block; }
.pane.collapsed .pane-caret { transform: rotate(-90deg); }
.pane-title { flex: 1; }
#chat-list { height: 100%; overflow-y: auto; padding: 0 8px 8px; }
#ws-body { height: 100%; overflow-y: auto; padding: 0 8px 8px; }
/* hide the pane bodies entirely while the sidebar is closed (no animation there) */
#sidebar:not(.open) .pane-body { display: none; }
#ws-new {
  background: transparent; color: var(--text); border: none; border-radius: 3px;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
}
#ws-new:hover { background: var(--panel-2); }
#ws-list { display: flex; flex-direction: column; gap: 2px; }
.ws-item {
  display: flex; align-items: center; gap: 4px; padding: 7px 9px;
  border-radius: 4px; color: var(--muted); cursor: pointer;
}
.ws-item:hover { background: var(--panel-2); color: var(--text); }
.ws-item.active { background: var(--panel-2); color: var(--text); }
.ws-item-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-item-del { background: none; border: none; color: var(--muted); font-size: 16px; line-height: 1; padding: 0 4px; opacity: 0; }
.ws-item:hover .ws-item-del { opacity: 1; }
.ws-item-del:hover { color: var(--err); }
.ws-empty { color: var(--muted); font-size: 13px; padding: 6px 9px; }
#ws-tabs { display: flex; gap: 2px; padding: 0 2px; margin-top: 2px; border-bottom: 1px solid var(--border); }
.ws-tab {
  flex: 1; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 6px 8px 7px; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color 0.12s ease, border-color 0.12s ease;
}
.ws-tab:hover { color: var(--text); }
.ws-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
#ws-files { padding-top: 8px; }
.ws-files-head { display: flex; align-items: center; gap: 6px; padding: 0 2px 6px; }
.ws-files-title { flex: 1; font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Target-folder chip: the folder uploads / new files are created in. */
.ws-target-chip {
  display: flex; align-items: center; gap: 4px;
  max-width: 110px; flex: none;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 4px; padding: 2px 4px 2px 6px;
  font-size: 11px; line-height: 1.5;
}
.ws-target-chip[hidden] { display: none; }
.ws-target-chip svg { flex: none; }
.ws-target-chip-label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}
.ws-target-chip-clear, #ws-target-clear {
  background: none; border: none; color: var(--accent);
  font-size: 13px; line-height: 1; padding: 0 3px; border-radius: 3px;
}
#ws-target-clear:hover { color: var(--text); background: var(--hover); }
#ws-new-folder {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 4px 6px; display: flex; align-items: center;
}
#ws-new-folder:hover { color: var(--text); background: var(--hover); }
#ws-upload {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 4px 6px; display: flex; align-items: center;
}
#ws-upload:hover { color: var(--text); background: var(--hover); }
#ws-download {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 4px 6px; display: flex; align-items: center;
}
#ws-download:hover { color: var(--text); background: var(--hover); }
.ws-newfile-wrap { position: relative; }
#ws-new-file {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 4px 6px; display: flex; align-items: center;
}
#ws-new-file:hover { color: var(--text); background: var(--hover); }
#ws-new-file[aria-expanded="true"] { color: var(--accent); background: var(--accent-soft); }
.ws-newfile-menu {
  position: fixed; z-index: 1000; display: none;
  min-width: 184px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 24px var(--shadow); padding: 4px;
  flex-direction: column; gap: 2px;
}
.ws-newfile-menu.open { display: flex; }
.ws-newfile-item {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: var(--text);
  padding: 7px 9px; border-radius: 4px; font-size: 13px; text-align: left; white-space: nowrap;
}
.ws-newfile-item:hover { background: var(--panel-2); }
.ws-newfile-item svg { color: var(--muted); flex: none; }
#ws-file-list { display: flex; flex-direction: column; gap: 1px; }
.ws-file { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 4px; }
.ws-file:hover { background: var(--panel-2); }
.ws-file-icon { flex: none; display: flex; align-items: center; color: var(--muted); }
.ws-file-icon svg { display: block; }
/* Folder rows: a small caret that toggles the subtree. */
.ws-folder-caret {
  width: 14px; flex: none; text-align: center; font-size: 10px;
  color: var(--muted); cursor: pointer; user-select: none;
  transition: transform 0.12s ease;
}
.ws-folder-caret.collapsed { transform: rotate(-90deg); }
.ws-folder-caret:hover { color: var(--text); }
.ws-folder .ws-file-name { cursor: pointer; }
/* The folder currently targeted by uploads / new-file actions. */
.ws-folder.ws-folder-selected { background: var(--accent-soft); }
.ws-folder.ws-folder-selected:hover { background: var(--accent-soft); }
.ws-folder.ws-folder-selected .ws-file-name { color: var(--accent); }
/* Drag & drop: moving files/folders within the workspace tree. */
.ws-file[draggable="true"] { cursor: grab; }
.ws-file.dragging { opacity: 0.45; }
.ws-file.drop-over { background: var(--accent-soft); outline: 1px dashed var(--accent); }
.ws-dropzone {
  display: none; margin: 4px 2px; padding: 8px;
  border: 1px dashed var(--border); border-radius: 4px;
  color: var(--muted); font-size: 12px; text-align: center;
}
body.ws-dragging .ws-dropzone { display: block; }
.ws-dropzone.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.ws-file-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-file-size { font-size: 11px; color: var(--muted); flex: none; }
.ws-file-act { background: none; border: none; color: var(--muted); font-size: 14px; line-height: 1; padding: 0 3px; opacity: 0; }
.ws-file:hover .ws-file-act { opacity: 1; }
.ws-file-act:hover { color: var(--text); }
.ws-file-act:last-child:hover { color: var(--err); }
/* Right-click context menu for a workspace file. */
.ws-file-ctx {
  position: fixed; z-index: 1000;
  min-width: 160px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 24px var(--shadow); padding: 4px;
  flex-direction: column; gap: 2px;
}
.ws-file-ctx:not([hidden]) { display: flex; }
.ws-file-ctx-item {
  background: none; border: none; color: var(--text);
  padding: 7px 9px; border-radius: 4px; font-size: 13px; text-align: left; white-space: nowrap;
}
.ws-file-ctx-item:hover { background: var(--panel-2); }
.ws-file-ctx-item.danger { color: var(--err); }
.ws-file-ctx-item.danger:hover { background: var(--err); color: var(--white); }
/* Unsaved-changes dot shown next to a file that's open in the editor. */
.ws-file-dot { width: 7px; height: 7px; border-radius: 50%; background: transparent; flex: none; }
.ws-file-dot.show { background: var(--accent); }
/* Clickable filename opens the file in the editor. */
.ws-file-name.clickable { cursor: pointer; }
.ws-file-name.clickable:hover { color: var(--accent); text-decoration: underline; }

/* ---------- git panel ---------- */
#ws-git { padding-top: 8px; }
.ws-git-head { display: flex; align-items: center; gap: 6px; padding: 0 2px 6px; }
.ws-git-title { flex: 1; display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text); }
.ws-git-title svg { color: var(--muted); flex: none; }
.ws-git-branch { font-size: 12px; color: var(--accent); font-family: ui-monospace, "Cascadia Code", Consolas, monospace; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ws-git-refresh { background: none; border: none; color: var(--muted); border-radius: 4px; padding: 4px 6px; display: flex; align-items: center; }
#ws-git-refresh:hover { color: var(--text); background: var(--hover); }
#ws-git-graph { background: none; border: none; color: var(--muted); border-radius: 4px; padding: 4px 6px; display: flex; align-items: center; cursor: pointer; }
#ws-git-graph:hover { color: var(--text); background: var(--hover); }
#ws-git-graph[aria-pressed="true"] { color: var(--accent); background: var(--hover); }
.ws-git-hint { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.ws-git-clone { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.ws-git-clone input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 6px 8px; font-size: 12px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}
.ws-git-clone input:focus { outline: none; border-color: var(--accent); }
.ws-git-status { font-size: 12px; color: var(--muted); padding: 0 2px 6px; }
.ws-git-group { border-top: 1px solid var(--border); padding: 8px 0; }
.ws-git-group:first-of-type { border-top: none; }
.ws-git-group-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 5px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.ws-git-group-actions { display: flex; gap: 4px; }
.ws-git-files { display: flex; flex-direction: column; gap: 1px; }
.ws-git-file { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 4px; }
.ws-git-file:hover { background: var(--panel-2); }
.ws-git-file.current { background: var(--accent-soft); }
.ws-git-file .ws-file-icon { color: var(--muted); }
.ws-git-file-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-git-file-url { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.ws-git-hash { font-size: 11px; color: var(--accent); font-family: ui-monospace, "Cascadia Code", Consolas, monospace; flex: none; }
.ws-git-badge { font-size: 10px; color: var(--muted); flex: none; text-transform: uppercase; letter-spacing: 0.02em; font-weight: 600; }
.ws-git-badge.m { color: var(--warn, #d9a441); }
.ws-git-badge.a { color: var(--ok, #4caf7d); }
.ws-git-badge.d { color: var(--err); }
.ws-git-badge.r { color: var(--accent); }
.ws-git-badge.u { color: var(--err); }
.ws-git-badge.\? { color: var(--muted); }
.ws-git-empty { color: var(--muted); font-size: 12px; padding: 4px 8px; }
.ws-git-commit-msg {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 6px 8px; font-size: 13px; font-family: inherit; resize: vertical; margin-bottom: 6px;
}
.ws-git-commit-msg:focus { outline: none; border-color: var(--accent); }
.ws-git-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.ws-git-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 5px 10px; font-size: 12px; font-weight: 500;
}
.ws-git-btn:hover { background: var(--hover-strong); }
.ws-git-btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: var(--white); }
.ws-git-btn.primary:hover { background: var(--accent); }
.ws-git-btn.danger { color: var(--err); }
.ws-git-btn.danger:hover { background: var(--err); color: var(--white); border-color: var(--err); }
.ws-git-mini {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 3px 7px; font-size: 11px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.ws-git-mini:hover { color: var(--text); background: var(--hover); }
.ws-git-mini.plus, .ws-git-mini.minus { font-size: 15px; line-height: 1; padding: 2px 8px; }
.ws-git-mini.danger { color: var(--err); }
.ws-git-mini.danger:hover { color: var(--white); background: var(--err); }

/* ---------- git branch graph (editor tab) ---------- */
.ws-git-graph { height: 100%; overflow: hidden; display: flex; flex-direction: column; padding: 4px 8px 8px; }
.ws-git-graph-scroll { flex: 1; overflow-y: auto; }
.ws-git-graph-empty { color: var(--muted); font-size: 12px; padding: 8px; }
.ws-git-graph-row { display: flex; align-items: center; gap: 12px; padding: 3px 4px; border-radius: 4px; }
.ws-git-graph-row:hover { background: var(--panel-2); }
.ws-git-graph-head { font-size: 11px; font-weight: 700; color: var(--muted); padding-top: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.ws-git-graph-head:hover { background: none; }
.ws-git-graph-graphhead { overflow: visible; text-align: center; white-space: nowrap; }
.ws-git-graph-lane { position: relative; flex: none; }
.ws-git-graph-lane svg { display: block; width: 100%; height: 100%; }
.ws-git-graph-desc { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.ws-git-graph-subj { font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-git-graph-date { flex: none; width: 130px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.ws-git-graph-author { flex: none; width: 60px; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-git-graph-commit { flex: none; width: 78px; font-size: 11px; color: var(--muted); font-family: var(--mono, monospace); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-git-graph-label {
  flex: none;
  font-size: 10px; font-weight: 600; line-height: 1;
  background: var(--user-bubble); color: var(--text);
  padding: 2px 6px; border-radius: 3px; white-space: nowrap; cursor: pointer;
  max-width: 110px; overflow: hidden; text-overflow: ellipsis;
  border-style: solid;
  border-width: 1px;
  border-left-width:10px;
}
.ws-git-graph-label:hover { filter: brightness(1.15); }
.ws-git-graph-label.remote { opacity: 0.75; }
.ws-git-graph-label.checked-out {
  font-weight: bold;
}
/* Branch context menu (right-click a branch label). */
.ws-git-ctx {
  position: fixed; z-index: 1000;
  min-width: 170px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 24px var(--shadow); padding: 4px;
  flex-direction: column; gap: 2px;
}
.ws-git-ctx:not([hidden]) { display: flex; }
.ws-git-ctx-item {
  background: none; border: none; color: var(--text);
  padding: 7px 9px; border-radius: 4px; font-size: 13px; text-align: left; white-space: nowrap;
}
.ws-git-ctx-item:hover { background: var(--panel-2); }
.ws-git-ctx-item.danger { color: var(--err); }
.ws-git-ctx-item.danger:hover { background: var(--err); color: var(--white); }

/* header workspace chip */
#ws-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-2); color: var(--muted);
  border: none; border-radius: 4px; padding: 6px 10px;
  max-width: 220px;
}
#ws-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
#ws-chip:hover { color: var(--text); background: var(--hover-strong); }
#ws-chip.attached { color: var(--accent); background: var(--accent-soft); }
#ws-chip-caret { flex: none; opacity: 0.7; transition: transform 0.15s ease; }
#ws-chip[aria-expanded="true"] #ws-chip-caret { transform: rotate(180deg); }
.ws-chip-menu {
  position: fixed; z-index: 1000; display: none;
  min-width: 200px; max-width: 280px; max-height: 320px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 24px var(--shadow); padding: 4px;
}
.ws-chip-menu.open { display: block; }
.ws-chip-menu-head {
  padding: 6px 9px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
}
.ws-chip-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; color: var(--text);
  padding: 7px 9px; border-radius: 4px; font-size: 13px; text-align: left;
  white-space: nowrap; overflow: hidden;
}
.ws-chip-item:hover { background: var(--panel-2); }
.ws-chip-item.active { color: var(--accent); background: var(--accent-soft); }
.ws-chip-item .ws-chip-item-name { overflow: hidden; text-overflow: ellipsis; }
.ws-chip-item svg { color: var(--muted); flex: none; }
.ws-chip-item.active svg { color: var(--accent); }
.ws-chip-item .ws-chip-check { margin-left: auto; color: var(--accent); flex: none; }
.ws-chip-empty { padding: 8px 9px; font-size: 13px; color: var(--muted); }
.chat-item {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px;
  margin-bottom: 2px; border-radius: 4px; color: var(--muted); cursor: pointer;
}
.chat-item:hover { background: var(--panel-2); color: var(--text); }
.chat-item.active { background: var(--panel-2); color: var(--text); }
.chat-title {
  flex: 1; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-del {
  background: none; border: none; color: var(--muted);
  font-size: 17px; line-height: 1; padding: 0 4px; opacity: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--err); }
#sidebar-footer {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 8px;
  margin-top: auto;
	flex-direction: column;
}
#sidebar.open #sidebar-footer { flex-direction: row; justify-content: flex-start; padding: 10px 12px; margin-top: auto; }
#status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
#status-dot.ok { background: var(--ok); }
#status-dot.bad { background: var(--err); }
#settings-btn,
#signout-btn {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 8px 8px; font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
#settings-btn:hover,
#signout-btn:hover { color: var(--text); background: var(--hover); }

/* main column */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; container-type: inline-size; }
header {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  background: var(--background);
}
/* rail icons (chats + workspace) — visible when collapsed, hidden when open */
#chats-icon,
#ws-icon {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; width: 39px; height: 39px;
  display: flex; align-items: center; justify-content: center;
}
#chats-icon:hover, #ws-icon:hover { color: var(--text); background: var(--hover); }
#sidebar.open #chats-icon, #sidebar.open #ws-icon { display: none; }
/* close button — hidden when collapsed, visible when open */
#sidebar-close {
  background: none; border: none; color: var(--muted);
  border-radius: 3px; width: 24px; height: 24px;
  display: none; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
}
#sidebar-close:hover { color: var(--text); background: var(--hover); }
#sidebar.open #sidebar-close { display: flex; }
/* pane-head icons — shown only when the sidebar is open */
.pane-icon { display: none; align-items: center; justify-content: center; color: var(--muted); flex: none; }
#sidebar.open .pane-head .pane-icon { display: inline-flex; }
/* "Open menu" button — mobile only (see the max-width: 700px media query). */
#menu-btn {
  display: none; background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 8px 8px; line-height: 1; flex: none;
  align-items: center; justify-content: center;
}
#menu-btn:hover { color: var(--text); background: var(--hover); }
#model-select {
  background: var(--panel-2); color: var(--text); border: none;
  border-radius: 4px; padding: 6px 10px; max-width: 340px;
}
#model-select:hover { background: var(--hover-strong); }
#model-hint { color: var(--err); font-size: 13px; display: flex; align-items: center; gap: 6px; }
#model-hint svg { flex: none; }
#theme-btn {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 8px 8px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
#theme-btn:hover { color: var(--text); background: var(--hover); }
/* voice controls — a single segmented pill: speaker (auto-speak) + mic (voice mode).
   Combining the two voice toggles into one control saves header room on mobile. */
#tts-btn {
  display: flex; align-items: center; gap: 2px;
  margin-left: auto; /* the old #prompt-btn's auto-margin: keeps the right-side controls pushed right */
  background: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 2px; line-height: 1;
}
#tts-btn button {
  background: none; border: none; color: var(--muted);
  border-radius: 6px; padding: 6px 8px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
#tts-btn button:hover { color: var(--text); background: var(--hover); }
#tts-btn button.on { color: var(--accent); background: var(--accent-soft); }
/* "Open editor" button — mobile only. Hidden by default (desktop has the
   editor as a side panel); shown by JS when a file is open on a phone. */
#chat-editor-btn {
  display: none; background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 8px 8px; line-height: 1; flex: none;
  align-items: center; justify-content: center;
}
#chat-editor-btn:hover { color: var(--text); background: var(--hover); }

/* The chat column is resizable, so adapt the header to its *actual* width
   (container queries) rather than the viewport. */
@container (max-width: 520px) {
  header { gap: 8px; padding: 10px 12px; }
  #model-select { max-width: none; flex: 1; min-width: 0; }
  #ws-chip { max-width: none; padding: 6px 8px; flex: none; }
  #ws-chip-label { display: none; }
}
@container (max-width: 380px) {
  header { gap: 6px; padding: 8px 10px; }
  #model-select { max-width: none; flex: 1; min-width: 0; padding: 6px 8px; }
  #theme-btn { padding: 6px 6px; }
  #tts-btn button { padding: 5px 6px; }
}

/* context / token usage indicator (ring + % above the composer, VS Code style) */
#ctx-row {
  max-width: 780px; margin: 0 auto 6px; padding: 0 2px;
  display: flex; justify-content: flex-end;
}
#ctx-wrap { position: relative; }
#ctx-btn {
  background: none; border: none; color: var(--muted);
  padding: 2px 0; line-height: 1; font-size: 12px;
  font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 6px;
}
#ctx-btn:hover { color: var(--accent); }
#ctx-btn.warn { color: var(--warn, #d29922); }
#ctx-btn.err { color: var(--err); }
.ctx-ring { display: inline-flex; width: 18px; height: 18px; }
.ctx-ring svg { width: 18px; height: 18px; display: block; }
.ctx-ring-bg { fill: none; stroke: var(--panel-2); stroke-width: 3.5; }
.ctx-ring-arc {
  fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  transition: stroke-dashoffset 0.25s ease;
}
#ctx-btn.warn .ctx-ring-arc { stroke: var(--warn, #d29922); }
#ctx-btn.err .ctx-ring-arc { stroke: var(--err); }
.ctx-pct { min-width: 26px; text-align: left; }
.ctx-pop {
  position: absolute; bottom: calc(100% + 8px); right: 0; z-index: 50;
  width: 280px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 28px var(--shadow); padding: 12px;
}
.ctx-pop-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ctx-pop-title { font-weight: 600; font-size: 13px; }
.ctx-pop-model { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.ctx-section-title { font-weight: 600; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.ctx-quota { margin-bottom: 4px; }
.ctx-quota-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.ctx-quota-label b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.ctx-bar { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; display: flex; }
.ctx-bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.25s ease; }
.ctx-bar-fill.warn { background: var(--warn, #d29922); }
.ctx-bar-fill.err { background: var(--err); }
.ctx-bar-reserve { height: 100%; width: 0; background: var(--border); opacity: 0.7; }
.ctx-legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; margin-top: 6px; }
.ctx-legend-swatch { width: 10px; height: 10px; border-radius: 2px; background: var(--border); opacity: 0.7; display: inline-block; }
.ctx-warn { color: var(--warn, #d29922); font-size: 11px; margin: 8px 0 2px; }
.ctx-rows { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.ctx-row { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); }
.ctx-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.ctx-empty { color: var(--muted); font-size: 12px; margin-top: 10px; }
.ctx-pop.no-data .ctx-quota, .ctx-pop.no-data .ctx-warn, .ctx-pop.no-data .ctx-rows { display: none; }
#theme-btn .icon-sun { display: none; }
[data-theme="light"] #theme-btn .icon-sun { display: block; }
[data-theme="light"] #theme-btn .icon-moon { display: none; }

#messages { flex: 1; overflow-y: auto; padding: 24px 0 8px; }
.empty { text-align: center; color: var(--muted); margin-top: 18vh; font-size: 16px; }
.msg {
  max-width: 780px; margin: 0 auto 18px; padding: 0 20px;
  display: flex; flex-direction: column;
}
.msg.user { align-items: flex-end; }
.msg.system { align-items: center; }
.msg.system .msg-role { color: var(--accent, #7aa2f7); }
.msg.system .bubble {
  background: transparent; border: 1px dashed var(--border);
  color: var(--muted); font-size: 0.92em; text-align: center;
  padding: 6px 14px;
}
.msg-role { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.bubble {
  background: var(--panel-2);
  border-radius: 6px; padding: 10px 14px;
  overflow-wrap: break-word; max-width: 100%;
}
.msg.user .bubble { background: var(--user-bubble); border-color: transparent; }
.bubble pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 10px 12px; overflow-x: auto;
}
.bubble code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; }
/* code block wrapper with a header row (language + download) */
.bubble .code-block { margin: 8px 0; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.bubble .code-block pre { border: none; border-radius: 0; margin: 0; }
.bubble .code-block-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 4px 10px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.bubble .code-block-lang {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace;
}
.bubble .code-block-actions { display: inline-flex; gap: 6px; }
.code-copy-btn, .code-dl-btn {
  background: transparent; border: none; color: var(--muted);
  border-radius: 5px; padding: 1px 8px; font-size: 11px; cursor: pointer;
  white-space: nowrap;
}
.code-copy-btn:hover, .code-dl-btn:hover { color: var(--text); background: var(--hover); }
.code-copy-btn.copied, .code-dl-btn.saved { color: var(--ok); }
.code-dl-btn { display: inline-flex; align-items: center; gap: 4px; }
.bubble :not(pre) > code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 12px 0 6px; line-height: 1.3; font-weight: 600;
}
.bubble h1 { font-size: 1.35em; }
.bubble h2 { font-size: 1.2em; }
.bubble h3 { font-size: 1.1em; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 1em; }
.bubble > h1:first-child, .bubble > h2:first-child, .bubble > h3:first-child,
.bubble > h4:first-child, .bubble > h5:first-child, .bubble > h6:first-child { margin-top: 0; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; max-width: 100%; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.bubble th { background: var(--code-bg); }
.bubble tbody tr:nth-child(even) { background: var(--row-stripe); }
.bubble blockquote {
  margin: 8px 0; padding: 4px 12px;
  border-left: 3px solid var(--accent-2);
  background: var(--quote-bg);
  color: var(--muted); border-radius: 0 6px 6px 0;
}
.bubble blockquote p { margin: 0; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg-error {
  color: var(--err); margin-top: 6px; font-size: 13px;
  display: flex; align-items: flex-start; gap: 6px;
}
.msg-error svg { flex: none; margin-top: 2px; }
.msg-note { color: var(--muted); margin-top: 4px; font-size: 12px; }
/* inline citation links the model adds for web sources — small + unobtrusive */
.bubble a {
  color: var(--accent); text-decoration: none;
  font-size: 0.82em; padding: 0 1px;
}
.bubble a:hover { text-decoration: underline; color: var(--accent-2); }
.usage-note {
  color: var(--muted); font-size: 11px; margin-top: 4px;
  padding: 2px 8px; border-radius: 3px;
  background: var(--panel-2); display: flex;
  gap:3px;
  font-variant-numeric: tabular-nums;
}
.usage-part { display: inline-flex; align-items: center; gap: 3px; }
.dev-event-icon { vertical-align: -2px; margin-right: 6px; color: var(--accent); }
.msg-actions {
  display: flex; gap: 6px; margin-top: 4px;
  opacity: 0; transition: opacity 0.12s ease;
}
.msg.assistant:hover .msg-actions { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: 1; } }
.copy-btn {
  background: var(--panel-2); border: none;
  color: var(--muted); border-radius: 4px; padding: 2px 9px; font-size: 12px;
}
.copy-btn:hover { color: var(--text); background: var(--hover-strong); }
.copy-btn.copied { color: var(--ok); }
.speak-btn.speaking { color: var(--accent); border-color: var(--accent); }
.speak-btn { display: inline-flex; align-items: center; gap: 4px; }
.speak-btn svg { flex: none; }
/* "Files" footer listing downloadable code files in a message */
.msg-files {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 6px; padding: 6px 10px;
}
.msg-files-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); margin-right: 2px;
}
.msg-file-chip {
  background: var(--panel-2); border: none; color: var(--muted);
  border-radius: 4px; padding: 2px 9px; font-size: 12px; cursor: pointer;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  display: inline-flex; align-items: center; gap: 5px;
}
.msg-file-chip:hover { color: var(--text); background: var(--hover-strong); }
.typing {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.15; } }

/* thinking bubble — transparent, collapsible timeline of reasoning + tool uses */
.thinking {
  background: transparent; border: none;
  margin-bottom: 4px; font-size: 13px;
}
.thinking-head {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 2px 3px;
  cursor: pointer; color: var(--muted); user-select: none;
}
.thinking-head:hover { color: var(--text); }
.thinking-robot, .thinking-caret { flex: none; }
.thinking-label { font-weight: 600; }
.thinking.live .thinking-label::after { content: "…"; animation: blink 1s infinite; }
/* collapse/expand caret (workspace-chip style) — visible on hover or expanded */
.thinking-caret {
  margin-left: auto;
  opacity: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.thinking-head:hover .thinking-caret,
.thinking.live .thinking-caret,
.thinking.open .thinking-caret { opacity: 0.8; }
.thinking.live .thinking-caret,
.thinking.open .thinking-caret { transform: rotate(180deg); }
.thinking-body {
  display: none;
  padding: 2px 2px 4px;
  color: var(--muted);
  max-height: 260px; overflow-y: auto;
  font-size: 12.5px; line-height: 1.55;
}
.thinking.open .thinking-body,
.thinking.live .thinking-body { display: block; }
/* reasoning text — indented behind a pipe */
.think-text {
  border-left: 2px solid var(--border);
  padding-left: 10px;
  margin: 3px 6px;
  white-space: pre-wrap; overflow-wrap: break-word;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
/* a tool use, one line in the thinking timeline */
.think-tool {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 0;
}
.think-tool-icon { flex: none; display: inline-flex; }
.think-tool-icon svg { display: block; }
.think-tool-label { overflow-wrap: anywhere; }
.think-tool-count { flex: none; font-size: 11px; }
.tool-link {
  color: var(--accent); text-decoration: none; overflow-wrap: anywhere;
}
.tool-link:hover { text-decoration: underline; color: var(--accent-2); }

/* composer */
#composer { padding: 10px 20px 18px; }
.composer-inner {
  display: flex; align-items: flex-end; gap: 8px; max-width: 780px;
  margin: 0 auto; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px;
}
#input {
  flex: 1; background: none; border: none; outline: none; color: var(--text);
  font: inherit; resize: none; max-height: 160px; padding: 6px;
}
#send-btn, #stop-btn { border: none; border-radius: 4px; padding: 8px 16px; color: var(--white); font-weight: 600; }
#send-btn { background: var(--accent-2); }
#send-btn:hover { background: var(--accent); }
#stop-btn { background: var(--danger); }

/* attach button */
#attach-btn {
  flex: none; width: 38px; height: 38px; border-radius: 4px;
  border: none; background: none;
  color: var(--muted); display: flex; align-items: center; justify-content: center;
}
#attach-btn:hover { color: var(--text); background: var(--hover); }

/* mic (speech-to-text) button */
#mic-btn {
  flex: none; width: 38px; height: 38px; border-radius: 4px;
  border: none; background: none;
  color: var(--muted); display: flex; align-items: center; justify-content: center;
}
#mic-btn:hover { color: var(--text); background: var(--hover); }
#mic-btn.listening { color: var(--danger); background: var(--hover); animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* pending-attachment preview row above the composer */
#attach-preview {
  display: flex; flex-wrap: wrap; gap: 8px; max-width: 780px;
  margin: 0 auto 8px; padding: 0 2px;
}
.attach-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 6px 4px 4px; max-width: 220px;
}
.attach-thumb { width: 30px; height: 30px; object-fit: cover; border-radius: 5px; }
.attach-icon { font-size: 16px; line-height: 1; display: inline-flex; align-items: center; }
.attach-name {
  font-size: 12px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach-rm {
  flex: none; width: 20px; height: 20px; border: none; border-radius: 5px;
  background: none; color: var(--muted); font-size: 15px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.attach-rm:hover { color: var(--err); background: var(--hover); }
.attach-warn {
  width: 100%; font-size: 12px; color: var(--err);
  background: var(--panel); border: 1px dashed var(--border);
  border-radius: 4px; padding: 5px 10px;
  display: flex; align-items: center; gap: 6px;
}
.attach-warn svg { flex: none; }

/* drag & drop highlight */
#composer.dragging .composer-inner { border-color: var(--accent); border-style: dashed; }

/* attachments rendered inside a message */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg.user .msg-attachments { justify-content: flex-end; }
.msg-attach {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 8px 4px 4px; max-width: 240px;
}
.msg-attach.image { padding: 3px; }
.msg-attach.image img {
  max-width: 180px; max-height: 140px; border-radius: 3px;
  cursor: zoom-in; display: block;
}
.msg-attach-icon { font-size: 16px; line-height: 1; display: inline-flex; align-items: center; }
.msg-attach-name {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* shared modal system (settings, system prompt, …) */
.modal {
  position: fixed; inset: 0; z-index: 30; background: var(--overlay);
  display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 20px; width: min(420px, 90vw);
  max-height: 90vh; overflow-y: auto;
}
/* Full-screen settings modal — the Public API tab has a large monitoring panel. */
#modal .modal-box {
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  border-radius: 0; border: none; padding: 28px 32px;
}
.modal-box h2 { margin: 0 0 14px; font-size: 17px; }
.modal-sub { margin: -6px 0 14px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.modal-sub strong { color: var(--text); font-weight: 600; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field-hint { color: var(--text); font-weight: 500; }
.field-help { margin: 5px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }
.field input {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; padding: 8px 10px; font: inherit;
}
.field textarea {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; padding: 8px 10px; font: inherit;
  resize: vertical; min-height: 90px; line-height: 1.5;
}
/* input + button on one row (e.g. API key + Generate) */
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; min-width: 0; }
.key-row button {
  flex: none; border: 1px solid var(--border); border-radius: 4px;
  background: var(--panel-2); color: var(--text); padding: 8px 12px;
  font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.key-row button:hover { background: var(--hover-strong); }
/* toggle row (checkbox settings) */
.field-toggle { margin-bottom: 4px; }
.toggle-label {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  cursor: pointer; margin-bottom: 0;
}
.toggle-label .toggle-title { display: block; font-size: 13px; color: var(--text); }
.toggle-label .toggle-desc { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.field-toggle input[type="checkbox"] {
  flex: none; margin: 0;
  width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions button {
  border-radius: 4px; padding: 7px 14px; border: none;
  background: var(--panel-2); color: var(--text);
}
.modal-actions button:hover { background: var(--hover-strong); }
.modal-actions .modal-primary { background: var(--accent-2) !important; color: var(--white); font-weight: 600; }
.modal-actions .modal-primary:hover { background: var(--accent) !important; }

/* Model tab — divider above the system prompt block */
.model-prompt-section {
  margin-top: 18px; padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* settings tabs (General / Model / Shortcuts) */
.settings-tabs {
  display: flex; gap: 4px; margin: 0 0 14px;
  border-bottom: 1px solid var(--border);
}
.settings-tab-btn {
  background: none; border: none; color: var(--muted);
  padding: 7px 12px; font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.settings-tab-btn:hover { color: var(--text); }
.settings-tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.settings-tab[hidden] { display: none; }

/* Public API tab — monitoring + management panel */
.pa-section {
  margin-top: 18px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.pa-section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 10px;
}
.pa-section h3 { margin: 0 0 10px; font-size: 14px; color: var(--text); }
.pa-section-head h3 { margin: 0; }
.pa-section-actions { display: flex; gap: 8px; }
.pa-section-actions button {
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--panel-2); color: var(--text); padding: 6px 12px;
  font: inherit; font-size: 12px; cursor: pointer;
}
.pa-section-actions button:hover { background: var(--hover-strong); }

.pa-status { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.pa-status-note { font-size: 12px; color: var(--muted); }
.pa-badge {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 12px;
}
.pa-badge-on { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.pa-badge-off { background: color-mix(in srgb, var(--err) 20%, transparent); color: var(--err); }

.pa-health { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.pa-health-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 7px 12px;
}
.pa-health-name { width: 70px; font-size: 13px; color: var(--text); }
.pa-health-dot { font-size: 12px; font-weight: 600; }
.pa-up { color: var(--ok); }
.pa-down { color: var(--err); }
.pa-health-latency { margin-left: auto; font-size: 12px; color: var(--muted); }

.pa-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px;
}
.pa-tile {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 12px; text-align: center;
}
.pa-tile-value { font-size: 20px; font-weight: 700; color: var(--text); }
.pa-tile-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.pa-by-model { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.pa-model-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 6px 10px; border-radius: 4px; background: var(--panel-2);
}
.pa-model-name { font-size: 13px; color: var(--text); font-weight: 500; }
.pa-model-detail { font-size: 12px; color: var(--muted); }

.pa-logsize-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--muted);
}
.pa-logsize { color: var(--text); }

.pa-empty { font-size: 12px; color: var(--muted); padding: 8px 0; }

.pa-inflight { display: flex; flex-direction: column; gap: 6px; }
.pa-inflight-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 8px 12px;
}
.pa-inflight-meta { font-size: 13px; color: var(--text); }
.pa-abort-btn {
  border: 1px solid var(--danger); border-radius: 4px;
  background: transparent; color: var(--danger); padding: 5px 12px;
  font: inherit; font-size: 12px; cursor: pointer;
}
.pa-abort-btn:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); }

.pa-requests { max-height: 320px; overflow-y: auto; }
.pa-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.pa-table th, .pa-table td {
  text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.pa-table th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.pa-table td { color: var(--text); }
.pa-ok { color: var(--ok); }
.pa-err { color: var(--err); }

/* shortcut rows (Shortcuts tab) */
.shortcut-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-label { font-size: 13px; color: var(--text); }
.shortcut-chip {
  min-width: 120px; text-align: center;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; padding: 6px 10px;
  font-size: 12px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}
.shortcut-chip:hover { background: var(--hover-strong); }
.shortcut-chip.recording {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-soft);
}

/* ---------------- image viewer (workspace images) ---------------- */
.imgviewer {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(8, 10, 16, 0.92);
  display: flex; flex-direction: column;
}
.imgviewer[hidden] { display: none; }
.imgviewer-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--border); flex: none;
}
.imgviewer-name {
  flex: 1; font-size: 13px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.imgviewer-count { font-size: 12px; color: var(--muted); flex: none; }
.imgviewer-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.imgviewer-sep { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }
/* Icon buttons match the app's borderless toolbar buttons (e.g. #ws-upload). */
.imgviewer-btn {
  background: none; border: none; color: var(--muted);
  border-radius: 4px; padding: 6px; display: flex; align-items: center; justify-content: center;
}
.imgviewer-btn svg { display: block; }
.imgviewer-btn:hover { color: var(--text); background: var(--hover); }
.imgviewer-btn:active { background: var(--hover-strong); }
.imgviewer-close:hover { color: var(--err); }
.imgviewer-stage {
  flex: 1; min-height: 0; overflow: hidden; position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: grab; touch-action: none;
}
.imgviewer-stage.grabbing { cursor: grabbing; }
.imgviewer-img {
  max-width: none; max-height: none;
  transform-origin: center center;
  user-select: none; -webkit-user-drag: none;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}
.imgviewer-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--muted); background: var(--panel);
  border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px;
  pointer-events: none; opacity: 0.85; white-space: nowrap;
}

/* Editor styles live in editor.css (linked after this file). */

/* small screens: sidebar becomes a full-width overlay sliding in from the top */
@media (max-width: 700px) {
  #sidebar {
    position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 28;
    width: 100%; height: 100%;
    transform: translateX(-100%); transition: transform 0.18s ease;
  }
  #sidebar.open { width: 100%; transform: translateY(0); }
  #backdrop.show { display: block; }

  /* Tighten the header so it fits on narrow screens. */
  header { gap: 6px; padding: 8px 10px; }
  #menu-btn { display: flex; }
  #model-select { max-width: none; flex: 1; min-width: 0; }
  #model-hint { display: none; }
  /* Workspace chip becomes icon-only so it stops pushing the other
     header buttons off the page. */
  #ws-chip { max-width: none; padding: 6px 8px; flex: none; }
  #ws-chip-label { display: none; }
  /* Show the "open editor" button (JS toggles [hidden] when a file is open). */
  #chat-editor-btn:not([hidden]) { display: flex; }
}
#backdrop {
  position: fixed; inset: 0; z-index: 27; background: var(--overlay);
  display: none;
}

/* ---------------- login / entry page ---------------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; margin: 0; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--panel-2), var(--bg));
}
.login-wrap {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; align-items: center;
  gap: 34px;
}
.logo {
  display: flex; align-items: baseline; justify-content: center;
  font-family: "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 200;
  font-size: clamp(40px, 9vw, 64px);
  letter-spacing: 0.02em;
  color: var(--text);
  user-select: none;
  line-height: 1;
}
.logo-o {
  display: inline-block;
  width: 0.72em; height: 0.72em;
  margin-right: 0.08em;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}
.login-form {
  width: 100%;
  display: flex; flex-direction: column; gap: 12px;
}
.login-label {
  font-size: 13px; color: var(--muted); text-align: left;
}
.login-input {
  width: 100%;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 12px 14px; font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 116, 232, 0.25);
}
.login-error {
  color: var(--err); font-size: 13px; text-align: center;
}
.login-btn {
  margin-top: 4px;
  background: var(--accent-2); color: var(--white);
  border: none; border-radius: 6px; padding: 12px 16px;
  font-weight: 600; font-size: 15px;
  transition: background 0.15s ease, transform 0.05s ease;
}
.login-btn:hover { background: var(--accent); }
.login-btn:active { transform: translateY(1px); }
.login-btn:disabled { opacity: 0.6; cursor: default; }
.login-hint {
  margin: 2px 0 0; color: var(--muted); font-size: 13px; text-align: center;
}

/* toast notifications — stacked at bottom-center, auto-dismiss */
#toast-stack {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 1000;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; /* clicks pass through except on the toasts themselves */
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 9px 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 24px var(--shadow);
  color: var(--text); font-size: 13.5px; line-height: 1.35;
  cursor: pointer;
  animation: toast-in 0.18s ease;
}
.toast.out { animation: toast-out 0.22s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }
.toast-icon { display: inline-flex; flex-shrink: 0; }
.toast-info .toast-icon { color: var(--accent); }
.toast-success .toast-icon { color: var(--ok); }
.toast-warning .toast-icon { color: #d9a13b; }
.toast-error .toast-icon { color: var(--err); }
.toast-msg { word-break: break-word; }
.toast-close {
  border: none; background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px; border-radius: 4px; flex-shrink: 0;
}
.toast-close:hover { color: var(--text); background: var(--hover); }
