/* ReFlow matte design system — flat surfaces, minimal shadows, no gradients,
   no scale transforms. Light mode only (OS dark-mode preference overridden).
   Palette: white / gray / ReFlow teal. Shared with the company's ReFlow app;
   Geist/Geist Mono come from next/font there — here they are named first in
   the stacks and fall back to system fonts (no build step, offline). */

:root {
  color-scheme: light;

  /* Type */
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* Surfaces */
  --background: #ffffff;
  --surface: #ffffff;
  --surface-muted: #f9fafb;   /* gray-50 */
  --surface-hover: #f3f4f6;   /* gray-100 */
  --surface-sunken: #f3f4f6;

  /* Text */
  --foreground: #111827;      /* gray-900 */
  --text: #111827;
  --text-muted: #4b5563;      /* gray-600 */
  --text-subtle: #9ca3af;     /* gray-400 */

  /* Borders */
  --border: #e5e7eb;          /* gray-200 */
  --border-strong: #d1d5db;   /* gray-300 */

  /* Accent — ReFlow teal (teal-600 ramp) */
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-active: #115e59;
  --accent-soft: #f0fdfa;
  --accent-soft-hover: #ccfbf1;
  --accent-soft-border: #99f6e4;
  --accent-text: #0f766e;
  --accent-ring: rgba(13, 148, 136, 0.22);

  /* Platform header. These match the ReFlow/PoS app bar so the ReFuels apps
     read as one suite — change them there and here together. The bar is the
     only dark surface in this app, hence its own white-alpha scale. */
  --header-bg: #1f3d3d;
  --header-fg: #ffffff;
  --header-fg-muted: rgba(255, 255, 255, 0.7);
  --header-border: rgba(255, 255, 255, 0.1);
  --header-ghost: rgba(255, 255, 255, 0.05);
  --header-ghost-hover: rgba(255, 255, 255, 0.1);
  --header-ghost-border: rgba(255, 255, 255, 0.15);
  --header-ring: rgba(255, 255, 255, 0.4);

  /* Status */
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-soft-border: #fecaca;
  --danger-text: #b91c1c;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --success-text: #166534;
  --warning: #d97706;
  --warning-soft: #fff7ed;
  --warning-text: #c2410c;

  /* Radii */
  --radius-btn: 8px;
  --radius-chip: 10px;
  --radius-card: 12px;
  --radius-modal: 14px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.03);

  /* Layout */
  --maxw: 46rem;
  --gutter: max(1.25rem, calc((100% - var(--maxw)) / 2));
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.55;
  letter-spacing: -0.005em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---- Header ------------------------------------------------------------
   Deliberately flat, matching the ReFlow/PoS bar: no gradient, no shadow, no
   scale on hover. Only colour transitions, and only the gear moves. */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
}
.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1600px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  min-width: 0;
}
.brand-logo { display: block; height: 36px; width: auto; flex-shrink: 0; }
.brand-title {
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--header-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hdr-controls { display: flex; align-items: center; gap: 0.5rem; }

/* Shared ghost treatment for every control in the bar. */
.hdr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 36px;
  padding: 0 0.75rem;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--header-fg-muted);
  background: var(--header-ghost);
  border: 1px solid var(--header-ghost-border);
  border-radius: var(--radius-btn);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.hdr-btn:hover { background: var(--header-ghost-hover); color: var(--header-fg); }
.hdr-btn:focus-visible {
  outline: 2px solid var(--header-ring);
  outline-offset: 2px;
}
.hdr-btn-icon { width: 36px; padding: 0; }
.hdr-gear { transition: transform 0.3s ease; }
.hdr-btn-icon:hover .hdr-gear { transform: rotate(45deg); }

/* Signed-in user. The avatar is the one warm accent on an otherwise
   white-on-dark bar, so it reads as the personal corner of the app. */
.hdr-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 36px;
  padding: 0 0.625rem 0 0.3125rem;
  background: var(--header-ghost);
  border: 1px solid var(--header-ghost-border);
  border-radius: var(--radius-btn);
}
.hdr-user[hidden] { display: none; }
.hdr-user-avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1;
}
.hdr-user-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--header-fg);
  max-width: 12rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  padding: 0.4rem 0.7rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn-secondary:hover { background: var(--surface-hover); }
