:root {
  /* ── Color tokens — the single design system (theme switching removed; keep this identity). ──
     The identity is a calm technical instrument: a warm-neutral paper (light)
     with hairline borders and ONE confident petrol-teal accent; a warm charcoal
     for dark. No AI beige, no default purple/blue, no rainbow glow.

     The OS scheme preference (prefers-color-scheme) is a USER preference, not a
     theme switcher: each token is declared twice — first the light value as a
     fallback for engines without light-dark(), then the same token with
     light-dark(<light>, <dark>) so Chrome ≥123 resolves both schemes from one
     definition. `color-scheme: light dark` also flips UA widgets (scrollbars,
     form controls) with the same preference. No toggle UI exists; the media
     state applies instantly with no flash. ── */
  color-scheme: light dark;
  scrollbar-gutter: stable;
  /* Light fallbacks FIRST (engines without light-dark(); dropped where the
     light-dark() declarations below parse). Keep in sync with the light half. */
  --bg: #f7f6f3;
  --panel: #ffffff;
  --panel-2: #efede8;
  --border: #e3e0d9;
  --text: #1d1b18;
  --muted: #635e56;
  --accent: #0e6e63;
  --accent-hover: #0a5c53;
  --accent2: #b45309;
  --usage-in: #0e6e63;
  --usage-out: #b45309;
  --danger: #b3261e;
  --success: #1a7f37;
  --warning: #9a6700;
  --btn-fg: #ffffff;
  --on-accent-muted: #d7f0ea;
  --shadow-1: 0 1px 2px rgba(29, 27, 24, 0.05);
  --shadow-2: 0 1px 2px rgba(29, 27, 24, 0.05), 0 12px 32px rgba(29, 27, 24, 0.07);

  /* The same tokens with light-dark(<light>, <dark>) — both schemes from ONE
     definition; these win wherever light-dark() is supported. */
  --bg: light-dark(#f7f6f3, #1a1815);
  --panel: light-dark(#ffffff, #23211d);
  --panel-2: light-dark(#efede8, #2b2823);
  --border: light-dark(#e3e0d9, #6b6355);
  --text: light-dark(#1d1b18, #eae6de);
  --muted: light-dark(#635e56, #a8a195);
  --accent: light-dark(#0e6e63, #53b8a9);
  --accent-hover: light-dark(#0a5c53, #67c7b9);
  --accent2: light-dark(#b45309, #d98831);
  --usage-in: light-dark(#0e6e63, #53b8a9);
  --usage-out: light-dark(#b45309, #d98831);
  --danger: light-dark(#b3261e, #e5675f);
  --success: light-dark(#1a7f37, #58b877);
  --warning: light-dark(#9a6700, #d9a03c);
  --btn-fg: light-dark(#ffffff, #101b18);
  --on-accent-muted: light-dark(#d7f0ea, #0f2f2a);
  --shadow-1: 0 1px 2px light-dark(rgba(29, 27, 24, 0.05), rgba(0, 0, 0, 0.45));
  --shadow-2: 0 1px 2px light-dark(rgba(29, 27, 24, 0.05), rgba(0, 0, 0, 0.45)),
    0 12px 32px light-dark(rgba(29, 27, 24, 0.07), rgba(0, 0, 0, 0.5));

  /* Aliases: components historically spell "ink on accent" three ways
     (--accent-contrast, --on-accent, --accent-ink). Route them all through
     --btn-fg so the dark scheme flips them together. */
  --accent-contrast: var(--btn-fg);
  --on-accent: var(--btn-fg);
  --accent-ink: var(--btn-fg);

  /* Legacy spellings some components predate: route them to their semantic
     twin so every surface resolves scheme-aware ink/surfaces. */
  --ink: var(--text);
  --fg: var(--text);
  --secondary-layer: var(--panel-2);
  --warn: var(--warning);
  --bg-subtle: var(--panel-2);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* ── Content layout (consistent width & gutters across hub views) ── */
  --content-max: 1040px;
  --content-gutter: clamp(16px, 4vw, 40px);

  /* ── Spacing scale (8px grid) ── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-8: 48px;

  /* ── Radius scale ── */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* ── Control sizing (consistent hit targets) ── */
  --control: 36px;
  --control-icon: 18px;
  --input-h: 36px;

  /* ── Type scale (tighter ratio, workhorse sans) ── */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 24px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--text-base)/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  accent-color: var(--accent);
  caret-color: var(--accent);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* ── Browser surfaces carry the design too ── */
::selection { background: var(--accent); color: var(--btn-fg); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 2px solid var(--bg);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Buttons ── */
.btn {
  background: var(--accent);
  color: var(--btn-fg);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 14px;
  height: var(--input-h);
  font-weight: 600;
  font: inherit;
  cursor: pointer;
  transition: background 150ms ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); background: transparent; }

/* Consistent icon-button scale (mic, +, and any icon action across surfaces). */
.icon-btn {
  width: var(--control);
  height: var(--control);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  flex: 0 0 auto;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn svg { width: var(--control-icon); height: var(--control-icon); display: block; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: var(--text-sm);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color 150ms ease;
}
.chip:hover { border-color: var(--accent); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent2); }

.tag {
  font-size: var(--text-xs);
  color: var(--muted);
  font-weight: 500;
}

/* ── Shared layout/utility tokens ── */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.section-head h2 { margin: 0; font-size: var(--text-lg); font-weight: 600; }
.link {
  font-size: var(--text-sm);
  color: var(--muted);
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
}
.link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.muted { color: var(--muted); }

/* A compact switch (background-agent enable/disable toggle). */
.switch {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
  transition: background 150ms ease, border-color 150ms ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 150ms ease, background 150ms ease;
}
.switch[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-pressed="true"]::after { transform: translateX(16px); background: var(--btn-fg); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The "thinking" state: a calm single-accent ring (replaces the rainbow glow). */
.glow { position: relative; }
.glow::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--on-accent-muted);
  animation: glow-pulse 1.6s ease-in-out infinite;
  z-index: -1;
}
@keyframes glow-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
  .glow::before { animation: none; }
  .switch, .switch::after { transition: none; }
  .btn, .icon-btn, .chip { transition: none; }
}

/* ── Theme variants ──
   The default (above) is "paper": a warm-neutral light with a petrol-teal
   accent. Each theme restyles the same custom properties. */

/* ── Accessibility utility ──
   Visually-hidden but screen-reader-available (UX-AUDIT-2026-08-28 UX-007:
   surfaces whose design has no visible page title still need an h1). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* ── Shared MCP-server UI (CAP-FB-20260831-MCP-AGENT-UI-01) ──────────────────
   The add/edit MCP-server editor + server rows are one shared control
   (lib/mcp-server-editor.js), used by the GLOBAL "MCP servers" section in
   Settings and the PER-AGENT section in the agent create/edit dialog. These
   rules live here (theme.css, loaded by both surfaces) so the two never drift.
   Also the small form primitives the editor relies on (.field, .test-status). */
.field { display: grid; gap: 0.25rem; }
.field-label { font-size: var(--text-xs); color: var(--muted); }
.test-status { margin-top: 8px; font-size: var(--text-xs); display: flex; align-items: center; gap: 6px; }
.test-status.testing { color: var(--muted); }
.test-status.ok { color: var(--success, #0e6e63); }
.test-status.err { color: var(--danger, #b3261e); }
.mcp-toolbar { display: flex; gap: var(--space-2); margin: var(--space-2) 0 var(--space-3); }
.mcp-server-list { display: grid; gap: var(--space-2); }
.mcp-empty { padding: var(--space-4); border: 1px dashed var(--border); border-radius: var(--radius-md); margin: 0; }
.mcp-server-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); background: var(--bg); }
.mcp-server-card.is-disabled { opacity: 0.6; }
.mcp-server-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.mcp-server-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mcp-server-name { font-weight: 600; }
.mcp-server-tag { font-weight: 600; font-size: 10px; letter-spacing: 0.02em; text-transform: uppercase; padding: 1px 6px; border-radius: var(--radius-sm); border: 1px solid var(--border); color: var(--muted); }
.mcp-server-meta { display: flex; align-items: center; gap: 8px; font-size: var(--text-xs); min-width: 0; }
.mcp-server-url { text-overflow: ellipsis; white-space: nowrap; overflow-x: auto; }
.mcp-badge { flex: 0 0 auto; font-size: 10px; font-weight: 600; letter-spacing: 0.02em; padding: 1px 6px; border-radius: var(--radius-sm); border: 1px solid var(--border); color: var(--muted); }
.mcp-server-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.mcp-remove { color: var(--danger, #b3261e); }
.mcp-editor { border: 1px solid var(--accent); border-radius: var(--radius-md); padding: var(--space-4); background: var(--panel); margin-bottom: var(--space-3); }
.mcp-editor-title { margin: 0 0 var(--space-3); font-size: var(--text-sm); }
.mcp-editor-hint { margin: 0 0 var(--space-3); font-size: var(--text-xs); color: var(--muted); }
.mcp-editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mcp-editor-grid input, .mcp-editor-grid select { width: 100%; }
.mcp-editor .test-status { margin-top: var(--space-3); }
.mcp-editor-actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; }
@media (max-width: 640px) {
  .mcp-editor-grid { grid-template-columns: 1fr; }
}
