/* ============================================================================
   Design tokens — every color in the app derives from these. Two themes:
   dark (default) and light, switched via <html data-theme="light|dark">
   (set by the boot script in index.html + the ☀/🌙 header toggle, persisted
   in localStorage). Component rules must ONLY use tokens / color-mix() of
   tokens, never raw hex, or the light theme breaks.
   Accent is the lime "Focus+" green: --accent is the TEXT-SAFE step (readable
   on the theme surface — olive in light, lime in dark); --accent-fill is the
   CTA fill (always lime) and pairs with --accent-fg (near-black) text.
   ========================================================================== */
:root {
  color-scheme: dark;
  --bg: #141416;            /* app background */
  --bg2: #1C1C21;           /* surface: header, cards, sidebar, modals */
  --bg3: #26262C;           /* raised controls / inputs */
  --border: #2E2E36;
  --fg: #EDEDEA;
  --fg-muted: #94949D;
  --accent: #C9E265;        /* lime — text-safe on the dark surface */
  --accent-hi: #DBEF8A;
  --accent-fill: #C9E265;   /* CTA / primary button fill */
  --accent-fg: #191E06;     /* text on --accent-fill */
  --accent-soft: rgba(201, 226, 101, 0.13);
  --success: #6BC48A;
  --danger: #E86A6A;
  --warn: #D9B75B;
  --info: #7EB3E8;
  --violet: #B09CFF;
  --chart-1: #3987e5;       /* dataviz series 1 (blue, dark-surface step) */
  --chart-2: #199e70;       /* dataviz series 2 (aqua, dark-surface step) */
  --term-bg: #131318;       /* terminal-style logs (dark in both themes) */
  --term-fg: #C9C9CF;
  --scroll-thumb: #45454F;
  --shadow-1: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.16);
  --shadow-2: 0 24px 64px rgba(0,0,0,.55);
  --r-s: 8px; --r-m: 12px; --r-l: 16px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F1F0EA;            /* warm off-white */
  --bg2: #FFFFFF;
  --bg3: #F6F5F0;
  --border: #E5E4DB;
  --fg: #1C1C19;
  --fg-muted: #82827A;
  --accent: #5D7909;        /* olive — text-safe on white */
  --accent-hi: #4A6107;
  --accent-fill: #D3EC5C;
  --accent-fg: #1A2005;
  --accent-soft: rgba(148, 190, 15, 0.15);
  --success: #2F9958;
  --danger: #D64C4C;
  --warn: #A97918;
  --info: #3878B8;
  --violet: #7C63D8;
  --chart-1: #2a78d6;
  --chart-2: #1baf7a;
  --scroll-thumb: #C9C8BE;
  --shadow-1: 0 1px 2px rgba(35,35,20,.05), 0 8px 24px rgba(35,35,20,.07);
  --shadow-2: 0 24px 64px rgba(35,35,20,.28);
}