/* display:inline-flex above would otherwise beat the browser's [hidden] rule. */
.btn-secondary[hidden] { display: none; }

/* ---- Sidebar ------------------------------------------------------------ */
.app-body { flex: 1; display: flex; min-height: 0; }
.main-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative; /* anchors .jump-latest */
}
.sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.8rem 0.6rem;
  background: var(--surface-muted);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.new-chat { justify-content: center; }
.chat-search {
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
}
.chat-search:focus { outline: 2px solid var(--accent-ring); border-color: var(--accent); }
.chat-list { display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  cursor: pointer;
}
.chat-item:hover { background: var(--surface-hover); }
.chat-item.active { background: var(--accent-soft); border-color: var(--accent-soft-border); }
.chat-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  color: var(--text);
}
.chat-item-time { flex-shrink: 0; font-size: 0.6875rem; color: var(--text-subtle); }
.chat-item-action {
  display: none;
  padding: 2px;
  line-height: 0;
  font-size: 0.8125rem;
  color: var(--text-subtle);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.chat-item:hover .chat-item-action { display: block; }
.chat-item-action:hover { color: var(--text); background: var(--surface-hover); }
.chat-item-rename {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.8125rem;
  padding: 1px 4px;
  border: 1px solid var(--accent);
  border-radius: 4px;
}
.chat-list-empty { padding: 0.4rem 0.55rem; font-size: 0.8125rem; color: var(--text-subtle); }

/* ---- Transcript -------------------------------------------------------- */
#chat {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.5rem var(--gutter);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
/* Transcript items must never be squeezed when the log overflows — children
   with overflow:hidden (the tool chips) would otherwise collapse vertically. */
#chat > * { flex-shrink: 0; }
#chat::-webkit-scrollbar { width: 8px; }
#chat::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
}
#chat::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.bubble {
  border-radius: var(--radius-card);
  padding: 0.7rem 0.95rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: fade 0.12s ease-out;
}
.bubble.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  color: var(--text);
}
.bubble.assistant {
  align-self: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  color: var(--text);
  /* Assistant text is rendered markdown, not preformatted text. */
  white-space: normal;
}

/* Markdown inside assistant bubbles */
.bubble.assistant p { margin: 0.55em 0; }
.bubble.assistant > :first-child { margin-top: 0.1em; }
.bubble.assistant > :last-child { margin-bottom: 0.1em; }
.bubble.assistant h1,
.bubble.assistant h2,
.bubble.assistant h3,
.bubble.assistant h4,
.bubble.assistant h5,
.bubble.assistant h6 {
  margin: 1em 0 0.35em;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.bubble.assistant h1 { font-size: 1.0625rem; }
.bubble.assistant h2 { font-size: 1rem; }
.bubble.assistant h3 { font-size: 0.9375rem; }
.bubble.assistant h4,
.bubble.assistant h5,
.bubble.assistant h6 { font-size: 0.875rem; }
.bubble.assistant hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0.9em 0;
}
.bubble.assistant ul,
.bubble.assistant ol { margin: 0.45em 0; padding-left: 1.35em; }
.bubble.assistant li { margin: 0.2em 0; }
.bubble.assistant code {
  font-family: var(--font-mono);
  font-size: 0.8125em;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.08em 0.3em;
}
.bubble.assistant pre {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 0.6rem 0.75rem;
  overflow-x: auto;
  margin: 0.55em 0;
}
.bubble.assistant pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.75rem;
}
.bubble.assistant table {
  border-collapse: collapse;
  margin: 0.55em 0;
  display: block;          /* lets wide tables scroll instead of overflowing */
  overflow-x: auto;
  max-width: 100%;
}
.bubble.assistant th,
.bubble.assistant td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  text-align: left;
  font-size: 0.8125rem;
}
.bubble.assistant th { background: var(--surface-muted); font-weight: 600; }
.bubble.assistant blockquote {
  margin: 0.55em 0;
  padding: 0.1rem 0 0.1rem 0.75rem;
  border-left: 2px solid var(--accent);
  color: var(--text-muted);
}
/* While the agent works, the status line below shows progress — hide the
   still-empty answer bubble instead of rendering a blank card. */
.bubble.assistant:empty { display: none; }

