/* minimal dashboard styling */
* { box-sizing: border-box; }

/* Iteration pill — discreet live indicator while the agent loops.
   Slate / dark-blue palette, no green, smaller type. */
.iter-pill {
  display: inline-flex; align-items: center; gap: 7px;
  margin-left: 10px;
  padding: 3px 11px 3px 9px;
  background: linear-gradient(135deg, #1e293b, #334155);
  color: #e2e8f0;
  border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .35);
  vertical-align: middle;
}
.iter-pill[hidden] { display: none; }
.iter-pill-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #93c5fd;
  box-shadow: 0 0 0 0 rgba(147, 197, 253, .8);
  animation: iter-pulse 1.2s ease-out infinite;
}
.iter-pill-label { opacity: .7; text-transform: uppercase; font-size: 9.5px; }
.iter-pill-num {
  display: inline-block;
  min-width: 1.2em; text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.iter-pill-num.bump { animation: iter-bump .35s ease-out; }
@keyframes iter-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(147, 197, 253, .85); }
  70%  { box-shadow: 0 0 0 7px rgba(147, 197, 253, 0); }
  100% { box-shadow: 0 0 0 0 rgba(147, 197, 253, 0); }
}
@keyframes iter-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.45); }
  100% { transform: scale(1); }
}

body {
  font-family: SwissReSanRegu, "Segoe UI", Helvetica, Arial, sans-serif;
  margin: 0; padding: 0; background: #f6f7f9; color: #1f2328;
}
header { background: #0d1117; color: #fff; padding: 16px 28px; }
header h1 { margin: 0; font-size: 18px; font-weight: 600; }
header .header-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
}
header .brand-link {
  color: #fff; text-decoration: none;
  display: inline-flex; align-items: baseline; gap: 10px;
}
header .brand-link:hover { text-decoration: none; opacity: .9; }
header .brand-name { font-size: 18px; font-weight: 600; }
header .brand-subtitle {
  font-size: 12px; font-weight: 400; color: #8b949e;
}
header .docs-nav {
  display: inline-flex; align-items: center; gap: 14px;
  font-size: 12px; color: #8b949e;
}
header .auth-status {
  display: inline-flex; align-items: center; gap: 10px;
  margin-left: auto;
}
header .auth-status-user {
  font-size: 12px; color: #c9d1d9; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
header .auth-status-signout {
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid #30363d;
  background: transparent;
  color: #c9d1d9;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  transition: background .15s ease, border-color .15s ease;
}
header .auth-status-signout:hover {
  background: #21262d; border-color: #8b949e;
}
header .docs-menu { position: relative; }
header .docs-menu > summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #8b949e;
  text-transform: uppercase; letter-spacing: .08em;
  font-size: 10.5px; font-weight: 600;
  user-select: none;
  transition: background .15s, color .15s;
}
header .docs-menu > summary::-webkit-details-marker { display: none; }
header .docs-menu > summary:hover {
  color: #fff; background: rgba(255, 255, 255, .06);
}
header .docs-menu[open] > summary {
  color: #fff; background: rgba(255, 255, 255, .08);
}
header .docs-nav-caret {
  font-size: 10px; transition: transform .15s ease;
  opacity: .8;
}
header .docs-menu[open] .docs-nav-caret { transform: rotate(180deg); }
header .docs-menu-panel {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 200px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  padding: 6px;
  display: flex; flex-direction: column;
  z-index: 50;
}
header .docs-menu-panel a {
  display: block;
  padding: 8px 12px;
  color: #c9d1d9;
  text-decoration: none;
  font-size: 13px;
  border-radius: 6px;
  margin-left: 0;
}
header .docs-menu-panel a:hover {
  background: #1f6feb22; color: #79c0ff;
  text-decoration: none;
}
main { max-width: 1100px; margin: 24px auto; padding: 0 24px; }
h2 { font-size: 20px; margin-top: 32px; }
h3 { font-size: 15px; margin: 18px 0 6px; color: #57606a; text-transform: uppercase; letter-spacing: .04em; }
.card {
  background: #fff; border: 1px solid #d0d7de; border-radius: 8px;
  padding: 16px 20px; margin-bottom: 16px;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid #eaeef2; }
th { background: #f6f8fa; font-weight: 600; }
a { color: #0969da; text-decoration: none; }
a:hover { text-decoration: underline; }
.count { color: #6e7781; font-size: 13px; font-weight: normal; }
code { background: #f6f8fa; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
pre { background: #f6f8fa; padding: 12px; border-radius: 6px; overflow-x: auto; font-size: 12px; }

/* ===========================================================================
   AI / chat view — modern Copilot/Claude/ChatGPT-inspired styling
   ========================================================================= */

/* Design tokens scoped to the AI page so we don't leak into the rest of the
   dashboard. */
.ai-page {
  --c-bg:          #f9fafb;
  --c-surface:     #ffffff;
  --c-surface-2:   #f3f4f6;
  --c-border:      #e5e7eb;
  --c-border-strong: #d1d5db;
  --c-text:        #111827;
  --c-text-muted:  #6b7280;
  --c-text-dim:    #9ca3af;
  --c-accent:      #1e40af;
  --c-accent-hi:   #1d4ed8;
  --c-accent-lo:   #eff6ff;
  --c-success:     #10b981;
  --c-danger:      #ef4444;
  --c-warn:        #f59e0b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 26px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 4px 6px rgba(15, 23, 42, .04), 0 24px 48px rgba(15, 23, 42, .08);

  --font-ui: SwissReSanRegu, "Segoe UI", "SF Pro Text",
             Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Pin the AI page directly to the viewport (below the header) so it does
     not depend on the ancestor <main>'s max-width / padding. This is the
     most robust way to get a full-bleed chat surface regardless of which
     layout the rest of the site uses. */
  position: fixed;
  top: 52px; left: 0; right: 0; bottom: 0;
  overflow: auto;
  margin: 0;
  padding: 24px 24px 16px;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-ui);
  display: flex; flex-direction: column;
  box-sizing: border-box;
  z-index: 1;
}

/* Tab panels fill the remaining vertical space below the sub-tabs so the
   chat shell can use min-height: 100% to anchor the composer at the
   bottom. */
.ai-tab {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  min-height: 0;
}

/* Sub-tabs (Chat / Search strategy) -------------------------------------- */
.ai-subtabs {
  display: flex; gap: 4px;
  margin: 0 auto 18px;
  padding: 4px;
  background: var(--c-surface-2);
  border-radius: 999px;
  width: max-content;
  flex: 0 0 auto;
}
.ai-subtab {
  appearance: none; border: none; background: transparent;
  padding: 7px 18px;
  font: inherit; font-size: 13px; font-weight: 500;
  color: var(--c-text-muted); cursor: pointer;
  border-radius: 999px;
  transition: background .15s, color .15s;
}
.ai-subtab:hover { color: var(--c-text); }
.ai-subtab.is-active {
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-sm);
}

/* Chat shell ------------------------------------------------------------- */
/* The shell is the visible "stage" for the conversation: framed with a
   thin border so it stands out against the page's grayish background, and
   wider than before so rendered markdown has room to breathe. */
.chat-shell {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  width: 100%;
  max-width: 1040px;
  margin: 12px auto 16px;
  padding: 8px 12px 12px;
  min-height: 0;
  box-sizing: border-box;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  position: relative;
}

/* Transcript: flexible region that fills the available vertical space ---- */
.transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  /* Generous horizontal padding so rendered markdown sits well inside the
     framed shell rather than crowding its left/right edges. */
  padding: 12px 24px 24px;
  scroll-behavior: smooth;
  display: flex; flex-direction: column;
  min-height: 240px;
}
.transcript:empty { display: none; }

/* Custom scrollbar */
.transcript::-webkit-scrollbar { width: 10px; }
.transcript::-webkit-scrollbar-thumb {
  background: transparent; border-radius: 10px;
}
.transcript:hover::-webkit-scrollbar-thumb { background: #d1d5db; }
.transcript::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* Empty state with suggestion cards -------------------------------------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  padding: 32px 16px 16px;
  margin: auto;
  width: 100%;
  max-width: 640px;
}
.empty-state-mark {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-hi));
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(30, 64, 175, .28);
}
.empty-state-title {
  font-size: 24px; font-weight: 600; letter-spacing: -.01em;
  margin: 0 0 6px;
}
.empty-state-sub {
  color: var(--c-text-muted); font-size: 14px;
  margin: 0 0 28px;
  max-width: 480px;
}
.empty-state-prompts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  width: 100%;
}
.prompt-card {
  appearance: none;
  text-align: left;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font: inherit;
  cursor: pointer;
  color: var(--c-text);
  display: flex; flex-direction: column; gap: 4px;
  transition: border-color .15s, transform .15s, box-shadow .15s, background .15s;
}
.prompt-card:hover {
  border-color: var(--c-accent);
  background: var(--c-accent-lo);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.prompt-card-title {
  font-size: 12px; font-weight: 600;
  color: var(--c-accent);
  text-transform: uppercase; letter-spacing: .04em;
}
.prompt-card-body {
  font-size: 13.5px; color: var(--c-text);
  line-height: 1.4;
}
.prompt-card-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 16px;
  font-size: 13px;
  color: var(--c-text-mute);
  border: 1px dashed var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-surface);
}