* { box-sizing: border-box; }
/* --- Themed scrollbars (whole platform) --- thin, rounded, floating thumb that
   sits in-theme at rest and lifts to the accent on hover. Firefox uses the two-value
   scrollbar-color; WebKit/Chromium uses the ::-webkit-scrollbar pseudo-elements. The
   transparent border + background-clip:padding-box gives the thumb breathing room so it
   reads as a slim pill rather than a full-width bar. */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb); border: 3px solid transparent; background-clip: padding-box;
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); background-clip: padding-box; }
::-webkit-scrollbar-thumb:active { background: var(--accent-hi); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
/* The hidden attribute must always win — class display rules (.chip etc.) otherwise
   override the browser's default [hidden]→display:none and "hidden" elements draw. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: "Segoe UI Variable Text", "Segoe UI", -apple-system, Inter, Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  transition: background 0.15s ease, color 0.15s ease;
}

/* --- Header (compact) --- */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 16px; background: var(--bg2);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-btn { display: none; background: transparent; color: var(--fg); font-size: 20px;
  border: 0; padding: 4px 10px; border-radius: var(--r-s); cursor: pointer; }
.logo { width: 30px; height: 30px; border-radius: 10px;
  background: var(--accent-fill); color: var(--accent-fg); display: flex;
  align-items: center; justify-content: center; font-weight: 800; font-size: 13px;
  letter-spacing: -0.5px; flex-shrink: 0; }
h1 { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: -0.01em; }
.sub { color: var(--fg-muted); font-size: 11px; }
.tabs { display: flex; gap: 2px; margin-left: auto;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.tab { background: transparent; border: 0; color: var(--fg-muted);
  padding: 5px 14px; border-radius: 999px; cursor: pointer; font-size: 13px; font-family: inherit;
  transition: color 0.12s, background 0.12s; }
.tab:hover { color: var(--fg); }
.tab.active { background: var(--bg2); color: var(--fg); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.theme-btn { background: transparent; border: 1px solid var(--border); color: var(--fg-muted);
  width: 30px; height: 30px; padding: 0; border-radius: 999px; cursor: pointer; font-size: 14px;
  line-height: 1; flex-shrink: 0; }
.theme-btn:hover { color: var(--fg); border-color: var(--fg-muted); }
.notify-btn { background: transparent; border: 1px solid var(--border); color: var(--fg-muted);
  width: 30px; height: 30px; padding: 0; border-radius: 999px; cursor: pointer; font-size: 14px;
  line-height: 1; flex-shrink: 0; }
.notify-btn:hover { color: var(--fg); border-color: var(--fg-muted); }
.notify-btn.active { color: var(--success); border-color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent); }
.notify-btn.blocked { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.cli-status { color: var(--fg-muted); font-size: 11px; }
.cli-status.ok { color: var(--success); }
.cli-status.err { color: var(--danger); }
.push-status { font-size: 12px; color: var(--fg-muted); align-self: center; white-space: nowrap; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.push-status.ok { color: var(--success); }
.push-status.err { color: var(--danger); }
.chip.preview-live { color: var(--success); border-color: var(--success); text-decoration: none; }
.chip.preview-live:hover { background: color-mix(in srgb, var(--success) 12%, transparent); }
.chip.preview-stop { color: var(--danger); border-color: var(--danger);
  cursor: pointer; font-family: inherit; line-height: normal; appearance: none; -webkit-appearance: none; }
.chip.preview-stop:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.chip.preview-stop:disabled { opacity: 0.6; cursor: default; }
.chip.preview-stale { color: var(--fg-muted); border-color: var(--border); opacity: 0.85; }
.chip.agentoff { color: var(--warn); border-color: var(--warn); }
.pt-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.pt-row .pt-name { width: 150px; }
.pt-row .pt-cmd { flex: 1; min-width: 0; }
.pt-row .pt-web { white-space: nowrap; font-size: 12px; margin: 0; }
.pp-row { border: 1px solid var(--border); border-radius: var(--r-s); padding: 8px; margin-bottom: 8px; }
.pp-row > * { margin-bottom: 6px; }
.pp-row > :last-child { margin-bottom: 0; }
.pp-line { display: flex; gap: 6px; align-items: center; }
.pp-row .pp-name { flex: 1; min-width: 0; font-weight: 600; }
.pp-row .pp-del { flex: 0 0 auto; }
.pv-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.pv-row:last-child { border-bottom: 0; }
.pv-row .pv-name { font-size: 13px; font-weight: 600; min-width: 140px; }
.pv-addrow select { max-width: 280px; font-size: 12px; padding: 4px 8px; }
.main-pv-sel { max-width: 190px; font-size: 12px; padding: 4px 8px; align-self: center; }
.chat-header .actions #mainPvLink { align-self: center; max-width: 220px; }
.card-pv-row { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.card-pv-row select { flex: 1; min-width: 0; font-size: 11px; padding: 3px 6px; }
.card-pv-row button { white-space: nowrap; }
.card-pv-row button.accent { color: var(--accent); border-color: var(--accent); }
/* ⏳ (starting) / ⓘ (running) reopen button for the live preview console. */
.card-pv-row button.pv-info { padding: 3px 7px; }
.card-pv-row button.pv-info.live { color: var(--accent); border-color: var(--accent); }

/* Live preview console */
.pv-console-modal { width: min(920px, 94vw); }
.pv-console-head-right { display: flex; align-items: center; gap: 8px; }
.pv-console-log { max-height: 60vh; min-height: 200px; line-height: 1.45; }
.pv-console-log .pv-exit { color: var(--danger); font-style: italic; }
.pv-info-btn { padding: 2px 7px; margin-left: 4px; }
.agent-row { cursor: pointer; }
.agent-row:hover td { background: var(--bg3); }
.agent-chevron { color: var(--fg-muted); font-size: 10px; display: inline-block; width: 12px; }
.agent-graph-row td { background: var(--bg2); padding: 10px 14px; border-bottom: 1px solid var(--border); }
/* "Currently working on" dropdown (expanded agent row, above the usage graph) */
.agent-work { margin-bottom: 12px; }
.aw-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-muted); margin: 0 0 6px 2px; }
.aw-job { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--r-s); background: var(--bg3); margin-bottom: 4px; }
.aw-kind { flex: none; font-size: 10px; text-transform: uppercase; letter-spacing: .03em; padding: 2px 7px; border-radius: 10px; background: var(--accent-fill); color: var(--accent-fg); font-weight: 700; }
.aw-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aw-proj { flex: none; color: var(--fg-muted); font-size: 12px; }
.aw-elapsed { flex: none; color: var(--fg-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

main { flex: 1; overflow: hidden; }
.tab-panel { display: none; height: 100%; }
.tab-panel.active { display: flex; }

/* --- Sidebar --- */
.sidebar {
  width: 230px; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-head { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px 8px; color: var(--fg-muted);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.sidebar ul { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.sidebar li {
  padding: 8px 10px; border-radius: 10px; margin-bottom: 3px;
  cursor: pointer; border: 1px solid transparent;
}
.sidebar li:hover { background: var(--bg3); }
.sidebar li.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.sidebar li .s-name { font-weight: 600; font-size: 13px; }
.sidebar li .s-folder { font-size: 10px; color: var(--fg-muted); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar li .s-model { font-size: 10px; color: var(--accent); margin-top: 1px; }

/* Conversations nested under each session */
.sidebar .convos { list-style: none; margin: 2px 0 6px; padding: 0 0 0 14px; }
.sidebar .convos li {
  padding: 5px 8px; font-size: 12px; border-radius: 8px;
  display: flex; align-items: center; gap: 6px; margin-bottom: 1px;
  border: 1px solid transparent;
}
.sidebar .convos li .c-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-muted); flex-shrink: 0; }
.sidebar .convos li.active .c-dot { background: var(--accent); }
.sidebar .convos li.active { background: var(--bg3); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.sidebar .convos li .c-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
.sidebar .convos li.archived .c-name { color: var(--fg-muted); font-style: italic; }
.sidebar .convos li .c-menu {
  background: transparent; border: 0; color: var(--fg-muted);
  padding: 2px 4px; border-radius: 3px; cursor: pointer; font-size: 13px;
  opacity: 0; transition: opacity 0.1s;
}
.sidebar .convos li:hover .c-menu { opacity: 1; }
.sidebar .convos li .c-menu:hover { background: var(--border); color: var(--fg); }
.sidebar .convo-add {
  font-size: 11px; color: var(--fg-muted); padding: 3px 8px 3px 22px;
  cursor: pointer; margin-bottom: 6px;
}
.sidebar .convo-add:hover { color: var(--accent); }
.sidebar .archived-toggle {
  font-size: 10px; color: var(--fg-muted); padding: 2px 8px 2px 22px;
  cursor: pointer; text-transform: uppercase; letter-spacing: 0.5px;
}
.sidebar .archived-toggle:hover { color: var(--fg); }

/* Preset pill bar above composer */
.preset-pick-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.preset-pick-bar[hidden] { display: none; }
.preset-pick-bar .pill {
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); color: var(--fg);
  padding: 3px 10px; border-radius: 999px; font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
}
.preset-pick-bar .pill .rm {
  background: transparent; border: 0; color: var(--fg-muted); cursor: pointer; padding: 0;
  font-size: 14px; line-height: 1;
}

/* Text-file chip in attach bar */
.attach-bar .file-chip {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 4px 8px; font-size: 12px; display: flex; align-items: center; gap: 6px; color: var(--fg);
}
.attach-bar .file-chip .doc-ico { color: var(--accent); }
.attach-bar .file-chip .rm {
  background: transparent; border: 0; color: var(--fg-muted); cursor: pointer; padding: 0; font-size: 14px;
}

/* Presets tab */
.presets-wrap { flex: 1; display: flex; overflow: hidden; }
.presets-sidebar { width: 240px; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; }
.presets-sidebar ul { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.presets-sidebar li {
  padding: 8px 10px; border-radius: 10px; margin-bottom: 3px;
  cursor: pointer; font-size: 13px; border: 1px solid transparent;
}
.presets-sidebar li:hover { background: var(--bg3); }
.presets-sidebar li.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.presets-editor { flex: 1; padding: 18px 24px; overflow-y: auto; display: flex; flex-direction: column; }
.presets-editor textarea {
  width: 100%; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 10px 12px; font-family: Consolas, monospace; font-size: 13px;
  resize: vertical; min-height: 300px;
}
.presets-editor textarea:focus { outline: none; border-color: var(--accent); }
.presets-editor textarea.drag-over { border-color: var(--accent); background: var(--accent-soft); }
#tab-presets { display: none; }
#tab-presets.active { display: flex; }

/* Planner tab */
.planner-wrap { flex: 1; display: flex; min-width: 0; overflow: hidden; }
.planner-sidebar { width: 260px; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; }
.planner-sidebar ul { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.planner-sidebar li { padding: 8px 10px; border-radius: 10px; margin-bottom: 3px;
  cursor: pointer; border: 1px solid transparent; }
.planner-sidebar li:hover { background: var(--bg3); }
.planner-sidebar li.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.planner-main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.planner-editor { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.planner-editor[hidden] { display: none; }
.planner-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.planner-title-block { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.planner-title { width: 100%; background: transparent; color: var(--fg); border: 0; padding: 0;
  font-size: 18px; font-weight: 700; font-family: inherit; }
.planner-title:focus { outline: none; }
.planner-link-row { display: flex; align-items: center; gap: 8px; }
.planner-link-row select { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 6px 9px; font-size: 13px; min-width: 220px; }
.planner-link-row select:focus { outline: none; border-color: var(--accent); }
.planner-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(320px, 0.85fr) minmax(360px, 1.15fr);
  gap: 12px; padding: 12px 16px; overflow: hidden; }
.planner-spec, .planner-chat { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.planner-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin-bottom: 8px; }
.planner-section-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-muted); }
#planSpec, #planComposer { width: 100%; background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 10px 12px; font-size: 13px; font-family: inherit; resize: none; }
#planSpec { flex: 1; min-height: 0; line-height: 1.5; }
#planComposer { min-height: 92px; line-height: 1.45; }
#planSpec:focus, #planComposer:focus { outline: none; border-color: var(--accent); }
.planner-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 10px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: var(--r-s); display: flex; flex-direction: column; gap: 10px; }
.planner-msg { max-width: 92%; padding: 9px 11px; border-radius: var(--r-s); border: 1px solid var(--border);
  background: var(--bg3); color: var(--fg); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.planner-msg.user { align-self: flex-end; background: var(--accent-fill); color: var(--accent-fg); border-color: transparent; }
.planner-msg.claude { align-self: flex-start; background: var(--bg3); }
.planner-msg.system { align-self: center; max-width: 100%; color: var(--fg-muted); background: transparent; border-color: var(--border); }
.pm-author { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; opacity: .78; }
.planner-composer { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; flex-shrink: 0; }

/* --- Chat area --- */
.chat-area { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; min-width: 0; }
.empty { color: var(--fg-muted); text-align: center; padding: 60px 16px; flex: 1;
  display: flex; align-items: center; justify-content: center; }
.empty[hidden] { display: none; }
.chat-wrap { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.chat-wrap[hidden] { display: none; }

/* Per-project sub-tabs (Chat / Knowledge) inside the project view */
.proj-subtabs {
  display: flex; gap: 4px; padding: 8px 16px; flex-shrink: 0;
  background: var(--bg2); border-bottom: 1px solid var(--border);
}
.proj-subtab {
  background: transparent; border: 1px solid transparent; color: var(--fg-muted);
  padding: 5px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.proj-subtab:hover { color: var(--fg); background: var(--bg3); }
.proj-subtab.active { color: var(--fg); background: var(--bg3); border-color: var(--border);
  box-shadow: inset 0 -2px 0 var(--accent); font-weight: 600; }
.proj-panel { display: none; flex: 1; min-height: 0; overflow: hidden; }
.proj-panel.active { display: flex; flex-direction: column; }
#projKnowledgePanel { padding: 12px 16px; }
#projKnowledgePanel .knowledge-wrap { height: auto; flex: 1; min-height: 0; }

/* Log / Git / History sub-panels (were modals) — fill the project view inline */
#projLogPanel, #projGitPanel, #projHistoryPanel { padding: 12px 16px; gap: 10px; }
.proj-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-shrink: 0;
}
.proj-panel-head h3 { margin: 0; font-size: 15px; }
.proj-panel-head-right { display: flex; align-items: center; gap: 8px; }
#projLogPanel .publog-list { max-height: none; flex: 1; min-height: 0; }
#projGitPanel .git-body { height: auto; flex: 1; min-height: 0; }
#projHistoryPanel .history-list { flex: 1; min-height: 0; }
.config-panel[hidden] { display: none; }
.attach-bar[hidden] { display: none; }

.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg2); flex-shrink: 0;
}
.chat-title { flex: 1; min-width: 0; }
.title-display {
  color: var(--fg); font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.actions { display: flex; gap: 6px; flex-shrink: 0; }

/* --- Messages --- */
.chat-status-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px; background: var(--accent-soft); color: var(--fg);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  font-size: 12px; font-weight: 600;
}
.chat-status-bar[hidden] { display: none; }
.chat-status-bar .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); animation: pulse 1s infinite;
}
.chat-status-bar .phrase { color: var(--accent); font-style: italic; }
.chat-status-bar .timer { color: var(--fg-muted); font-weight: normal; }
.chat-status-bar .queued { margin-left: auto; color: var(--fg-muted); font-weight: normal; font-size: 11px; }

.messages {
  flex: 1; overflow-y: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
  overflow-anchor: auto;         /* browser keeps visible content pinned when we insert above */
  overscroll-behavior: contain;  /* don't bubble scroll to outer page during momentum */
  -webkit-overflow-scrolling: touch;
}
/* Virtualization: spacers reserve vertical space for off-screen (not-yet-rendered) messages
   so the scrollbar represents the true content size and the thumb stays stable. */
.virt-spacer { flex: 0 0 auto; }
.msg {
  max-width: 85%; padding: 10px 14px; border-radius: var(--r-l);
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
  font-size: 14px; line-height: 1.5;
}
.msg.user { align-self: flex-end; background: var(--accent-fill); color: var(--accent-fg);
  border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--bg2);
  border: 1px solid var(--border); border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-1); }
.msg.assistant.working .text::after {
  content: '';
  display: inline-block;
  width: 28px; height: 12px;
  background:
    radial-gradient(circle 3px at 4px 6px, var(--accent) 99%, transparent 100%),
    radial-gradient(circle 3px at 14px 6px, var(--accent) 99%, transparent 100%),
    radial-gradient(circle 3px at 24px 6px, var(--accent) 99%, transparent 100%);
  animation: dot-bounce 1.2s infinite;
  vertical-align: middle;
}
@keyframes dot-bounce {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-2px); }
}
.msg.assistant.working .saying {
  display: block; font-size: 11px; color: var(--accent);
  font-weight: 600; margin-bottom: 4px;
  font-style: italic;
}
.msg.assistant:not(.working) .saying { display: none; }