/* Agent activity log — a matte muted panel with a teal tick */
.note {
  align-self: stretch;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-muted);
  padding: 0.3rem 0.6rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-btn);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note.error {
  color: var(--danger-text);
  background: var(--danger-soft);
  border-color: var(--danger-soft-border);
  border-left-color: var(--danger);
}

/* Tool calls — a compact chip (chevron · name · argument preview) that sizes
   to its content; click expands it to a full-width panel with the complete
   arguments. Consecutive chips pull together so a run of calls reads as one
   group. */
details.note {
  align-self: flex-start;
  max-width: 100%;
  padding: 0.3rem 0.7rem;
  border-left: 1px solid var(--border);
  white-space: normal;
  text-overflow: clip;
}
details.note[open] { align-self: stretch; }

/* One turn's calls live in a single "Tool usage" group: open while the agent
   works, collapsed to one line when the turn finishes. */
.tool-group-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.45rem;
}
.tool-group-body details.note {
  align-self: stretch;
  background: var(--surface);
}
.tool-group-body details.note pre { background: var(--surface-muted); }
details.note summary {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  cursor: pointer;
  list-style: none;
}
details.note summary::-webkit-details-marker { display: none; }
.tool-chevron {
  flex: none;
  color: var(--accent);
  font-size: 0.9375rem;
  line-height: 1;
  transition: transform 0.15s ease;
}
details.note[open] > summary > .tool-chevron { transform: rotate(90deg); }
.tool-name {
  flex: none;
  color: var(--text);
  font-weight: 600;
}
.tool-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-subtle);
}
details.note pre {
  margin: 0.45rem 0 0.15rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.75rem;
}
.tool-result-label {
  margin-top: 0.55rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-subtle);
}
/* Cap tall results (e.g. a 200-row query) so the chip stays compact. */
.tool-result pre {
  max-height: 18rem;
  overflow-y: auto;
}

/* Live activity indicator — pulsing logo + what the agent is doing now */
.status {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.1rem 0.15rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.status img {
  height: 18px;
  width: auto;
  animation: pulse 1.5s ease-in-out infinite;
}

/* Floating return-to-latest button, shown after scrolling up mid-stream */
.jump-latest {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 8rem; /* refined from the live composer height in chat.js */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(13, 148, 136, 0.35);
  z-index: 5;
  transition: background 0.12s ease;
}
.jump-latest:hover { background: var(--accent-hover); }
/* display:flex above would defeat the hidden attribute without this */
.jump-latest[hidden] { display: none; }

/* ---- Empty state ------------------------------------------------------- */
.empty {
  align-self: stretch;
  margin: auto 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 2rem 0;
}
.empty-lead {
  margin: 0;
  font-size: 1rem;
  color: var(--text-muted);
  max-width: 30rem;
}
.empty-examples { display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start; }
.example {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.example::before { content: "\2192\00a0\00a0"; color: var(--accent); }
.example:hover { background: var(--accent-soft); border-color: var(--accent-soft-border); }

/* ---- Composer ---------------------------------------------------------- */
.composer {
  padding: 0.9rem var(--gutter) 0.8rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
#chat-form { display: flex; gap: 0.6rem; align-items: stretch; }
.composer-actions {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.45rem;
}
.composer-actions .btn-secondary { justify-content: center; }
.composer-actions #send { width: 100%; }
#message {
  flex: 1;
  resize: none;
  padding: 0.55rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
#message::placeholder { color: var(--text-subtle); }
#message:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
#send {
  padding: 0 1.1rem;
  height: 2.5rem;
  border: 0;
  border-radius: var(--radius-btn);
  background: var(--accent);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background 0.12s ease;
}
#send:hover:not(:disabled) { background: var(--accent-hover); }
#send:active:not(:disabled) { background: var(--accent-active); }
#send:disabled { opacity: 0.5; cursor: default; }
.composer-hint {
  margin: 0.5rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-subtle);
  text-align: right;
}

/* ---- Focus, motion, mobile -------------------------------------------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#message:focus-visible { outline: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.88); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* The user chip is the first thing to go, as in the PoS bar: the wordmark and
   the way out to the portal matter more on a narrow screen than whose name it is. */
@media (max-width: 640px) {
  .hdr-user { display: none; }
}

@media (max-width: 520px) {
  .btn-secondary span { display: none; }
  .app-header-inner { padding: 0.75rem 1rem; }
  #send { padding: 0 0.9rem; }
}

/* ---- Settings dialog ---------------------------------------------------- */
#settings {
  width: min(31rem, calc(100vw - 2.5rem));
  max-height: min(42rem, calc(100vh - 2.5rem));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-modal);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1);
}
#settings::backdrop { background: rgba(17, 24, 39, 0.35); }

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem 0.55rem;
}
.settings-head h2 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.settings-close {
  display: flex;
  padding: 0.3rem;
  border: 0;
  border-radius: var(--radius-btn);
  background: none;
  color: var(--text-subtle);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.settings-close:hover { background: var(--surface-hover); color: var(--text); }

.settings-tabs {
  display: flex;
  gap: 1rem;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--border);
}
.settings-tab {
  padding: 0.45rem 0.1rem;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1rem 1.1rem 1.1rem;
  overflow-y: auto;
}
/* Author styles override the browser's default [hidden] rule. Keep inactive
   tab panels out of layout even though active panels use display:flex. */