/* Messages --------------------------------------------------------------- */
.msg {
  display: flex; gap: 14px;
  margin: 18px 0;
  animation: msg-in .25s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  display: none;
}

.msg-body {
  flex: 1 1 auto; min-width: 0;
}
.msg-meta {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px;
}
.msg-role {
  font-size: 12px; font-weight: 600; color: var(--c-text);
}
.msg-content {
  font-size: 13.5px; line-height: 1.55;
  color: var(--c-text);
  word-wrap: break-word; overflow-wrap: anywhere;
}
/* Override github-markdown-css which would otherwise force 16px on
   anything tagged `.markdown-body`. */
.msg-content.markdown-body { font-size: 13.5px; line-height: 1.55; }
.msg-content.markdown-body h1 { font-size: 1.5em; }
.msg-content.markdown-body h2 { font-size: 1.3em; }
.msg-content.markdown-body h3 { font-size: 1.15em; }
.msg-content.markdown-body h4,
.msg-content.markdown-body h5,
.msg-content.markdown-body h6 { font-size: 1em; }
.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { padding-left: 22px; }
.msg-content code {
  background: var(--c-surface-2); padding: 1px 6px;
  border-radius: 4px; font-size: .92em;
}
.msg-content pre {
  background: #0f172a; color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 12.5px; line-height: 1.55;
  overflow-x: auto;
  margin: 12px 0;
  border: none;
}
.msg-content pre code { background: transparent; padding: 0; color: inherit; font-size: inherit; }
.msg-content blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--c-border-strong);
  color: var(--c-text-muted);
}
.msg-content table {
  font-size: 13px; margin: 10px 0;
  border-collapse: collapse;
}
.msg-content th, .msg-content td {
  padding: 6px 10px; border: 1px solid var(--c-border);
}
.msg-content th { background: var(--c-surface-2); }

/* User bubble: lightly tinted card to differentiate from assistant prose */
.msg-user .msg-content {
  background: var(--c-accent-lo);
  border: 1px solid #dbeafe;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: inline-block;
  cursor: text;
  transition: border-color .12s, box-shadow .12s;
}
.msg-user .msg-content:not([data-editing]):hover {
  border-color: var(--c-accent);
  box-shadow: var(--shadow-sm);
}

/* Assistant message: render the markdown inside a soft card with proper
   inner padding, instead of letting `github-markdown-css`'s white background
   bleed edge-to-edge against the framed chat shell. */
.msg-assistant .msg-content.markdown-body {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}
.msg-assistant .msg-content.markdown-body:empty {
  display: none;
}

/* Message hover actions (Copy / Regenerate) ------------------------------ */
.msg-actions {
  display: flex; gap: 6px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity .15s;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions { opacity: 1; }
.msg-act {
  appearance: none;
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 10px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  color: var(--c-text-muted);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.msg-act:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
  border-color: var(--c-border);
}

/* Inline editor for a user prompt (Edit & re-run) ------------------------ */
.msg-user .msg-content[data-editing] {
  display: block;
  width: 100%;
  padding: 8px 10px;
}
.msg-edit-input {
  width: 100%;
  box-sizing: border-box;
  min-height: 60px;
  resize: vertical;
  font: inherit;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm, 6px);
  padding: 8px 10px;
  line-height: 1.5;
}
.msg-edit-input:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 2px var(--c-accent-lo);
}
.msg-edit-actions {
  display: flex; gap: 6px; justify-content: flex-end;
  margin-top: 6px;
}
.msg-edit-save,
.msg-edit-cancel {
  appearance: none;
  font: inherit; font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid transparent;
}
.msg-edit-save {
  background: var(--c-accent);
  color: #fff;
  border-color: var(--c-accent);
}
.msg-edit-save:hover { filter: brightness(1.05); }
.msg-edit-cancel {
  background: transparent;
  color: var(--c-text-muted);
  border-color: var(--c-border);
}
.msg-edit-cancel:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}