/* Definitive "done" marker on completed assistant replies */
.msg.assistant.done { border-left: 3px solid var(--success); padding-left: 12px; }
.msg.assistant.done .meta::before {
  content: '✓ done';
  display: inline-flex; align-items: center;
  background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success);
  border: 1px solid var(--success); border-radius: 999px;
  padding: 1px 8px; font-weight: 600; letter-spacing: 0.3px;
  margin-right: 8px;
}
.msg.assistant.error-done { border-left: 3px solid var(--danger); padding-left: 12px; }
.msg.assistant.error-done .meta::before {
  content: '✕ stopped';
  display: inline-flex; align-items: center;
  background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger);
  border: 1px solid var(--danger); border-radius: 999px;
  padding: 1px 8px; font-weight: 600; margin-right: 8px;
}
.msg.tool {
  align-self: flex-start; background: var(--bg3); color: var(--fg-muted);
  font-family: Consolas, "SF Mono", monospace; font-size: 12px; padding: 6px 10px;
  border-radius: var(--r-s); max-width: 100%;
}
.msg.tool .tool-name { color: var(--accent); font-weight: 600; }
.msg.tool details { margin-top: 4px; }
.msg.tool summary { cursor: pointer; color: var(--fg); }
.msg.tool pre { margin: 4px 0 0; white-space: pre-wrap; max-height: 280px; overflow: auto;
  background: var(--bg); padding: 8px; border-radius: 6px; font-size: 11px; }
.msg.error { align-self: center; background: color-mix(in srgb, var(--danger) 12%, var(--bg2));
  border: 1px solid var(--danger); color: var(--danger); font-size: 12px; }
.msg.system { align-self: center; background: transparent; color: var(--fg-muted); font-size: 11px; }
.msg .meta { font-size: 10px; color: color-mix(in srgb, var(--accent-fg) 55%, transparent); margin-top: 4px; }
.msg.assistant .meta { color: var(--fg-muted); }

.msg .img-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg .thinking {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 6px 10px; margin-bottom: 8px; font-size: 12px;
}
.msg .thinking summary {
  cursor: pointer; color: var(--fg-muted); list-style: none;
  display: flex; align-items: center; gap: 6px;
}
.msg .thinking summary::-webkit-details-marker { display: none; }
.msg .thinking summary .brain { color: var(--violet); }
.msg .thinking summary .elapsed { color: var(--accent); font-weight: 600; }
.msg .thinking summary .chev { margin-left: auto; color: var(--fg-muted); transition: transform 0.1s; }
.msg .thinking[open] summary .chev { transform: rotate(90deg); }
.msg .thinking pre {
  margin: 8px 0 0; font-family: inherit; font-size: 12px;
  color: var(--fg-muted); white-space: pre-wrap;
  border-left: 2px solid var(--border); padding-left: 10px;
}
.msg .thinking.live summary .elapsed::after {
  content: ' · thinking…'; color: var(--fg-muted); font-weight: normal;
  animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: 0.5; } }

.msg .img-attachments img {
  max-width: 220px; max-height: 180px; border-radius: var(--r-s);
  border: 1px solid var(--border); object-fit: cover;
}

/* --- Composer --- */
.composer {
  padding: 10px 14px; border-top: 1px solid var(--border); background: var(--bg2);
  flex-shrink: 0;
}
.composer textarea {
  width: 100%; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-m);
  padding: 10px 12px; font-family: inherit; font-size: 14px;
  resize: vertical; min-height: 44px;
}
.composer textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.composer-actions {
  display: flex; align-items: center; margin-top: 6px; gap: 8px;
}
.attach-btn {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 6px 10px; cursor: pointer; font-size: 16px; line-height: 1;
}
.attach-btn:hover { border-color: var(--accent); }
.composer-actions .muted { flex: 1; font-size: 11px; }

.attach-bar {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
  padding: 8px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--r-m);
}
.attach-thumb { position: relative; }
.attach-thumb img {
  width: 60px; height: 60px; object-fit: cover;
  border-radius: var(--r-s); border: 1px solid var(--border);
}
.attach-thumb button {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; padding: 0;
  background: var(--danger); color: white; border-radius: 50%;
  border: 2px solid var(--bg2); font-size: 12px; line-height: 1; cursor: pointer;
}

/* --- Config slide-over --- */
.config-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9;
}
.config-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 460px; max-width: 100%;
  background: var(--bg2); border-left: 1px solid var(--border);
  padding: 18px; overflow-y: auto; overflow-x: hidden;
  box-shadow: var(--shadow-2);
  z-index: 10;
}
.config-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.config-head h2 { margin: 0; font-size: 15px; }

label {
  display: block; color: var(--fg-muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.5px; margin: 12px 0 5px;
}
label.check {
  display: flex; align-items: center; gap: 8px; color: var(--fg);
  text-transform: none; letter-spacing: normal; font-size: 13px; margin: 6px 0;
}
input[type=text], select {
  width: 100%; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 7px 10px; font-size: 13px; font-family: inherit;
}
input[type=text]:focus, select:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
.radios { display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 0; }
.radios label { color: var(--fg); text-transform: none; letter-spacing: normal; font-size: 13px;
  display: flex; align-items: center; gap: 6px; margin: 4px 0; }

.save-row { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.muted { color: var(--fg-muted); font-size: 12px; }

button {
  font-family: inherit; cursor: pointer; font-size: 13px;
  border-radius: 10px; padding: 6px 12px; border: 0;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent-fill); color: var(--accent-fg); font-weight: 700; }
button.primary:hover { background: var(--accent-hi); }
:root[data-theme="light"] button.primary:hover { background: color-mix(in srgb, var(--accent-fill) 82%, var(--accent-fg)); }
button.ghost { background: var(--bg3); color: var(--fg); border: 1px solid var(--border); }
button.ghost:hover { background: var(--border); }
button.ghost.danger { color: var(--danger); }
button.small { padding: 3px 9px; font-size: 12px; }

/* --- Stats / Dashboard --- */
#tab-stats { display: none; }
#tab-stats.active { display: flex; }
.stats-wrap { display: flex; flex-direction: column; gap: 14px; padding: 18px 22px;
  width: 100%; overflow-y: auto; position: relative; }
/* Loading overlay while the dashboard fetches its stats — hidden unless .loading is set */
.stats-loading { display: none; }
.stats-wrap.loading .stats-loading { display: flex; position: absolute; inset: 0; z-index: 5;
  flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  color: var(--fg-muted); font-size: 13px; background: color-mix(in srgb, var(--bg) 78%, transparent); }
.spin.spin-lg { width: 22px; height: 22px; border-width: 3px; }
.stats-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.stats-head h2 { font-size: 18px; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.total-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-l);
  padding: 16px 18px; box-shadow: var(--shadow-1); position: relative; overflow: hidden; }
.total-card h3 { margin: 0 0 8px; font-size: 11px; color: var(--fg-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px; }
.total-card .big { font-size: 26px; font-weight: 750; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; }
.total-card .big .unit { font-size: 13px; font-weight: 500; color: var(--fg-muted); margin-left: 2px; }
.total-card .breakdown { color: var(--fg-muted); font-size: 11px; margin-top: 6px; }
.total-card .delta { display: inline-block; margin-top: 8px; font-size: 11px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 9px; }
.total-card .delta.down { color: var(--danger); background: color-mix(in srgb, var(--danger) 16%, transparent); }

/* Dashboard date-range selector (today / yesterday / week / month / custom / all time) */
.stats-range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.stats-range select { width: auto; padding: 6px 9px; font-size: 12px; }
.stats-custom { display: inline-flex; align-items: center; gap: 6px; }
.stats-custom[hidden] { display: none; }
.stats-custom-sep { color: var(--fg-muted); }
.stats-range input[type=date] { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 5px 8px; font-size: 12px; font-family: inherit; color-scheme: dark; }
:root[data-theme="light"] .stats-range input[type=date] { color-scheme: light; }
.stats-range input[type=date]:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
.stats-table { width: 100%; border-collapse: collapse; background: var(--bg2);
  border: 1px solid var(--border); border-radius: var(--r-m); overflow: hidden; }
.stats-table th, .stats-table td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px;
}
.stats-table th { background: var(--bg3); color: var(--fg-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px; font-size: 10.5px; }
.stats-table tr:last-child td { border-bottom: 0; }
.stats-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table th.num { text-align: right; }

/* Dashboard chart cards + tables live inside .dash-card panels */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dash-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-l);
  padding: 14px 16px; box-shadow: var(--shadow-1); min-width: 0; }