.settings-panel[hidden] { display: none; }

.usage-totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin: 0;
}
.usage-totals > div {
  padding: 0.55rem 0.75rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
}
.usage-totals dt {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}
.usage-totals dd {
  margin: 0.15rem 0 0;
  font-family: var(--font-mono);
  font-size: 1.0625rem;
  font-weight: 600;
}

.price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.price-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}
.price-unit {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 400;
  color: var(--text-subtle);
}
.price-grid input {
  padding: 0.45rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.price-grid input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.cost-lines {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
}
.cost-lines > div {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.cost-lines dd { margin: 0; font-family: var(--font-mono); color: var(--text); }
.cost-lines .total {
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
  font-weight: 600;
  color: var(--text);
}
.cost-lines .total dd { font-weight: 600; }

.settings-foot {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
}
.settings-hint {
  margin: 0;
  font-size: 0.6875rem;
  line-height: 1.5;
  color: var(--text-subtle);
}

/* --- Agent memory settings -------------------------------------------- */
.memory-intro {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.memory-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
}
.memory-form > label,
.memory-form-row label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}
.memory-form textarea,
.memory-form select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
}
.memory-form textarea { resize: vertical; min-height: 4.5rem; }
.memory-form textarea:focus,
.memory-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.memory-form-row {
  display: grid;
  grid-template-columns: 1fr 10rem;
  gap: 0.75rem;
  align-items: center;
}
.memory-form-actions { display: flex; gap: 0.5rem; }
.memory-form-actions > button:first-child {
  padding: 0.45rem 0.75rem;
  border: 0;
  border-radius: var(--radius-btn);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.memory-form-actions > button:first-child:disabled { opacity: 0.5; }
.memory-error {
  margin: 0;
  font-size: 0.75rem;
  color: var(--danger-text);
}
.memory-list-head {
  display: flex;
  justify-content: space-between;
  padding-top: 0.2rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}
.memory-count {
  min-width: 1.5rem;
  padding: 0 0.4rem;
  text-align: center;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
}
.memory-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 16rem;
  overflow-y: auto;
}
.memory-card {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
}
.memory-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}
.memory-badge {
  padding: 0.08rem 0.4rem;
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-muted);
  border-radius: var(--radius-pill);
}
.memory-badge.always {
  color: var(--accent-text);
  background: var(--accent-soft);
}
.memory-badges { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
/* Outlined rather than filled, so it stays legible next to the scope badge. */
.memory-badge.shared {
  background: none;
  border: 1px solid var(--border-strong);
}
.memory-card-actions { display: flex; gap: 0.4rem; }
.memory-action {
  padding: 0;
  font: inherit;
  font-size: 0.6875rem;
  color: var(--text-muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.memory-action:hover { color: var(--text); }
.memory-action.danger:hover { color: var(--danger-text); }
.memory-card-content {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* --- Charts (render_chart tool) -------------------------------------- */
.chart-card {
  margin: 0.5rem var(--gutter);
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

/* --- Clarifying questions (ask_user tool) ----------------------------- */
.ask-card {
  margin: 0.5rem var(--gutter);
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--radius-card);
}
.ask-question {
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.ask-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.ask-option {
  padding: 0.35rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--radius-pill);
  color: var(--accent-text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.ask-option:hover {
  background: var(--accent-soft-hover);
}
.ask-card.answered .ask-option {
  opacity: 0.5;
  pointer-events: none;
}