/* Composer --------------------------------------------------------------- */
.composer-wrap {
  flex: 0 0 auto;
  margin: 8px 0 0;
  padding-top: 8px;
  /* Fade into the chat shell's surface (not the page's gray bg) so the
     composer sits cleanly inside the framed area. */
  background: linear-gradient(180deg, transparent, var(--c-surface) 32%);
  display: flex; flex-direction: column; gap: 8px;
}
.composer {
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-xl);
  padding: 14px 18px 10px;
  box-shadow: var(--shadow-md);
  transition: border-color .15s, box-shadow .15s;
  display: flex; flex-direction: column; gap: 6px;
}
.composer:focus-within {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 4px rgba(30, 64, 175, .12), var(--shadow-md);
}
.composer textarea {
  width: 100%;
  border: none; background: transparent; outline: none; resize: none;
  padding: 4px 4px 6px;
  margin: 0;
  font-family: inherit; font-size: 13.5px; line-height: 1.55;
  color: var(--c-text);
  min-height: 24px;
  max-height: 220px;
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--c-text-dim); }

.composer-toolbar {
  display: flex; align-items: center; gap: 6px;
}
.composer-tools {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  flex: 1 1 auto; min-width: 0;
}

/* ---- Compact composer chips --------------------------------------------
   The chat options (Model / Env / Scope chips, action buttons, popover
   menu items) are squeezed to ~1/3 of their original visual footprint
   so the composer toolbar stays out of the way. Sizes are absolute px
   on purpose: a single `font-size` on `.composer-tools` would not shrink
   the popover panel (which is positioned absolutely and not a font-size
   descendant in some browsers).
   ----------------------------------------------------------------------- */
.composer-tools .chip-toggle,
.composer-tools .chip-select,
.composer-tools .chip-menu > summary,
.composer-tools .chip-btn {
  padding: 2px 7px;
  font-size: 9.5px;
  line-height: 1.3;
  gap: 4px;
}
.composer-tools .chip-select { padding: 1px 1px 1px 7px; }
.composer-tools .chip-menu > summary { padding: 2px 5px 2px 7px; }
.composer-tools .chip-select-label,
.composer-tools .chip-btn-label,
.composer-tools .chip-menu-value {
  font-size: 9px;
}
.composer-tools .chip-menu-value { max-width: 80px; }
.composer-tools .chip-menu-caret,
.composer-tools .chip-select select { font-size: 9.5px; }
.composer-tools .chip-select select {
  padding: 0 14px 0 2px;
  background-size: 8px;
  background-position: right 3px center;
}

/* Popover panel that opens from the Scope chip — keep the same compact
   feel so the dropdown isn't visually heavier than the chip that opened it.
   All selectors are scoped under .composer-tools so they only override the
   in-toolbar popover, not anything else that might one day reuse
   .chip-menu-panel elsewhere on the page. */
.composer-tools .chip-menu-panel { min-width: 110px; padding: 3px; }
.composer-tools .chip-menu-item { padding: 3px 6px; font-size: 10px; gap: 6px; }
.composer-tools .chip-menu-item-label { font-size: 10px; }
.composer-tools .chip-menu-item.is-child .chip-menu-item-label { font-size: 9.5px; }
.composer-tools .chip-menu-tick { width: 13px; height: 13px; font-size: 10px; }
.composer-tools .chip-menu-tick::before { font-size: 10px; }
.composer-tools .chip-menu-item input[type="checkbox"]:checked ~ .chip-menu-tick::before { font-size: 9px; }
.composer-tools .chip-menu-children { margin-left: 9px; padding-left: 10px; }
.composer-tools .chip-menu-expander { width: 14px; height: 14px; }