.dash-card h3 { margin: 0 0 4px; font-size: 13px; font-weight: 700; letter-spacing: -0.01em; }
.dash-card .dash-sub { color: var(--fg-muted); font-size: 11px; margin-bottom: 8px; }
.dash-card .stats-table { border: 0; border-top: 1px solid var(--border); border-radius: 0; margin-top: 8px; }
.dash-card .stats-table th { background: transparent; }
.dash-chart { width: 100%; }
.dash-chart svg { display: block; width: 100%; height: auto; }
.dash-chart .bar { transition: opacity 0.1s; }
.dash-chart .bar-hit:hover + .bar, .dash-chart .bar:hover { opacity: 0.75; }
.dash-empty { color: var(--fg-muted); font-size: 12px; padding: 26px 0; text-align: center; }
/* Shared hover tooltip for the dashboard charts */
.viz-tip { position: fixed; z-index: 600; pointer-events: none;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-2); padding: 8px 11px; font-size: 12px; line-height: 1.5;
  max-width: 260px; }
.viz-tip .tip-title { font-weight: 700; margin-bottom: 2px; }
.viz-tip .tip-row { color: var(--fg-muted); display: flex; gap: 12px; justify-content: space-between; }
.viz-tip .tip-row b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .agents-wrap, .settings-wrap, #tab-stats {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .stats-table { min-width: 720px; }
}

/* --- Folder picker modal --- */
.folder-row { display: flex; gap: 6px; }
/* min-width:0 lets flex inputs shrink below their intrinsic (size=20) width — otherwise
   two side-by-side inputs floor at ~180px each and force a horizontal scrollbar. */
.folder-row input[type=text] { flex: 1; min-width: 0; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px; backdrop-filter: blur(2px); }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-l);
  width: 560px; max-width: 100%; max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-2); }
.modal-head { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 15px; }
.browse-toolbar { display: flex; gap: 6px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: var(--bg3); }
.browse-path { flex: 1; background: var(--bg2); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 6px 10px; font-family: Consolas, monospace; font-size: 12px; }
.browse-path:focus { outline: none; border-color: var(--accent); }
.browse-shortcuts { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); }
.browse-shortcuts .chip { background: var(--bg3); border: 1px solid var(--border); color: var(--fg);
  padding: 4px 10px; border-radius: 999px; font-size: 12px; cursor: pointer; }
.browse-shortcuts .chip:hover { border-color: var(--accent); color: var(--accent); }
.sidebar-search-row { padding: 0 12px 8px; }
.sidebar-search-row input { width: 100%; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: 12px; }
.sidebar-search-row input:focus { outline: none; border-color: var(--accent); }
.browse-filter-row { padding: 8px 12px 0; }
.browse-filter-row input { width: 100%; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-s); padding: 6px 10px; font-size: 12px; }
.browse-filter-row input:focus { outline: none; border-color: var(--accent); }
.browse-list { list-style: none; margin: 0; padding: 6px 0;
  overflow-y: auto; flex: 1; min-height: 200px; }
.browse-list li { padding: 7px 14px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
  border-left: 3px solid transparent; }
.browse-list li:hover { background: var(--bg3); }
.browse-list li.selected { background: var(--accent-soft); border-left-color: var(--accent); }
.browse-list li .folder-ico { color: var(--accent); }
.browse-list li.empty { color: var(--fg-muted); font-style: italic; cursor: default; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px;
  padding: 10px 16px; border-top: 1px solid var(--border); }
.modal-foot .muted { margin-right: auto; }

/* Convo dropdown menu */
.popover {
  position: fixed; z-index: 500;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-m);
  box-shadow: var(--shadow-2);
  min-width: 180px; padding: 4px;
}
.popover[hidden] { display: none; }
.popover button {
  display: block; width: 100%; text-align: left; background: transparent;
  color: var(--fg); padding: 8px 12px; border-radius: 8px;
  font-size: 13px;
}
.popover button:hover { background: var(--bg3); }
.popover button.danger { color: var(--danger); }
.popover .divider { height: 1px; background: var(--border); margin: 4px 0; }
.popover input[type=text] {
  width: 100%; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; font-size: 13px; font-family: inherit; margin-bottom: 4px;
}

/* --- Preset picker list --- */
.preset-pick-list {
  list-style: none; margin: 0; padding: 6px 0;
  overflow-y: auto; flex: 1; min-height: 240px;
}
.preset-pick-list li {
  padding: 8px 16px; cursor: pointer; display: flex; gap: 10px; align-items: center;
  border-bottom: 1px solid var(--border);
}
.preset-pick-list li:hover { background: var(--bg3); }
.preset-pick-list li:last-child { border-bottom: 0; }
.preset-pick-list li.selected { background: var(--accent-soft); }
.preset-pick-list li input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; flex-shrink: 0; }
.preset-pick-list .p-name { flex: 1; font-size: 13px; }
.preset-pick-list .p-preview {
  font-size: 11px; color: var(--fg-muted);
  max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preset-pick-list li.empty { color: var(--fg-muted); font-style: italic; cursor: default;
  padding: 24px; justify-content: center; }

/* --- History list --- */
.history-list { list-style: none; margin: 0; padding: 6px 0; overflow-y: auto;
  flex: 1; min-height: 240px; }
.history-list li {
  padding: 10px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border); display: flex; gap: 12px;
  align-items: flex-start;
}
.history-list li:hover { background: var(--bg3); }
.history-list li:last-child { border-bottom: 0; }
.history-list li.active { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: 13px; }
.history-list .h-main { flex: 1; min-width: 0; }
.history-list .h-preview {
  font-size: 13px; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.history-list .h-sub { font-size: 11px; color: var(--fg-muted); margin-top: 4px; }
.history-list .h-empty { padding: 30px; text-align: center; color: var(--fg-muted); cursor: default; }
.history-list .h-actions { flex-shrink: 0; }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--bg2); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-m); padding: 10px 16px; font-size: 13px;
  box-shadow: var(--shadow-2); z-index: 200; max-width: 80vw;
}
.toast[hidden] { display: none; }
.toast.ok     { border-color: var(--success); }
.toast.err    { border-color: var(--danger); }

/* --- Mobile --- */
.sidebar-close { display: none; }

@media (max-width: 760px) {
  .menu-btn { display: block; }
  .sidebar-close { display: inline-block; }
  html, body { height: 100dvh; }
  body { overflow: hidden; overscroll-behavior: none; }
  .tabs .tab { padding: 6px 10px; }
  header { gap: 8px; padding: 6px 10px; flex-wrap: wrap; }
  .brand .sub { display: none; }
  .cli-status { display: none; }
  h1 { font-size: 13px; }
  .brand { flex: 1 1 auto; }
  .tabs {
    order: 2; width: 100%; margin-left: 0;
    overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }

  .sidebar {
    position: absolute; top: 0; left: 0; bottom: 0; z-index: 20; width: 260px;
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: var(--shadow-2);
  }
  .sidebar.open { transform: translateX(0); }

  .config-panel { width: 100%; }
  .chat-header {
    flex-direction: column; align-items: stretch;
    padding: 6px 10px; gap: 4px;
  }
  .chat-title {
    display: flex; align-items: baseline; gap: 8px;
    overflow: hidden;
  }
  .chat-title .title-display {
    flex-shrink: 0; font-size: 14px;
  }
  .chat-title .sub {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 11px;
  }
  .actions {
    overflow-x: auto; flex-wrap: nowrap;
    margin: 0 -10px; padding: 0 10px 2px;
    scrollbar-width: none;
  }
  .actions::-webkit-scrollbar { display: none; }
  .actions button { padding: 6px 10px; font-size: 12px; flex-shrink: 0; min-height: 32px; }
  .composer-actions { flex-wrap: wrap; }
  .composer-actions .muted { flex-basis: 100%; order: -1; margin: 0 0 2px; }
  .messages { padding: 10px; gap: 8px; }
  .msg { max-width: 95%; }
  .composer { padding: 8px 10px; }
  .composer textarea { font-size: 16px; }    /* avoid iOS zoom-on-focus */
  .composer-actions button,
  .attach-btn { min-height: 40px; }
  .composer-actions { gap: 6px; }

  .totals { grid-template-columns: 1fr 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .toast {
    left: 10px; right: 10px; bottom: max(12px, env(safe-area-inset-bottom));
    transform: none; max-width: none;
  }
}

/* ===================== WORK BOARD ===================== */
#tab-board { flex-direction: column; padding: 14px 16px; overflow: hidden; }
.board-empty { color: var(--fg-muted); padding: 40px; text-align: center; margin: auto; }
.board-wrap { display: flex; flex-direction: column; height: 100%; width: 100%; gap: 12px; }
.board-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.board-head h2 { margin: 0; font-size: 17px; }
.board-head .sub { font-size: 12px; color: var(--fg-muted); margin-top: 2px; }
.board-actions { display: flex; align-items: center; gap: 8px; }
.worker-badge { font-size: 11px; color: var(--success); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px; background: var(--bg2); white-space: nowrap; }

.board-cols { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
  flex: 1; overflow: hidden; }
.board-col { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-l);
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-1); }
.col-head { padding: 11px 13px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--fg-muted); border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; }
.col-count { background: var(--bg3); color: var(--fg); border-radius: 999px; padding: 1px 8px; font-size: 11px; }
.col-cards { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.col-empty { color: var(--fg-muted); font-size: 12px; text-align: center; padding: 16px 6px; opacity: 0.6; }

.card { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--r-m);
  padding: 11px; cursor: pointer; transition: border-color 0.12s, box-shadow 0.12s, transform 0.08s; }