/* Pill toggle (checkbox) */
.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--c-surface-2);
  border: 1px solid transparent;
  font-size: 12.5px; color: var(--c-text-muted);
  cursor: pointer; user-select: none;
  transition: background .15s, color .15s, border-color .15s;
}
.chip-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chip-toggle:hover { background: #e5e7eb; color: var(--c-text); }
.chip-toggle:has(input:checked) {
  background: var(--c-accent-lo);
  color: var(--c-accent);
  border-color: #bfdbfe;
}
.chip-toggle:has(input:checked)::before {
  content: "\2713";          /* check */
  font-size: 11px; font-weight: 700;
}

/* Pill select (Model / Env) */
.chip-select {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 4px 4px 10px;
  background: var(--c-surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
  transition: background .15s, border-color .15s;
}
.chip-select:hover { background: #e5e7eb; }
.chip-select-label {
  font-size: 11px; font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}

/* Action chip (e.g. New conversation) styled to match `.chip-select`
   visually so it sits naturally in the same toolbar row. */
.chip-btn {
  appearance: none;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--c-surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  color: var(--c-text-muted);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip-btn:hover {
  background: #e5e7eb;
  color: var(--c-text);
}
.chip-btn-label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
}

/* Round mic (Dictate) button — sits just left of the send button. Neutral
   surface so it reads as secondary to the accent-coloured send button. */
.composer-mic {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border: none; border-radius: 50%;
  background: var(--c-surface-2); color: var(--c-text-muted);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, transform .05s, box-shadow .15s;
}
.composer-mic:hover { background: #e5e7eb; color: var(--c-text); }
.composer-mic:active { transform: scale(.96); }

/* Active dictation state — red tint + soft pulse so it reads as "listening". */
.composer-mic.is-recording {
  background: #fde2e1;
  color: #b91c1c;
  animation: mic-pulse 1.4s ease-in-out infinite;
}
.composer-mic.is-recording:hover { background: #fbcfcd; color: #b91c1c; }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(185, 28, 28, .0); }
  50%      { box-shadow: 0 0 0 4px rgba(185, 28, 28, .18); }
}
@media (prefers-reduced-motion: reduce) {
  .composer-mic.is-recording { animation: none; }
}

/* Attached-image thumbnails inside the composer (multimodal input). */
.img-previews {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 8px 4px 2px;
}
.img-thumb {
  position: relative; display: inline-flex;
  width: 56px; height: 56px;
  border: 1px solid var(--c-border); border-radius: 8px;
  overflow: hidden; background: var(--c-surface-2);
}
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-thumb-x {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; line-height: 16px;
  border: none; border-radius: 50%;
  background: var(--c-text); color: #fff;
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.img-thumb-x:hover { background: #b91c1c; }

/* Attached images rendered in the user's chat bubble. */
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.msg-image {
  max-width: 240px; max-height: 240px;
  border: 1px solid var(--c-border); border-radius: 8px;
  object-fit: contain; background: var(--c-surface-2);
}

/* Editable DAX/SQL query blocks — users can tweak the generated query in
   place before running it (Run reads the live text). */
pre.editable-query > code {
  outline: none; cursor: text; caret-color: var(--c-accent);
  white-space: pre-wrap; word-break: break-word;
}
pre.editable-query { transition: box-shadow .15s, border-color .15s; }
pre.editable-query:focus-within {
  box-shadow: 0 0 0 2px var(--c-accent-lo), 0 0 0 3px var(--c-accent);
  border-radius: 6px;
}

/* Pill group with a leading label and one or more chip-toggles inside
   (e.g. Scope: [FRM] [ORM]). Visually pairs the label with the toggles
   without forcing a single-select dropdown. */
.chip-group {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 6px 3px 10px;
  background: var(--c-surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
}
.chip-group .chip-toggle {
  padding: 3px 9px;
  background: transparent;
  font-size: 12px;
}
.chip-group .chip-toggle:hover { background: #e5e7eb; }

/* Pill popover for multi-select chips (e.g. Scope). Uses native <details>
   so it stays accessible and toggles without any JS for open/close. */
.chip-menu {
  position: relative;
  display: inline-block;
}
.chip-menu > summary {
  list-style: none;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 7px 2px 9px;
  background: var(--c-surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer; user-select: none;
  font-size: 11.5px; line-height: 1.4; color: var(--c-text-muted);
  transition: background .15s, border-color .15s, color .15s;
}
.chip-menu > summary::-webkit-details-marker { display: none; }
.chip-menu > summary:hover { background: #e5e7eb; }
.chip-menu[open] > summary {
  background: var(--c-accent-lo);
  color: var(--c-accent);
  border-color: #bfdbfe;
}
.chip-menu.is-none > summary {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}
.chip-menu-value {
  font-weight: 600; color: var(--c-text);
  font-size: 11.5px;
  max-width: 110px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip-menu[open] .chip-menu-value { color: var(--c-accent); }
.chip-menu.is-none .chip-menu-value { color: #991b1b; }
.chip-menu-caret {
  color: var(--c-text-muted);
  transition: transform .15s;
}
.chip-menu[open] .chip-menu-caret { transform: rotate(180deg); }

.chip-menu-panel {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 140px;
  display: flex; flex-direction: column; gap: 1px;
  padding: 4px;
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.chip-menu-item {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px; color: var(--c-text);
  transition: background .12s;
}
.chip-menu-item:hover { background: var(--c-surface-2); }
/* Hide the native checkbox; the visible state is the .chip-menu-tick pill. */
.chip-menu-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
  pointer-events: none;
}
.chip-menu-item input[type="checkbox"]:focus-visible ~ .chip-menu-tick {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}
/* Custom toggle: + (off) -> filled accent dot with check (on). */
.chip-menu-tick {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px dashed var(--c-border-strong);
  color: var(--c-text-muted);
  font-size: 12px; line-height: 1;
  transition: background .15s, border-color .15s, color .15s, transform .15s;
}
.chip-menu-tick::before {
  content: "+";
  font-weight: 600;
  transition: transform .15s;
}
.chip-menu-item:hover .chip-menu-tick {
  border-color: var(--c-accent);
  color: var(--c-accent);
}
.chip-menu-item input[type="checkbox"]:checked ~ .chip-menu-tick {
  background: var(--c-accent);
  border: 1.5px solid var(--c-accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(30, 64, 175, .25);
}
.chip-menu-item input[type="checkbox"]:checked ~ .chip-menu-tick::before {
  content: "\2713";        /* check mark */
  font-size: 10px;
  font-weight: 700;
  transform: scale(1);
}
.chip-menu-item-label {
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
  color: var(--c-text);
}

/* ---- Parent / sub-scope groups ----------------------------------------
   Parent rows look like a normal chip-menu-item but carry an inline
   expander button on the right (chip-menu-expander) which collapses or
   reveals the .chip-menu-children block below.
   ----------------------------------------------------------------------- */
.chip-menu-group { display: contents; }
.chip-menu-children {
  display: flex; flex-direction: column; gap: 1px;
  margin: 1px 0 2px 0;
  padding: 1px 0 1px 14px;
  border-left: 1.5px solid var(--c-border);
  margin-left: 12px;
}
.chip-menu-children.is-collapsed { display: none; }
.chip-menu-item.is-child {
  font-weight: 500;
  color: var(--c-text-muted);
}
.chip-menu-item.is-child .chip-menu-item-label {
  font-weight: 500;
  font-size: 11.5px;
  color: var(--c-text-muted);
}
.chip-menu-item.is-child input[type="checkbox"]:checked ~ .chip-menu-item-label {
  color: var(--c-text);
  font-weight: 600;
}
.chip-menu-expander {
  margin-left: auto;
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--c-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.chip-menu-expander:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}
.chip-menu-expander svg { transition: transform .15s; }
.chip-menu-expander.is-collapsed svg { transform: rotate(-90deg); }

/* Parent in indeterminate state: outline-only filled tick with a dash */
.chip-menu-item input[type="checkbox"]:indeterminate ~ .chip-menu-tick {
  background: transparent;
  border: 1.5px solid var(--c-accent);
  color: var(--c-accent);
}
.chip-menu-item input[type="checkbox"]:indeterminate ~ .chip-menu-tick::before {
  content: "\2013";        /* en-dash */
  font-size: 11px;
  font-weight: 700;
}
.chip-select select {
  appearance: none; -webkit-appearance: none;
  border: none; background: transparent; outline: none;
  font: inherit; font-size: 12.5px; color: var(--c-text);
  padding: 1px 18px 1px 4px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
  background-repeat: no-repeat;
  background-position: right 4px center;
  background-size: 10px;
}

/* Round send / stop button */
.composer-send {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border: none; border-radius: 50%;
  background: var(--c-accent); color: #fff;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, transform .05s, box-shadow .15s, opacity .15s;
  box-shadow: 0 2px 6px rgba(30, 64, 175, .35);
}
.composer-send:hover { background: var(--c-accent-hi); }
.composer-send:active { transform: scale(.96); }
.composer-send .icon-stop { display: none; }
.composer-send.is-sending {
  background: var(--c-text-muted);
  box-shadow: 0 2px 6px rgba(107, 114, 128, .25);
  animation: send-pulse 1.4s ease-in-out infinite;
}
.composer-send.is-sending .icon-send { display: none; }
.composer-send.is-sending .icon-stop { display: block; }
@keyframes send-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(107, 114, 128, .35); }
  50%      { box-shadow: 0 0 0 6px rgba(107, 114, 128, 0); }
}

/* Footer row beneath the composer */
.composer-status {
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  font-size: 12px;
}
.composer-spacer { flex: 1 1 auto; }
.status-text {
  color: var(--c-text-muted);
  font-variant-numeric: tabular-nums;
}
.session-usage {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--c-text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  padding: 2px 9px 2px 6px;
  border: 1px solid var(--c-border, rgba(0,0,0,.12));
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  background: var(--c-surface, #fff);
  transition: border-color .15s, background .15s;
}
.session-usage:hover { border-color: var(--c-accent); background: var(--c-surface-2, #f3f4f6); }
.session-usage[hidden] { display: none; }
.session-usage[aria-expanded="true"] { border-color: var(--c-accent); }
.usage-donut { flex: 0 0 auto; }
.usage-donut-track { stroke: var(--c-border-strong, rgba(0,0,0,.18)); }
.usage-donut-fill { transition: stroke-dashoffset .35s ease, stroke .35s ease; }
.session-usage-label { line-height: 1; }

/* Popup menu anchored above the donut (clear / compact). */
.usage-widget { position: relative; display: inline-flex; }
.usage-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 220px;
  display: flex; flex-direction: column; gap: 1px;
  padding: 4px;
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.usage-menu[hidden] { display: none; }
.usage-menu-item {
  display: flex; align-items: center; gap: 8px;
  appearance: none; background: none; border: none;
  padding: 6px 8px; margin: 0;
  border-radius: var(--radius-sm);
  cursor: pointer; text-align: left;
  font: inherit; font-size: 12.5px; color: var(--c-text);
  transition: background .12s;
}
.usage-menu-item:hover { background: var(--c-surface-2); }
.usage-menu-item svg { flex: 0 0 auto; color: var(--c-text-muted); }

/* Granular breakdown at the top of the expanded usage widget. */
.usage-menu-details {
  display: flex; flex-direction: column; gap: 1px;
  padding: 2px 4px 4px;
  font-variant-numeric: tabular-nums;
}
.usage-stat-head {
  margin-top: 6px;
  font-size: 9px; font-weight: 500; letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}
.usage-stat-head:first-child { margin-top: 0; }
.usage-stat {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 1px 4px;
  font-size: 10.5px; font-weight: 400; color: var(--c-text);
}
.usage-stat-k { color: var(--c-text-muted); }
.usage-stat-v { font-weight: 400; }
.usage-stat-empty { color: var(--c-text-muted); font-style: italic; }
.usage-menu-sep {
  height: 1px; margin: 5px 2px;
  background: var(--c-border, rgba(0,0,0,.1));
}
.link-btn {
  display: inline-flex; align-items: center; gap: 5px;
  appearance: none; background: none; border: none;
  padding: 0; margin: 0;
  font: inherit; font-size: 12px; color: var(--c-text-muted);
  cursor: pointer;
}
.link-btn:hover { color: var(--c-accent); }

/* ===========================================================================
   Inline DAX runner — refined to match the new design
   ========================================================================= */
.dax-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 0 0;
  padding: 6px 10px;
  background: #1e293b;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 12px;
  color: #cbd5e1;
}
.dax-bar .dax-tag {
  background: rgba(245, 158, 11, .18); color: #fbbf24;
  font-weight: 700; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 4px;
  font-size: 10.5px;
}
.dax-bar button {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 11px;
  font-size: 12px; font-weight: 600;
  background: var(--c-accent); color: #fff;
  border: none; border-radius: 999px;
  cursor: pointer;
  transition: background .12s;
}
.dax-bar button:hover { background: var(--c-accent-hi); }
.dax-bar button.secondary {
  background: rgba(148, 163, 184, .15);
  color: #cbd5e1;
}
.dax-bar button.secondary:hover { background: rgba(148, 163, 184, .25); }
.dax-bar button:disabled { opacity: .5; cursor: progress; }
.dax-bar .dax-status,
.dax-bar .dax-meta {
  font-size: 11px; color: #94a3b8; font-weight: 500;
}
.dax-bar .dax-meta { margin-left: auto; }
.dax-bar + pre { margin-top: 0 !important; border-top-left-radius: 0 !important; border-top-right-radius: 0 !important; }

/* ------------------------------------------------------------------------
   Inline SQL runner — same skeleton as the DAX bar so it sits naturally
   alongside it; the only visual difference is the SQL tag (blue) and the
   per-block scope picker (orm / frm) so the user can route the query.
   ------------------------------------------------------------------------ */
.sql-bar { /* alias of dax-bar */
  display: flex; align-items: center; gap: 8px;
  margin: 14px 0 0;
  padding: 6px 10px;
  background: #1e293b;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 12px;
  color: #cbd5e1;
}
.sql-bar .sql-tag {
  background: rgba(59, 130, 246, .22); color: #60a5fa;
  font-weight: 700; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 4px;
  font-size: 10.5px;
}
.sql-bar button {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 11px;
  font-size: 12px; font-weight: 600;
  background: var(--c-accent); color: #fff;
  border: none; border-radius: 999px;
  cursor: pointer;
  transition: background .12s;
}
.sql-bar button:hover { background: var(--c-accent-hi); }
.sql-bar button.secondary {
  background: rgba(148, 163, 184, .15);
  color: #cbd5e1;
}
.sql-bar button.secondary:hover { background: rgba(148, 163, 184, .25); }
.sql-bar button:disabled { opacity: .5; cursor: progress; }
.sql-bar .sql-scope {
  background: rgba(15, 23, 42, .55);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, .3);
  border-radius: 6px;
  font-size: 11px; font-weight: 600;
  padding: 2px 6px;
  cursor: pointer;
}
.sql-bar .sql-status,
.sql-bar .sql-meta {
  font-size: 11px; color: #94a3b8; font-weight: 500;
}
.sql-bar .sql-meta { margin-left: auto; }
.sql-bar + pre { margin-top: 0 !important; border-top-left-radius: 0 !important; border-top-right-radius: 0 !important; }
.sql-inline-result {
  margin: 8px 0 16px;
}
.sql-inline-result:empty { display: none; }
.sql-inline-result .tabulator {
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  background: var(--c-surface);
}
.sql-error-hdr {
  background: #fef2f2; color: #991b1b;
  border: 1px solid #fecaca; border-bottom: none;
  padding: 8px 12px; font-weight: 600; font-size: 13px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
pre.sql-error {
  margin: 0;
  background: #fff5f5; color: #7f1d1d;
  border: 1px solid #fecaca;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
  max-height: 50vh; overflow: auto;
}

.dax-inline-result {
  margin: 8px 0 16px;
}
.dax-inline-result:empty { display: none; }
.dax-inline-result .tabulator {
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  background: var(--c-surface);
}

/* ------------------------------------------------------------------------
   Generic result visualization — Table/Chart toggle + Chart.js canvas that
   sit inside every .dax-inline-result / .sql-inline-result slot.
   ------------------------------------------------------------------------ */
.result-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 6px 0 8px;
  font-size: 12px; color: #475569;
}
.result-viewtoggle {
  display: inline-flex;
  border: 1px solid var(--c-border); border-radius: 999px; overflow: hidden;
}
.result-viewtoggle .rv-btn {
  background: var(--c-surface); color: #475569;
  border: none; padding: 4px 14px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .12s, color .12s;
}
.result-viewtoggle .rv-btn + .rv-btn { border-left: 1px solid var(--c-border); }
.result-viewtoggle .rv-btn.is-active { background: var(--c-accent); color: #fff; }
.result-chart-controls {
  display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.result-chart-controls[hidden] { display: none; }
.result-chart-controls label {
  display: inline-flex; align-items: center; gap: 5px; font-weight: 600;
}
.result-chart-controls select {
  border: 1px solid var(--c-border); border-radius: 6px;
  background: var(--c-surface); color: inherit;
  font-size: 12px; padding: 2px 6px; cursor: pointer;
}
.rv-y { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rv-y[hidden],
.result-chart-controls label[hidden] { display: none; }
.rv-y-item {
  display: inline-flex; align-items: center; gap: 4px;
  font-weight: 500; white-space: nowrap;
}
.result-chart-pane {
  height: 42vh; padding: 4px 2px 0;
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  background: var(--c-surface);
}
.result-chart-pane[hidden] { display: none; }
.result-chart-pane canvas { width: 100% !important; height: 100% !important; }
.result-pane.result-table-pane[hidden] { display: none; }

/* A ```chart block's raw JSON spec is hidden once the table+chart renders
   in its place (a parse failure leaves the block visible as a fallback). */
pre.is-viz-source { display: none; }

.dax-error-hdr {
  background: #fef2f2; color: #991b1b;
  border: 1px solid #fecaca; border-bottom: none;
  padding: 8px 12px; font-weight: 600; font-size: 13px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
pre.dax-error {
  margin: 0;
  background: #fff5f5; color: #7f1d1d;
  border: 1px solid #fecaca;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
  max-height: 50vh; overflow: auto;
}

/* ===========================================================================
   Tabulator overrides (inline DAX result tables)
   ========================================================================= */
.tabulator { border: none; background: transparent; font-size: 12.5px; }
.tabulator .tabulator-tableholder { overflow-x: auto !important; }
.tabulator .tabulator-tableholder::-webkit-scrollbar { height: 10px; }
.tabulator .tabulator-tableholder::-webkit-scrollbar-thumb {
  background: var(--c-border-strong); border-radius: 5px;
}
.tabulator .tabulator-tableholder::-webkit-scrollbar-thumb:hover { background: var(--c-text-dim); }
.tabulator .tabulator-header { background: var(--c-surface-2); border-bottom: 1px solid var(--c-border-strong); }
.tabulator .tabulator-header .tabulator-col { background: transparent; border-right: 1px solid var(--c-border); }
.tabulator .tabulator-header .tabulator-col-title { font-weight: 600; color: var(--c-text); }
.tabulator .tabulator-row { border-bottom: 1px solid #f3f4f6; }
.tabulator .tabulator-row.tabulator-row-even { background: #fafbfc; }
.tabulator .tabulator-row:hover { background: var(--c-accent-lo) !important; }
.tabulator-footer { background: var(--c-surface-2); border-top: 1px solid var(--c-border); }
.tabulator .tabulator-header-filter input {
  padding: 3px 6px; font-size: 12px;
  border: 1px solid var(--c-border-strong); border-radius: 4px;
}

/* Live agent-loop activity panel — inline inside each assistant message,
   styled to feel chat-native (light surface, sans-serif, subtle border).
   While running it stays expanded; when finished it auto-collapses to a
   single discreet "Thought for Xs · N iter" disclosure, just like the
   reasoning blocks in Copilot/Claude/ChatGPT. */
.msg-activity-slot { margin-bottom: 6px; }
.msg-activity-slot:empty { display: none; }

.agent-activity {
  /* Local slate / dark-blue palette for the iteration loop. No green,
     no Bootstrap defaults — cohesive steel-blue tones. */
  --act-ink:      #1e293b;   /* primary dark slate-blue text */
  --act-muted:    #64748b;   /* slate-500 */
  --act-dim:      #94a3b8;   /* slate-400 */
  --act-line:     #cbd5e1;   /* slate-300 hairlines */
  --act-live:     #1e3a8a;   /* deep blue — active iteration */
  --act-live-bg:  #eef2f8;   /* faint blue wash */
  --act-done:     #475569;   /* slate-600 — finished iteration */
  --act-done-bg:  #f1f5f9;   /* slate-100 */
  --act-err:      #9b3b3b;   /* muted brick — failure */
  --act-warn:     #92722e;   /* muted ochre */

  margin: 0 0 4px;
  background: var(--c-surface-2);
  color: var(--act-ink);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 11.5px;
  line-height: 1.5;
  overflow: hidden;
}

/* Shared step-icon sizing so every glyph in the loop stays consistent. */
.agent-activity .act-ic {
  width: 13px; height: 13px;
  flex: 0 0 auto;
  vertical-align: -2px;
  margin-right: 1px;
}
.agent-activity .act-header {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  cursor: pointer; user-select: none;
  background: transparent;
  border-bottom: 1px solid var(--c-border);
  outline: none;
  color: var(--act-muted);
}
.agent-activity .act-header:hover { background: rgba(30, 41, 59, .03); }
.agent-activity .act-chevron {
  display: inline-flex; color: var(--act-dim);
  transition: transform 0.15s ease;
}
.agent-activity.collapsed .act-chevron { transform: rotate(-90deg); }
.agent-activity.collapsed .act-header { border-bottom-color: transparent; }
.agent-activity .act-title { color: var(--act-ink); font-weight: 600; font-size: 11.5px; }
.agent-activity .act-summary { color: var(--act-muted); flex: 1; font-size: 11px; }
.agent-activity .act-body {
  max-height: 360px; overflow: auto;
  padding: 8px 10px;
  transition: max-height 0.2s ease, padding 0.2s ease;
}
.agent-activity.collapsed .act-body {
  max-height: 0; padding-top: 0; padding-bottom: 0;
}
.agent-activity .act-line {
  white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  color: var(--act-muted);
}
.agent-activity .act-time { color: var(--act-dim); opacity: .8; margin-right: 6px; }
.agent-activity .act-iter { color: var(--act-live); font-weight: 700; }
.agent-activity .act-tool { color: var(--act-live); font-weight: 600; }
.agent-activity .act-ok   { color: var(--act-done); font-weight: 600; }
.agent-activity .act-err  { color: var(--act-err); font-weight: 600; }
.agent-activity .act-think{ color: var(--act-muted); font-style: italic; }
.agent-activity .act-final{ color: var(--act-ink); font-weight: 700; }
.agent-activity .act-tokens { color: #4c5b73; font-weight: 600; }
.agent-activity .act-kw   { color: var(--act-ink); }
.agent-activity .act-val  { color: #5b6b85; }
.agent-activity .act-preview { color: var(--act-muted); }

/* Per-iteration foldable group — compact accordion. Rows stack flush with
   shared hairline separators (no gaps / outer margins) so the loop reads as
   one continuous list rather than detached cards. */
.agent-activity .act-iter-group {
  margin: 0;
  border-left: 3px solid var(--act-line);
  border-top: 1px solid var(--act-line);
  background: rgba(30, 41, 59, .015);
  padding: 0;
  transition: border-color .2s, background .2s;
}
.agent-activity .act-iter-group:first-of-type { border-top: none; }
.agent-activity .act-iter-group.live {
  border-left-color: var(--act-live);
  background: var(--act-live-bg);
}
.agent-activity .act-iter-group.finished {
  border-left-color: var(--act-done);
  background: var(--act-done-bg);
  opacity: .9;
}
.agent-activity .act-iter-group > summary {
  list-style: none;
  cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  user-select: none;
}
.agent-activity .act-iter-group > summary::-webkit-details-marker { display: none; }
.agent-activity .act-iter-group > summary::marker { content: ""; }
.agent-activity .act-iter-group > summary:hover { background: rgba(30, 41, 59, .04); }

.agent-activity .act-iter-chev {
  display: inline-flex;
  color: var(--act-dim); transition: transform .15s ease;
}
.agent-activity .act-iter-chev .act-ic { width: 10px; height: 10px; }
.agent-activity .act-iter-group[open] > summary .act-iter-chev { transform: rotate(0deg); }
.agent-activity .act-iter-group:not([open]) > summary .act-iter-chev { transform: rotate(-90deg); }

/* Loop glyph that leads the iteration row */
.agent-activity .act-iter-ic { display: inline-flex; color: var(--act-muted); }
.agent-activity .act-iter-ic .act-ic { width: 11px; height: 11px; }
.agent-activity .act-iter-group.live > summary .act-iter-ic { color: var(--act-live); }
.agent-activity .act-iter-group.finished > summary .act-iter-ic { color: var(--act-done); }

.agent-activity .act-iter-badge {
  background: var(--c-surface);
  color: var(--act-ink);
  border: 1px solid var(--act-line);
  padding: 0 5px; border-radius: 999px;
  font-size: 9.5px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.agent-activity .act-iter-group.live > summary .act-iter-badge {
  background: var(--act-live);
  color: #fff;
  border-color: transparent;
}
.agent-activity .act-iter-group.finished > summary .act-iter-badge {
  background: rgba(71, 85, 105, .12);
  color: var(--act-done);
  border-color: rgba(71, 85, 105, .25);
}
.agent-activity .act-iter-label {
  color: var(--act-muted); text-transform: uppercase; font-size: 8.5px;
  letter-spacing: .05em; font-weight: 600;
}
.agent-activity .act-iter-status { flex: 1; display: flex; align-items: center; }
.agent-activity .act-iter-time {
  color: var(--act-dim); font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.agent-activity .act-iter-group.live > summary .act-iter-time {
  color: var(--act-live); font-weight: 600;
}

/* Tool hint shown in the iteration summary so a folded iter still says
   what it did, e.g.  🔧 list_tables   or   🔧 get_table 'Credit Exposures' */
.agent-activity .act-iter-tool {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent-activity .act-iter-tool-arrow { display: inline-flex; color: var(--act-live); }
.agent-activity .act-iter-tool-arrow .act-ic { width: 11px; height: 11px; }
.agent-activity .act-iter-tool-name  { color: var(--act-live); font-weight: 600; }
.agent-activity .act-iter-tool-arg   { color: #5b6b85; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10.5px; }
.agent-activity .act-iter-tool-more  { color: var(--act-muted); }
.agent-activity .act-iter-tool-count { color: var(--act-muted); font-size: 10.5px; }
.agent-activity .act-iter-group.finished > summary .act-iter-tool-arrow { color: var(--act-done); }
.agent-activity .act-iter-group.finished > summary .act-iter-tool-name  { color: var(--act-done); }

/* "Thinking…" placeholder shown while the model reasons before it commits
   to a tool. Muted + gently pulsing so it reads as transient. Replaced by
   the tool name (or "Composing answer") as soon as the step is known. */
.agent-activity .act-iter-thinking {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--act-dim); font-style: italic; font-weight: 500;
  animation: act-think-pulse 1.4s ease-in-out infinite;
}
.agent-activity .act-iter-thinking .act-ic { width: 12px; height: 12px; }
@keyframes act-think-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* Answer-writing step: the final pass that composes the reply instead of
   calling a tool. Styled in calm slate so it reads as a wrap-up, not a tool. */
.agent-activity .act-iter-group.is-answer > summary .act-iter-ic { color: var(--act-done); }
.agent-activity .act-iter-group.is-answer .act-iter-tool-arrow,
.agent-activity .act-iter-group.is-answer .act-iter-tool-name { color: var(--act-done); }

.agent-activity .act-iter-body {
  padding: 2px 10px 5px 26px;
}

/* Live indicator: three bouncing dots */
.act-dots { display: inline-flex; gap: 4px; align-items: center; }
.act-dots > i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--act-live); display: inline-block;
  animation: act-dot-bounce 1.1s ease-in-out infinite;
}
.act-dots > i:nth-child(2) { animation-delay: .15s; }
.act-dots > i:nth-child(3) { animation-delay: .30s; }
@keyframes act-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .35; }
  40%           { transform: translateY(-4px); opacity: 1; }
}

/* Finished iterations swap the working dots for a slate checkmark icon. */
.agent-activity .act-iter-check { display: none; color: var(--act-done); }
.agent-activity .act-iter-check .act-ic { width: 11px; height: 11px; }
.agent-activity .act-iter-group.finished > summary .act-dots { display: none; }
.agent-activity .act-iter-group.finished > summary .act-iter-check { display: inline-flex; }

/* ---------------------------------------------------------------------------
   Explicit sign-in gate (#auth-gate)
   Full-screen overlay revealed by checkAuthGate() only when the user is not
   signed in. Hidden by default (the `hidden` attribute) so signed-in users
   never see a flash of it on refresh.
   --------------------------------------------------------------------------- */
.auth-gate {
  /* The design tokens are scoped to `.ai-page`, but #auth-gate is a SIBLING
     of .ai-page (not a descendant), so it must define the tokens it uses here.
     Custom properties inherit, so these cascade to all .auth-gate-* children.
     Without this the overlay had no background — the sign-in card floated as
     unstyled text over the page. */
  --c-bg:          #f9fafb;
  --c-surface:     #ffffff;
  --c-border:      #e5e7eb;
  --c-text:        #111827;
  --c-text-muted:  #6b7280;
  --c-text-dim:    #9ca3af;
  --c-accent:      #1e40af;
  --c-accent-hi:   #1d4ed8;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-lg: 0 4px 6px rgba(15, 23, 42, .04), 0 24px 48px rgba(15, 23, 42, .08);
  --font-ui: SwissReSanRegu, "Segoe UI", "SF Pro Text",
             Roboto, "Helvetica Neue", Arial, sans-serif;

  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--c-bg);
  font-family: var(--font-ui);
}
.auth-gate[hidden] { display: none; }

.auth-gate-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  padding: 40px 36px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-gate-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--c-accent);
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: .5px;
}

.auth-gate-title {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 650;
  color: var(--c-text);
}

.auth-gate-sub {
  margin: 0 0 24px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--c-text-muted);
}

.auth-gate-btn {
  display: inline-block;
  width: 100%;
  box-sizing: border-box;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  background: var(--c-accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background .12s ease;
}
.auth-gate-btn:hover { background: var(--c-accent-hi); }
.auth-gate-btn[hidden] { display: none; }

.auth-gate-access {
  margin: 18px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--c-text-dim);
}

/* ------------------------------------------------------------------ */
/* About page — business-facing pitch                                  */
/* ------------------------------------------------------------------ */
.about-page { padding: 32px 24px 48px; }

.about-wrap {
  width: 100%;
  max-width: 1020px;
  margin: 0 auto;
}

.about-hero { text-align: center; padding: 12px 8px 28px; }

.about-kicker {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--c-accent);
  background: var(--c-accent-lo);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.about-title {
  margin: 0 0 14px;
  font-size: 34px;
  line-height: 1.15;
  font-weight: 750;
  color: var(--c-text);
  letter-spacing: -0.01em;
}

.about-lede {
  max-width: 760px;
  margin: 0 auto;
  font-size: 17px;
  line-height: 1.6;
  color: var(--c-text-muted);
}
.about-lede strong { color: var(--c-text); font-weight: 650; }

.about-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px 26px;
}

.about-graph { margin: 8px 0 28px; }
.about-graph h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
  color: var(--c-text);
}
.about-graph .about-sub {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--c-text-muted);
}
.about-graph .mermaid {
  display: flex;
  justify-content: center;
  overflow-x: auto;
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.about-card-wide { grid-column: 1 / -1; }
@media (max-width: 720px) {
  .about-grid { grid-template-columns: 1fr; }
  .about-title { font-size: 27px; }
}

.about-grid h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text);
}
.about-grid p {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--c-text-muted);
}
.about-grid strong { color: var(--c-text); font-weight: 650; }

.about-close {
  text-align: center;
  padding: 8px 8px 4px;
}
.about-close p {
  max-width: 640px;
  margin: 0 auto 18px;
  font-size: 16px;
  line-height: 1.55;
  color: var(--c-text-muted);
}
.about-close strong { color: var(--c-text); }

.about-cta {
  display: inline-block;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  background: var(--c-accent);
  color: #fff;
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
  transition: background .12s ease;
}
.about-cta:hover { background: var(--c-accent-hi); }

/* ------------------------------------------------------------------ */
/* Conversation history drawer (local-first chat persistence)          */
/* ------------------------------------------------------------------ */
.history-toggle {
  position: fixed;
  top: 64px; left: 16px;
  z-index: 6;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  font: inherit; font-size: 13px; font-weight: 600;
  color: #fff;
  background: var(--c-accent);
  border: 1px solid var(--c-accent);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.history-toggle:hover { background: var(--c-accent-hi); border-color: var(--c-accent-hi); }
.history-toggle[aria-expanded="true"] {
  color: #fff; background: var(--c-accent); border-color: var(--c-accent);
}

.history-drawer {
  position: fixed;
  top: 52px; left: 0; bottom: 0;
  width: 280px;
  z-index: 5;
  display: flex; flex-direction: column;
  padding: 56px 12px 16px;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  box-shadow: var(--shadow-md);
  box-sizing: border-box;
}
.history-drawer[hidden] { display: none; }

.history-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 6px 10px;
  border-bottom: 1px solid var(--c-border);
}
.history-title { font-size: 13px; font-weight: 650; color: var(--c-text); }
.history-new {
  appearance: none; border: none; background: transparent;
  font: inherit; font-size: 13px; font-weight: 550;
  color: var(--c-accent); cursor: pointer; padding: 4px 6px;
  border-radius: var(--radius-sm);
}
.history-new:hover { background: var(--c-accent-lo); }

.history-list {
  list-style: none; margin: 8px 0 0; padding: 0;
  overflow-y: auto; flex: 1 1 auto;
}
.history-empty {
  padding: 12px 8px; font-size: 13px; color: var(--c-text-dim);
}
.history-item {
  display: flex; align-items: center; gap: 4px;
  border-radius: var(--radius-sm);
  transition: background .1s;
}
.history-item:hover { background: var(--c-surface-2); }
.history-item.is-active { background: var(--c-accent-lo); }
.history-open {
  flex: 1 1 auto; min-width: 0;
  appearance: none; border: none; background: transparent;
  font: inherit; font-size: 13px; color: var(--c-text);
  text-align: left; cursor: pointer;
  padding: 8px 8px; border-radius: var(--radius-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-del {
  flex: 0 0 auto;
  appearance: none; border: none; background: transparent;
  font: inherit; font-size: 16px; line-height: 1; color: var(--c-text-dim);
  cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm);
  opacity: 0; transition: opacity .1s, color .1s;
}
.history-item:hover .history-del { opacity: 1; }
.history-del:hover { color: var(--c-danger); }