.card:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: var(--shadow-1); transform: translateY(-1px); }
.card.status-working { border-color: color-mix(in srgb, var(--accent) 65%, transparent); }
.card.status-failed { border-color: var(--danger); }
/* flex-wrap: a done card's top line (badge + result chip + time/token chips) can be wider than
   the column — without wrapping the chips overflow the card and overlap the content below. */
.card-top { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-bottom: 6px; }
/* Completed-card top line: result badge centred, time/tokens floated right of the "Done" badge.
   Two auto margins split the free space evenly, so the result sits centred between them. */
.card-top-result { margin-left: auto; display: flex; align-items: center; }
.card-top-meta { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.card-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.card-body-prev { font-size: 12px; color: var(--fg-muted); margin-top: 5px; line-height: 1.4; }
.card-imgs { font-size: 11px; color: var(--fg-muted); margin-top: 5px; }
.card-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.card-comment { font-size: 11px; color: var(--fg-muted); margin-top: 7px;
  border-left: 2px solid var(--border); padding-left: 7px; line-height: 1.4; }
.card-btns { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.card-btns button.accent { color: var(--accent); border-color: var(--accent); }

.badge { font-size: 10px; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.04em; }
.badge.inbox { background: var(--bg3); border: 1px solid var(--border); color: var(--fg-muted); }
.badge.hold { background: color-mix(in srgb, var(--violet) 14%, transparent); color: var(--violet); }
.badge.working { background: var(--accent-soft); color: var(--accent); }
.badge.done { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.badge.needs_info { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.badge.blocked { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.badge.failed { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

.chip { font-size: 10px; padding: 2px 8px; border-radius: 999px; background: var(--bg2);
  border: 1px solid var(--border); color: var(--fg-muted); white-space: nowrap;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; display: inline-block; }
.chip.model { color: var(--accent); }
.chip.branch { color: var(--fg-muted); font-family: monospace; }
.chip.dep.met { color: var(--success); }
.chip.dep.unmet { color: var(--warn); }

.spin { width: 11px; height: 11px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.card-timer { font-size: 10px; font-weight: 600; color: var(--accent);
  font-variant-numeric: tabular-nums; margin-left: auto; }

/* card modals */
.card-modal { width: 560px; max-width: 94vw; max-height: 90vh; overflow-y: auto; }
.card-form { display: flex; flex-direction: column; padding: 4px 2px; }
.card-form label { font-size: 12px; color: var(--fg-muted); margin: 10px 0 4px; }
.card-form input[type=text], .card-form textarea, .card-form select {
  background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 8px 10px; font-size: 13px; font-family: inherit; }
.card-form textarea:focus, .card-form input:focus, .card-form select:focus { outline: none; border-color: var(--accent); }
.card-form-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.dep-search { width: 100%; box-sizing: border-box; margin-top: 6px; font-size: 12px; padding: 4px 8px;
  border: 1px solid var(--border); border-radius: var(--r-s); background: var(--bg3); color: var(--fg); }
.card-deps { display: flex; flex-direction: column; gap: 1px; max-height: 200px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--r-s); padding: 4px; background: var(--bg3); }
.dep-check { font-size: 12px; color: var(--fg); display: flex; align-items: center; gap: 6px;
  margin: 0; padding: 2px 4px; border-radius: 4px; }
.dep-check:hover { background: var(--bg2); }
.attach-chip { font-size: 11px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 3px 8px; margin: 3px 4px 0 0; display: inline-flex; align-items: center; gap: 6px; }
.attach-chip button { background: transparent; border: 0; color: var(--fg-muted); cursor: pointer; }

.card-detail { padding: 4px 2px; }
.dc-meta { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.dc-section { margin-bottom: 14px; }
.dc-section h4 { margin: 0 0 6px; font-size: 12px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.dc-taskbody { font-size: 13px; white-space: pre-wrap; line-height: 1.5; background: var(--bg3);
  border: 1px solid var(--border); border-radius: var(--r-s); padding: 10px; }
.dc-imgs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.dc-imgs img { max-width: 160px; max-height: 120px; border-radius: var(--r-s); border: 1px solid var(--border); }
.dc-comment { font-size: 13px; margin-bottom: 8px; border-left: 2px solid var(--border); padding-left: 10px; line-height: 1.5; white-space: pre-wrap; }
/* Sequential sub-tasks: modal editor rows + tile progress + detail checklist */
/* Card engine/effort overrides */
.card-effort { display: flex; align-items: center; gap: 12px; margin: 6px 0; flex-wrap: wrap; }
.card-effort select { background: var(--bg3); color: var(--fg); border: 1px solid var(--border); border-radius: var(--r-s); padding: 6px 8px; font-size: 13px; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
#cardModelRow { margin: 6px 0; }
#cardModelRow select { width: 100%; }
.chip.engine { background: color-mix(in srgb, var(--violet) 14%, transparent); color: var(--violet); border-color: color-mix(in srgb, var(--violet) 35%, transparent); }
.chip.engine.codex { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
.chip.fast { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.chip.reason { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); border-color: color-mix(in srgb, var(--info) 32%, transparent); }

/* Settings — model registry editor */
.settings-wrap { display: flex; flex-direction: column; gap: 14px; padding: 14px 16px; width: 100%; overflow-y: auto; }
.documents-wrap { display: flex; flex-direction: column; gap: 14px; padding: 14px 16px; width: 100%; overflow-y: auto; }
.doc-projects { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.doc-proj-check { display: inline-flex; align-items: center; gap: 4px; font-weight: 400; }
.doc-proj-check input { width: auto; margin: 0; }
.dc-doc-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.settings-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-l);
  padding: 18px 20px; box-shadow: var(--shadow-1); }

/* Anthropic key usage dropdown (each duplicate check: reasoning + result) */
.usage-drop { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.usage-drop > summary { cursor: pointer; font-size: 13px; font-weight: 600; list-style: none; user-select: none; }
.usage-drop > summary::-webkit-details-marker { display: none; }
.usage-drop > summary::before { content: '▸'; display: inline-block; margin-right: 6px; color: var(--fg-muted); transition: transform .12s; }
.usage-drop[open] > summary::before { transform: rotate(90deg); }
.usage-drop-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0 6px; flex-wrap: wrap; }
.usage-drop-actions { display: flex; gap: 6px; }
.uu-row { border: 1px solid var(--border); border-radius: var(--r-s); padding: 8px 10px; margin-top: 8px; background: var(--bg); }
.uu-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.uu-title { font-weight: 600; font-size: 13px; flex: 1; min-width: 0; }
.uu-when { color: var(--fg-muted); font-size: 11px; white-space: nowrap; }
.uu-badge { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.uu-badge.dup { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.uu-badge.uniq { color: var(--success); border-color: color-mix(in srgb, var(--success) 45%, transparent); background: color-mix(in srgb, var(--success) 12%, transparent); }
.uu-badge.err { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.uu-match { font-size: 12px; color: var(--fg-muted); margin-top: 4px; }
.uu-reason { font-size: 13px; margin-top: 4px; }
.uu-foot { font-size: 11px; margin-top: 5px; }
.uu-tok { white-space: nowrap; }
.models-cols { display: flex; gap: 32px; flex-wrap: wrap; }
.model-discover-status { margin-bottom: 12px; font-size: 12px; }
.models-engine { flex: 1; min-width: 320px; }
.models-engine h3 { margin: 0 0 12px; font-size: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.models-head { display: flex; gap: 8px; font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--fg-muted); margin-bottom: 6px; padding: 0 2px; }
.models-head span:first-child { flex: 0 0 38%; }
.models-head span:last-child { flex: 1; }
.models-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.model-row { display: flex; align-items: center; gap: 8px; }
.model-row .m-id { flex: 0 0 38%; }
.model-row .m-label { flex: 1; }
.model-row input { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 7px 9px; font-size: 13px; font-family: inherit; min-width: 0; }
.model-row input:focus { outline: none; border-color: var(--accent); }
.model-row .m-del { flex: 0 0 auto; padding: 5px 9px; }
.model-guidance-drop { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.model-guidance-drop > summary { cursor: pointer; font-size: 13px; font-weight: 600; user-select: none; }
.model-guidance { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.model-guide-row { display: grid; grid-template-columns: 72px minmax(92px, 140px) minmax(120px, 170px) 1fr;
  align-items: baseline; gap: 8px; padding: 7px 9px; border: 1px solid var(--border);
  border-radius: var(--r-s); background: var(--bg); font-size: 12px; }
.model-guide-row code { color: var(--fg-muted); overflow-wrap: anywhere; }
.model-guide-engine { text-transform: uppercase; font-size: 10px; letter-spacing: .04em;
  color: var(--violet); }
.model-guide-engine.codex { color: var(--success); }
.a-maxjobs-input { width: 58px; background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 4px 6px; font-size: 13px; font-family: inherit; text-align: center; }
.a-maxjobs-input:focus { outline: none; border-color: var(--accent); }

.card-tasks { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.card-task-row { display: flex; align-items: center; gap: 6px; }
.card-task-row .ct-mark { min-width: 22px; text-align: right; font-size: 12px; color: var(--fg-muted); }
.card-task-row.done .ct-mark { color: var(--success); }
.card-task-row input { flex: 1; background: var(--bg3); color: var(--fg); border: 1px solid var(--border); border-radius: var(--r-s); padding: 6px 8px; font-size: 13px; }
.card-task-row.done input { opacity: 0.75; }
#cardAddTaskBtn { align-self: flex-start; margin-bottom: 8px; }
.card-tasks-prog { font-size: 12px; color: var(--fg-muted); margin: 4px 0; }
.dc-tasklist { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.dc-task { padding: 4px 8px; border-radius: 6px; }
.dc-task.done { color: var(--fg-muted); }
.dc-task.current { background: var(--bg3); border: 1px solid var(--border); }
.dc-comment .dc-author { font-size: 11px; font-weight: 600; color: var(--fg-muted); display: block; margin-bottom: 2px; }
.dc-comment.claude { border-left-color: var(--accent); }
.dc-comment.user { border-left-color: var(--success); }
.dc-log { background: var(--term-bg); border: 1px solid var(--border); border-radius: var(--r-s); padding: 10px;
  font-size: 11px; font-family: monospace; white-space: pre-wrap; max-height: 240px; overflow-y: auto; color: var(--term-fg); }
.dc-answer { border-top: 1px solid var(--border); padding-top: 12px; }
.dc-answer textarea { width: 100%; background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 8px 10px; font-size: 13px; font-family: inherit; }
.dc-answer textarea:focus { outline: none; border-color: var(--accent); }
.dc-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

@media (max-width: 900px) {
  .board-cols { grid-template-columns: 1fr 1fr; overflow-y: auto; }
}

@media (max-width: 760px) {
  #tab-board { padding: 10px; }
  .board-wrap { gap: 10px; min-height: 0; }
  .board-head { align-items: stretch; gap: 8px; }
  .board-head > div:first-child { min-width: 0; }
  .board-actions {
    width: 100%; flex-wrap: wrap; align-items: stretch; gap: 6px;
  }
  .board-search, #boardFilter { flex: 1 1 150px; min-width: 0; width: auto; }
  .worker-badge { flex: 1 1 100%; text-align: center; }
  .board-actions button { flex: 1 1 auto; min-height: 38px; }
  .planner-wrap { flex-direction: column; }
  .planner-sidebar { width: 100%; max-height: 210px; border-right: 0; border-bottom: 1px solid var(--border); }
  .planner-head { align-items: stretch; flex-direction: column; }
  .planner-body { grid-template-columns: 1fr; overflow-y: auto; }
  .planner-spec, .planner-chat { min-height: 420px; }
  .planner-link-row { flex-wrap: wrap; }
  .planner-link-row select { min-width: 0; width: 100%; }
  .board-cols {
    display: flex; gap: 10px; overflow-x: auto; overflow-y: hidden;
    scroll-snap-type: x mandatory; padding-bottom: 6px;
  }
  .board-col {
    flex: 0 0 min(88vw, 380px); scroll-snap-align: start;
    min-height: 0; max-height: 100%;
  }
  .col-cards { max-height: none; }
  .done-controls { padding: 8px; }
  .card { padding: 12px; }
  .card-btns button, .card-pv-row button { min-height: 34px; }
  .modal-backdrop { padding: 8px; align-items: flex-start; overflow-y: auto; }
  .modal, .card-modal, .dc-big {
    width: 100%; max-width: none; max-height: calc(100dvh - 16px);
    border-radius: 8px;
  }
  .modal-head { position: sticky; top: 0; z-index: 4; background: var(--bg2); }
  .repo-picker, .knowledge-body, .git-body {
    flex-direction: column; min-height: 0;
  }
  .repo-orgs, .git-refs { width: 100%; max-height: 180px; border-right: 0; border-bottom: 1px solid var(--border); }
  .git-c-author, .git-c-date { display: none; }
  .models-engine { min-width: 0; flex-basis: 100%; }
  .model-row { align-items: stretch; }
  .model-guide-row { grid-template-columns: 1fr; gap: 3px; }
}

/* memories */
.memories-toolbar { display: flex; align-items: center; gap: 10px; padding: 4px 0 10px; }
.memory-content { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 12px; font-size: 12px; white-space: pre-wrap; max-height: 55vh; overflow-y: auto;
  color: var(--fg); font-family: inherit; line-height: 1.5; }
.modal-foot .danger { color: var(--danger); border-color: var(--danger); }

/* knowledge (per-project sub-tab) */
.knowledge-wrap { display: flex; flex-direction: column; height: 100%; width: 100%; gap: 12px; }
.knowledge-body { display: flex; gap: 12px; flex: 1; overflow: hidden; }
.knowledge-sidebar { width: 280px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--r-m); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; }
.knowledge-sidebar ul { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.knowledge-sidebar li { padding: 8px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; margin-bottom: 4px; }
.knowledge-sidebar li:hover { background: var(--bg3); }
.knowledge-sidebar li.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.knowledge-sidebar li .s-name { font-size: 12px; font-weight: 600; font-family: monospace; }
.knowledge-sidebar li .s-folder { font-size: 10px; color: var(--fg-muted); margin-top: 2px; }
.knowledge-view { flex: 1; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--r-m); overflow: hidden; display: flex; }
.knowledge-view .empty { margin: auto; max-width: 420px; text-align: center; padding: 24px; }
.knowledge-content { flex: 1; margin: 0; padding: 18px 22px; overflow-y: auto;
  font-size: 13px; line-height: 1.6; white-space: pre-wrap; color: var(--fg);
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; }
@media (max-width: 900px) {
  .knowledge-body { flex-direction: column; }
  .knowledge-sidebar { width: 100%; max-height: 200px; }
}

/* image thumbnails in the card attach bar */
.attach-thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 4px;
  border: 1px solid var(--border); vertical-align: middle; }

/* global board: project filter + project chip */
#boardFilter { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 6px 10px; font-size: 12px; }
#boardFilter:focus { outline: none; border-color: var(--accent); }
.chip.project { color: var(--fg); background: var(--bg3); font-weight: 600; }

/* rich details editor (text + inline screenshots) */
.rich-input { min-height: 130px; max-height: 45vh; overflow-y: auto;
  background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 10px 12px; font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; cursor: text; }
.rich-input:focus { outline: none; border-color: var(--accent); }
.rich-input:empty::before { content: attr(data-placeholder); color: var(--fg-muted); pointer-events: none; }
.rich-img { display: block; max-width: 100%; max-height: 220px; margin: 8px 0;
  border-radius: var(--r-s); border: 1px solid var(--border); }
.dc-taskbody .rich-img { max-height: 320px; }

/* keep board header buttons on one line */
.board-actions button { white-space: nowrap; }
.board-head { flex-wrap: wrap; }

/* agents tab */
.agents-wrap { display: flex; flex-direction: column; gap: 14px; padding: 14px 16px; width: 100%; overflow-y: auto; }
.agent-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.agent-dot.on { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent); }
.agent-dot.off { background: var(--fg-muted); }
.maxjobs-input { width: 52px; padding: 3px 6px; font-size: 13px; text-align: center;
  background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 5px; }
.maxjobs-input:focus { border-color: var(--accent); outline: none; }
.enroll-body p { font-size: 13px; }
.enroll-key { background: var(--bg3); border: 1px solid var(--accent); border-radius: var(--r-s);
  padding: 12px; font-family: monospace; font-size: 13px; word-break: break-all; user-select: all; }
#agentsTable .a-actions { display: flex; gap: 4px; flex-wrap: wrap; }
#agentsTable .danger { color: var(--danger); border-color: var(--danger); }

/* PR chip */
.chip.pr { color: var(--success); text-decoration: none; border-color: var(--success); }
.chip.pr:hover { background: color-mix(in srgb, var(--success) 12%, transparent); }

/* DevOps repo picker */
.repo-picker { display: flex; gap: 12px; min-height: 320px; }
.repo-orgs { width: 220px; flex-shrink: 0; border: 1px solid var(--border); border-radius: var(--r-s);
  background: var(--bg3); display: flex; flex-direction: column; overflow: hidden; }
.repo-orgs ul { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.repo-orgs li { padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; margin-bottom: 4px; }
.repo-orgs li:hover { background: var(--bg2); }
.repo-orgs li.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.repo-orgs li .s-name { font-size: 13px; font-weight: 600; }
.repo-orgs li .s-folder { font-size: 10px; color: var(--fg-muted); }
.repo-list-wrap { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
/* Filter + refresh live in their own ROW, so .browse-path's flex:1 stretches it
   horizontally (correct) instead of vertically down the column (the old bug). */
.repo-filter-row { display: flex; gap: 6px; align-items: center; }
#repoList { flex: 1; max-height: 300px; }
#repoList .r-name { font-weight: 600; }

/* generic dialog */
.dlg-modal { width: 420px; max-width: 92vw; }
.dlg-body { padding: 4px 2px 8px; display: flex; flex-direction: column; }
.dlg-msg { font-size: 13px; line-height: 1.5; margin: 4px 0 8px; white-space: pre-wrap; word-break: break-word; }
.dlg-body label { font-size: 12px; color: var(--fg-muted); margin: 6px 0 4px; }
.dlg-body input, .dlg-body select { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 8px 10px; font-size: 13px; }
.dlg-body input:focus, .dlg-body select:focus { outline: none; border-color: var(--accent); }
.dlg-danger { background: var(--danger) !important; color: #fff !important; }

/* publish confirm: the "what this will publish" merge list — made prominent and scannable */
.dlg-extra { margin: 2px 0 8px; }

/* notifications dialog (the 🔔 header icon) */
.notify-dialog { border: 1px solid var(--border); border-radius: var(--r-s);
  background: var(--bg3); padding: 10px 12px; }
.notify-dialog-lead { margin: 0 0 6px; font-size: 12px; color: var(--fg-muted); }
.notify-dialog-list { margin: 0; padding-left: 18px; display: grid; gap: 3px;
  font-size: 13px; line-height: 1.4; }
.notify-dialog-hint { margin: 8px 0 0; font-size: 11px; color: var(--fg-muted); }
.dlg-merges { border: 1px solid var(--border); border-radius: var(--r-s); background: var(--bg3);
  padding: 8px 9px; }
.dlg-merges-head { display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--fg-muted); margin: 0 2px 7px; }
.dlg-merges-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px;
  height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 700; letter-spacing: 0; }
.dlg-merges-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column;
  gap: 5px; max-height: 240px; overflow-y: auto; }
.dlg-merge { display: flex; align-items: baseline; gap: 9px; padding: 7px 9px; border-radius: var(--r-s);
  background: var(--bg2); border-left: 3px solid var(--accent); }
.dlg-merge-title { flex: 1 1 auto; min-width: 0; font-size: 13.5px; font-weight: 600; line-height: 1.35;
  color: var(--fg); word-break: break-word; }
.dlg-merge-branch { flex: 0 1 auto; min-width: 0; max-width: 45%; font-family: Consolas, "SF Mono", monospace;
  font-size: 11px; color: var(--fg-muted); background: var(--bg3); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* card detail run log: room for full history */
.dc-log-tall { max-height: 45vh; min-height: 120px; }

/* bigger card detail + output files */
.dc-big { width: 920px; max-width: 95vw; max-height: 92vh; }
.dc-files { display: flex; flex-direction: column; gap: 3px; max-height: 180px; overflow-y: auto; }
.dc-file { display: flex; align-items: center; gap: 8px; text-align: left;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 6px 10px; color: var(--fg); font-size: 12px; font-family: monospace; cursor: pointer; }
.dc-file:hover:not(:disabled) { border-color: var(--accent); }
.dc-file:disabled { opacity: 0.5; cursor: default; }
.dc-file-badge { color: var(--accent); font-weight: 700; width: 14px; }
#agentsTable .a-usage { white-space: nowrap; }

/* board search + done column controls */
.board-search { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: 12px; width: 190px; }
.board-search:focus { outline: none; border-color: var(--accent); }
.done-controls { padding: 8px 10px 0; display: flex; flex-direction: column; gap: 6px; }
.done-controls select { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 4px 8px; font-size: 11px; }
#doneCustomRange { display: flex; align-items: center; gap: 4px; }
#doneCustomRange input { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 3px 6px; font-size: 11px; flex: 1; min-width: 0; }
.done-pager { display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 8px; border-top: 1px solid var(--border); font-size: 11px; }

/* card whose project has no agent — it can't run */
.chip.noagent { color: var(--warn); border-color: var(--warn); }

/* possible-duplicate flag — card paused in "Needs attention" pending user confirm */
.chip.dupwarn { color: var(--warn); border-color: var(--warn); }
.dc-dupwarn { margin-bottom: 12px; padding: 8px 10px; border-radius: var(--r-s);
  border: 1px solid var(--warn); color: var(--warn);
  background: color-mix(in srgb, var(--warn) 8%, transparent); font-size: 12px; }

/* agent picker inside the folder browser */
#browseAgentSel { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 6px 8px; font-size: 12px; max-width: 180px; }
#browseAgentSel:focus { outline: none; border-color: var(--accent); }

/* per-run collapsible logs + small rich editor (card follow-up) */
.dc-runs { display: flex; flex-direction: column; gap: 6px; }
.dc-run { border: 1px solid var(--border); border-radius: var(--r-s); background: var(--bg3); }
.dc-run summary { cursor: pointer; padding: 8px 12px; font-size: 12px; color: var(--fg-muted);
  user-select: none; }
.dc-run summary:hover { color: var(--fg); }
.dc-run[open] summary { border-bottom: 1px solid var(--border); color: var(--fg); }
.dc-run .dc-log { border: 0; border-radius: 0 0 var(--r-s) var(--r-s); max-height: 40vh; }
.rich-input-small { min-height: 64px; max-height: 30vh; }

/* card modals: title bar stays put while the body scrolls */
.card-modal .modal-head { position: sticky; top: 0; background: var(--bg2); z-index: 3; }

/* usage month picker */
#usageMonthSel { background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 6px 10px; font-size: 12px; }
#usageMonthSel:focus { outline: none; border-color: var(--accent); }

/* working card whose agent is disconnected */
.badge.agentgone { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

/* branch already merged into main */
.chip.mergedchip { color: var(--success); border-color: var(--success); }

/* run finished but made no code changes — waits in review to be marked complete */
.chip.nochangeschip { color: var(--fg-muted); border-color: var(--border); }

/* link between a source card and the merge card resolving it */
.chip.mergelink { color: var(--info); border-color: var(--info); }
.chip.mergelink:hover { background: color-mix(in srgb, var(--info) 12%, transparent); }
.chip.mergelink.warn { color: var(--warn); border-color: var(--warn); }
.chip.mergelink.warn:hover { background: color-mix(in srgb, var(--warn) 12%, transparent); }

/* pending review */
.badge.review { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.card.status-review { border-color: color-mix(in srgb, var(--info) 45%, transparent); }

/* ---- Publish log ---- */
.publog-range { width: auto; max-width: 150px; font-size: 12px; padding: 4px 8px; }
.publog-list { max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 2px; }
.publog-empty { color: var(--fg-muted); font-size: 13px; padding: 20px; text-align: center; }
.publog-item { background: var(--bg2); border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--r-s); padding: 8px 10px; }
.publog-item.publog-ok { border-left-color: var(--success); }
.publog-item.publog-failed { border-left-color: var(--danger); }
.publog-item.publog-running { border-left-color: var(--accent); }
.publog-row { display: flex; align-items: center; gap: 10px; }
.publog-badge { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.publog-badge-ok { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.publog-badge-failed { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.publog-badge-running { background: var(--accent-soft); color: var(--accent); }
.publog-label { font-size: 13px; font-weight: 600; color: var(--fg); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.publog-when { font-size: 11px; color: var(--fg-muted); white-space: nowrap; }
.publog-cmd { font-family: monospace; font-size: 11px; color: var(--fg-muted); margin: 6px 0 0; word-break: break-all; }
.publog-running { font-size: 12px; color: var(--accent); margin-top: 6px; }
.publog-out { background: var(--term-bg); border: 1px solid var(--border); border-radius: var(--r-s); padding: 8px;
  font-size: 11px; font-family: monospace; white-space: pre-wrap; max-height: 220px; overflow-y: auto;
  color: var(--term-fg); margin: 6px 0 0; }
.publog-out-live { border-color: var(--accent); }   /* still streaming */

/* Merges shipped by a publish (and the pending-publish block at the top of the log). */
.publog-merges-head, .publog-merges-none { font-size: 11px; color: var(--fg-muted); margin: 8px 0 3px; }
.publog-merges { display: flex; flex-direction: column; gap: 3px; }
.publog-merge { display: flex; align-items: baseline; gap: 8px; font-size: 12px;
  padding: 3px 8px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; }
.publog-merge .pm-icon { color: var(--accent); flex: none; }
.publog-merge .pm-title { color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.publog-merge .pm-branch { font-family: monospace; font-size: 10px; color: var(--fg-muted); white-space: nowrap; }
.publog-merge .pm-when { font-size: 10px; color: var(--fg-muted); white-space: nowrap; }
.publog-pending { border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); border-radius: var(--r-s); padding: 8px 10px; margin-bottom: 10px;
  background: var(--accent-soft); }
.publog-pending-head { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 6px; }

/* Projects list: a project has merges landed but not yet published. */
.sidebar li .s-merge-badge { display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 8px; padding: 0 5px; vertical-align: middle; }

/* ===== Git graph (🌳 Git — VS-style commit tree) ===== */
.git-modal { width: 1180px; max-width: 96vw; }
.git-body { display: flex; gap: 0; height: 74vh; border: 1px solid var(--border); border-radius: var(--r-m); overflow: hidden; }
.git-refs { width: 240px; flex: none; background: var(--bg2); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 6px 0; }
.git-ref-group { margin-bottom: 6px; }
.git-ref-head { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--fg-muted);
  padding: 8px 12px 4px; position: sticky; top: 0; background: var(--bg2); }
.git-ref-item { display: flex; align-items: center; gap: 6px; padding: 4px 12px; cursor: pointer; font-size: 12px; }
.git-ref-item:hover { background: var(--bg3); }
.git-ref-item.current { color: var(--accent); font-weight: 600; }
.git-ref-item.offscreen { opacity: .5; }
.git-ref-ic { flex: none; color: var(--fg-muted); font-size: 11px; }
.git-ref-item.current .git-ref-ic { color: var(--accent); }
.git-ref-nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.git-ref-cur { flex: none; margin-left: auto; font-size: 9px; font-weight: 700; letter-spacing: .04em;
  background: var(--accent-fill); color: var(--accent-fg); border-radius: 8px; padding: 1px 6px; }

.git-graph-wrap { flex: 1; overflow: auto; background: var(--bg); }
.git-empty { padding: 24px; text-align: center; }
.git-table { min-width: 100%; font-size: 12px; }
.git-row { display: flex; align-items: stretch; border-bottom: 1px solid color-mix(in srgb, var(--fg) 4%, transparent); }
.git-row:hover { background: var(--bg2); }
.git-row.flash { animation: gitflash 1.2s ease-out; }
@keyframes gitflash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
.git-hrow { position: sticky; top: 0; z-index: 2; background: var(--bg3); color: var(--fg-muted);
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
.git-hrow:hover { background: var(--bg3); }
.git-c-graph { flex: none; display: flex; align-items: center; }
.git-svg { display: block; }
.git-c-msg { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 0 12px;
  overflow: hidden; }
.git-subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.git-sha { flex: none; margin-left: auto; font-family: monospace; font-size: 11px; color: var(--fg-muted); }
.git-c-author { flex: none; width: 150px; display: flex; align-items: center; color: var(--fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 10px; }
.git-c-date { flex: none; width: 130px; display: flex; align-items: center; color: var(--fg-muted);
  white-space: nowrap; font-variant-numeric: tabular-nums; }
.git-hrow .git-c-author, .git-hrow .git-c-date, .git-hrow .git-c-msg { color: var(--fg-muted); }
.git-chip { flex: none; font-size: 10px; padding: 1px 7px; border-radius: 10px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--bg3); }
.git-chip.local { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); }
.git-chip.remote { color: var(--fg-muted); }
.git-chip.tag { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.git-chip.head { color: var(--accent-fg); background: var(--accent-fill); border-color: var(--accent-fill); font-weight: 600; }

/* ===== Customer portal + system users (Auth, Users, Customers, Inbox) ===== */
.user-box { display: flex; gap: 8px; align-items: center; }
.tab-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tab-head h2 { margin: 0; }
.inbox-wrap, .customers-wrap, .users-wrap { display: flex; flex-direction: column; width: 100%; padding: 18px; overflow: auto; }

/* Form fields shared by the admin modals + auth pages */
.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.fld > input, .fld > select, .fld > textarea,
.auth-card input, .modal-body input, .modal-body select, .modal-body textarea {
  background: var(--bg2); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font: inherit; }
.fld-label { font-weight: 600; margin: 12px 0 6px; }
.chk { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.chk input { width: auto; }
.checklist { display: flex; flex-direction: column; gap: 2px; max-height: 180px; overflow: auto;
  border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.modal-body { padding: 16px; overflow: auto; max-height: 68vh; }

/* Data tables */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { color: var(--fg-muted); font-weight: 600; font-size: 12px; }
.row-actions { display: flex; gap: 6px; }

.perm-badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); color: var(--fg-muted); background: var(--bg3); }
.perm-badge.admin { color: var(--accent-fg); background: var(--accent-fill); border-color: var(--accent-fill); }

/* Customers */
.customer-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; background: var(--bg2); }
.customer-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.customer-projects { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.cproj-rows { display: flex; flex-direction: column; gap: 6px; }
.cproj-row { display: flex; gap: 6px; align-items: center; }
.cproj-row .cproj-sel { flex: 1; min-width: 0; }
.cproj-row .cproj-friendly { flex: 1; min-width: 0; }

/* Support inbox */
.inbox-split { display: flex; gap: 14px; flex: 1; min-height: 0; }
.inbox-list { width: 320px; flex-shrink: 0; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.inbox-detail { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 16px; min-width: 0; }
.inbox-item { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.inbox-item:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.inbox-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.inbox-item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.inbox-item-title { font-weight: 600; }
.tkt-type { font-size: 12px; font-weight: 600; }
.tkt-type.bug { color: var(--danger); }
.tkt-type.feature { color: var(--violet, var(--info)); }
.tkt-status { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); color: var(--fg-muted); }
.tkt-status.s-new { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); background: color-mix(in srgb, var(--info) 12%, transparent); }
.tkt-status.s-approved, .tkt-status.s-published { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); background: color-mix(in srgb, var(--success) 12%, transparent); }
.tkt-status.s-in_progress, .tkt-status.s-merged { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tkt-status.s-denied { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.tkt-status.s-deferred { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.tkt-status.s-cancelled { color: var(--fg-muted); border-color: var(--border); background: color-mix(in srgb, var(--fg-muted) 10%, transparent); }
.tkt-detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.tkt-summary { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin: 8px 0; white-space: pre-wrap; }
.tkt-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.tkt-conversation { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.tkt-msg { padding: 8px 10px; border-radius: 6px; background: var(--bg2); }
.tkt-msg.assistant { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.tkt-timeline { margin-top: 12px; font-size: 13px; color: var(--fg-muted); }
.tkt-timeline ul { margin: 4px 0 0; padding-left: 18px; }

/* Auth pages (login.html, portal.html) */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-brand h1 { font-size: 18px; margin: 0; }
.auth-card h2 { margin: 0 0 14px; }
.auth-card .fld input, .auth-card > input { width: 100%; box-sizing: border-box; }
.auth-card .primary { width: 100%; margin-top: 8px; }
.auth-err { color: var(--danger); margin-top: 12px; min-height: 18px; font-size: 13px; }

/* Portal app */
/* Fill the viewport exactly and clip: the chat area scrolls internally instead of
   growing the whole page off the bottom of the screen. */
.portal-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.portal-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.portal-header h1 { font-size: 18px; margin: 0; }
.portal-main { display: flex; gap: 18px; padding: 18px; flex: 1; min-height: 0; flex-wrap: wrap; }
.portal-new { flex: 1; min-width: 320px; min-height: 0; display: flex; flex-direction: column; }
.portal-controls { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.portal-type { display: flex; gap: 12px; }
.portal-chat { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; background: var(--bg2); }
.portal-msg { padding: 8px 12px; border-radius: 10px; max-width: 80%; white-space: pre-wrap; }
.portal-msg.bot { background: var(--bg3); align-self: flex-start; }
.portal-msg.user { background: var(--accent-fill); color: var(--accent-fg); align-self: flex-end; }
.portal-attach-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.portal-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 240px; border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 7px; background: var(--bg3); color: var(--fg); font-size: 12px; }
.portal-chip button { border: 0; background: transparent; color: var(--fg-muted); cursor: pointer; padding: 0 2px; }
.portal-compose { display: flex; gap: 8px; margin-top: 10px; flex-shrink: 0; }
.portal-attach-btn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.portal-compose textarea { flex: 1; background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 8px; font: inherit; }
#pSubmit { margin-top: 10px; }
.portal-tickets { width: 300px; flex-shrink: 0; }
.portal-tickets h3 { margin-top: 0; }
.portal-tgroup { margin-bottom: 14px; }
.portal-tgroup-name { font-size: 12px; font-weight: 600; color: var(--fg-muted); text-transform: uppercase;
  letter-spacing: 0.04em; margin: 0 0 6px 2px; }
.portal-ticket { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--bg2);
  cursor: pointer; }
.portal-ticket:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.portal-ticket-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Ticket detail modal (customer read-only view) */
.portal-modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; background: color-mix(in srgb, #000 55%, transparent); overflow: auto; }
.portal-modal-card { position: relative; width: 100%; max-width: 640px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 12px; padding: 22px; }
.portal-modal-close { position: absolute; top: 12px; right: 12px; }
.portal-modal-card .tkt-detail-head h2 { margin: 0; font-size: 18px; }
.portal-ticket-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.portal-ticket-attachments img { max-width: 160px; max-height: 120px; object-fit: contain;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }

/* Chat "thinking" indicator shown while awaiting the bot reply: animated dots +
   cycling status text + a live elapsed timer, so the wait feels responsive. */
.portal-msg.typing { display: flex; gap: 9px; align-items: center; min-width: 190px; }
.typing-dots { display: inline-flex; gap: 5px; align-items: center; flex-shrink: 0; }
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-muted);
  display: inline-block; animation: portal-typing 1.2s infinite ease-in-out both; }
.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }
.typing-text { color: var(--fg-muted); font-size: 13px; }
.typing-time { margin-left: auto; color: var(--fg-muted); font-size: 12px; opacity: 0.8;
  font-variant-numeric: tabular-nums; }
@keyframes portal-typing {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Portal mobile layout */
@media (max-width: 760px) {
  .portal-app { height: 100dvh; }
  .portal-header { padding: 10px 14px; }
  .portal-header h1 { font-size: 16px; }
  /* Stacked layout: the whole column scrolls (header stays put), and the chat gets a
     fixed, comfortable height with its own internal scroll. */
  .portal-main { flex-direction: column; flex-wrap: nowrap; gap: 14px; padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .portal-new { min-width: 0; flex: none; }
  .portal-controls { gap: 10px; }
  .portal-controls .fld, .portal-controls select { width: 100%; }
  .portal-chat { flex: none; height: 50vh; min-height: 220px; }
  .portal-msg { max-width: 90%; }
  .portal-compose { flex-wrap: wrap; }
  .portal-attach-btn { width: 100%; }
  .portal-tickets { width: 100%; }
  /* 16px inputs stop iOS Safari from auto-zooming on focus */
  .portal-compose textarea, #pProject, .auth-card input { font-size: 16px; }
}
