/* =============================================================
   DESIGN TOKENS — Jeen Style Guide
   Sourced from @jeenai-team/jeen-ui (JeenAI-Team/jeen-storybook).
   Existing --color-* names are kept so the rest of the stylesheet
   inherits the system. Primary CTAs are ink; --color-accent is the
   client theme secondary (magenta) used for links and selection.
   ============================================================= */

:root,
[data-theme="light"] {
  --color-bg:         #f9fafb;
  --color-surface:    #ffffff;
  --color-surface-2:  #efeff0;
  --color-surface-3:  #e5e7eb;
  --color-border:     #d2d3d4;
  --color-border-2:   #7f8084;
  --color-text:       #030712;
  --color-muted:      #7f8084;
  --color-faint:      #7f8084;
  --color-subtle:     #4b4d53;
  --color-ink-soft:   #1e2026;
  --color-accent:     #9e257f;
  --color-accent-2:   #7a1d63;
  --color-accent-fg:  #ffffff;
  --color-accent-muted: #9e257f1a;
  --color-brand:      #7a7afe;
  --color-success:    #38a169;
  --color-success-bg: #38a1691a;
  --color-error:      #e53e3e;
  --color-error-bg:   #e53e3e1a;
  --color-warning:    #dd6b20;
  --color-warning-bg: #dd6b201a;
  --shadow-xs:    2px 4px 6px 0px rgba(30, 32, 38, 0.12);
  --shadow-sm:    2px 4px 6px 0px rgba(30, 32, 38, 0.18);
  --shadow-md:    2px 4px 10px 0px rgba(30, 32, 38, 0.22);
  --shadow-lg:    2px 4px 15px 0px rgba(30, 32, 38, 0.28);
  --shadow-focus: 0 0 0 4px rgba(149, 146, 158, 0.15);
  --shadow-focus-selected: 0 0 0 4px rgba(79, 106, 245, 0.15);
  --code-bg:   #efeff0;
  --code-text: #030712;
  --color-bg-tertiary: #f9fafb;
  --color-dim-bg:  #9e257f1a;
  --color-dim-text: #9e257f;
  --color-overlay: rgba(3, 7, 18, 0.4);
  --btn-primary-bg:     #1e2026;
  --btn-primary-hover:  #4b4d53;
  --btn-primary-active: #030712;
  --btn-primary-fg:     #ffffff;
  --btn-primary-disabled: #d2d3d4;
  --font-sans: 'Urbanist', 'Noto Sans Hebrew', system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Monaco, Consolas, monospace;
  --text-xs:   12px;
  --text-sm:   12px;
  --text-base: 14px;
  --text-md:   16px;
  --text-lg:   18px;
  --text-xl:   24px;
  --text-2xl:  32px;
  --text-3xl:  48px;
  --weight-normal:   400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-6:  24px;
  --space-8:  32px;
  --space-12: 48px;
  --space-16: 64px;
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-pill: 24px;
  --radius-full: 9999px;
  --topbar-bg: rgba(255, 255, 255, 0.88);
  --line-height: 1.2;
}

[data-theme="dark"] {
  --color-bg:         #030712;
  --color-surface:    #1e2026;
  --color-surface-2:  #2a2c33;
  --color-surface-3:  #4b4d53;
  --color-border:     #4b4d53;
  --color-border-2:   #7f8084;
  --color-text:       #ffffff;
  --color-muted:      #7f8084;
  --color-faint:      #7f8084;
  --color-subtle:     #d2d3d4;
  --color-ink-soft:   #efeff0;
  --color-accent:     #c44da3;
  --color-accent-2:   #e8a8d4;
  --color-accent-fg:  #ffffff;
  --color-accent-muted: #9e257f33;
  --color-brand:      #7a7afe;
  --color-success:    #38a169;
  --color-success-bg: #38a16933;
  --color-error:      #e53e3e;
  --color-error-bg:   #e53e3e33;
  --color-warning:    #dd6b20;
  --color-warning-bg: #dd6b2033;
  --shadow-xs:    2px 4px 6px 0px rgba(3, 7, 18, 0.18);
  --shadow-sm:    2px 4px 6px 0px rgba(3, 7, 18, 0.32);
  --shadow-md:    2px 4px 10px 0px rgba(3, 7, 18, 0.48);
  --shadow-lg:    2px 4px 12px 0px rgba(3, 7, 18, 0.64);
  --shadow-focus: 0 0 0 4px rgba(149, 146, 158, 0.25);
  --shadow-focus-selected: 0 0 0 4px rgba(79, 106, 245, 0.25);
  --code-bg:   #2a2c33;
  --code-text: #ffffff;
  --color-bg-tertiary: #030712;
  --color-dim-bg:  #9e257f33;
  --color-dim-text: #e8a8d4;
  --color-overlay: rgba(3, 7, 18, 0.6);
  --btn-primary-bg:     #ffffff;
  --btn-primary-hover:  #efeff0;
  --btn-primary-active: #d2d3d4;
  --btn-primary-fg:     #030712;
  --btn-primary-disabled: #4b4d53;
  --topbar-bg: rgba(3, 7, 18, 0.88);
}

/* =============================================================
   GLOBAL RESET + THEME TRANSITIONS
   ============================================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 200ms ease, border-color 200ms ease,
              color 200ms ease, box-shadow 200ms ease;
}

.no-transitions *, .no-transitions *::before, .no-transitions *::after {
  transition: none !important;
}

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-weight: var(--weight-medium);
  line-height: var(--line-height, 1.2);
  letter-spacing: 0;
  color: var(--color-text);
}

code, pre, .mono { font-family: var(--font-mono); font-size: var(--text-sm); }

:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* =============================================================
   APP LAYOUT
   ============================================================= */

/* Lock the shell to exactly one viewport tall so the sidebar + main area each
   scroll internally instead of growing the whole page past one screen. */
.app-layout { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 100;
  height: 48px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar-brand { display: flex; align-items: center; gap: var(--space-2); }

.topbar-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.topbar-logo {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: block;
}

.topbar-title {
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  letter-spacing: 0;
}

.topbar-subtitle {
  font-size: var(--text-sm); color: var(--color-faint);
  margin-inline-start: var(--space-2); display: none;
}
@media (min-width: 640px) { .topbar-subtitle { display: inline; } }

.topbar-actions { display: flex; align-items: center; gap: var(--space-2); }

.layout-body { display: flex; flex: 1; overflow: hidden; position: relative; }

.sidebar {
  width: 240px; flex-shrink: 0;
  border-inline-end: 1px solid var(--color-border);
  background: var(--color-surface);
  overflow: hidden; /* pane handles its own scroll */
  display: flex; flex-direction: column;
  transition: width 250ms ease;
}

.sidebar.collapsed { width: 56px; overflow: hidden; }

.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .sidebar-section-content,
.sidebar.collapsed .info-card,
.sidebar.collapsed .sidebar-tabs,
.sidebar.collapsed .sidebar-tab-pane { opacity: 0; pointer-events: none; }

.main-content {
  flex: 1; min-width: 0; overflow-y: auto;
  padding: var(--space-6);
  background: var(--color-bg-tertiary);
}

.main-inner {
  width: 100%;           /* fills the available .main-content width    */
  margin-inline: auto;   /* keeps content centred on ultra-wide screens */
  display: flex; flex-direction: column; gap: var(--space-4);
}

.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: var(--color-overlay);
}
.sidebar-overlay.active { display: block; }

/* =============================================================
   BUTTONS
   ============================================================= */

button {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2); height: 36px; padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  font-family: var(--font-sans); font-size: var(--text-base);
  font-weight: var(--weight-medium);
  cursor: pointer; white-space: nowrap; border: none;
}

button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.btn-primary {
  background: var(--btn-primary-bg); color: var(--btn-primary-fg); border: none;
  height: 40px; padding: 8px 16px;
  font-size: var(--text-base); font-weight: var(--weight-medium); width: 100%;
}
.btn-primary:hover { background: var(--btn-primary-hover); }
.btn-primary:active { background: var(--btn-primary-active); }

.btn-secondary, .export-button, .copy-results-button, .describe-button {
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover, .export-button:hover,
.copy-results-button:hover, .describe-button:hover {
  background: var(--color-surface-2);
  border-color: var(--color-muted);
}

.btn-ghost, .copy-button, .toggle-prompt-button {
  background: transparent; color: var(--color-muted); border: none;
}
.btn-ghost:hover, .copy-button:hover, .toggle-prompt-button:hover {
  background: var(--color-surface-2); color: var(--color-text);
}

.btn-destructive, .clear-history-btn {
  background: transparent; color: var(--color-error);
  border: 1px solid var(--color-error); width: 100%; font-size: var(--text-sm);
}
.clear-history-btn:hover { background: var(--color-error-bg); }

.btn-icon, .sidebar-toggle-btn, .theme-toggle {
  width: 32px; height: 32px; padding: 0;
  border-radius: var(--radius-pill); background: transparent; border: none;
  color: var(--color-muted); display: flex;
  align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.btn-icon:hover, .sidebar-toggle-btn:hover, .theme-toggle:hover {
  background: var(--color-surface-2); color: var(--color-text);
}

.theme-icon {
  display: flex; align-items: center; justify-content: center;
  transition: transform 200ms ease, opacity 200ms ease;
}
.theme-toggling .theme-icon { transform: rotate(180deg); opacity: 0; }

.btn-loading { opacity: 0.75; cursor: wait; pointer-events: none; }
.btn-loading::after {
  content: ''; width: 14px; height: 14px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite; margin-inline-start: var(--space-2);
}

.info-card > button:not(.clear-history-btn) {
  width: 100%; background: var(--btn-primary-bg); color: var(--btn-primary-fg);
  border: none; margin-bottom: var(--space-3);
}
.info-card > button:not(.clear-history-btn):hover { background: var(--btn-primary-hover); }

.profile-generate-btn {
  background: var(--btn-primary-bg); color: var(--btn-primary-fg); border: none;
  height: 40px; padding: 0 var(--space-4); font-size: var(--text-base);
  margin-top: var(--space-3); border-radius: var(--radius-pill); cursor: pointer;
}
.profile-generate-btn:hover { background: var(--btn-primary-hover); }

.profile-switch-btn {
  background: transparent; color: var(--color-accent);
  border: 1px solid var(--color-accent); padding: 0 var(--space-3);
  height: 32px; font-size: var(--text-sm);
}
.profile-switch-btn:hover { background: var(--color-accent); color: var(--color-accent-fg); }

.profile-download-btn {
  background: var(--color-success-bg); color: var(--color-success);
  border: 1px solid var(--color-success); height: 32px; font-size: var(--text-sm);
}
.profile-download-btn:hover { background: var(--color-success); color: var(--color-accent-fg); }

.profile-retry-btn {
  background: var(--color-warning-bg); color: var(--color-warning);
  border: 1px solid var(--color-warning); border-radius: var(--radius-md);
  height: 36px; padding: 0 var(--space-4); cursor: pointer;
  font-family: var(--font-sans); margin-top: var(--space-3);
}
.profile-retry-btn:hover { background: var(--color-warning); color: var(--color-accent-fg); }

.enhance-chart-btn {
  background: var(--btn-primary-bg); color: var(--btn-primary-fg); border: none;
  height: 36px; padding: 0 var(--space-4); border-radius: var(--radius-pill);
  font-weight: var(--weight-medium); cursor: pointer; font-family: var(--font-sans);
  display: flex; align-items: center; gap: var(--space-2);
}
.enhance-chart-btn:hover:not(:disabled) { background: var(--btn-primary-hover); }
.enhance-chart-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.button-spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3); border-top-color: var(--btn-primary-fg);
  border-radius: var(--radius-full); animation: spin 0.8s linear infinite;
}

/* =============================================================
   INPUTS
   ============================================================= */

textarea, input[type="text"], select {
  width: 100%; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-base); color: var(--color-text);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
input[type="text"], select {
  height: 40px; padding: 0 var(--space-3);
}
select { height: 36px; cursor: pointer; }
textarea {
  padding: var(--space-3); resize: vertical;
  line-height: 1.5; min-height: 80px;
}
textarea::placeholder, input[type="text"]::placeholder { color: var(--color-muted); }
textarea:hover, input[type="text"]:hover { border-color: var(--color-muted); }
textarea:focus, input[type="text"]:focus, select:focus {
  outline: none; border-color: var(--color-text); box-shadow: var(--shadow-focus);
}
label {
  display: block; font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--color-muted); margin-bottom: var(--space-2);
}
.result-filter-input, .table-search-input {
  height: 36px; padding: 0 var(--space-3); font-size: var(--text-sm);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); color: var(--color-text);
  width: 100%; margin-bottom: var(--space-2);
}
.result-filter-input:focus, .table-search-input:focus {
  outline: none; border-color: var(--color-text); box-shadow: var(--shadow-focus);
}

/* =============================================================
   CARDS
   ============================================================= */

.card, .result-card, .query-section {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-sm);
}
.result-card { padding: var(--space-4); border-radius: var(--radius-md); box-shadow: none; }
.result-card h2 { font-size: var(--text-md); margin-bottom: var(--space-3); }

[data-theme="dark"] .card-glass {
  background: color-mix(in srgb, var(--color-surface) 70%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
[data-theme="light"] .card-glass { background: var(--color-surface); box-shadow: var(--shadow-md); }

.info-card {
  background: transparent; padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.info-card h3 {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--color-faint); text-transform: uppercase;
  letter-spacing: 0.08em; margin-bottom: var(--space-3);
}

/* =============================================================
   QUERY SECTION
   ============================================================= */

.input-group { display: flex; flex-direction: column; gap: var(--space-3); }

/* =============================================================
   SKELETON LOADING
   ============================================================= */

.skeleton {
  border-radius: var(--radius-md);
  background: linear-gradient(90deg,
    var(--color-surface-2) 25%, var(--color-surface-3) 50%, var(--color-surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.loading {
  padding: var(--space-4) 0; display: flex;
  flex-direction: column; gap: var(--space-3);
}

.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--color-border-2); border-top-color: var(--color-accent);
  border-radius: var(--radius-full); animation: spin 0.6s linear infinite; flex-shrink: 0;
}

/* =============================================================
   ERROR STATES
   ============================================================= */

.error-message, .error-inline {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-error-bg);
  border-inline-start: 3px solid var(--color-error);
  border-start-start-radius: 0; border-end-start-radius: 0; border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md);
  color: var(--color-error); font-size: var(--text-base); margin-top: var(--space-3);
  max-width: 100%;
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* =============================================================
   RESULTS
   ============================================================= */

.results-section { display: flex; flex-direction: column; gap: var(--space-4); margin-top: var(--space-4); }
.question-display { font-size: var(--text-md); color: var(--color-muted); font-style: italic; }
.results-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.results-display { overflow-x: auto; }
.results-display table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.results-display thead th {
  position: sticky; top: 0; padding: var(--space-2) var(--space-4);
  background: var(--color-surface-2); border-bottom: 1px solid var(--color-border-2);
  /* Spec: uppercase + letter-spaced + muted, sticky */
  font-weight: var(--weight-semibold); color: var(--color-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: start; white-space: nowrap; cursor: pointer;
}
.results-display thead th:hover { background: var(--color-surface-3); }
.results-display tbody tr { border-bottom: 1px solid var(--color-border); transition: background 100ms ease; }
.results-display tbody tr:nth-child(even) { background: var(--color-surface-2); }
.results-display tbody tr:hover { background: var(--color-surface-3); }
.results-display tbody td { padding: var(--space-3) var(--space-4); color: var(--color-text); vertical-align: middle; }
.results-display tbody td:not(.num-cell):not(.cell-id) {
  max-width: 48ch;
  white-space: normal;
  overflow-wrap: anywhere;
}
.no-results { text-align: center; padding: var(--space-12) var(--space-6); color: var(--color-muted); font-style: italic; }

/* ── Display-limit bar (row window control below the table) ──────────────── */
/* Shows "Showing [25] of 487 rows · Show all · 5%" */
.display-limit-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0 var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-muted);
  flex-wrap: wrap;
}
.dlb-label { white-space: nowrap; }
/* Number input — hide spin arrows, keep it compact */
.dlb-input {
  width: 58px;
  height: 26px;
  padding: 0 var(--space-2);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  text-align: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  -moz-appearance: textfield;
}
.dlb-input::-webkit-outer-spin-button,
.dlb-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.dlb-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
/* "Show all" button */
.dlb-show-all {
  height: 26px; padding: 0 var(--space-3);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  background: transparent;
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}
.dlb-show-all:hover { background: var(--color-dim-bg); }
/* Percentage badge */
.dlb-pct {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-faint);
  user-select: none;
}

/* ── Table cell: null → faint em-dash ─────────────────────────────────────── */
/* Aligned with the numeric rail so the grid stays calm. */
.cell-null {
  color: var(--color-faint);
  font-style: normal;
  user-select: none;
}

/* ── Table cell: ID columns → mono + faint ────────────────────────────────── */
/* IDs are identity, not data. Keep them unobtrusive. */
td.cell-id {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-faint);
  letter-spacing: 0;
}

/* ── Table cell: signed delta columns → direction color ───────────────────── */
/* The ONLY numeric cells that get color — change/YoY/variance columns only. */
.cell-delta-pos {
  color: var(--color-success);
  font-weight: var(--weight-medium);
}
.cell-delta-neg {
  color: var(--color-error);
  font-weight: var(--weight-medium);
}
/* ── Trace panel ──────────────────────────────────────────────────────────── */
.trace-panel {
    padding: 8px 0;
    font-size: var(--text-sm);
}
.trace-empty {
    color: var(--color-faint);
    padding: 24px 0;
    text-align: center;
    font-size: var(--text-sm);
}
.trace-summary {
    display: flex;
    gap: 12px;
    padding: 8px 0 12px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 12px;
    font-size: var(--text-xs);
    color: var(--color-muted);
    flex-wrap: wrap;
}
.trace-summary-chip {
    background: var(--color-surface-2);
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    white-space: nowrap;
}
.trace-event {
    display: grid;
    grid-template-columns: 8px 18px 160px 1fr 60px;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid var(--color-border-2);
    cursor: pointer;
    user-select: none;
}
.trace-event:last-child { border-bottom: none; }
.trace-event:hover { background: var(--color-surface-2); border-radius: var(--radius-sm); }
.trace-event-icon { font-size: 13px; text-align: center; }
.trace-event-name {
    font-family: var(--font-sans);
    font-size: 12px;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.trace-event-bar-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
}
.trace-event-bar {
    height: 6px;
    border-radius: 3px;
    min-width: 2px;
    flex-shrink: 0;
    background: var(--color-border-2);
    transition: width 0.2s;
}
.trace-event-bar[data-ntype="llm"]   { background: var(--color-accent); }
.trace-event-bar[data-ntype="db"]    { background: var(--color-success); }
.trace-event-bar[data-ntype="logic"] { background: var(--color-border-2); }
.trace-event-detail {
    font-size: 11px;
    color: var(--color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.trace-event-status[data-status="error"]   { color: var(--color-error); }
.trace-event-status[data-status="blocked"] { color: var(--color-warning); }
.trace-event-status[data-status="retry"]   { color: var(--color-warning); }
.trace-event-ms {
  font-size: 10px;
  color: var(--color-faint);
  text-align: end;
  font-family: var(--font-mono);
  white-space: nowrap;
}
/* Slowest pipeline step — flagged with a badge + bold name. */
.trace-slowest-badge {
  flex: none;
  font-size: 9px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: var(--radius-full);
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid var(--color-error);
  white-space: nowrap;
}
.trace-event-slowest .trace-event-name { font-weight: var(--weight-semibold); }
.trace-event-slowest .trace-event-ms   { color: var(--color-error); font-weight: var(--weight-semibold); }
/* Occurrence ordinal for steps that ran more than once (e.g. retries). */
.trace-event-count {
  flex: none;
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: var(--weight-semibold);
  padding: 1px 5px;
  border-radius: var(--radius-full);
  background: var(--color-surface-3);
  color: var(--color-muted);
  white-space: nowrap;
}
.trace-event-expanded {
    grid-column: 3 / -1;
    background: var(--color-surface-2);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    margin: 2px 0 6px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--color-text);
    word-break: break-all;
    white-space: pre-wrap;
    display: none;
}
.trace-event.is-open .trace-event-expanded { display: block; }

.trace-prompt-label {
  font-size: 10px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  margin-top: 8px;
  margin-bottom: 4px;
}
.trace-prompt-pre {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  max-height: 280px;
  margin: 0;
}

.llm-text-answer {
  padding: var(--space-4) var(--space-6);
  color: var(--color-text); font-size: var(--text-base); line-height: 1.7;
  background: var(--color-surface-2); border-radius: var(--radius-md);
  border-inline-start: 3px solid var(--color-accent);
  white-space: pre-wrap; word-wrap: break-word;
}
.table-controls { margin-bottom: var(--space-3); }

/* =============================================================
   SQL / CODE DISPLAY
   ============================================================= */

.sql-editor-wrapper {
  position: relative; border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); overflow: hidden; background: var(--code-bg);
}
.sql-copy-btn {
  position: absolute; top: var(--space-2); inset-inline-end: var(--space-2); z-index: 10;
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); height: 28px; padding: 0 var(--space-2);
  font-size: var(--text-xs); color: var(--color-muted); cursor: pointer;
  display: flex; align-items: center; gap: var(--space-1); font-family: var(--font-sans);
}
.sql-copy-btn:hover { background: var(--color-surface-3); color: var(--color-text); }
#sql-editor { min-height: 100px; }
.cm-editor {
  background: var(--code-bg) !important;
  font-family: var(--font-mono) !important;
  font-size: var(--text-sm) !important;
  max-height: 400px; overflow-y: auto;
}
.cm-gutters {
  background: var(--code-bg) !important;
  border-inline-end: 1px solid var(--color-border) !important;
  color: var(--color-faint) !important;
}
.sql-display {
  background: var(--code-bg); color: var(--code-text);
  padding: var(--space-4); border-radius: var(--radius-md);
  overflow-x: auto; font-family: var(--font-mono);
  font-size: var(--text-sm); line-height: 1.5; margin-bottom: var(--space-2);
  border: 1px solid var(--color-border);
}

/* =============================================================
   TABS
   ============================================================= */

.prompt-tabs {
  display: flex; gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--space-4); overflow-x: auto;
}
.prompt-tab {
  padding: var(--space-2) var(--space-4); background: transparent;
  border: none; border-bottom: 3px solid transparent;
  cursor: pointer; font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--color-muted); height: auto; white-space: nowrap;
  position: relative; bottom: -2px;
}
.prompt-tab:hover { background: var(--color-surface-2); color: var(--color-text); }
.prompt-tab.active { color: var(--color-accent); border-bottom-color: var(--color-accent); background: transparent; }
.prompt-tab-content { min-height: 200px; }
.tab-pane { animation: fadeUp 0.2s ease-out; }
.prompt-subtabs {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  margin-bottom: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.prompt-subtab {
  height: 28px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.prompt-subtab:hover {
  color: var(--color-text);
  background: var(--color-surface);
}
.prompt-subtab.active {
  color: var(--color-accent);
  border-color: var(--color-border);
  background: var(--color-surface);
}
.prompt-subpane { animation: fadeUp 0.16s ease-out; }

/* =============================================================
   PROMPT SECTIONS
   ============================================================= */

.prompt-content {
  margin-top: var(--space-3); padding: var(--space-3);
  background: var(--color-surface-2); border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}
.structured-prompt { display: flex; flex-direction: column; gap: var(--space-2); }
.structured-prompt .prompt-section {
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); overflow: hidden;
  margin-top: 0; padding-top: 0;
}
.prompt-section-header {
  padding: var(--space-2) var(--space-3); background: var(--color-surface-2);
  cursor: pointer; display: flex; align-items: center; gap: var(--space-2);
  font-weight: var(--weight-medium); color: var(--color-text);
  user-select: none; height: auto;
}
.prompt-section-header:hover { background: var(--color-surface-3); }
.section-arrow { color: var(--color-accent); font-size: var(--text-xs); width: 15px; display: inline-block; }
.section-title { flex: 1; font-size: var(--text-sm); }
.prompt-section-content { padding: var(--space-3); background: var(--color-surface); border-top: 1px solid var(--color-border); }
.prompt-text {
  background: var(--code-bg); color: var(--code-text); padding: var(--space-3);
  border-radius: var(--radius-sm); overflow-x: auto; font-family: var(--font-mono);
  font-size: var(--text-xs); line-height: 1.5; margin: 0;
  white-space: pre-wrap; word-wrap: break-word; border: 1px solid var(--color-border);
}
.prompt-display {
  background: var(--code-bg); color: var(--code-text); padding: var(--space-3);
  border-radius: var(--radius-md); overflow-x: auto; font-family: var(--font-mono);
  font-size: var(--text-xs); line-height: 1.5; margin: 0;
  white-space: pre-wrap; word-wrap: break-word;
}
.sql-example {
  margin-bottom: var(--space-3); padding: var(--space-2) var(--space-3);
  background: var(--color-surface-2); border-radius: var(--radius-sm);
  border-inline-start: 3px solid var(--color-accent);
}
.example-question { margin-bottom: var(--space-2); color: var(--color-muted); font-size: var(--text-sm); }
.example-sql pre {
  background: var(--code-bg); color: var(--code-text); padding: var(--space-2);
  border-radius: var(--radius-sm); margin: 4px 0 0 0; overflow-x: auto;
  font-family: var(--font-mono); font-size: var(--text-xs); border: 1px solid var(--color-border);
}
.documentation-list { margin: 0; padding-inline-start: var(--space-4); }
.documentation-list li { margin-bottom: var(--space-2); color: var(--color-muted); line-height: 1.6; font-size: var(--text-sm); }
.conversation-item {
  margin-bottom: var(--space-3); padding: var(--space-2) var(--space-3);
  background: var(--color-warning-bg); border-radius: var(--radius-sm);
  border-inline-start: 3px solid var(--color-warning);
}
.conv-question { margin-bottom: var(--space-2); color: var(--color-warning); font-size: var(--text-sm); }
.conv-sql pre {
  background: var(--code-bg); color: var(--code-text); padding: var(--space-2);
  border-radius: var(--radius-sm); margin: 4px 0 0 0; overflow-x: auto;
  font-family: var(--font-mono); font-size: var(--text-xs); border: 1px solid var(--color-border);
}
.current-question-text {
  font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--color-accent);
  padding: var(--space-2) var(--space-3); background: var(--color-surface-2);
  border-radius: var(--radius-sm); border-inline-start: 3px solid var(--color-accent);
}

/* =============================================================
   SIDEBAR — TABLES & HISTORY
   ============================================================= */

.tables-list {
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 1px;
  padding-inline-end: var(--space-1);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-2) transparent;
}
.question-history {
  overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-1);
  padding-inline-end: var(--space-1);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-2) transparent;
}
.tables-list::-webkit-scrollbar,
.question-history::-webkit-scrollbar {
  width: 8px;
}
.tables-list::-webkit-scrollbar-track,
.question-history::-webkit-scrollbar-track {
  background: transparent;
}
.tables-list::-webkit-scrollbar-thumb,
.question-history::-webkit-scrollbar-thumb {
  background: var(--color-border-2);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
.tables-list::-webkit-scrollbar-thumb:hover,
.question-history::-webkit-scrollbar-thumb:hover {
  background: var(--color-muted);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* Long table / question names stay fully readable: each list scrolls
   horizontally instead of truncating, and vertically so it fits one screen. */
.tables-list,
.question-history { overflow-x: auto; }
.tables-list .table-item { width: max-content; min-width: 100%; }
.tables-list .table-name { overflow: visible; text-overflow: clip; }
.question-history .history-item { width: max-content; min-width: 100%; }
.question-history .question-text { overflow: visible; text-overflow: clip; }

/* =============================================================
   CONNECTION PILL (sidebar header)
   ============================================================= */
.sidebar-header {
  padding: var(--space-3) var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--color-border);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.sidebar-brand { display: flex; align-items: center; gap: var(--space-2); }
.sidebar-brand-text {
  font-size: var(--text-md); font-weight: var(--weight-semibold);
  color: var(--color-text); letter-spacing: -0.01em;
}
.connection-pill-wrap {
  position: relative;
  display: flex; align-items: center; gap: var(--space-2);
  height: 30px; padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}
.connection-pill-wrap:hover { border-color: var(--color-border-2); background: var(--color-surface-3); }
.connection-status-dot {
  width: 7px; height: 7px; border-radius: var(--radius-full);
  background: var(--color-success);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-success) 18%, transparent);
  flex-shrink: 0;
}
.connection-status-dot[data-status="connecting"] {
  background: var(--color-warning);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-warning) 18%, transparent);
}
.connection-status-dot[data-status="error"] {
  background: var(--color-error);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-error) 18%, transparent);
}
.connection-pill-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: var(--weight-medium);
  color: var(--color-text);
}
.connection-pill-caret { color: var(--color-muted); flex-shrink: 0; }
/* Custom connection switcher — replaced the native <select> overlay. */
.connection-switcher { position: relative; }
.connection-pill-wrap:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.connection-panel {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 50;
  padding: var(--space-1);
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-2) transparent;
}
.connection-panel[hidden] { display: none; }
.connection-panel::-webkit-scrollbar { width: 8px; }
.connection-panel::-webkit-scrollbar-track { background: transparent; }
.connection-panel::-webkit-scrollbar-thumb {
  background: var(--color-border-2);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
.connection-panel-search {
  width: 100%;
  height: 28px;
  padding: 0 var(--space-2);
  font-size: var(--text-xs);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  margin-bottom: var(--space-1);
}
.connection-panel-search:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
.connection-panel-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
  outline: none;
}
.connection-panel-item:hover,
.connection-panel-item:focus {
  background: var(--color-surface-2);
}
.connection-panel-item.is-current {
  background: var(--color-dim-bg);
  color: var(--color-accent-2);
  font-weight: var(--weight-medium);
}
[data-theme="dark"] .connection-panel-item.is-current {
  background: var(--color-dim-bg);
  color: var(--color-dim-text);
}
.connection-panel-item-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.connection-panel-item-type {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: lowercase;
  color: var(--color-muted);
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  padding: 1px var(--space-2);
}
.connection-panel-item.is-current .connection-panel-item-type {
  background: var(--color-surface);
  color: var(--color-accent-2);
}
.connection-panel-item-check {
  flex-shrink: 0;
  width: 12px; height: 12px;
  color: var(--color-accent-2);
}
[data-theme="dark"] .connection-panel-item-check { color: var(--color-dim-text); }
.connection-panel-empty {
  padding: var(--space-3);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-faint);
  font-style: italic;
}
.connection-panel-footer {
  margin-top: var(--space-1);
  padding-top: var(--space-1);
  border-top: 1px solid var(--color-border);
}
.connection-panel-footer-btn {
  width: 100%;
  height: auto;
  padding: var(--space-2);
  background: transparent;
  color: var(--color-muted);
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-normal);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  justify-content: center;
  font-family: var(--font-sans);
}
.connection-panel-footer-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}
/* ── Table item: accordion layout ─────────────────────── */
.table-item {
  display: flex; flex-direction: column;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.table-item-header {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 5px var(--space-3);
  cursor: pointer; font-size: var(--text-sm); color: var(--color-text);
  border-radius: var(--radius-sm); user-select: none;
  min-width: 0;
}
.table-item-header:hover { background: var(--color-surface-2); }
.table-item.is-active > .table-item-header {
  background: var(--color-dim-bg);
  color: var(--color-accent-2);
  font-weight: var(--weight-medium);
}
[data-theme="dark"] .table-item.is-active > .table-item-header {
  background: var(--color-dim-bg);
  color: var(--color-dim-text);
}
.table-item .table-icon {
  flex-shrink: 0; opacity: 0.45; color: var(--color-muted);
}
.table-item.is-active .table-icon { opacity: 1; color: var(--color-accent-2); }
[data-theme="dark"] .table-item.is-active .table-icon { color: var(--color-dim-text); }
.table-item .table-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* col count badge — hidden when actions are visible */
.table-col-count {
  flex-shrink: 0;
  font-size: 10px; font-family: var(--font-mono);
  color: var(--color-faint);
  background: var(--color-surface-2);
  border-radius: var(--radius-full);
  padding: 1px 5px;
  transition: opacity 100ms ease;
}
.table-item-header:hover .table-col-count { opacity: 0; pointer-events: none; }

/* Expand arrow */
.table-expand-arrow {
  flex-shrink: 0;
  font-size: 8px; color: var(--color-faint);
  transition: transform 150ms ease, color 150ms ease;
  width: 10px; text-align: center;
}
.table-expand-arrow.open {
  transform: rotate(90deg);
  color: var(--color-accent);
}

/* Action buttons (Explore / Schema / Copy) — visible only on header hover */
.table-item-actions {
  display: none;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
  position: absolute; inset-inline-end: var(--space-2);
}
.table-item-header {
  position: relative; /* needed for absolute actions */
}
.table-item-header:hover .table-item-actions { display: flex; }
.table-action-btn {
  width: 22px; height: 22px; padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 11px; cursor: pointer;
  color: var(--color-muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-sans);
}
.table-action-btn:hover {
  background: var(--color-surface-3);
  border-color: var(--color-border);
  color: var(--color-accent);
}

/* Expanded columns list */
.table-columns-list {
  display: none;
  padding: var(--space-1) var(--space-2) var(--space-2) 30px;
  border-inline-start: 2px solid var(--color-border);
  margin-inline-start: 18px;
  margin-bottom: 2px;
}
.table-columns-list.open { display: block; }
.table-col-row {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 2px 0;
  cursor: pointer;
}
.table-col-row:hover .table-col-name { color: var(--color-accent); }
.table-col-name {
  flex: 1; min-width: 0;
  font-size: var(--text-xs); font-family: var(--font-mono);
  color: var(--color-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color 100ms ease;
}
.table-col-type-badge {
  flex-shrink: 0;
  font-size: 10px; font-family: var(--font-mono);
  padding: 1px 5px; border-radius: var(--radius-full);
  letter-spacing: 0;
}
.table-col-type-numeric { background: var(--color-dim-bg); color: var(--color-accent); }
[data-theme="dark"] .table-col-type-numeric { background: var(--color-dim-bg); color: var(--color-accent-2); }
.table-col-type-text    { background: var(--color-surface-3); color: var(--color-muted); }
.table-col-type-date    { background: var(--color-success-bg); color: var(--color-success); }
.table-col-type-bool    { background: var(--color-warning-bg); color: var(--color-warning); }
.table-col-type-other   { background: var(--color-surface-3); color: var(--color-faint); }
.table-cols-loading {
  font-size: var(--text-xs); color: var(--color-faint);
  padding: var(--space-2) 0; font-style: italic;
}

/* Description subtitle under table name */
.table-description {
  display: none;
  font-size: var(--text-xs);
  color: var(--color-faint);
  font-style: italic;
  padding: 1px var(--space-3) 4px 30px; /* indent under the table icon */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  transition: color 100ms ease;
}
.table-description.open { display: block; }
.table-item.is-active .table-description { color: var(--color-muted); }
/* Search highlight inside name or description */
.table-item-header mark,
.table-description mark {
  background: transparent;
  color: var(--color-accent);
  font-weight: var(--weight-semibold);
  font-style: normal;
}

/* Table count badge in section header */
.table-count-badge {
  font-size: 10px; font-family: var(--font-mono);
  font-weight: var(--weight-normal);
  color: var(--color-faint);
  letter-spacing: 0;
}
.history-empty {
  padding: var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-faint);
  font-style: italic;
  text-align: center;
  line-height: 1.5;
}
.history-item {
  padding: var(--space-2) var(--space-3); background: var(--color-surface-2);
  border-radius: var(--radius-md); display: flex; align-items: center;
  gap: var(--space-2); font-size: var(--text-sm); color: var(--color-muted);
  border: 1px solid transparent; transition: background 100ms ease, color 100ms ease;
}
.history-item:hover { background: var(--color-surface-3); color: var(--color-text); border-color: var(--color-border); }
.history-item.pinned-item { background: var(--color-warning-bg); border-inline-start: 2px solid var(--color-warning); }
.history-item.pinned-item:hover { opacity: 0.9; color: var(--color-text); }
.pin-icon { font-size: var(--text-sm); cursor: pointer; flex-shrink: 0; padding: 2px; opacity: 0.5; transition: transform 150ms ease, opacity 150ms ease; }
.pin-icon:hover { transform: scale(1.2); opacity: 1; }
.question-text { flex: 1; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-controls { margin-bottom: var(--space-2); }
.sample-questions { list-style: none; }
.sample-questions li {
  padding: var(--space-2) var(--space-3); background: var(--color-surface-2);
  border-radius: var(--radius-md); margin-bottom: var(--space-2); cursor: pointer;
  font-size: var(--text-sm); color: var(--color-muted);
}
.sample-questions li:hover { background: var(--color-surface-3); color: var(--color-text); }

/* =============================================================
   CHART FEATURE
   ============================================================= */

.chart-toggle-wrapper { margin-bottom: var(--space-3); }
.view-toggle-group {
  display: inline-flex; gap: 0; background: var(--color-surface-2);
  border-radius: var(--radius-md); padding: var(--space-1); border: 1px solid var(--color-border);
}
.view-toggle-btn {
  padding: var(--space-2) var(--space-4); font-size: var(--text-sm);
  font-weight: var(--weight-medium); color: var(--color-muted);
  background: transparent; border: none; border-radius: var(--radius-sm);
  cursor: pointer; height: auto;
}
.view-toggle-btn.active { background: var(--color-surface); color: var(--color-accent); box-shadow: var(--shadow-xs); }
.view-toggle-btn:disabled { cursor: not-allowed; opacity: 0.45; }
.chart-view-container { display: flex; flex-direction: column; gap: var(--space-3); min-height: 400px; }
.chart-controls {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-3) var(--space-4); background: var(--color-surface-2);
  border-radius: var(--radius-md); border: 1px solid var(--color-border);
}
.chart-type-selector { display: flex; align-items: center; gap: var(--space-2); }
.chart-type-selector label { font-weight: var(--weight-medium); color: var(--color-muted); font-size: var(--text-sm); margin-bottom: 0; }
.chart-type-dropdown {
  padding: var(--space-1) var(--space-3); font-size: var(--text-sm);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); color: var(--color-text);
  cursor: pointer; font-family: var(--font-sans);
}
.chart-type-dropdown:focus { outline: none; border-color: var(--color-accent); box-shadow: var(--shadow-focus); }
.chart-display {
  width: 100%; height: 500px; background: var(--color-surface);
  border-radius: var(--radius-lg); border: 1px solid var(--color-border); padding: var(--space-4);
}
.chart-display[data-chart-type="map"] {
  height: min(680px, 70vh);
  min-height: 520px;
  padding: var(--space-3);
}
.chart-error, .chart-loading { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; color: var(--color-muted); gap: var(--space-3); }
.chart-not-available { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; text-align: center; gap: var(--space-2); }
.chart-not-available p { font-size: var(--text-md); color: var(--color-muted); }
.chart-not-available .reason { font-size: var(--text-sm); color: var(--color-faint); font-style: italic; }
/* ── Chart-type dropdown (designed button + portaled floating menu) ──────── */
/* Slim container — the old full-width gray panel is gone; the button is a
   compact inline control that sits in the chart toolbar row. */
.chart-type-selector-container { margin-bottom: var(--space-3); }

.ctype { position: relative; display: inline-flex; }
.ctype-btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 6px 10px; line-height: 1; cursor: pointer;
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); color: var(--color-text);
  font-family: var(--font-sans); font-size: var(--text-base); font-weight: var(--weight-semibold);
  transition: border-color 120ms ease, background 120ms ease;
}
.ctype-btn:hover { border-color: var(--color-accent); }
.ctype-btn:focus-visible { outline: none; border-color: var(--color-accent); box-shadow: var(--shadow-focus); }
.ctype-btn-icon { display: inline-flex; color: var(--color-accent); }
.ctype-btn-label { white-space: nowrap; }
.ctype-caret { display: inline-flex; color: var(--color-faint); }
.ctype.is-open .ctype-btn { border-color: var(--color-accent); background: var(--color-dim-bg); }

/* Portaled to <body>; position:fixed so it escapes the results card
   (overflow:hidden) and the chat thread (overflow-y:auto) clipping. */
.ctype-menu {
  position: fixed; z-index: 1000;
  width: 230px; max-height: 380px; overflow-y: auto;
  padding: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.ctype-menu[hidden] { display: none; }
.ctype-menu::-webkit-scrollbar { width: 8px; }
.ctype-menu::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 9999px; }

.ctype-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; text-align: start; cursor: pointer;
  border: none; background: transparent; border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-base);
  font-weight: var(--weight-medium); color: var(--color-text);
}
.ctype-item--divider {
  border-bottom: 1px solid var(--color-border);
  border-radius: 0; margin-bottom: 3px; padding-bottom: 10px;
}
.ctype-item-icon { flex-shrink: 0; color: var(--color-muted); }
.ctype-item-label { flex: 1; }
.ctype-check { flex-shrink: 0; color: var(--color-accent); display: none; }
.ctype-item:hover, .ctype-item.is-active { background: var(--color-surface-2); }
.ctype-item.is-selected { background: var(--color-dim-bg); font-weight: var(--weight-bold); }
.ctype-item.is-selected .ctype-item-icon { color: var(--color-accent); }
.ctype-item.is-selected .ctype-check { display: inline-flex; }

/* ── Chart toolbar row: chart-type dropdown + Columns disclosure + pills ──── */
.chart-toolbar-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.chart-toolbar-row .chart-type-selector-container { margin-bottom: 0; }

/* The real column/quick-options container melts into the toolbar row so its
   children (Columns button, divider, pills, expand panel) become direct flex
   items of .chart-toolbar-row. */
#chart-options-panel-container { display: contents; }
/* The map options panel keeps its own boxed look and spans the full row. */
#map-options-panel-container { flex-basis: 100%; width: 100%; }

.chart-options-panel-container {
  margin-bottom: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}
.map-options-panel { display: flex; flex-direction: column; gap: var(--space-3); }
.map-options-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.map-options-section { display: flex; flex-direction: column; gap: var(--space-2); }
.map-palette-field { max-width: 220px; }
.map-feedback {
  display: none;
  margin: var(--space-2) 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-warning);
  border-radius: var(--radius-md);
  background: var(--color-warning-bg);
  color: var(--color-warning);
  font-size: var(--text-xs);
}
/* Shared by the map options panel (heading + palette field). */
.chart-options-heading {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
}
.chart-options-field {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 140px; flex: 1 1 140px;
  font-size: var(--text-xs); color: var(--color-muted);
}

/* Columns disclosure button — mirrors the chart-type dropdown button. */
.chart-cols-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; line-height: 1; cursor: pointer;
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); color: var(--color-text);
  font-family: var(--font-sans); font-size: var(--text-base); font-weight: var(--weight-semibold);
  transition: border-color 120ms ease, background 120ms ease;
}
.chart-cols-btn:hover { border-color: var(--color-accent); }
.chart-cols-btn:focus-visible { outline: none; border-color: var(--color-accent); box-shadow: var(--shadow-focus); }
.chart-cols-btn.is-open { border-color: var(--color-accent); background: var(--color-dim-bg); color: var(--color-dim-text); }
.chart-cols-caret { display: inline-flex; color: var(--color-faint); }
.chart-cols-btn.is-open .chart-cols-caret { color: var(--color-dim-text); }

.chart-opts-divider { width: 1px; height: 18px; background: var(--color-border); margin: 0 2px; }

/* Colour palette picker — "Colors" disclosure with swatch dots, chips below. */
.chart-palette-dots { display: inline-flex; gap: 3px; align-items: center; }
.chart-palette-dots i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.chart-palette-expand { align-items: center; gap: var(--space-2); }
.chart-palette-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px; line-height: 1.2; cursor: pointer;
  border: 1px solid var(--color-border); border-radius: 14px;
  background: var(--color-surface); color: var(--color-muted);
  font-family: var(--font-sans); font-size: var(--text-sm); font-weight: var(--weight-semibold);
  transition: background 100ms ease, border-color 100ms ease, color 100ms ease;
}
.chart-palette-chip .chart-palette-dots i { width: 10px; height: 10px; }
.chart-palette-chip:hover { border-color: var(--color-accent); color: var(--color-text); }
.chart-palette-chip:focus-visible { outline: none; border-color: var(--color-accent); box-shadow: var(--shadow-focus); }
.chart-palette-chip.is-active {
  background: var(--color-dim-bg);
  border-color: var(--color-accent);
  color: var(--color-dim-text);
  font-weight: var(--weight-bold);
}

/* Quick-option pills (Labels / Legend / Zoom / Sort). */
.chart-opts-toggles { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chart-opt-toggle {
  padding: 5px 12px; line-height: 1.2; cursor: pointer;
  border: 1px solid var(--color-border); border-radius: 14px;
  background: var(--color-surface); color: var(--color-muted);
  font-family: var(--font-sans); font-size: var(--text-sm); font-weight: var(--weight-semibold);
  transition: background 100ms ease, border-color 100ms ease, color 100ms ease;
}
.chart-opt-toggle:hover { border-color: var(--color-accent); color: var(--color-text); }
.chart-opt-toggle:focus-visible {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
.chart-opt-toggle.is-on {
  background: var(--color-dim-bg);
  border-color: var(--color-accent);
  color: var(--color-dim-text);
  font-weight: var(--weight-bold);
}
.chart-opt-toggle.is-mixed {
  border-color: var(--color-accent);
  background: linear-gradient(90deg, var(--color-dim-bg) 50%, var(--color-surface) 50%);
  color: var(--color-dim-text);
}
.chart-opt-toggle:disabled,
.chart-opt-toggle[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

/* Column pickers — full-width panel that expands below the toolbar row. */
.chart-cols-expand {
  flex-basis: 100%; width: 100%;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3);
  margin-top: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.chart-cols-expand[hidden] { display: none; }
.chart-col-field {
  display: flex; flex-direction: column; gap: 5px;
  flex: 1 1 150px; min-width: 150px;
}
.chart-col-field > span {
  font-size: var(--text-xs); font-weight: var(--weight-bold);
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--color-faint);
}
.chart-options-select {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
}
.chart-options-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}

/* =============================================================
   INSIGHTS
   ============================================================= */

/* =============================================================
   INSIGHTS PANEL — redesigned (ins-* prefix)
   Follows Insights Mockup.html spec exactly.
   ============================================================= */

/* Emphasis spans (accent / positive / negative / raw number) */
.hl-accent { color: var(--color-accent);  font-weight: 600; }
.hl-pos    { color: var(--color-success); font-weight: 500; }
.hl-neg    { color: var(--color-error);   font-weight: 500; }
.hl-num    { font-family: var(--font-mono); font-size: 0.9375em; }

/* Card wrapper */
.ins-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Header row: title (left) + TTFT badge (right) */
.ins-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.ins-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}
/* Spark icon chip */
.ins-spark {
  width: 22px; height: 22px;
  border-radius: 7px;
  display: grid; place-items: center;
  background: var(--color-dim-bg);
  color: var(--color-accent);
  flex-shrink: 0;
}
/* TTFT badge — quiet, monospace, top-right */
.ttft {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-faint);
  white-space: nowrap;
}

/* Lead summary paragraph */
.ins-summary {
  font-size: 1.0625rem;
  line-height: 1.55;
  letter-spacing: -0.01em;
  color: var(--color-text);
  margin: 0;
}

/* Horizontal divider */
.ins-divider {
  height: 1px;
  background: var(--color-border);
}

/* Section subheading: uppercase 11px label */
.ins-subhead {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-faint);
  margin-bottom: 8px;
}

/* Findings / suggestions list */
.ins-list { display: flex; flex-direction: column; }
.ins-item {
  display: flex;
  gap: 12px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--color-border);
}
.ins-item:last-child { border-bottom: none; }

/* Icon chip inside list items */
.ins-item-icon {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 7px;
  display: grid; place-items: center;
  margin-top: 1px;
}
.ins-item-icon--check {
  background: var(--color-dim-bg);
  color: var(--color-accent);
}
.ins-item-icon--arrow {
  background: var(--color-success-bg);
  color: var(--color-success);
}
.ins-item-body {
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--color-text);
}
.ins-item-body .hl-num { font-size: 0.8125rem; }

/* Follow-up questions: 2-column grid on wide, 1-column on narrow */
.ins-followups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
@media (max-width: 640px) { .ins-followups { grid-template-columns: minmax(0, 1fr); } }

/* Individual follow-up chip */
.ins-followup {
  display: flex;
  align-items: flex-start;   /* top-align so the arrow sits with the first line
                                when a long question wraps to multiple lines */
  gap: 10px;
  width: 100%;
  text-align: start;
  padding: 11px 13px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  font: inherit;
  transition: border-color 120ms ease, background 120ms ease;
}
.ins-followup:hover {
  border-color: var(--color-accent);
  background: var(--color-dim-bg);
}
.ins-followup-q {
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
  /* Always wrap long questions instead of truncating; break over-long tokens
     (URLs, IDs) so nothing spills out of the chip. */
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ins-followup svg {
  flex-shrink: 0;
  margin-top: 2px;           /* align the arrow with the first line of text */
  color: var(--color-faint);
  transition: color 120ms ease;
}
.ins-followup:hover svg { color: var(--color-accent); }
.ins-followup:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* Loading / error / empty states */
.ins-loading {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ins-stream-status {
  font-size: 0.75rem;
  color: var(--color-faint);
  font-family: var(--font-mono);
  margin: 0;
}
.ins-error {
  font-size: 0.875rem;
  color: var(--color-error);
  margin: 0;
}
.ins-empty {
  font-size: 0.875rem;
  color: var(--color-muted);
  margin: 0;
}

/* =============================================================
   INSIGHTS PANEL — legacy styles kept for backward compat
   ============================================================= */
.insights-section { background: var(--color-surface); border-radius: var(--radius-md); padding: var(--space-4); }
.insights-header { margin-bottom: var(--space-3); padding-bottom: var(--space-2); border-bottom: 1px solid var(--color-border); }
.insights-header h3 { font-size: var(--text-md); color: var(--color-text); margin: 0; }
.insights-content { display: flex; flex-direction: column; gap: var(--space-3); }
.insights-summary { padding: var(--space-3) var(--space-4); background: var(--color-surface-2); border-inline-start: 3px solid var(--color-accent); border-start-start-radius: 0; border-end-start-radius: 0; border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md); font-size: var(--text-base); color: var(--color-text); line-height: 1.5; }
.insights-findings { padding: var(--space-3) var(--space-4); background: var(--color-warning-bg); border-inline-start: 3px solid var(--color-warning); border-start-start-radius: 0; border-end-start-radius: 0; border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md); }
.insights-findings strong { display: block; margin-bottom: var(--space-2); color: var(--color-text); font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.insights-findings ul, .insights-suggestions ul { margin: 0; padding-inline-start: var(--space-4); }
.insights-findings li, .insights-suggestions li { margin-bottom: var(--space-2); color: var(--color-muted); line-height: 1.5; font-size: var(--text-sm); }
.insights-suggestions { padding: var(--space-3) var(--space-4); background: var(--color-success-bg); border-inline-start: 3px solid var(--color-success); border-start-start-radius: 0; border-end-start-radius: 0; border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md); }
.insights-suggestions strong { display: block; margin-bottom: var(--space-2); color: var(--color-text); font-size: var(--text-sm); font-weight: var(--weight-semibold); }

/* ── Follow-up questions chip list ─────────────────────────────────── */
.follow-up-section { padding-top: var(--space-3); }
.follow-up-label {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.06em;
  color: var(--color-muted); margin-bottom: var(--space-2); text-transform: uppercase;
}
/* Single-column stack — each question on its own row, text wraps freely */
.follow-up-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.follow-up-chip {
  display: flex;
  align-items: flex-start;   /* top-align arrow with first line of text */
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-2);
  border-radius: 10px;
  cursor: pointer;
  text-align: start;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: inherit;
  line-height: 1.45;
}
.follow-up-chip:hover {
  border-color: var(--color-accent);
  background: var(--color-surface-2);
  box-shadow: 0 1px 4px rgba(3, 7, 18, 0.06);
}
.follow-up-chip:active { background: var(--color-surface-3); }
.follow-up-chip-text {
  flex: 1;
  white-space: normal;   /* allow wrapping */
  word-break: break-word;
}
.follow-up-chip-arrow {
  flex-shrink: 0;
  margin-top: 2px;        /* nudge arrow to align with first text line */
  font-size: var(--text-base); color: var(--color-faint);
  transition: color 0.12s, transform 0.12s;
}
.follow-up-chip:hover .follow-up-chip-arrow { color: var(--color-accent); transform: translateX(2px); }
.insights-loading { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4); }
.insights-loading p { display: none; }
.insights-error { padding: var(--space-3) var(--space-4); background: var(--color-error-bg); border-inline-start: 3px solid var(--color-error); border-start-start-radius: 0; border-end-start-radius: 0; border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md); color: var(--color-error); font-size: var(--text-sm); }
.insights-empty { padding: var(--space-8) var(--space-6); text-align: center; color: var(--color-muted); font-style: italic; font-size: var(--text-sm); }

/* =============================================================
   DATA PROFILING
   ============================================================= */

.profiling-card { margin-top: var(--space-4); }
.profiling-header { cursor: pointer; user-select: none; padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); display: flex; align-items: center; }
.profiling-header:hover { background-color: var(--color-surface-2); }
.profiling-header h2 { margin: 0; display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-md); }
#profiling-arrow { font-size: var(--text-xs); display: inline-block; transition: transform 150ms ease; }
.profiling-content { margin-top: var(--space-3); padding: var(--space-4); background: var(--color-surface-2); border-radius: var(--radius-md); border: 1px solid var(--color-border); }
.profiling-prompt { padding: var(--space-4); background: var(--color-surface); border-radius: var(--radius-md); border: 1px solid var(--color-border); }
.profiling-prompt p { margin-bottom: var(--space-3); color: var(--color-muted); font-size: var(--text-base); }
.profiling-prompt ul { margin: var(--space-3) 0; padding-inline-start: var(--space-6); color: var(--color-muted); }
.profiling-prompt li { margin: var(--space-2) 0; font-size: var(--text-sm); }
.profiling-library-selector { display: flex; gap: var(--space-3); margin: var(--space-4) 0; flex-wrap: wrap; }
.library-option { display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-3) var(--space-4); background: var(--color-surface-2); border: 2px solid var(--color-border); border-radius: var(--radius-md); cursor: pointer; flex: 1; min-width: 200px; }
.library-option:hover { border-color: var(--color-accent); background: var(--color-surface-3); }
.library-option input[type="radio"] { margin-top: 3px; accent-color: var(--color-accent); }
.library-label { display: flex; flex-direction: column; gap: var(--space-1); }
.library-label strong { color: var(--color-text); font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.library-label small { color: var(--color-muted); font-size: var(--text-xs); }
.profiling-report-info { display: flex; align-items: center; gap: var(--space-2); flex: 1; }
.report-type-badge { padding: var(--space-1) var(--space-3); background: var(--color-accent); color: var(--color-accent-fg); border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.profiling-actions { padding: var(--space-3) var(--space-4); background: var(--color-surface-2); border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.profiling-report { background: var(--color-surface); border-radius: var(--radius-md); border: 1px solid var(--color-border); overflow: hidden; }
.profile-iframe { width: 100%; height: 800px; border: none; display: block; }
.profiling-loading { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-6) var(--space-4); }
.profiling-loading p { display: none; }
.profiling-error { text-align: center; padding: var(--space-6); background: var(--color-warning-bg); border: 1px solid var(--color-warning); border-radius: var(--radius-md); }
.profiling-error p { margin: var(--space-2) 0; color: var(--color-warning); font-size: var(--text-base); }
.profiling-error .error-detail { font-size: var(--text-sm); color: var(--color-muted); font-style: italic; }

/* =============================================================
   DESCRIBE / STATS
   ============================================================= */

.describe-section {
  margin-top: var(--space-4);
  padding: var(--space-4) 0 0;
  background: var(--color-surface);
  border-radius: 0;
  border: 0;
  border-top: 1px solid var(--color-border);
}
.describe-section h3 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-3);
}
.stats-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: var(--space-4); }
.stat-column { background: var(--color-surface); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--color-border); }
.stat-column h4 { font-size: var(--text-sm); color: var(--color-accent); margin-bottom: var(--space-2); border-bottom: 2px solid var(--color-accent); padding-bottom: var(--space-1); font-weight: var(--weight-semibold); }
.stats-table { width: 100%; border-collapse: collapse; }
.stats-table td { padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--color-border); font-size: var(--text-sm); }
.stats-table td:first-child { font-weight: var(--weight-medium); color: var(--color-muted); width: 50%; }
.stats-table td:last-child { color: var(--color-text); text-align: end; }
.stats-table tr:last-child td { border-bottom: none; }
.stats-tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-4); border-bottom: 2px solid var(--color-border); overflow-x: auto; }
.stats-tab { padding: var(--space-2) var(--space-4); background: transparent; border: none; border-bottom: 3px solid transparent; cursor: pointer; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-muted); height: auto; white-space: nowrap; position: relative; bottom: -2px; }
.stats-tab:hover { color: var(--color-accent); background: var(--color-surface-2); }
.stats-tab.active { color: var(--color-accent); border-bottom-color: var(--color-accent); font-weight: var(--weight-semibold); }
.stats-tab-content-container { padding: var(--space-4); background: var(--color-surface); border-radius: var(--radius-md); border: 1px solid var(--color-border); min-height: 300px; }
.stats-tab-content { display: none; animation: fadeUp 0.2s ease-out; }
.stats-tab-content.active { display: block; }
.outlier-column-section { margin-bottom: var(--space-6); padding: var(--space-4); background: var(--color-surface-2); border-radius: var(--radius-md); border: 1px solid var(--color-border); }
.outlier-column-section h4 { color: var(--color-accent); margin-bottom: var(--space-3); font-size: var(--text-sm); border-bottom: 2px solid var(--color-accent); padding-bottom: var(--space-1); }
.outliers-list { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.outlier-badge { background: var(--color-error); color: var(--color-accent-fg); padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.boxplot-container { margin-top: var(--space-4); padding: var(--space-2); background: var(--color-surface); border-radius: var(--radius-sm); border: 1px solid var(--color-border); }
.missing-values-table { width: 100%; border-collapse: collapse; background: var(--color-surface); }
.missing-values-table thead { background: var(--color-surface-2); }
.missing-values-table th { padding: var(--space-2) var(--space-3); text-align: start; font-weight: var(--weight-semibold); font-size: var(--text-sm); color: var(--color-muted); border-bottom: 1px solid var(--color-border-2); }
.missing-values-table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border); font-size: var(--text-sm); color: var(--color-text); }
.missing-values-table tr:last-child td { border-bottom: none; }
.missing-bar-container { width: 150px; height: 16px; background: var(--color-surface-2); border-radius: var(--radius-full); overflow: hidden; border: 1px solid var(--color-border); }
.missing-bar { height: 100%; transition: width 300ms ease; }
.missing-low    { background: var(--color-success); }
.missing-medium { background: var(--color-warning); }
.missing-high   { background: var(--color-error); }
.correlation-heatmap { overflow-x: auto; }
.correlation-table { width: 100%; border-collapse: collapse; background: var(--color-surface); font-size: var(--text-xs); }
.correlation-table th { padding: var(--space-2); background: var(--color-surface-2); color: var(--color-muted); font-weight: var(--weight-medium); border: 1px solid var(--color-border); }
.correlation-header { writing-mode: vertical-rl; text-orientation: mixed; min-width: 40px; max-width: 40px; }
.correlation-row-header { text-align: start; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; font-weight: var(--weight-medium); color: var(--color-muted); }
.correlation-cell { padding: var(--space-2); text-align: center; border: 1px solid var(--color-border); font-weight: var(--weight-medium); cursor: pointer; color: var(--color-text); transition: transform 150ms ease; }
.correlation-cell:hover { transform: scale(1.1); box-shadow: var(--shadow-md); z-index: 10; position: relative; }

/* =============================================================
   TOASTS
   ============================================================= */

.toast { position: fixed; bottom: var(--space-6); inset-inline-end: var(--space-6); padding: var(--space-3) var(--space-4); background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); font-family: var(--font-sans); font-size: var(--text-sm); opacity: 0; transform: translateX(20px); transition: opacity 200ms ease, transform 200ms ease; z-index: 10000; max-width: 400px; }
.toast.show { opacity: 1; transform: translateX(0); }
.toast.toast-error { background: var(--color-error-bg); color: var(--color-error); border-color: var(--color-error); }
.toast.toast-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.toast.toast-info { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border-2); }

/* =============================================================
   ANIMATIONS
   ============================================================= */

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* =============================================================
   RESPONSIVE
   ============================================================= */

@media (max-width: 767px) {
  .sidebar {
    position: fixed; left: 0; top: 48px; bottom: 0; z-index: 50;
    transform: translateX(-100%); box-shadow: var(--shadow-lg);
    width: 280px; border-inline-end: 1px solid var(--color-border);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { padding: var(--space-4); }
  .prompt-tabs, .stats-tabs { overflow-x: auto; }
  .chart-display { height: 350px; }
  .chart-controls { flex-direction: column; gap: var(--space-2); align-items: stretch; }
}

@media (min-width: 768px) {
  .sidebar { width: 240px; }
  .sidebar.collapsed { width: 56px; }
}

/* =============================================================
   REDUCED MOTION
   ============================================================= */

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

/* =============================================================
   TOPBAR ICON BUTTONS (history / settings)
   ============================================================= */
.topbar-icon-btn {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: transparent; color: var(--color-muted);
  cursor: pointer; padding: 0;
}
.topbar-icon-btn:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border-2);
  color: var(--color-text);
}

/* =============================================================
   INFO-CARD HEADER (sidebar sections)
   ============================================================= */
.info-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-2);
}
.info-card-header h3 { margin: 0; }
/* Last sidebar info-card drops its bottom border so the sidebar doesn't end
   on a stray separator line. */
.sidebar .info-card:last-child { border-bottom: 0; }

/* =============================================================
   SIDEBAR TABS (Tables / Recent switcher)
   ============================================================= */
.sidebar-tabs {
  display: flex; flex-shrink: 0;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 0 var(--space-3);
}
.sidebar-tab {
  flex: 1;
  height: 34px; padding: 0;
  background: transparent; border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--font-sans);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  color: var(--color-muted);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  position: relative; bottom: -1px;
  white-space: nowrap;
  transition: color 150ms ease;
}
.sidebar-tab:hover { color: var(--color-text); }
.sidebar-tab.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}
/* The active tab badge (table count) */
.sidebar-tab .table-count-badge {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: var(--weight-normal);
  color: inherit;
  opacity: 0.75;
  letter-spacing: 0;
}

/* Tab content pane — fills remaining sidebar height and scrolls */
.sidebar-tab-pane {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: var(--space-3);
  display: flex; flex-direction: column; gap: var(--space-2);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-2) transparent;
}
.sidebar-tab-pane::-webkit-scrollbar { width: 8px; }
.sidebar-tab-pane::-webkit-scrollbar-track { background: transparent; }
.sidebar-tab-pane::-webkit-scrollbar-thumb {
  background: var(--color-border-2);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
.sidebar-tab-pane::-webkit-scrollbar-thumb:hover {
  background: var(--color-muted);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* Toolbar inside the Tables pane: search input + refresh btn */
.sidebar-pane-toolbar {
  display: flex; align-items: center; gap: var(--space-2);
  justify-content: flex-end; /* refresh right-aligned when search is hidden */
  flex-shrink: 0;
}
.sidebar-pane-toolbar .table-search-input {
  flex: 1; margin: 0;
}
.refresh-btn {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent; color: var(--color-muted);
  cursor: pointer; padding: 0;
}
.refresh-btn:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border);
  color: var(--color-text);
}

/* =============================================================
   QUERY CARD
   ============================================================= */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.card-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-2);
}
.query-card { padding: var(--space-3) var(--space-4); }
.query-input-wrap {
  position: relative;
}
.query-input-wrap textarea {
  width: 100%;
  min-height: 56px;
  max-height: 160px;
  padding: var(--space-3) var(--space-3) 38px var(--space-3);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  resize: none;
  line-height: 1.5;
}
.query-input-wrap textarea:focus {
  outline: none; border-color: var(--color-text); box-shadow: var(--shadow-focus);
}
.ask-btn {
  position: absolute;
  inset-inline-end: 8px; bottom: 8px;
  height: 26px;
  width: auto; min-width: 0;
  padding: 0 10px;
  background: var(--btn-primary-bg); color: var(--btn-primary-fg);
  border: none; border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; gap: 6px;
  z-index: 1;
}
.ask-btn:hover { background: var(--btn-primary-hover); }

/* =============================================================
   EMPTY / HERO STATE (shown until the first question is asked)
   ============================================================= */

/* Hidden by default — only revealed in the empty state. */
.hero,
.hero-suggestions { display: none; }

/* Center the column horizontally + vertically while empty. We center within
   the viewport (not the main-content box, which is stretched tall by the
   sidebar) by giving the inner column a viewport-based min-height. */
#main-content[data-ui-state="empty"] .main-inner {
  max-width: 760px;
  margin-inline: auto;
  min-height: calc(100vh - 96px);
  justify-content: center;
  gap: var(--space-6);
}

#main-content[data-ui-state="empty"] .hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  text-align: center;
}
#main-content[data-ui-state="empty"] .hero-suggestions { display: block; }

/* The "Ask a question" label is redundant under the hero heading. */
#main-content[data-ui-state="empty"] .query-card .card-label { display: none; }

/* A touch more breathing room for the input in the empty state. */
#main-content[data-ui-state="empty"] .query-card { padding: var(--space-4); }
#main-content[data-ui-state="empty"] .query-input-wrap textarea { min-height: 72px; }

.hero-connection {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 5px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
  font-size: var(--text-sm);
  color: var(--color-muted);
}
.hero-connection strong { color: var(--color-text); font-weight: var(--weight-semibold); }
.hero-connection-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--color-success);
  flex: none;
}

.hero-title {
  font-size: clamp(1.5rem, 1rem + 2vw, 2.25rem);
  font-weight: var(--weight-bold);
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--color-text);
  margin: 0;
}

.hero-suggestions-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-faint);
  margin-bottom: var(--space-3);
}
.hero-suggestions-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.hero-chip {
  height: auto;
  max-width: 100%;
  padding: 7px var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.3;
  white-space: normal;
  text-align: start;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.hero-chip:hover {
  border-color: var(--color-accent);
  background: var(--color-surface-2);
}
.hero-chip .hero-chip-icon {
  margin-inline-end: 6px;
  opacity: 0.6;
  font-size: var(--text-xs);
}
.hero-chip.is-skeleton {
  pointer-events: none;
  color: transparent;
  background: var(--color-surface-2);
  border-color: transparent;
  width: 140px;
  height: 32px;
}

.ask-btn-kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  opacity: 0.85;
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.18);
}

/* =============================================================
   RESULTS HEADER + TOOLBAR
   ============================================================= */
.results-card { padding: 0; overflow: hidden; }
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.results-title-block { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.result-title {
  font-size: var(--text-md); font-weight: var(--weight-semibold);
  letter-spacing: -0.015em;
  margin: 0; color: var(--color-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.result-meta {
  font-size: var(--text-xs); color: var(--color-muted); margin: 0;
}
.results-card .chart-toggle-wrapper { margin: 0; }
.results-toolbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.results-toolbar .result-filter-input {
  flex: 1; max-width: 320px; margin: 0;
  height: 30px; font-size: var(--text-xs);
}
.toolbar-actions { display: flex; gap: var(--space-1); margin-inline-start: auto; }
.toolbar-btn {
  height: 28px; padding: 0 var(--space-3);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  background: transparent; color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.toolbar-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-border-2);
}
.results-card #results-display { padding: 0 var(--space-4) var(--space-4); }
.results-card #describe-section { margin: 0 var(--space-4) var(--space-4); }
.results-card #chart-view-container { padding: var(--space-3) var(--space-4) var(--space-4); }

/* =============================================================
   DATA TABLE — dim badges + tabular-nums
   ============================================================= */
.results-display .num-cell {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  text-align: end;
  white-space: nowrap;
}
.dim-badge {
  display: inline-block;
  padding: 2px var(--space-2);
  background: var(--color-dim-bg);
  color: var(--color-dim-text);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.01em;
}

/* =============================================================
   AUTOCOMPLETE / SUGGESTIONS DROPDOWN
   ============================================================= */
.question-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
  padding: var(--space-1);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-2) transparent;
}
.question-suggestions[hidden] { display: none; }
.question-suggestions::-webkit-scrollbar { width: 8px; }
.question-suggestions::-webkit-scrollbar-track { background: transparent; }
.question-suggestions::-webkit-scrollbar-thumb {
  background: var(--color-border-2);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
.suggestion-trigger-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2) var(--space-3) 4px;
  font-size: var(--text-xs);
  color: var(--color-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: var(--weight-semibold);
}
.suggestion-trigger-header .suggestion-trigger-hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: var(--weight-normal);
  color: var(--color-muted);
}
.suggestion-correction-note {
  margin: 4px var(--space-1);
  padding: 6px var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-muted);
  background: var(--color-warning-bg);
  border-inline-start: 3px solid var(--color-warning);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  transition: background 100ms ease;
}
.suggestion-correction-note:hover {
  background: var(--color-warning);
  color: var(--color-accent-fg);
}
.suggestion-correction-note:hover code {
  background: rgba(255, 255, 255, 0.2);
  color: inherit;
  border-color: transparent;
}
.suggestion-correction-note code {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.suggestion-group-header {
  padding: 6px var(--space-3) 2px;
  font-size: 10px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-faint);
  font-family: var(--font-mono);
  border-top: 1px solid var(--color-border);
  margin-top: 2px;
}
.suggestion-group-header:first-child { border-top: 0; margin-top: 0; }
.suggestion-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
  line-height: 1.4;
}
.suggestion-item:hover,
.suggestion-item.is-active {
  background: var(--color-surface-2);
}
.suggestion-item-text {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.suggestion-item-text mark {
  background: transparent;
  color: var(--color-accent);
  font-weight: var(--weight-semibold);
  padding: 0;
}
.suggestion-tier-tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px var(--space-2);
  border-radius: var(--radius-full);
  color: var(--color-muted);
  background: var(--color-surface-3);
}
.suggestion-tier-tag[data-tier="recent"] {
  color: var(--color-dim-text);
  background: var(--color-dim-bg);
}
.suggestion-tier-tag[data-tier="catalog"] {
  color: var(--color-accent);
  background: var(--color-dim-bg);
}
[data-theme="dark"] .suggestion-tier-tag[data-tier="catalog"] {
  background: var(--color-dim-bg);
  color: var(--color-accent-2);
}
.suggestion-tier-tag[data-tier="llm"] {
  color: var(--color-success);
  background: var(--color-success-bg);
}
.suggestion-tier-tag[data-tier="table"] {
  color: var(--color-muted);
  background: var(--color-surface-2);
  font-family: var(--font-mono);
  letter-spacing: 0;
  text-transform: none;
}
.suggestion-tier-tag[data-tier="template"] {
  color: var(--color-warning);
  background: var(--color-warning-bg);
}
.suggestion-tier-tag[data-tier="column"] {
  color: var(--color-success);
  background: var(--color-success-bg);
  font-family: var(--font-mono);
  letter-spacing: 0;
  text-transform: lowercase;
}
.suggestion-empty {
  padding: var(--space-3);
  text-align: center;
  color: var(--color-faint);
  font-size: var(--text-xs);
  font-style: italic;
}
.suggestion-loading {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--color-muted);
  font-size: var(--text-xs);
}
.suggestion-loading-dot {
  width: 6px; height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  opacity: 0.6;
  animation: suggestion-pulse 1.2s ease-in-out infinite;
}
.suggestion-loading-dot:nth-child(2) { animation-delay: 0.15s; }
.suggestion-loading-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes suggestion-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}
.suggestions-tip {
  font-size: var(--text-xs);
  color: var(--color-faint);
  margin: var(--space-2) 0 0;
  padding: 0 2px;
}
.suggestions-tip code {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

/* =============================================================
   REFINE THIS CHART — one slim row of natural-language chart edits,
   directly under the chart (hairline-separated).
   ============================================================= */
.chart-refine {
  display: block;
  margin-top: var(--space-3);
}
.chart-refine-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}
.chart-refine-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--color-accent);
}
/* Entry state — input + Apply */
.chart-refine-entry {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 200px;
}
.chart-refine-entry[hidden],
.chart-refine-applied[hidden] { display: none !important; }
.chart-refine-input {
  flex: 1;
  min-width: 0;
  padding: 7px 14px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  line-height: 1.4;
}
.chart-refine-input::placeholder { color: var(--color-faint); }
.chart-refine-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
.chart-refine-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.chart-refine-input[readonly] { cursor: progress; }
.chart-refine-apply {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 7px 14px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: var(--weight-bold);
  color: var(--color-accent-fg);
  background: var(--color-accent);
  border: none;
  border-radius: 14px;
  cursor: pointer;
}
.chart-refine-apply svg { display: block; }
.chart-refine-apply:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--color-accent-2); }
.chart-refine-apply:focus-visible,
.chart-refine-reset:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.chart-refine-apply:disabled,
.chart-refine-apply[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
[dir="rtl"] .chart-refine-apply svg { transform: scaleX(-1); }
/* Applied confirmation stays on its own compact row while entry remains usable. */
.chart-refine-applied {
  display: flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  max-width: 100%;
  margin-top: 6px;
  padding-inline-start: 22px;
  flex-wrap: wrap;
  color: var(--color-muted);
  font-size: 12.5px;
}
.chart-refine-applied-check { color: var(--color-success); font-weight: var(--weight-bold); }
.chart-refine-applied-label {
  font-weight: var(--weight-semibold);
  color: var(--color-success);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-refine-applied-instruction {
  max-width: min(42ch, 100%);
  overflow: hidden;
  color: var(--color-text);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-refine-session-hint { color: var(--color-faint); }
.chart-refine-dot { color: var(--color-faint); font-size: 12px; }
.chart-refine-reset {
  width: 30px;
  height: 30px;
  display: inline-flex;
  flex: 0 0 30px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  background: transparent;
  padding: 0;
  color: var(--color-muted);
  border-radius: 999px;
  cursor: pointer;
}
.chart-refine-reset:hover { border-color: var(--color-muted); color: var(--color-text); background: var(--color-surface-2); }
.chart-refine-reset:disabled { opacity: .5; cursor: not-allowed; }
/* One persistent live region announces progress and every outcome. */
.chart-refine-status {
  margin-top: 6px;
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--color-muted);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chart-refine-status:empty { display: none; }
.chart-refine-status[data-kind="success"] { color: var(--color-success); }
.chart-refine-status[data-kind="warn"] { color: var(--color-text); }
.chart-refine-status[data-kind="error"] { color: var(--color-error, #c0392b); }
.chart-refine-status[data-kind="progress"] { color: var(--color-faint); font-style: italic; }
/* What-if cue: dashed series on the canvas are hypothetical. */
.chart-scenario-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  padding: 3px 8px;
  border: 1px dashed var(--color-error, #c0392b);
  border-radius: 999px;
  font-size: var(--text-xs);
  line-height: 1.3;
  color: var(--color-error, #c0392b);
}
.chart-scenario-badge[hidden] { display: none; }
@media (max-width: 600px) {
  .chart-refine-entry { min-width: 0; width: 100%; align-items: stretch; flex-direction: column; }
  .chart-refine-apply { justify-content: center; min-height: 40px; }
  .chart-refine-applied { width: 100%; padding-inline-start: 0; }
  .chart-refine-session-hint { flex-basis: 100%; }
  .chart-actions-toolbar { justify-content: stretch; }
  .chart-actions-toolbar .chart-action-btn { flex: 1; justify-content: center; }
}

/* =============================================================
   CHART ACTIONS TOOLBAR (Save PNG, Copy)
   Sits above the chart canvas. Always visible while in chart view.
   ============================================================= */
.chart-actions-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  padding: 4px 0 8px 0;
}
.chart-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.chart-action-btn:hover:not(:disabled) {
  background: var(--color-surface-3);
  color: var(--color-text);
  border-color: var(--color-border-2);
}
.chart-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.chart-action-btn svg { display: block; }

/* =============================================================
   SETTINGS MODAL
   ============================================================= */
.settings-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3, 7, 18, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.settings-overlay[hidden] { display: none; }
.settings-modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  display: flex; flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.settings-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}
.settings-close-btn {
  width: 28px; height: 28px;
  padding: 0;
  font-size: 22px; line-height: 1;
  background: transparent;
  color: var(--color-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-close-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-border);
}
.settings-body {
  padding: var(--space-2) var(--space-4);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.settings-row {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}
.settings-row:last-child { border-bottom: 0; }
.settings-row-label-block { min-width: 0; }
.settings-row-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  margin-bottom: 2px;
}
.settings-row-help {
  font-size: var(--text-xs);
  color: var(--color-faint);
  line-height: 1.4;
}
.settings-row-control { justify-self: end; min-width: 0; width: 100%; }
.settings-select {
  width: 100%;
  height: 32px; padding: 0 var(--space-2);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
.settings-temp-wrap { width: 100%; }
.settings-footer {
  display: flex; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
}
.settings-reset-btn {
  height: 32px; padding: 0 var(--space-3);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-reset-btn:hover {
  background: var(--color-surface);
  color: var(--color-error);
  border-color: var(--color-error);
}
.settings-done-btn {
  height: 32px; padding: 0 var(--space-4);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  background: var(--color-accent);
  color: var(--color-accent-fg);
  border: none; border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-done-btn:hover { background: var(--color-accent-2); }

@media (max-width: 600px) {
  .settings-row { grid-template-columns: 1fr; }
  .settings-row-control { justify-self: stretch; }
}

/* =============================================================
   RUN DETAILS DRAWER (advanced / power-user panel)
   ============================================================= */

/* Backdrop — subtle dim, closes drawer on click */
.dev-drawer-overlay {
  position: fixed; inset: 0; z-index: 199;
  background: rgba(3, 7, 18, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}
.dev-drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Drawer panel — slides in from the right, below the topbar */
.dev-drawer {
  position: fixed;
  top: 48px; inset-inline-end: 0; bottom: 0;
  z-index: 200;
  width: min(var(--dev-drawer-width, 520px), 100vw);
  background: var(--color-surface);
  border-inline-start: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 250ms ease;
}
.dev-drawer.open {
  transform: translateX(0);
}
.dev-drawer.is-resizing {
  transition: none;
  user-select: none;
}
.dev-drawer-resize {
  position: absolute;
  top: 0;
  inset-inline-start: -5px;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
  touch-action: none;
  z-index: 2;
}
.dev-drawer-resize::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  inset-inline-start: 4px;
  width: 2px;
  background: transparent;
  transition: background 120ms ease;
}
.dev-drawer-resize:hover::after,
.dev-drawer.is-resizing .dev-drawer-resize::after {
  background: var(--color-accent);
}
.dev-drawer-resizing {
  cursor: ew-resize;
  user-select: none;
}

.dev-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.dev-drawer-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  letter-spacing: -0.01em;
}
.dev-drawer-close-btn {
  width: 28px; height: 28px; padding: 0;
  font-size: 20px; line-height: 1;
  background: transparent; color: var(--color-muted);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer;
}
.dev-drawer-close-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-border);
}

.dev-drawer-body {
  flex: 1; overflow-y: auto;
  padding: var(--space-4);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-2) transparent;
}
.dev-drawer-body::-webkit-scrollbar { width: 8px; }
.dev-drawer-body::-webkit-scrollbar-track { background: transparent; }
.dev-drawer-body::-webkit-scrollbar-thumb {
  background: var(--color-border-2);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* Active-state glow on the topbar button when drawer is open */
.topbar-icon-btn.is-active {
  background: var(--color-surface-2);
  border-color: var(--color-border-2);
  color: var(--color-accent);
}

/* Dot badge — appears once SQL is ready */
.dev-panel-badge {
  position: absolute;
  top: 4px; inset-inline-end: 4px;
  width: 6px; height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  border: 1.5px solid var(--color-surface);
  pointer-events: none;
}
/* The button needs relative positioning for the badge */
#dev-panel-btn { position: relative; }

@media (max-width: 600px) {
  .dev-drawer { width: 100vw; }
  .dev-drawer-resize { display: none; }
}

/* =============================================================
   COLUMN CONTEXT MENU
   ============================================================= */
.col-ctx-menu {
  display: none;
  position: fixed;
  z-index: 9000;
  width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1) 0;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  user-select: none;
  overflow: hidden;
}
.col-ctx-header {
  padding: 4px var(--space-3) 2px;
  font-size: 10px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-faint);
  font-family: var(--font-mono);
  border-top: 1px solid var(--color-border);
  margin-top: 2px;
}
.col-ctx-header:first-child { border-top: 0; margin-top: 0; }
.col-ctx-sep {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-1) 0;
}
.col-ctx-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 5px var(--space-3);
  cursor: pointer;
  color: var(--color-text);
  transition: background 80ms ease;
}
.col-ctx-item:hover {
  background: var(--color-surface-2);
}
.col-ctx-item-danger { color: var(--color-error); }
.col-ctx-item-danger:hover { background: var(--color-error-bg); }
.col-ctx-icon {
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-muted);
}
.col-ctx-icon-mono {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-muted);
}

/* Format indicator tag in column header */
.col-fmt-tag {
  display: inline-block;
  margin-inline-start: 3px;
  padding: 0 4px;
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: var(--weight-semibold);
  background: var(--color-accent);
  color: var(--color-accent-fg);
  border-radius: var(--radius-sm);
  vertical-align: middle;
  line-height: 14px;
}

/* Derived columns (% of total, running total, delta) */
.derived-col-header {
  background: var(--color-dim-bg);
  color: var(--color-dim-text);
  font-style: italic;
  font-weight: var(--weight-normal);
  white-space: nowrap;
  cursor: default;
}
.derived-col {
  background: var(--color-dim-bg);
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  text-align: end;
  white-space: nowrap;
  font-style: italic;
}
.derived-positive {
  background: var(--color-success-bg);
  color: var(--color-success);
}
.derived-negative {
  background: var(--color-error-bg);
  color: var(--color-error);
}

/* =============================================================
   ASK-CARD METRICS READOUT (token usage + LLM latency)
   ============================================================= */
.ask-metrics {
  position: absolute;
  inset-inline-end: var(--space-3);
  bottom: var(--space-2);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-faint);
  letter-spacing: 0;
  user-select: none;
  pointer-events: none;
  white-space: nowrap;
}
.ask-metrics[hidden] { display: none; }
/* Make the query card the positioning context so 'absolute' lands inside it. */
.query-card { position: relative; padding-bottom: var(--space-6); }
@media (max-width: 600px) {
  .ask-metrics {
    position: static;
    margin-top: var(--space-2);
    text-align: end;
  }
}

/* =============================================================
   INSIGHTS STREAMING (TTFT badge + progress)
   ============================================================= */
.insights-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
}
.insights-stream-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-faint);
  letter-spacing: 0;
  white-space: nowrap;
}
.insights-stream-status {
  font-size: var(--text-xs);
  color: var(--color-muted);
  margin-bottom: var(--space-2);
  font-family: var(--font-mono);
  letter-spacing: 0;
}

/* =============================================================
   QUESTION HISTORY SEARCH (sidebar filter)
   ============================================================= */
.question-search-input {
  margin-bottom: var(--space-2);
}

/* =============================================================
   HISTORY DRAWER
   ============================================================= */
.history-drawer-overlay {
  position: fixed; inset: 0; z-index: 199;
  background: rgba(3, 7, 18, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}
.history-drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.history-drawer {
  position: fixed;
  top: 48px; inset-inline-end: 0; bottom: 0;
  z-index: 200;
  width: min(480px, 100vw);
  background: var(--color-surface);
  border-inline-start: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 250ms ease;
}
.history-drawer.open {
  transform: translateX(0);
}

.history-drawer-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.history-drawer-header-top {
  display: flex; align-items: center; justify-content: space-between;
}
.history-drawer-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.history-drawer-body {
  flex: 1; overflow-y: auto;
  padding: var(--space-3) var(--space-4);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-2) transparent;
}
.history-drawer-body::-webkit-scrollbar { width: 8px; }
.history-drawer-body::-webkit-scrollbar-track { background: transparent; }
.history-drawer-body::-webkit-scrollbar-thumb {
  background: var(--color-border-2);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* Individual log entry */
.history-log-entry {
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-3) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: background 100ms ease, border-color 100ms ease;
  background: var(--color-surface);
}
.history-log-entry:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border-2);
}
.history-log-entry-question {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: var(--weight-medium);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.history-log-meta {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--color-faint);
  letter-spacing: 0;
}
.history-log-status {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}
.history-log-status[data-status="success"] {
  background: var(--color-success-bg);
  color: var(--color-success);
}
.history-log-status[data-status="error"] {
  background: var(--color-error-bg);
  color: var(--color-error);
}
.history-log-status[data-status="pending"],
.history-log-status[data-status="running"] {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}
.history-log-dot { font-size: 8px; color: var(--color-faint); }

.history-log-session {
  font-size: 10px;
  color: var(--color-muted);
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-log-empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--color-faint);
  font-size: var(--text-sm);
}

@media (max-width: 600px) {
  .history-drawer { width: 100vw; }
}

/* =============================================================
   SETTINGS PAGE (full-screen overlay)
   ============================================================= */

/* Overlay — sits below the topbar (48 px) so the top bar remains visible */
.sp-overlay {
  position: fixed; inset: 48px 0 0 0; z-index: 300;
  background: var(--color-bg);
  display: flex; flex-direction: column;
  animation: sp-fade-in 160ms ease-out;
}
/* Ensure the hidden attribute wins over display:flex */
.sp-overlay[hidden] { display: none !important; }
@keyframes sp-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* Two-column layout */
.sp-page {
  display: flex; flex: 1; min-height: 0;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sp-sidebar {
  width: 210px; flex-shrink: 0;
  border-inline-end: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.sp-sidebar-header {
  height: 48px;                       /* mirror topbar height */
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  display: flex; align-items: center; gap: var(--space-2);
}
.sp-sidebar-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  color: var(--color-faint);
  text-transform: uppercase;
  flex: 1;
}

/* Back / close button in settings sidebar header */
.sp-header-back-btn {
  width: 28px; height: 28px; padding: 0; flex-shrink: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--color-muted);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}
.sp-header-back-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-border);
}

/* Scrollable nav body */
.sp-nav-body {
  flex: 1; overflow-y: auto; padding: var(--space-2) var(--space-2);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-2) transparent;
}

/* Group label */
.sp-nav-group {
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-faint);
  padding: var(--space-3) var(--space-2) var(--space-1);
  margin-top: var(--space-2);
}
.sp-nav-group:first-child { margin-top: 0; }

/* Nav item */
.sp-nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; height: 34px; padding: 0 var(--space-3);
  background: transparent; border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-muted);
  cursor: pointer; text-align: start;
  position: relative;
  transition: background 100ms ease, color 100ms ease;
}
/* Gated entries (admin / connectors) are hidden via the attribute; the class's
   display:flex would otherwise beat the UA [hidden] rule. */
.sp-nav-item[hidden] { display: none; }
.sp-nav-item:hover { background: var(--color-surface-2); color: var(--color-text); }
.sp-nav-item.is-active {
  background: var(--color-dim-bg);
  color: var(--color-accent-2);
  font-weight: var(--weight-semibold);
}
[data-theme="dark"] .sp-nav-item.is-active {
  background: var(--color-dim-bg);
  color: var(--color-dim-text);
}
.sp-nav-item svg { flex-shrink: 0; opacity: 0.6; }
.sp-nav-item.is-active svg { opacity: 1; }
.sp-nav-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Custom-prompt dot */
.sp-nav-dot {
  position: absolute; top: 6px; inset-inline-end: 8px;
  width: 6px; height: 6px; border-radius: var(--radius-full);
  background: var(--color-accent);
  border: 1.5px solid var(--color-surface);
  pointer-events: none;
}

/* Bottom nav: pinned to bottom */
.sp-nav-bottom {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  margin-top: auto;
}

.sp-nav-group-bottom {
  margin-top: 0;
  padding-top: var(--space-1);
}

a.sp-nav-item {
  text-decoration: none;
  box-sizing: border-box;
}

/* MCP health check — in-progress placeholder (hides stale Healthy card) */
.mc-health-pending {
  border: 1px dashed var(--color-border);
  background: var(--color-surface-2);
}
.mc-health-pending-msg {
  margin: 0 14px 14px;
  font-size: 0.8rem;
  color: var(--color-muted);
  line-height: 1.45;
}
.mc-health-badge.mc-health-checking {
  background: var(--color-surface);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
}

/* Close / logout actions (slightly muted) */
.sp-close-btn,
.sp-logout-btn { color: var(--color-muted); }
.sp-close-btn:hover,
.sp-logout-btn:hover { color: var(--color-text); background: var(--color-surface-2); }
.sp-logout-btn:hover { color: var(--color-error); }

/* ── Content area ────────────────────────────────────────── */
.sp-content {
  flex: 1; min-width: 0; overflow-y: auto;
  padding: var(--space-8) min(64px, 6vw);
  background: var(--color-bg);
}

.sp-section-header {
  margin-bottom: var(--space-6);
}
.sp-prompt-title-row {
  display: flex; align-items: center; gap: var(--space-3); margin-bottom: 4px;
}
.sp-section-title {
  font-size: 1.3rem; font-weight: var(--weight-semibold);
  letter-spacing: -0.02em; color: var(--color-text); margin: 0;
}
.sp-section-desc {
  font-size: var(--text-sm); color: var(--color-muted);
  margin: 0; line-height: 1.5; max-width: 600px;
}

/* Badge (Default / Custom) */
.sp-badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: 0.02em; flex-shrink: 0;
}
.sp-badge-default {
  background: var(--color-surface-2); color: var(--color-muted);
  border: 1px solid var(--color-border);
}
.sp-badge-custom {
  background: var(--color-dim-bg); color: var(--color-accent-2);
  border: 1px solid color-mix(in srgb, var(--color-accent) 40%, var(--color-border));
}
[data-theme="dark"] .sp-badge-custom {
  background: var(--color-dim-bg); color: var(--color-dim-text);
  border-color: color-mix(in srgb, var(--color-accent) 40%, transparent);
}

/* ── Cards ───────────────────────────────────────────────── */
.sp-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-4);
  max-width: 800px;
}
.sp-card-title {
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--color-text); margin-bottom: var(--space-4);
}
.sp-card-footer {
  max-width: 800px; padding-top: var(--space-2);
}

/* Settings row (label + control) */
.sp-row {
  display: grid; grid-template-columns: 1fr 220px;
  gap: var(--space-3); align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}
.sp-row:last-child { border-bottom: 0; }
.sp-row-label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text); }
.sp-row-help  { font-size: var(--text-xs); color: var(--color-faint); margin-top: 2px; line-height: 1.4; }
.sp-row-control { justify-self: end; width: 100%; }
/* Catalog source toggle — needs room for icon + "MCP Server" label */
.sp-row--seg {
  grid-template-columns: 1fr auto;
  align-items: start;
}
.sp-row--seg .mc-seg {
  justify-self: end;
  flex-shrink: 0;
  width: max-content;
  max-width: 100%;
}

.saved-analyses-block {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}
.saved-analyses-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  color: var(--color-faint);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.saved-analyses-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.saved-analysis-item {
  padding: 7px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
}
.saved-analysis-item:hover,
.saved-analysis-item:focus {
  outline: none;
  border-color: var(--color-accent);
  background: var(--color-surface-2);
}
.saved-analysis-title {
  color: var(--color-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saved-analysis-question {
  margin-top: 2px;
  color: var(--color-muted);
  font-size: 11px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.saved-analysis-meta {
  margin-top: 4px;
  color: var(--color-faint);
  font-family: var(--font-mono);
  font-size: 10px;
}

/* ── Placeholder chips ───────────────────────────────────── */
.sp-placeholder-row {
  display: flex; align-items: flex-start; gap: var(--space-3);
  margin-bottom: var(--space-4); flex-wrap: wrap;
  font-size: var(--text-xs); color: var(--color-muted);
  max-width: 720px;
}
.sp-placeholder-label { flex-shrink: 0; padding-top: 3px; }
.sp-placeholder-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Chip in the reference bar */
.sp-ph-chip {
  font-family: var(--font-mono); font-size: var(--text-xs);
  padding: 2px 8px; border-radius: var(--radius-sm);
  background: var(--color-dim-bg); color: var(--color-accent-2);
  border: 1px solid color-mix(in srgb, var(--color-accent) 28%, var(--color-border));
  white-space: nowrap;
}
[data-theme="dark"] .sp-ph-chip {
  background: var(--color-dim-bg); color: var(--color-dim-text);
  border-color: color-mix(in srgb, var(--color-accent) 35%, transparent);
}

/* Inline chip inside the prompt read-only view */
.sp-ph-inline {
  font-family: var(--font-mono); font-size: 0.8em;
  padding: 1px 6px; border-radius: var(--radius-sm);
  background: var(--color-dim-bg); color: var(--color-accent-2);
  border: 1px solid color-mix(in srgb, var(--color-accent) 22%, var(--color-border));
  white-space: nowrap;
}
[data-theme="dark"] .sp-ph-inline {
  background: var(--color-dim-bg); color: var(--color-dim-text);
}
.sp-runtime-inline {
  font-family: var(--font-mono); font-size: 0.8em;
  padding: 1px 6px; border-radius: var(--radius-sm);
  background: var(--color-surface-2); color: var(--color-muted);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

/* ── Prompt resolved view controls ───────────────────────── */
.sp-resolve-bar {
  max-width: 960px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.sp-view-seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
}
.sp-view-seg button {
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.sp-view-seg button.is-active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-xs);
}
.sp-resolve-conn { width: min(300px, 100%); }
.sp-resolve-tokens {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.sp-token-pill {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: var(--weight-medium);
}
.sp-token-pill-strong {
  color: var(--color-accent-2);
  background: var(--color-dim-bg);
  border-color: color-mix(in srgb, var(--color-accent) 28%, var(--color-border));
}

/* ── Prompt body ─────────────────────────────────────────── */
.sp-prompt-body { max-width: 960px; margin-bottom: var(--space-4); }

/* Read-only rendered view */
.sp-prompt-view {
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  font-family: var(--font-mono); font-size: var(--text-sm);
  line-height: 1.65; white-space: pre-wrap; word-wrap: break-word;
  overflow-y: auto; max-height: 500px;
  cursor: default;
}
.sp-prompt-view-resolved {
  max-height: 620px;
  border-color: color-mix(in srgb, var(--color-accent) 35%, var(--color-border));
}
.sp-resolved-empty {
  min-height: 120px;
  color: var(--color-muted);
  font-family: var(--font-sans);
}
.sp-resolved-error {
  color: var(--color-error);
  border-color: var(--color-error);
  background: var(--color-error-bg);
}
.sp-resolved-summary {
  margin-bottom: var(--space-3);
  display: grid;
  gap: var(--space-2);
}
.sp-token-total {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--color-muted);
}
.sp-token-total b { color: var(--color-text); font-family: var(--font-mono); }
.sp-tokenizer {
  font-family: var(--font-mono);
  color: var(--color-faint);
}
.sp-resolved-note {
  font-size: var(--text-xs);
  color: var(--color-muted);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
}
.sp-resolved-note code {
  font-family: var(--font-mono);
  color: var(--color-accent-2);
}
.sp-token-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}
.sp-token-card {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 9px 10px;
}
.sp-token-card-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.sp-token-card-head code {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--color-accent-2);
}
.sp-token-card-head span {
  font-size: 0.62rem;
  color: var(--color-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sp-token-card-num {
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text);
}

/* Editable textarea */
.sp-prompt-textarea {
  width: 100%; min-height: 400px; height: 500px;
  font-family: var(--font-mono); font-size: var(--text-sm);
  line-height: 1.65; resize: vertical;
  background: var(--code-bg); color: var(--code-text);
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* ── Prompt footer (save / reset) ────────────────────────── */
/* Same width as .sp-prompt-body so Edit/Save sit on the body's right edge. */
.sp-prompt-footer {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 960px; padding-top: var(--space-2);
}
.sp-prompt-footer-right { display: flex; gap: var(--space-2); }

/* Buttons */
.sp-btn-primary {
  height: 36px; padding: 0 var(--space-4);
  background: var(--color-text); color: var(--color-surface);
  border: none; border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-sm);
  font-weight: var(--weight-semibold); cursor: pointer;
}
.sp-btn-primary:hover { opacity: 0.85; }
.sp-btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.sp-btn-secondary {
  height: 36px; padding: 0 var(--space-4);
  background: transparent; color: var(--color-text);
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-sm);
  font-weight: var(--weight-medium); cursor: pointer;
}
.sp-btn-secondary:hover { background: var(--color-surface-2); border-color: var(--color-border-2); }

.sp-btn-ghost {
  height: 36px; padding: 0 var(--space-3);
  background: transparent; color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-sm);
  cursor: pointer;
}
.sp-btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }
.sp-btn-ghost:disabled { opacity: 0.35; cursor: not-allowed; }

.sp-btn-reset:not(:disabled):hover {
  color: var(--color-error); border-color: var(--color-error);
  background: var(--color-error-bg);
}

/* ── Prompt version history ───────────────────────────────── */
.sp-version-history {
  max-width: 960px;
  margin-top: var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.sp-vh-summary {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-muted);
  cursor: pointer; user-select: none;
  background: var(--color-surface);
  list-style: none;
}
.sp-vh-summary::-webkit-details-marker { display: none; }
.sp-vh-summary::marker { display: none; }
.sp-vh-summary:hover { color: var(--color-text); background: var(--color-surface-2); }
.sp-version-history[open] > .sp-vh-summary { border-bottom: 1px solid var(--color-border); }

.sp-vh-count {
  margin-inline-start: auto;
  font-size: var(--text-xs);
  color: var(--color-faint);
  font-family: var(--font-mono);
}

.sp-vh-body {
  background: var(--color-bg);
  padding: var(--space-1) 0;
}
.sp-vh-loading {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-faint); margin: 0;
}

.sp-vh-row {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.sp-vh-row:last-child { border-bottom: 0; }

.sp-vh-row-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
}
.sp-vh-meta {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
}
.sp-vh-ver {
  font-family: var(--font-mono); font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-accent-2); background: var(--color-dim-bg);
  padding: 1px 7px; border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--color-accent) 22%, var(--color-border));
}
[data-theme="dark"] .sp-vh-ver {
  background: var(--color-dim-bg); color: var(--color-dim-text);
  border-color: color-mix(in srgb, var(--color-accent) 35%, transparent);
}
.sp-vh-date {
  font-size: var(--text-xs); color: var(--color-faint);
  font-family: var(--font-mono);
}
.sp-badge-active {
  background: var(--color-success-bg); color: var(--color-success);
  border: 1px solid transparent;
}

.sp-vh-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }
.sp-vh-btn {
  height: 26px; padding: 0 var(--space-3);
  background: transparent; color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: 12px;
  cursor: pointer; white-space: nowrap;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.sp-vh-btn:hover { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border-2); }
.sp-vh-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.sp-vh-restore:hover {
  color: var(--color-accent-2);
  border-color: color-mix(in srgb, var(--color-accent) 45%, var(--color-border));
  background: var(--color-dim-bg);
}
[data-theme="dark"] .sp-vh-restore:hover {
  background: var(--color-dim-bg);
  border-color: color-mix(in srgb, var(--color-accent) 40%, transparent);
}

.sp-vh-preview-area { margin-top: var(--space-3); }
.sp-vh-pre {
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-mono); font-size: 12px;
  line-height: 1.6; white-space: pre-wrap; word-wrap: break-word;
  overflow-y: auto; max-height: 300px;
  margin: 0;
}

/* ── About grid ───────────────────────────────────────────────────── */
.sp-about-grid {
  display: flex; flex-direction: column;
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-3);
}
.sp-about-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
}
.sp-about-row:last-child { border-bottom: 0; }
.sp-about-label { color: var(--color-muted); font-weight: var(--weight-medium); }
.sp-about-value { color: var(--color-text); font-family: var(--font-mono); font-size: var(--text-xs); }

/* ── AI Model cards ─────────────────────────────────────── */
.sp-model-group-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--color-muted); margin-bottom: var(--space-2);
}
.sp-model-group-label--dim { opacity: 0.6; }

.sp-model-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.sp-model-card:hover:not(.is-unavailable) {
  border-color: var(--color-accent); background: var(--color-surface-2);
}
.sp-model-card.is-active {
  border-color: var(--color-accent);
  background: oklch(from var(--color-accent) l c h / 0.06);
}
.sp-model-card.is-unavailable {
  opacity: 0.45; cursor: not-allowed;
}

.sp-model-info { flex: 1; min-width: 0; }
.sp-model-name {
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--color-text); display: flex; align-items: center; flex-wrap: wrap; gap: 4px;
}
.sp-model-card.is-active .sp-model-name { color: var(--color-accent); }
.sp-model-desc {
  font-size: var(--text-xs); color: var(--color-muted);
  margin-top: 2px; line-height: 1.45;
}

.sp-model-check {
  flex-shrink: 0; margin-inline-start: var(--space-3);
  color: var(--color-accent); display: flex;
}
.sp-model-unavail {
  font-size: 10px; font-weight: var(--weight-medium);
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-muted);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 4px; padding: 1px 6px;
}

/* Live credential-health dot shown before each model name. */
.sp-model-health {
  flex-shrink: 0;
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 2px transparent;
}
.sp-model-health--ok {
  background: oklch(0.72 0.18 145);            /* green */
  box-shadow: 0 0 0 3px oklch(0.72 0.18 145 / 0.18);
}
.sp-model-health--fail {
  background: oklch(0.63 0.22 25);             /* red */
  box-shadow: 0 0 0 3px oklch(0.63 0.22 25 / 0.18);
}
.sp-model-health--unknown {
  background: var(--color-border);             /* grey = not probed */
}

/* AI Models section toolbar (health summary + re-check button). */
.sp-models-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3);
  margin-top: var(--space-3);
}
.sp-models-health-summary {
  font-size: var(--text-xs); color: var(--color-muted);
}
.sp-model-search {
  width: min(240px, 100%);
  margin-inline-start: auto;
}
.sp-models-empty {
  margin: 0;
  padding: var(--space-5) var(--space-3);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-muted);
}

/* ── Prompts: nav count pill ─────────────────────────────────
   Number of custom prompts on the "Prompts" nav item. Swapped for the plain
   dot when the sidebar is icon-only (see the ≤640px block below). */
.sp-nav-count {
  margin-inline-start: auto; flex-shrink: 0;
  min-width: 16px; height: 16px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: var(--weight-semibold); line-height: 1;
  border-radius: var(--radius-full);
  background: var(--color-dim-bg); color: var(--color-accent-2);
}
[data-theme="dark"] .sp-nav-count { color: var(--color-dim-text); }
.sp-nav-count[hidden] { display: none; }
/* While the pill is showing, the corner dot would be redundant. */
.sp-nav-count:not([hidden]) ~ .sp-nav-dot { display: none; }

/* ── Prompts: list page ───────────────────────────────────── */
.sp-card--list { padding: var(--space-4); }
.sp-card--list .sp-card-title {
  display: flex; align-items: baseline; gap: var(--space-2);
  margin: 0 var(--space-2) var(--space-2);
}
.sp-card-count {
  font-size: 11px; font-weight: var(--weight-normal);
  color: var(--color-faint);
}

.sp-prompt-list { list-style: none; margin: 0; padding: 0; }

/* Each row is one <button>: whole row clickable, keyboard/focus for free. */
.sp-prompt-row {
  width: 100%;
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr) auto 128px 16px;
  gap: var(--space-3); align-items: center;
  min-height: 44px; padding: 0 var(--space-2);
  border: 0; border-bottom: 1px solid var(--color-border);
  background: transparent;
  font: inherit; text-align: start; color: var(--color-text);
  cursor: pointer;
  transition: background 100ms ease;
}
.sp-prompt-list li:last-child .sp-prompt-row { border-bottom: 0; }
.sp-prompt-row:hover { background: var(--color-surface-2); }
.sp-prompt-row:focus-visible {
  outline: 2px solid var(--color-accent); outline-offset: -2px;
  box-shadow: none; border-radius: var(--radius-sm);
}
.sp-prompt-row-name {
  font-size: 13px; font-weight: var(--weight-medium);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sp-prompt-row-desc {
  font-size: var(--text-xs); color: var(--color-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sp-prompt-row-status {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-width: 72px; justify-content: flex-start;
}
.sp-prompt-row-ago {
  font-size: 11px; color: var(--color-faint); white-space: nowrap;
}
.sp-prompt-row-model {
  font-family: var(--font-mono); font-size: 11px; color: var(--color-muted);
  text-align: end; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sp-prompt-row-chev {
  display: inline-flex; color: var(--color-faint);
  transition: color 100ms ease;
}
.sp-prompt-row:hover .sp-prompt-row-chev { color: var(--color-text); }

/* ── Prompts: editor back link (eyebrow above the title) ───── */
.sp-back-link {
  display: inline-flex; align-items: center; gap: 4px;
  height: 28px; padding: 0 var(--space-2);
  margin: 0 0 var(--space-2) -6px;
  background: transparent; border: none; border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-xs);
  font-weight: var(--weight-medium); color: var(--color-muted);
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease;
}
.sp-back-link:hover { background: var(--color-surface-2); color: var(--color-text); }
.sp-back-link:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; box-shadow: none; }

/* Responsive: on small screens the sidebar collapses */
@media (max-width: 640px) {
  .sp-sidebar { width: 52px; }
  .sp-nav-group,
  .sp-nav-label,
  .sp-sidebar-title { display: none; }
  .sp-content { padding: var(--space-4); }
  .sp-row { grid-template-columns: 1fr; }
  .sp-row-control { justify-self: stretch; }

  /* Icon-only rail: the count pill has no room, fall back to the dot. */
  .sp-nav-count { display: none; }
  .sp-nav-count:not([hidden]) ~ .sp-nav-dot { display: block; }

  /* Prompt rows: name + chevron on line one, status + model wrap below. */
  .sp-prompt-row {
    grid-template-columns: minmax(0, 1fr) 16px;
    grid-auto-flow: row; row-gap: 2px;
    min-height: 52px; padding: var(--space-2);
  }
  .sp-prompt-row-desc { display: none; }
  .sp-prompt-row-status { grid-column: 1; min-width: 0; }
  .sp-prompt-row-model { grid-column: 1; text-align: start; }
  /* Default rows have nothing on line two — don't reserve the space. */
  .sp-prompt-row-status:empty,
  .sp-prompt-row-model:empty { display: none; }
  .sp-prompt-row-chev { grid-row: 1; grid-column: 2; }

  /* The back link is the only textual wayfinding here — give it a 44px target. */
  .sp-back-link { height: 44px; padding: 0 var(--space-3); margin-inline-start: -12px; }
}

/* =============================================================
   AUTH — USER AVATAR, DROPDOWN & ROLE BADGES
   ============================================================= */

/* Avatar button in topbar */
.user-menu-wrap { position: relative; }

.user-avatar-btn {
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; padding: 0;
  border-radius: var(--radius-full);
  outline-offset: 2px;
}
.user-avatar-btn:focus-visible { box-shadow: var(--shadow-focus); }

.user-avatar {
  width: 28px; height: 28px;
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  font-family: var(--font-sans);
  letter-spacing: 0; line-height: 1;
  user-select: none; flex-shrink: 0;
}

/* Dropdown panel */
.user-dropdown {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0;
  min-width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
}
.user-dropdown-info {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-3) var(--space-4);
}
.user-dropdown-name {
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--color-text);
}
.user-dropdown-email {
  font-size: var(--text-xs); color: var(--color-muted);
  word-break: break-all;
}
.user-dropdown-divider {
  height: 1px; background: var(--color-border); margin: 0;
}
.user-dropdown-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); color: var(--color-text);
  text-decoration: none;
  transition: background 0.12s;
}
.user-dropdown-item:hover { background: var(--color-surface-2); }
.user-dropdown-logout { color: var(--color-error); }
.user-dropdown-logout:hover { background: var(--color-error-bg); }

/* Interface language (account property; see auth.js). Labels are written in
   their own language, so each option carries its own lang/dir. */
.user-dropdown-lang {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
}
.user-dropdown-lang-label { font-size: var(--text-xs); color: var(--color-muted); white-space: nowrap; }
.user-lang-picker {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px;
  border: 1px solid var(--color-border); border-radius: var(--radius-full);
  background: var(--color-surface);
}
.user-lang-picker[aria-busy="true"] { opacity: .6; pointer-events: none; }
.user-lang-option {
  border: 0; border-radius: var(--radius-full); background: transparent;
  color: var(--color-muted); font: inherit; font-size: var(--text-xs);
  padding: 3px 10px; cursor: pointer; white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}
.user-lang-option:hover { color: var(--color-text); background: var(--color-surface-2); }
.user-lang-option[aria-checked="true"] { background: var(--color-text); color: var(--color-bg, #fff); }
.user-lang-option:focus-visible { box-shadow: var(--shadow-focus); outline: none; }

/* Role badges (inline and in table) */
.user-role-badge {
  display: inline-flex; align-items: center;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 2px 8px; border-radius: var(--radius-full);
  margin-top: 4px; width: fit-content;
}
.role-admin  { background: var(--color-accent-muted); color: var(--color-accent); }
.role-editor { background: color-mix(in srgb, var(--color-brand) 12%, transparent); color: var(--color-brand); }
.role-viewer { background: var(--color-surface-2); color: var(--color-muted); border: 1px solid var(--color-border); }
[data-theme="dark"] .role-admin  { color: var(--color-accent-2); }
[data-theme="dark"] .role-editor { color: var(--color-brand); }

/* Prompt model row (in settings prompt editor) */
.sp-prompt-model-row {
  display: flex; align-items: center; gap: var(--space-3);
  margin-top: var(--space-3);
}
.sp-prompt-model-label {
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--color-muted); white-space: nowrap;
}

/* =============================================================
   SETTINGS — USER MANAGEMENT PANEL
   ============================================================= */

/* Compact user table */
.sp-users-table {
  width: 100%; border-collapse: collapse;
  font-size: var(--text-sm);
}
.sp-users-table thead th {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-muted); text-align: start;
  border-bottom: 1px solid var(--color-border);
}
.sp-users-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background 0.1s;
}
.sp-users-table tbody tr:last-child { border-bottom: 0; }
.sp-users-table tbody tr:hover { background: var(--color-surface-2); }
.sp-users-table td {
  padding: var(--space-3) var(--space-3);
  vertical-align: middle;
}

/* Avatar in table */
.sp-user-cell {
  display: flex; align-items: center; gap: var(--space-3);
}
.sp-user-avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  font-family: var(--font-sans);
  user-select: none;
}
.sp-user-name  { font-weight: var(--weight-medium); color: var(--color-text); }
.sp-user-email { font-size: var(--text-xs); color: var(--color-muted); margin-top: 1px; }
.sp-user-you   {
  font-size: 10px; font-weight: 600; color: var(--color-accent);
  margin-inline-start: 4px;
}

/* Role select in table */
.sp-role-select,
.sp-metadata-role-select {
  font-size: var(--text-xs); padding: 4px 8px;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text);
  font-family: var(--font-sans); cursor: pointer;
}
.sp-role-select:disabled,
.sp-metadata-role-select:disabled { opacity: 0.5; cursor: default; }

.sp-role-field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: var(--text-xs); color: var(--color-muted);
}

/* Delete button */
.sp-user-del-btn {
  background: none; border: none; cursor: pointer;
  color: var(--color-faint); padding: 4px; border-radius: var(--radius-sm);
  display: flex; align-items: center;
  transition: color 0.12s, background 0.12s;
}
.sp-user-del-btn:hover { color: var(--color-error); background: var(--color-error-bg); }
.sp-user-del-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* Add user form */
.sp-add-user-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}
.sp-add-user-form .sp-add-full { grid-column: 1 / -1; }

.sp-add-user-input {
  width: 100%; padding: 8px 10px;
  font-size: var(--text-sm); font-family: var(--font-sans);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); color: var(--color-text);
  outline: none; box-sizing: border-box;
}
.sp-add-user-input:focus { border-color: var(--color-accent); box-shadow: var(--shadow-focus); }
.sp-add-user-input::placeholder { color: var(--color-faint); }

.sp-add-user-select {
  width: 100%; padding: 8px 10px;
  font-size: var(--text-sm); font-family: var(--font-sans);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); color: var(--color-text);
  cursor: pointer;
}

.sp-add-user-submit {
  height: 36px; padding: 0 var(--space-4);
  background: var(--color-accent); color: var(--color-accent-fg);
  border: none; border-radius: var(--radius-md);
  font-family: var(--font-sans); font-size: var(--text-sm);
  font-weight: var(--weight-semibold); cursor: pointer;
  transition: opacity 0.15s;
}
.sp-add-user-submit:hover { opacity: 0.85; }
.sp-add-user-submit:disabled { opacity: 0.4; cursor: not-allowed; }

.sp-users-error {
  font-size: var(--text-xs); color: var(--color-error);
  margin-top: var(--space-2); min-height: 16px;
}

/* =============================================================
   SETTINGS — ANALYTICS (admin usage dashboard)
   ============================================================= */

.sp-an-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
}
.sp-an-toolbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.sp-an-range {
  display: inline-flex; padding: 2px;
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.sp-an-range-btn {
  height: 26px; padding: 0 10px; border: 0; border-radius: calc(var(--radius-md) - 2px);
  background: transparent; color: var(--color-muted);
  font-family: var(--font-sans); font-size: var(--text-xs); font-weight: var(--weight-medium);
  cursor: pointer; transition: background 0.12s, color 0.12s;
}
.sp-an-range-btn:hover { color: var(--color-text); }
.sp-an-range-btn.is-active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow); }

.sp-an-body { display: flex; flex-direction: column; gap: var(--space-4); }
.sp-an-body[hidden] { display: none; }
.sp-an-skeleton { height: 96px; border-radius: var(--radius-md); margin-bottom: var(--space-3); }

.sp-an-notice { padding: var(--space-4); font-size: var(--text-sm); color: var(--color-muted); }
.sp-an-notice strong { color: var(--color-text); }
.sp-an-notice p { margin: var(--space-2) 0 0; }
.sp-an-notice-error { border-color: var(--color-error); }

/* KPI cards */
.sp-an-kpis {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.sp-an-kpi {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface); min-width: 0;
}
.sp-an-kpi-label {
  font-size: var(--text-xs); color: var(--color-muted);
  text-transform: uppercase; letter-spacing: 0.05em; font-weight: var(--weight-semibold);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sp-an-kpi-value {
  margin-top: 4px; display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap;
  font-size: 1.35rem; font-weight: var(--weight-semibold); color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.sp-an-kpi-delta { font-size: var(--text-xs); font-weight: var(--weight-medium); }
.sp-an-kpi-delta.is-good    { color: var(--color-success); }
.sp-an-kpi-delta.is-bad     { color: var(--color-error); }
.sp-an-kpi-delta.is-neutral { color: var(--color-muted); }

/* Cards */
.sp-an-card { padding: var(--space-4); min-width: 0; }
.sp-an-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.sp-an-card-head-wrap { flex-wrap: wrap; }
.sp-an-card-title { margin: 0; font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
.sp-an-card-sub { font-size: var(--text-xs); color: var(--color-muted); }
.sp-an-subtitle {
  margin: var(--space-4) 0 var(--space-2); font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-muted);
}
.sp-an-grid-2 { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.sp-an-chart { width: 100%; height: 280px; }

/* Tables */
.sp-an-table-wrap { overflow-x: auto; }
.sp-an-table td, .sp-an-table th { white-space: nowrap; }
.sp-an-table td:first-child, .sp-an-table th:first-child { white-space: normal; }
.sp-an-table .is-num { text-align: end; font-variant-numeric: tabular-nums; }
.sp-an-mono { font-family: var(--font-mono); font-size: var(--text-xs); }
.sp-an-muted { color: var(--color-muted); }
.sp-an-question { display: inline-block; max-width: 420px; white-space: normal; }
.sp-an-empty {
  padding: var(--space-4); text-align: center;
  font-size: var(--text-sm); color: var(--color-muted);
}
.sp-an-empty-wide { grid-column: 1 / -1; padding: var(--space-3); text-align: start; }
.sp-an-thumbs { display: inline-flex; gap: var(--space-2); }
.sp-an-thumb-up { color: var(--color-success); }
.sp-an-thumb-down { color: var(--color-error); }

/* Badges */
.sp-an-badge {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px;
  border-radius: var(--radius-full); font-size: 11px; font-weight: var(--weight-medium);
  background: var(--color-surface-2); color: var(--color-muted); border: 1px solid var(--color-border);
}
.sp-an-badge-up      { color: var(--color-success); background: var(--oksoft); border-color: transparent; }
.sp-an-badge-down    { color: var(--color-error);   background: var(--errsoft); border-color: transparent; }
.sp-an-badge-cleared { text-decoration: line-through; }
.sp-an-badge-rating  { color: #d4a017; letter-spacing: 1px; background: transparent; border-color: transparent; padding: 0; }
.sp-an-badge-role    { height: 16px; padding: 0 6px; font-size: 10px; }

/* Feedback feed */
.sp-an-filters { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.sp-an-filters select.sp-role-select { width: auto; max-width: 200px; flex: 0 0 auto; }
.sp-an-feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.sp-an-feed-item { padding: var(--space-3) 0; border-top: 1px solid var(--color-border); }
.sp-an-feed-item:first-child { border-top: 0; padding-top: 0; }
.sp-an-feed-meta {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  font-size: var(--text-xs); color: var(--color-muted);
}
.sp-an-feed-user { font-weight: var(--weight-medium); color: var(--color-text); }
.sp-an-feed-message { margin: var(--space-2) 0 0; font-size: var(--text-sm); color: var(--color-text); white-space: pre-wrap; }
.sp-an-feed-question { margin: var(--space-1) 0 0; font-size: var(--text-xs); color: var(--color-muted); }
.sp-an-feed-foot { display: flex; justify-content: center; margin-top: var(--space-3); }
.sp-an-more[hidden] { display: none; }

/* Overview / execution-runs subviews */
.sp-an-views {
  display: flex;
  gap: var(--space-1);
  margin-block: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.sp-an-view-btn {
  position: relative;
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 0;
  background: transparent;
  color: var(--color-muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.sp-an-view-btn::after {
  content: "";
  position: absolute;
  inset-inline: var(--space-2);
  inset-block-end: -1px;
  height: 2px;
  background: transparent;
  border-radius: var(--radius-full);
}
.sp-an-view-btn:hover { color: var(--color-text); }
.sp-an-view-btn.is-active { color: var(--color-text); }
.sp-an-view-btn.is-active::after { background: var(--color-accent); }
.sp-an-view-btn:focus-visible,
.sp-an-run-open:focus-visible,
.sp-an-run-back:focus-visible,
.sp-an-copy:focus-visible,
#sp-an-runs-more:focus-visible,
.sp-an-runs-card .sp-role-select:focus-visible,
.sp-an-run-query:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.sp-an-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.sp-an-plaintext { unicode-bidi: plaintext; }
.sp-an-runs-card { max-width: none; }
.sp-an-runs-desc { margin: var(--space-1) 0 0; }
.sp-an-runs-table { min-width: 880px; }
.sp-an-runs-table td:first-child,
.sp-an-runs-table th:first-child { white-space: normal; }
.sp-an-run-row { cursor: pointer; }
.sp-an-run-row:hover { background: var(--color-surface-2); }
.sp-an-run-open {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-align: start;
  cursor: pointer;
}
.sp-an-run-open-icon {
  grid-column: 2;
  grid-row: 1;
  color: var(--color-muted);
  font-size: 18px;
  line-height: 1;
}
[dir="rtl"] .sp-an-run-open-icon { transform: scaleX(-1); }
.sp-an-run-question {
  display: -webkit-box;
  min-width: 240px;
  max-width: 420px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.35;
}
.sp-an-run-mobile-meta { display: none; grid-column: 1 / -1; grid-row: 2; }
.sp-an-run-time {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 120px;
}
.sp-an-run-time span:last-child { color: var(--color-muted); font-size: var(--text-xs); }
.sp-an-run-user {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 170px;
  overflow: hidden;
}
.sp-an-run-user > bdi {
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-an-run-user-email {
  overflow: hidden;
  color: var(--color-muted);
  font-size: var(--text-xs);
  text-overflow: ellipsis;
}
.sp-an-run-route { display: inline-flex; align-items: center; gap: var(--space-1); }
.sp-an-run-route { margin-top: var(--space-1); }
.sp-an-run-outcome-success { color: var(--color-text); background: var(--oksoft); border-color: var(--color-success); }
.sp-an-run-outcome-error { color: var(--color-text); background: var(--errsoft); border-color: var(--color-error); }
.sp-an-run-outcome-refused { color: var(--color-text); background: var(--color-warning-bg); border-color: var(--color-warning); }
.sp-an-run-outcome-unknown { color: var(--color-muted); }
.sp-an-run-error { color: var(--color-text); overflow-wrap: anywhere; }
.sp-an-runs-foot-status { font-size: var(--text-xs); color: var(--color-muted); }
.sp-an-run-load-error, .sp-an-run-detail-error { width: 100%; text-align: start; }
.sp-an-run-load-error .sp-btn-secondary,
.sp-an-run-detail-error .sp-btn-secondary { margin-top: var(--space-3); }
#sp-an-runs-more:disabled { opacity: 0.55; cursor: wait; }

.sp-an-run-detail-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.sp-an-run-back { flex: none; min-height: 40px; }
.sp-an-run-detail-heading { min-width: 0; flex: 1; }
.sp-an-run-detail-title {
  margin: 0 0 var(--space-1);
  color: var(--color-text);
  font-size: var(--text-lg);
  line-height: 1.3;
  unicode-bidi: plaintext;
  overflow-wrap: anywhere;
}
.sp-an-run-id-line { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.sp-an-run-context {
  display: flex;
  gap: var(--space-2) var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-xs);
}
.sp-an-run-context strong { color: var(--color-text); font-weight: var(--weight-medium); }
.sp-an-copy { min-height: 32px; }
.sp-an-run-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}
.sp-an-run-block {
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.sp-an-run-block-wide { grid-column: 1 / -1; }
.sp-an-run-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.sp-an-run-block-head h4 { margin: 0; }
.sp-an-run-block h4 {
  margin: 0 0 var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sp-an-run-copy {
  margin: 0;
  color: var(--color-text);
  font-size: var(--text-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sp-an-run-summary { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.sp-an-run-failure {
  padding: var(--space-3);
  border: 1px solid var(--color-error);
  border-inline-start-width: 4px;
  border-radius: var(--radius-md);
  background: var(--errsoft);
  color: var(--color-text);
}
.sp-an-run-failure-refused { border-color: var(--color-warning); background: var(--color-warning-bg); }
.sp-an-run-failure p { margin: var(--space-1) 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.sp-an-run-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}
.sp-an-run-metric {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-xs);
}
.sp-an-run-metric strong {
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.sp-an-run-query {
  max-height: 360px;
  margin: 0;
  padding: var(--space-3);
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  font: var(--text-xs)/1.55 var(--font-mono);
  text-align: start;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sp-an-run-trace {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: run-trace;
}
.sp-an-run-trace-item {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: var(--space-2);
  padding-block: var(--space-2);
  counter-increment: run-trace;
}
.sp-an-run-trace-item + .sp-an-run-trace-item { border-top: 1px solid var(--color-border); }
.sp-an-run-trace-item.is-error {
  margin-inline: calc(-1 * var(--space-2));
  padding-inline: var(--space-2);
  border-inline-start: 3px solid var(--color-error);
  background: var(--errsoft);
}
.sp-an-run-trace-index::before {
  content: counter(run-trace);
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--color-surface-3);
  color: var(--color-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.sp-an-run-trace-main { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); min-height: 24px; }
.sp-an-run-trace-item p { margin: var(--space-1) 0 0; color: var(--color-text); font-size: var(--text-xs); white-space: pre-wrap; overflow-wrap: anywhere; }
.sp-an-lineage-route,
.sp-an-lineage-note,
.sp-an-lineage-attempt { margin: 0 0 var(--space-2); font-size: var(--text-sm); }
.sp-an-lineage-note { color: var(--color-muted); }
.sp-an-lineage-attempt { font-weight: 600; }
.sp-an-stage + .sp-an-stage { margin-top: var(--space-2); }
.sp-an-stage-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2, transparent);
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-align: start;
  cursor: pointer;
}
.sp-an-stage-toggle::before {
  content: "›";
  display: inline-block;
  margin-inline-end: var(--space-2);
  font-weight: 400;
}
[dir="rtl"] .sp-an-stage-toggle::before { content: "‹"; }
.sp-an-stage-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
.sp-an-stage-toggle:focus-visible { outline: 2px solid var(--color-focus, var(--color-accent)); outline-offset: 2px; }
.sp-an-stage-hint { margin: 0 0 var(--space-1); color: var(--color-muted); font-size: var(--text-xs); }
.sp-an-stage .sp-an-run-trace {
  border-inline-start: 2px solid var(--color-border);
  margin-inline-start: 11px;
  padding-inline-start: var(--space-3);
}
.sp-an-lineage-marker {
  margin: var(--space-1) 0 var(--space-2);
  padding: var(--space-2);
  border-inline-start: 3px solid var(--color-success);
  background: var(--color-success-bg);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 600;
  list-style: none;
}
@media (max-width: 760px) {
  .sp-an-stage-toggle { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 760px) {
  .sp-an-toolbar { width: 100%; justify-content: space-between; }
  .sp-an-runs-card { padding: var(--space-3); }
  .sp-an-runs-card .sp-an-filters { width: 100%; }
  .sp-an-runs-card .sp-an-filters select.sp-role-select { flex: 1 1 150px; max-width: none; }
  .sp-an-runs-table-wrap { overflow: visible; }
  .sp-an-runs-table { display: block; min-width: 0; width: 100%; }
  .sp-an-runs-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .sp-an-runs-table tbody { display: grid; gap: var(--space-2); }
  .sp-an-runs-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
  }
  .sp-an-runs-table td { display: none; padding: 0; border: 0; }
  .sp-an-runs-table td:first-child { display: block; min-width: 0; }
  .sp-an-runs-table td:nth-child(2) { display: block; align-self: start; }
  .sp-an-run-question { min-width: 0; max-width: none; font-size: var(--text-sm); }
  .sp-an-run-mobile-meta { display: block; grid-column: 1 / -1; color: var(--color-muted); font-size: var(--text-xs); }
  .sp-an-run-route { display: none; }
  .sp-an-run-open { grid-template-columns: minmax(0, 1fr) auto; min-height: 44px; }
  .sp-an-run-detail-grid { grid-template-columns: 1fr; }
  .sp-an-run-block-wide { grid-column: auto; }
  .sp-an-run-metrics { grid-template-columns: 1fr; }
  .sp-an-run-detail-head { flex-direction: column; }
  .sp-an-run-back { min-height: 44px; }
  .sp-an-run-context { display: grid; grid-template-columns: 1fr; }
}

/* =============================================================
   DEVELOPER PANEL — Run Header, SQL Stats, Log Toolbar, Prompts
   ============================================================= */

/* ─ Run header (question + status + meta chips) ───────────────────── */
.dp-run-header {
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 8px;
}
.dp-run-question {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 0 8px;
}
.dp-run-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

/* Meta chip */
.dp-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--color-surface-2);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}
.dp-chip strong { font-weight: 600; color: var(--color-text); }
.dp-chip-status {
  font-family: var(--font-sans);
  font-weight: var(--weight-medium);
  font-size: var(--text-xs);
}
.dp-status-ok  { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.dp-status-error { background: var(--color-error-bg);   color: var(--color-error);   border-color: var(--color-error); }

/* ─ SQL stats bar ────────────────────────────────────────────────── */
.dp-sql-stats {
  display: flex;
  gap: 10px;
  padding: 6px 0 8px;
  font-size: var(--text-xs);
  flex-wrap: wrap;
  align-items: center;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 6px;
}
.dp-stat-chip {
  font-family: var(--font-mono);
  color: var(--color-muted);
  white-space: nowrap;
}
.dp-stat-chip strong { color: var(--color-text); }
.dp-stat-warn { color: var(--color-warning); }

/* ─ Route chip colour variants ───────────────────────────────────── */
/* unsafe = red, out_of_scope = amber, greeting/from_memory = info blue.
   needs_query keeps the neutral default. */
.dp-route-unsafe {
  background: var(--color-error-bg);
  border-color: var(--color-error);
  color: var(--color-error);
}
.dp-route-warn {
  background: var(--color-warning-bg);
  border-color: var(--color-warning);
  color: var(--color-warning);
}
.dp-route-info {
  background: oklch(93% 0.04 250 / 0.5);
  border-color: oklch(60% 0.12 250);
  color: oklch(45% 0.13 250);
}
[data-theme="dark"] .dp-route-info {
  background: oklch(30% 0.08 250 / 0.5);
  border-color: oklch(55% 0.14 250);
  color: oklch(78% 0.13 250);
}
.dp-route-unsafe strong,
.dp-route-warn strong,
.dp-route-info strong { color: inherit; }

/* ─ Timing-semantic chip colour variants ─────────────────────────── */
/* End-to-end total: accent tint to mark it as the headline number */
.dp-chip-total {
  background: var(--color-dim-bg);
  border-color: var(--color-accent);
  color: var(--color-dim-text);
}
/* Wall-clock time: neutral steel */
.trace-chip-wall, .dp-chip-wall {
  background: oklch(82% 0.005 260 / 0.5);
  border-color: oklch(70% 0.01 260);
  color: var(--color-muted);
}
/* DB execution time: green tint */
.trace-chip-db, .dp-chip-db {
  background: oklch(90% 0.07 145 / 0.35);
  border-color: oklch(55% 0.16 145);
  color: oklch(40% 0.14 145);
}
[data-theme="dark"] .trace-chip-db,
[data-theme="dark"] .dp-chip-db {
  background: oklch(30% 0.10 145 / 0.5);
  border-color: var(--color-success);
  color: oklch(70% 0.18 145);
}
/* Network+proxy overhead: amber tint */
.trace-chip-net, .dp-chip-net {
  background: oklch(94% 0.10 80 / 0.35);
  border-color: oklch(60% 0.15 80);
  color: oklch(42% 0.13 80);
}
[data-theme="dark"] .trace-chip-net,
[data-theme="dark"] .dp-chip-net {
  background: oklch(28% 0.10 80 / 0.5);
  border-color: oklch(55% 0.16 80);
  color: oklch(72% 0.16 80);
}

/* ─ Slow-timing emphasis ─────────────────────────────────────────────
   Any timing value over 3s is flagged red so the bottleneck pops out.
   Listed after the coloured variants so it overrides them.            */
.trace-summary-chip.is-slow,
.dp-chip.is-slow {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
  color: var(--color-error);
}
.trace-summary-chip.is-slow strong,
.dp-chip.is-slow strong { color: var(--color-error); }
.trace-event-ms.is-slow {
  color: var(--color-error);
  font-weight: var(--weight-semibold);
}
.dp-stat-chip.is-slow,
.dp-stat-chip.is-slow strong {
  color: var(--color-error);
  font-weight: var(--weight-semibold);
}

/* ─ Stacked timing breakdown bar ─────────────────────────────────────
   Partitions total query time into LLM / DB / pipeline / net segments. */
.timing-bar-wrap { margin: 10px 0 4px; }
.timing-bar {
  display: flex;
  height: 8px;
  width: 100%;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--color-surface-3);
}
.timing-bar-seg { height: 100%; }
.timing-bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--color-muted);
}
.timing-bar-key { display: inline-flex; align-items: center; gap: 4px; }
.timing-bar-dot {
  width: 8px; height: 8px;
  border-radius: 2px;
  display: inline-block;
}
/* Segment colours match the per-node bar palette (LLM=purple, DB=green,
   net=amber, pipeline=neutral). */
.timing-seg-llm   { background: var(--color-accent); }
.timing-seg-db    { background: var(--color-success); }
.timing-seg-net   { background: oklch(60% 0.15 80); }
.timing-seg-other { background: var(--color-border-2); }

/* ─ Synthetic (flask+network) trace row ──────────────────────────── */
.trace-event-synthetic {
  opacity: 0.72;
  border-top: 1px dashed var(--color-border);
  margin-top: 2px;
  padding-top: 2px;
}
.trace-event-synthetic .trace-event-name {
  font-style: italic;
  color: var(--color-muted);
}
.trace-event-bar[data-ntype="overhead"] {
  background: oklch(60% 0.15 80 / 0.55);
}

/* ─ Log toolbar (filter chips + search) ──────────────────────── */
.dp-log-toolbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 6px;
}
.trace-view-seg {
  display: inline-flex;
  align-self: flex-start;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.trace-view-seg button {
  height: 26px;
  min-width: 54px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}
.trace-view-seg button:hover {
  color: var(--color-text);
  background: var(--color-surface-3);
}
.trace-view-seg button.active {
  color: var(--color-accent-fg);
  background: var(--color-accent);
}
.dp-log-filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}
.dp-log-filter {
  height: 24px; padding: 0 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  font-family: var(--font-sans);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}
.dp-log-filter:hover { background: var(--color-surface-2); color: var(--color-text); }
.dp-log-filter.active { background: var(--color-accent); color: var(--color-accent-fg); border-color: var(--color-accent); }
.dp-log-filter[data-level="llm"].active  { background: var(--color-accent); border-color: var(--color-accent); }
.dp-log-filter[data-level="db"].active   { background: var(--color-success); border-color: var(--color-success); }
.dp-log-filter[data-level="warn"].active { background: var(--color-warning); border-color: var(--color-warning); }
.dp-log-filter[data-level="error"].active{ background: var(--color-error);   border-color: var(--color-error); }
.dp-lf-count { font-family: var(--font-mono); font-size: 10px; opacity: 0.75; }

.dp-log-search {
  height: 28px; width: 100%;
  padding: 0 8px;
  font-size: var(--text-xs);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-sans);
  margin: 0;
}
.dp-log-search:focus { outline: none; border-color: var(--color-accent); box-shadow: var(--shadow-focus); }

.dp-log-legend-btn {
  flex-shrink: 0;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  cursor: pointer;
  display: inline-grid; place-items: center;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}
.dp-log-legend-btn:hover { background: var(--color-surface-2); color: var(--color-text); }
.dp-log-legend-btn.active { background: var(--color-accent); color: var(--color-accent-fg); border-color: var(--color-accent); }

.trace-legend {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  line-height: 1.55;
  color: var(--color-muted);
}
.trace-legend-title { font-weight: var(--weight-bold); color: var(--color-text); margin-bottom: 6px; }
.trace-legend-list { margin: 0; padding-inline-start: 16px; display: flex; flex-direction: column; gap: 5px; }
.trace-legend-list strong { color: var(--color-text); }
.trace-lg-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  vertical-align: middle; margin: 0 1px;
}

/* ─ Level dot on trace events ────────────────────────────────── */
.trace-lv-dot {
  width: 6px; height: 6px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  align-self: center;
}
.trace-lv-info  { background: var(--color-border-2); }
.trace-lv-llm   { background: var(--color-accent); }
.trace-lv-db    { background: var(--color-success); }
.trace-lv-warn  { background: var(--color-warning); }
.trace-lv-error { background: var(--color-error); }

/* ─ Logical execution flow view ───────────────────────────────── */
.trace-flow {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}
.trace-flow-note {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: 1.5;
}
.trace-flow-note strong,
.trace-flow-note b {
  color: var(--color-text);
}
.trace-flow-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-muted);
  font-size: var(--text-xs);
}
.trace-flow-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.trace-flow-key {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  border: 1px solid transparent;
}
.trace-flow-key-llm {
  background: color-mix(in srgb, var(--color-accent) 18%, transparent);
  border-color: color-mix(in srgb, var(--color-accent) 70%, transparent);
}
.trace-flow-key-db {
  background: color-mix(in srgb, var(--color-success) 18%, transparent);
  border-color: color-mix(in srgb, var(--color-success) 70%, transparent);
}
.trace-flow-key-logic {
  background: color-mix(in oklch, var(--color-accent) 10%, var(--color-surface-2));
  border-color: color-mix(in oklch, var(--color-accent) 45%, var(--color-border));
}
.trace-flow-key-skipped {
  background: var(--color-surface-2);
  border-color: var(--color-border);
  opacity: 0.42;
}
.trace-flow-key-slowest {
  background: var(--color-warning-bg);
  border-color: var(--color-warning);
}
.trace-flow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  align-items: stretch;
}
.trace-flow-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.trace-flow-col-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 24px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--color-border-2);
  color: var(--color-text);
  font-size: 11px;
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.trace-flow-node {
  min-height: 78px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  transition: opacity 120ms ease, border-color 120ms ease, background 120ms ease;
}
.trace-flow-node.is-run {
  border-color: color-mix(in oklch, var(--color-accent) 52%, var(--color-border));
  background: color-mix(in oklch, var(--color-accent) 8%, var(--color-surface-2));
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--color-accent) 22%, transparent);
}
.trace-flow-node.is-skipped {
  opacity: 0.42;
}
.trace-flow-node.is-slowest {
  border-color: var(--color-warning);
  background: color-mix(in oklch, var(--color-warning-bg) 72%, var(--color-surface-2));
  box-shadow: 0 0 0 1px color-mix(in oklch, var(--color-warning) 45%, transparent),
              0 8px 22px color-mix(in oklch, var(--color-warning) 16%, transparent);
}
.trace-flow-node.is-slowest .trace-flow-node-name {
  color: var(--color-warning);
}
.trace-flow-node-main {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.trace-flow-node-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text);
  font-size: 12px;
  font-weight: var(--weight-semibold);
}
.trace-flow-node-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 10px;
}
.trace-flow-repeat {
  padding: 1px 5px;
  border-radius: var(--radius-full);
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid color-mix(in oklch, var(--color-warning) 60%, transparent);
  font-weight: var(--weight-semibold);
}
.trace-flow-slowest {
  padding: 1px 5px;
  border-radius: var(--radius-full);
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid color-mix(in oklch, var(--color-warning) 60%, transparent);
  font-family: var(--font-sans);
  font-size: 9px;
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.trace-flow-node-detail {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--color-faint);
  font-size: 11px;
  line-height: 1.35;
}
.trace-flow-llm.is-run {
  border-color: color-mix(in srgb, var(--color-accent) 70%, transparent);
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
}
.trace-flow-db.is-run {
  border-color: color-mix(in srgb, var(--color-success) 70%, transparent);
  background: color-mix(in srgb, var(--color-success) 8%, transparent);
}
.trace-flow-logic.is-run {
  border-color: color-mix(in oklch, var(--color-accent) 45%, var(--color-border));
}
.trace-flow-edges {
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  overflow-x: auto;
}
.trace-flow-edge-title {
  color: var(--color-muted);
  font-size: 11px;
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.trace-flow-edge-help {
  margin: 3px 0 8px;
  color: var(--color-faint);
  font-size: var(--text-xs);
  line-height: 1.45;
}
.trace-transition-svg {
  display: block;
  min-width: 900px;
  width: 100%;
  height: auto;
}
.trace-transition-edge path {
  fill: none;
  stroke: var(--color-faint);
  stroke-width: 1.2;
  stroke-linecap: round;
  opacity: 0.32;
}
.trace-transition-edge text {
  fill: var(--color-faint);
  font-family: var(--font-mono);
  font-size: 10px;
  paint-order: stroke;
  stroke: var(--color-surface-2);
  stroke-width: 4px;
  stroke-linejoin: round;
  opacity: 0.46;
}
.trace-transition-edge.is-near path {
  stroke: var(--color-muted);
  opacity: 0.58;
}
.trace-transition-edge.is-near text {
  fill: var(--color-muted);
  opacity: 0.7;
}
.trace-transition-edge.is-run path {
  stroke: var(--color-accent);
  stroke-width: 2.2;
  opacity: 1;
}
.trace-transition-edge.is-run text {
  fill: var(--color-text);
  font-weight: var(--weight-semibold);
  opacity: 1;
}
.trace-transition-edge.is-back path {
  stroke-dasharray: 4 3;
}
.trace-transition-node rect {
  fill: var(--color-surface);
  stroke: var(--color-border);
  stroke-width: 1;
}
.trace-transition-node text {
  fill: var(--color-muted);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  pointer-events: none;
}
.trace-transition-node.is-run rect {
  fill: color-mix(in oklch, var(--color-accent) 8%, var(--color-surface));
  stroke: color-mix(in oklch, var(--color-accent) 55%, var(--color-border));
  stroke-width: 1.4;
}
.trace-transition-node.is-run text {
  fill: var(--color-text);
}
.trace-transition-node.is-skipped {
  opacity: 0.55;
}
/* Post-query chart: a dashed branch off the step that sent the rows. */
.trace-chart-edge path { stroke-dasharray: 5 4; }
.trace-chart-node rect { stroke-dasharray: 4 3; }

/* Answer milestones: flags on the map and a time strip above it. */
.trace-milestone rect { stroke-width: 1; }
.trace-milestone text {
  font-size: 9.5px;
  font-weight: var(--weight-semibold);
  pointer-events: none;
}
.trace-milestone.trace-ms-table rect { fill: color-mix(in srgb, var(--color-success) 16%, var(--color-surface)); stroke: var(--color-success); }
.trace-milestone.trace-ms-answer rect { fill: color-mix(in srgb, var(--color-accent) 16%, var(--color-surface)); stroke: var(--color-accent); }
.trace-milestone.trace-ms-chart rect { fill: color-mix(in srgb, var(--color-warning) 18%, var(--color-surface)); stroke: var(--color-warning); }
.trace-milestone text { fill: var(--color-text); }
.trace-milestones { margin: 2px 0 10px; }
.trace-ms-track {
  position: relative;
  height: 4px;
  margin: 10px 6px 8px 22px;
  border-radius: 2px;
  background: var(--color-border);
}
.trace-ms-zero {
  position: absolute;
  top: -6px;
  left: -22px;
  color: var(--color-faint);
  font: 10px var(--font-mono);
}
.trace-ms-mark {
  position: absolute;
  top: -4px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border: 2px solid var(--color-surface-2);
  border-radius: 50%;
}
.trace-ms-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--color-muted); font-size: var(--text-xs); }
.trace-ms-chip { display: inline-flex; align-items: center; gap: 5px; }
.trace-ms-chip i { width: 8px; height: 8px; border-radius: 50%; }
.trace-ms-chip b { color: var(--color-text); font-variant-numeric: tabular-nums; }
.trace-ms-table.trace-ms-mark, .trace-ms-table i { background: var(--color-success); }
.trace-ms-answer.trace-ms-mark, .trace-ms-answer i { background: var(--color-accent); }
.trace-ms-chart.trace-ms-mark, .trace-ms-chart i { background: var(--color-warning); }
.trace-flow-reconcile {
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: 1.5;
}
.trace-flow-reconcile b { color: var(--color-text); }

.trace-flow-retries {
  padding: 8px 10px;
  border: 1px solid color-mix(in oklch, var(--color-warning) 40%, var(--color-border));
  border-radius: var(--radius-md);
  background: var(--color-warning-bg);
  color: var(--color-muted);
  font-size: var(--text-xs);
}
.trace-flow-retries strong {
  color: var(--color-warning);
}
.trace-flow-retries code {
  color: var(--color-text);
}

.post-query-work {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.post-query-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: 1.45;
}
.post-query-head strong {
  display: block;
  color: var(--color-text);
  font-size: 12px;
  margin-bottom: 2px;
}
.post-query-head span {
  display: block;
}
.post-query-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.post-query-card {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.post-query-card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 7px;
}
.post-query-title {
  color: var(--color-text);
  font-size: 12px;
  font-weight: var(--weight-semibold);
}
.post-query-kind {
  margin-top: 1px;
  color: var(--color-faint);
  font-size: 10px;
}
.post-query-status {
  flex: none;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  color: var(--color-muted);
  background: var(--color-surface);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.post-query-running {
  border-color: color-mix(in oklch, var(--color-accent) 45%, var(--color-border));
  background: color-mix(in oklch, var(--color-accent) 7%, var(--color-surface-2));
}
.post-query-running .post-query-status {
  color: var(--color-accent);
  border-color: color-mix(in oklch, var(--color-accent) 55%, transparent);
}
.post-query-done {
  border-color: color-mix(in srgb, var(--color-success) 55%, transparent);
}
.post-query-done .post-query-status {
  color: var(--color-success);
  border-color: color-mix(in oklch, var(--color-success) 55%, transparent);
}
.post-query-error {
  border-color: color-mix(in oklch, var(--color-error) 65%, var(--color-border));
  background: var(--color-error-bg);
}
.post-query-error .post-query-status {
  color: var(--color-error);
  border-color: color-mix(in oklch, var(--color-error) 60%, transparent);
}
.post-query-skipped {
  opacity: 0.72;
}
.post-query-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 7px;
}
.post-query-chips span {
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--color-surface-3);
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 10px;
}
.post-query-detail {
  color: var(--color-muted);
  font-size: 11px;
  line-height: 1.4;
}

@media (max-width: 1180px) {
  .trace-flow-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}
@media (max-width: 760px) {
  .trace-flow-grid {
    grid-template-columns: 1fr;
  }
  .post-query-grid {
    grid-template-columns: 1fr;
  }
}

/* ─ Insights card: LLM/token metric chips in header ─────────── */
.ins-meta-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.ins-meta-chip {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-faint);
  white-space: nowrap;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 2px 7px;
}

/* ─ Prompt tab: copy-all header ──────────────────────────────── */
.dp-prompt-hdr {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 4px 0 8px;
  margin-bottom: 4px;
}
.dp-token-est {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--color-faint);
}
.dp-copy-all {
  height: 24px; padding: 0 10px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  font-family: var(--font-sans);
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}
.dp-copy-all:hover { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border-2); }

/* ─ Prompt copy button inside trace event expand ─────────────── */
.trace-prompt-copy {
  height: 18px; padding: 0 6px;
  margin-inline-start: 6px;
  font-size: 10px;
  font-family: var(--font-sans);
  font-weight: var(--weight-normal);
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  vertical-align: middle;
  transition: background 100ms ease, color 100ms ease;
}
.trace-prompt-copy:hover { background: var(--color-surface-3); color: var(--color-text); }

/* =============================================================
   METADATA & CATALOG SETTINGS PANEL  (mc-* prefix)
   ============================================================= */

/* Source segmented control */
.mc-seg {
  display: inline-flex; background: var(--color-surface-2);
  border: 1px solid var(--color-border); border-radius: 9px;
  padding: 3px; gap: 3px;
}
.mc-seg button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 32px; padding: 0 12px; border-radius: 7px;
  font-size: 0.8125rem; font-weight: 500; color: var(--color-muted);
  background: transparent; border: none; cursor: pointer;
  white-space: nowrap; flex-shrink: 0; line-height: 1;
}
.mc-seg button:hover { color: var(--color-text); }
.mc-seg button.is-active {
  background: var(--color-surface); color: var(--color-text);
  box-shadow: var(--shadow-xs);
}
.mc-seg button.is-active svg { color: var(--color-accent); }

/* Source panel visibility */
.mc-source-panel { margin: 4px 0 0; border-top: 1px solid var(--color-border); padding-top: 14px; }
.mc-hidden { display: none !important; }

/* DB info grid */
.mc-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.mc-info-k { font-size: 0.68rem; color: var(--color-faint); font-weight: 500; display: block; }
.mc-info-v { font-size: 0.875rem; font-weight: 500; display: block; margin-top: 2px; }
.mc-mono { font-family: var(--font-mono); font-size: 0.8125rem; }
.mc-info-foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--color-border);
}

/* Status lines */
.mc-status { display: inline-flex; align-items: center; gap: 7px; font-size: 0.75rem; font-weight: 500; }
.mc-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--color-faint);
}
.mc-status-ok { color: var(--color-success); }
.mc-status-ok .mc-dot { background: var(--color-success); box-shadow: 0 0 0 3px var(--color-success-bg); }
.mc-status-muted { color: var(--color-faint); }
.mc-status-checking { color: var(--color-warning); }
.mc-dot-pulse { background: var(--color-warning); animation: mc-pulse 0.9s ease-in-out infinite; }
@keyframes mc-pulse { 0%,100%{opacity:1} 50%{opacity:0.35} }

/* Server list */
.mc-srv-listhead {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.mc-srv-listtitle { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; color: var(--color-muted); display: inline-flex; align-items: center; gap: 8px; }
.mc-srv-count { font-family: var(--font-mono); font-size: 0.62rem; font-weight: 600; padding: 1px 7px; border-radius: 9999px; background: var(--color-surface-2); color: var(--color-faint); }
.mc-srv-list { max-height: 210px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-surface); }
.mc-srv-row { display: flex; align-items: center; gap: 11px; padding: 11px 13px; cursor: pointer; border-inline-start: 2px solid transparent; }
.mc-srv-row + .mc-srv-row { border-top: 1px solid var(--color-border); }
.mc-srv-row:hover { background: var(--color-surface-2); }
.mc-srv-row-active { background: var(--color-dim-bg); border-inline-start-color: var(--color-accent); }
.mc-empty { padding: 22px; text-align: center; color: var(--color-faint); font-size: 0.8125rem; }

.mc-srv-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--color-faint); }
.mc-srv-dot-ok  { background: var(--color-success); box-shadow: 0 0 0 3px var(--color-success-bg); }
.mc-srv-dot-warn { background: var(--color-warning); box-shadow: 0 0 0 3px var(--color-warning-bg); }
.mc-srv-dot-err  { background: var(--color-error);  box-shadow: 0 0 0 3px var(--color-error-bg); }

.mc-srv-main { flex: 1; min-width: 0; overflow: hidden; }
.mc-srv-name { font-size: 0.8125rem; font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; }
/* text-overflow:ellipsis does not apply to flex containers, so the name text
   must truncate on an inner block element while the "active" tag stays put. */
.mc-srv-name-txt { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-srv-tag  { flex-shrink: 0; font-size: 0.54rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-accent-fg); background: var(--color-accent); padding: 1px 6px; border-radius: 5px; }
.mc-srv-ep   { font-family: var(--font-mono); font-size: 0.68rem; color: var(--color-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.mc-srv-badge { font-family: var(--font-mono); font-size: 0.62rem; font-weight: 600; color: var(--color-muted); background: var(--color-surface-2); border: 1px solid var(--color-border); padding: 2px 7px; border-radius: 6px; flex-shrink: 0; }
.mc-srv-actions { display: flex; gap: 3px; flex-shrink: 0; }
.mc-srv-ico { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; color: var(--color-faint); background: transparent; border: none; cursor: pointer; padding: 0; }
.mc-srv-ico:hover { background: var(--color-surface-3); color: var(--color-text); }
.mc-srv-del:hover { background: var(--color-error-bg); color: var(--color-error); }
.mc-srv-ico:disabled { opacity: 0.35; cursor: not-allowed; }

/* Add/Edit form */
.mc-form { margin-top: 14px; border: 1px solid var(--color-accent); border-radius: 12px; background: var(--color-surface); padding: 15px; }
.mc-form-head { font-size: 0.8125rem; font-weight: 600; margin-bottom: 13px; }
.mc-field { margin-bottom: 13px; }
.mc-field:last-child { margin-bottom: 0; }
.mc-field-label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--color-muted); margin-bottom: 6px; }
.mc-req { color: var(--color-accent); }
.mc-input { width: 100%; height: 36px; padding: 0 12px; font-size: 0.8125rem; font-family: var(--font-mono); color: var(--color-text); background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 8px; }
.mc-input:focus { outline: none; border-color: var(--color-accent); box-shadow: var(--shadow-focus); }
.mc-field-help { font-size: 0.68rem; color: var(--color-faint); margin-top: 5px; line-height: 1.5; }
.mc-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mc-mini-seg { display: inline-flex; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 8px; padding: 3px; gap: 2px; width: 100%; }
.mc-mini-seg button { flex: 1; height: 28px; border-radius: 6px; font-size: 0.74rem; font-weight: 500; color: var(--color-muted); font-family: var(--font-mono); background: transparent; border: none; cursor: pointer; padding: 0; }
.mc-mini-seg button.is-active { background: var(--color-surface-2); color: var(--color-text); box-shadow: var(--shadow-xs); }
.mc-form-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--color-border); }

/* Button variants used in MCP panel */
.sp-btn-ghost-sm { height: 28px; padding: 0 10px; font-size: 0.78rem; }
.sp-btn-primary-sm {
  height: 32px; padding: 0 14px; font-size: 0.8125rem; font-weight: 600;
  background: var(--color-accent); color: var(--color-accent-fg);
  border: none; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center;
}
.sp-btn-primary-sm:hover { filter: brightness(1.06); }
.sp-btn-primary-sm:disabled { opacity: 0.5; cursor: not-allowed; }
.mc-activate-btn { color: var(--color-success); border-color: var(--color-success); }
.mc-activate-btn:hover { background: var(--color-success-bg); }
.mc-deactivate-btn { color: var(--color-warning); border-color: var(--color-warning); }
.mc-deactivate-btn:hover { background: var(--color-warning-bg); }

/* Active server health section */
.mc-active-srv { margin-top: 14px; }
.mc-test-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mc-spin { animation: spin 0.8s linear infinite; }

/* Health report card */
.mc-health { margin-top: 14px; border: 1px solid var(--color-border); border-radius: 12px; overflow: hidden; background: var(--color-surface); }
.mc-health-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--color-border); background: var(--color-surface-2); flex-wrap: wrap; }
.mc-health-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 0.75rem; font-weight: 600; padding: 3px 10px; border-radius: 7px; }
.mc-health-healthy { background: var(--color-success-bg); color: var(--color-success); }
.mc-health-degraded { background: var(--color-warning-bg); color: var(--color-warning); }
.mc-health-down { background: var(--color-error-bg); color: var(--color-error); }
/* Truncate long server endpoint in health card header */
.mc-health-impl {
  font-family: var(--font-mono); font-size: 0.68rem; color: var(--color-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1;
}
.mc-health-when { font-size: 0.68rem; color: var(--color-faint); margin-inline-start: auto; }
.mc-health-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 1px; background: var(--color-border); }
.mc-health-cell { background: var(--color-surface); padding: 11px 14px; display: flex; flex-direction: column; gap: 3px; }
.mc-hk { font-size: 0.6rem; color: var(--color-faint); font-weight: 500; }
.mc-hv { font-family: var(--font-mono); font-size: 0.8125rem; font-weight: 500; }
.mc-health-sub { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-faint); padding: 13px 14px 7px; display: flex; align-items: center; gap: 8px; }
.mc-cap-row { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 14px 10px; }
.mc-cap-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 0.68rem; font-weight: 500; padding: 3px 9px; border-radius: 7px; background: var(--color-success-bg); color: var(--color-success); }
.mc-err-box { margin-top: 10px; padding: 11px 13px; border-radius: 8px; background: var(--color-error-bg); color: var(--color-error); font-size: 0.8125rem; }

/* Tool mapping */
.mc-map { border: 1px solid var(--color-border); border-radius: 10px; overflow: hidden; background: var(--color-surface); margin: 0 14px 4px; }
.mc-map-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 9px 12px; }
.mc-map-row + .mc-map-row { border-top: 1px solid var(--color-border); }
.mc-map-need { display: flex; align-items: center; gap: 9px; font-size: 0.8125rem; font-weight: 500; }
.mc-map-tool { font-family: var(--font-mono); font-size: 0.74rem; color: var(--color-accent); background: var(--color-dim-bg); padding: 3px 9px; border-radius: 6px; }
.mc-map-muted { color: var(--color-faint); background: var(--color-surface-2); }

/* Tools list */
.mc-tools { max-height: 180px; overflow-y: auto; border-top: 1px solid var(--color-border); }
.mc-tool-row { display: flex; align-items: center; gap: 11px; padding: 9px 14px; }
.mc-tool-row + .mc-tool-row { border-top: 1px solid var(--color-border); }
.mc-tool-ico { color: var(--color-accent); flex-shrink: 0; }
.mc-tool-main { flex: 1; min-width: 0; }
.mc-tool-name { font-family: var(--font-mono); font-size: 0.74rem; font-weight: 600; }
.mc-tool-desc { font-size: 0.68rem; color: var(--color-muted); margin-top: 1px; }
.mc-tool-need { font-size: 0.68rem; font-weight: 500; color: var(--color-accent); background: var(--color-dim-bg); padding: 2px 8px; border-radius: 6px; white-space: nowrap; flex-shrink: 0; }

/* Tool inspector */
.mc-tool-inspector {
  margin-top: 14px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  padding: 14px;
}
.mc-tool-inspector-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.mc-tool-test-grid { display: grid; gap: 12px; }
.mc-tool-schema-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.mc-schema-pre,
.mc-tool-result pre,
.mc-result-code,
.mc-json-area {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}
.mc-schema-pre,
.mc-tool-result pre,
.mc-result-code {
  max-height: 180px;
  overflow: auto;
  padding: 10px;
  margin: 0;
  white-space: pre-wrap;
}
.mc-json-area {
  min-height: 110px;
  resize: vertical;
  padding: 10px;
}
.mc-json-area:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
.mc-tool-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.mc-input-mode-tabs {
  display: inline-flex;
  margin-bottom: 8px;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  overflow: hidden;
}
.mc-input-mode-tab {
  border: 0;
  border-inline-end: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.68rem;
  padding: 4px 8px;
}
.mc-input-mode-tab:last-child { border-inline-end: 0; }
.mc-input-mode-tab:hover { background: var(--color-surface-2); color: var(--color-text); }
.mc-input-mode-tab.is-active { background: var(--color-dim-bg); color: var(--color-accent); }
.mc-guided-args { display: grid; gap: 10px; }
.mc-guided-field { padding: 10px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-bg); }
.mc-guided-field .mc-field-label { margin-bottom: 5px; }
.mc-guided-checkbox { display: inline-flex; align-items: center; gap: 7px; font-size: 0.75rem; color: var(--color-text); cursor: pointer; }
.mc-guided-unsupported { color: var(--color-muted); font-size: 0.72rem; font-style: italic; }
.mc-input-errors { margin-top: 7px; color: var(--color-error); font-size: 0.7rem; line-height: 1.45; }
.mc-tool-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.mc-tool-safety {
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-muted);
  font-size: 0.62rem;
  font-weight: 600;
  padding: 2px 7px;
}
.mc-tool-safety-ok { background: var(--color-success-bg); border-color: transparent; color: var(--color-success); }
.mc-tool-safety-warn { background: var(--color-warning-bg); border-color: transparent; color: var(--color-warning); }
.mc-tool-result {
  border-top: 1px solid var(--color-border);
  padding-top: 12px;
}
.mc-tool-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: 6px;
}
.mc-tool-result-error .mc-tool-result-head { color: var(--color-danger); }
.mc-result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.mc-result-tabs {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  overflow: hidden;
}
.mc-result-tab {
  border: 0;
  border-inline-end: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.68rem;
  padding: 4px 7px;
}
.mc-result-tab:last-child { border-inline-end: 0; }
.mc-result-tab:hover { background: var(--color-surface-2); color: var(--color-text); }
.mc-result-tab.is-active { background: var(--color-dim-bg); color: var(--color-accent); }
.mc-json-tree {
  max-height: 320px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.45;
}
.mc-json-tree-node { margin: 0; }
.mc-json-tree-node + .mc-json-tree-node,
.mc-json-tree-value + .mc-json-tree-value { margin-top: 3px; }
.mc-json-tree-node summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
}
.mc-json-tree-node summary::-webkit-details-marker { display: none; }
.mc-json-tree-node summary::before {
  content: '›';
  color: var(--color-muted);
  font-size: 0.9rem;
  line-height: 1;
  transform: rotate(0deg);
}
.mc-json-tree-node[open] > summary::before { transform: rotate(90deg); }
.mc-json-tree-children {
  margin: 4px 0 2px 10px;
  padding-inline-start: 10px;
  border-inline-start: 1px solid var(--color-border);
}
.mc-json-tree-value {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 20px;
}
.mc-json-key { color: var(--color-accent); overflow-wrap: anywhere; }
.mc-json-key::after { content: ':'; color: var(--color-muted); }
.mc-json-tree-type,
.mc-json-tree-empty { color: var(--color-muted); }
.mc-json-value { overflow-wrap: anywhere; }
.mc-json-string { color: var(--color-success); }
.mc-json-number { color: var(--color-warning); }
.mc-json-boolean,
.mc-json-null { color: var(--color-muted); }
.mc-result-details {
  margin-top: 8px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}
.mc-result-details summary {
  cursor: pointer;
  padding: 8px 10px;
  color: var(--color-muted);
  font-size: 0.72rem;
  font-weight: 600;
}
.mc-result-details .mc-result-code {
  width: calc(100% - 16px);
  margin: 0 8px 8px;
}
.mc-content-blocks { display: grid; gap: 8px; }
.mc-content-block {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}
.mc-content-block summary {
  cursor: pointer;
  padding: 8px 10px;
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
}
.mc-content-block summary span { color: var(--color-faint); font-family: var(--font-sans); font-weight: 400; }
.mc-content-block .mc-result-code { width: calc(100% - 16px); margin: 0 8px 8px; }
.mc-result-empty {
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-muted);
  font-size: 0.75rem;
}
.mc-output-validation {
  margin-bottom: 8px;
  border-radius: 8px;
  font-size: 0.72rem;
}
.mc-output-valid { padding: 8px 10px; background: var(--color-success-bg); color: var(--color-success); }
.mc-output-invalid { border: 1px solid var(--color-warning); color: var(--color-warning); }
.mc-output-invalid summary { cursor: pointer; padding: 8px 10px; }
.mc-output-invalid .mc-result-code { width: calc(100% - 16px); margin: 0 8px 8px; }
.mc-ai-assist {
  margin-top: 8px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-dim-bg);
  color: var(--color-text);
  font-size: 0.72rem;
}
.mc-ai-assist summary { cursor: pointer; padding: 8px 10px; font-weight: 600; color: var(--color-accent); }
.mc-ai-assist-body { display: grid; gap: 8px; padding: 0 10px 10px; line-height: 1.5; }
.mc-ai-assist-body ul { margin: 4px 0 0; padding-inline-start: 18px; }
.mc-ai-assist-body .mc-result-code { margin-top: 5px; }
.mc-ai-assist-loading { padding: 10px; color: var(--color-muted); }
.mc-ai-assist-error { padding: 10px; background: var(--color-error-bg); color: var(--color-error); border-color: transparent; }
.mc-tool-empty { border: 1px dashed var(--color-border); border-radius: 10px; }

/* Governance callout */
.mc-callout { display: flex; gap: 9px; margin-top: 14px; padding: 11px 13px; border-radius: 10px; background: var(--color-warning-bg); }
.mc-callout svg { color: var(--color-warning); flex-shrink: 0; margin-top: 1px; }
.mc-callout p { font-size: 0.75rem; line-height: 1.55; color: var(--color-text); }

/* Cache TTL card */
.mc-badge { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; background: var(--color-dim-bg); color: var(--color-accent); margin-inline-start: 8px; }
.mc-cache-pills { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 0 0 14px; }
.mc-cache-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 0.68rem; font-weight: 500;
  background: var(--color-surface-2); color: var(--color-muted);
  border: 1px solid var(--color-border); border-radius: 7px; padding: 4px 9px;
}
.mc-cache-pill b { color: var(--color-text); }
.mc-cache-hit  { background: var(--color-success-bg); color: var(--color-success); border-color: transparent; }
.mc-cache-live { background: var(--color-dim-bg); color: var(--color-accent); border-color: transparent; }
.mc-conn-name  { font-size: 0.875rem; font-weight: 500; color: var(--color-text); }

/* ── Metadata & Catalog panel — v2 adjustments ──────────────────────────── */

/* Inner source panel — matches mockup .panel  */
.mc-panel {
  margin: 4px 0 0;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-bg);          /* slightly off-surface, like mockup */
  padding: 16px;
}
.mc-hidden { display: none !important; }

/* Cache card — standalone sibling of the main card */
.mc-cache-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 4px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
  max-width: 800px;
}
.mc-cache-state {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 0 0 14px;
}
.mc-cache-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}

/* Status variants */
.mc-status-err { color: var(--color-error); }
.mc-status-err .mc-dot { background: var(--color-error); box-shadow: 0 0 0 3px var(--color-error-bg); }

/* Health capabilities meta-count  */
.mc-cap-meta {
  font-family: var(--font-mono); font-size: 0.68rem;
  color: var(--color-muted); margin-inline-start: auto;
}

/* Connection pill MCP badge */
.connection-mcp-badge {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--color-dim-bg);
  color: var(--color-accent);
  flex-shrink: 0;
  line-height: 1.6;
}

/* ── Delta improvements: degraded/unreachable/capabilities/needs ─────────── */

/* Degraded status — amber (reuse warning colour) */
.mc-status-warn { color: var(--color-warning); }
.mc-status-warn .mc-dot {
  background: var(--color-warning);
  box-shadow: 0 0 0 3px var(--color-warning-bg);
}

/* Degraded badge in health card header */
.mc-health-degraded { background: var(--color-warning-bg); color: var(--color-warning); }

/* Degraded note banner — amber strip above diagnostics grid */
.mc-note {
  margin: 0 14px 12px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--color-warning-bg);
  color: var(--color-warning);
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* Off-capability chip — faint surface, greyed out */
.mc-cap-off {
  background: var(--color-surface-2);
  color: var(--color-faint);
}

/* =============================================================
   CHAT MODE
   A conversation thread that reuses the NL->SQL pipeline. The header
   mode-switch toggles between the classic Ask screen and this panel.
   ============================================================= */

/* ── Header mode switch (Ask / Chat) ─────────────────────────── */
.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-inline-start: var(--space-3);
  padding: 2px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 9999px;
}
.mode-switch-btn {
  appearance: none;
  border: 0;
  height: 24px;
  cursor: pointer;
  padding: 0 12px;
  border-radius: 9999px;
  font-size: 0.75rem;
  line-height: 1;
  font-weight: 600;
  color: var(--color-faint);
  background: transparent;
  transition: color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
.mode-switch-btn:hover { color: var(--color-text); }
.mode-switch-btn.active {
  color: var(--color-accent);
  background: var(--color-surface);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}
.mode-switch-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* ── Panel shell ─────────────────────────────────────────────── */
/* In chat mode the main region becomes a full-height flex column so the
   thread scrolls internally and the composer stays pinned. */
#main-content.mode-chat {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-mode-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-tertiary);
}
.chat-mode-panel[hidden] { display: none; }

/* ── Scrollable thread ───────────────────────────────────────── */
.chat-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px clamp(16px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.chat-thread::-webkit-scrollbar { width: 10px; }
.chat-thread::-webkit-scrollbar-track { background: transparent; }
.chat-thread::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 9999px;
  border: 3px solid var(--color-bg-tertiary);
}

.chat-turn { display: flex; }
.chat-turn.chat-user { justify-content: flex-end; }
.chat-turn.chat-assistant { justify-content: flex-start; }

/* Avatar + bubble/card row */
.chat-row { display: flex; gap: 10px; }
.chat-row-user { align-items: flex-end; max-width: min(80%, 640px); }
.chat-row-assistant { align-items: flex-start; width: min(94%, 1100px); max-width: 100%; }
.chat-row-assistant > .chat-card,
.chat-row-assistant > .chat-thinking { flex: 1; min-width: 0; }

/* Turn avatars */
.chat-avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  user-select: none;
}
.chat-avatar-assistant {
  border-radius: 9px;
  background: var(--color-accent);
  font-size: 14px;
  font-weight: 800;
}
.chat-avatar-user { border-radius: 50%; background: var(--color-brand); }

/* User bubble */
.chat-user-bubble {
  padding: 12px 16px;
  background: var(--color-accent);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  font-size: 0.9375rem;
  line-height: 1.5;
  box-shadow: var(--shadow-xs);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Assistant card */
.chat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px 16px 16px 16px;
  box-shadow: var(--shadow-sm);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeUp 220ms ease both;
}
.chat-card-summary {
  font-size: 1rem;
  line-height: 1.55;
  letter-spacing: -0.01em;
  color: var(--color-text);
}
.chat-card-summary[hidden] { display: none; }

/* Real per-answer step trail (derived from the execution trace) */
.chat-steps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: -4px 0 -2px;
  font-size: 0.6875rem;
  color: var(--color-faint);
}
.chat-step {
  padding: 1px 8px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg, transparent);
  white-space: nowrap;
}
.chat-step-sep {
  color: var(--color-faint);
  opacity: 0.6;
}

/* Table/chart viz block */
.chat-card-viz { display: flex; flex-direction: column; gap: 12px; min-width: 0; max-width: 100%; }
.chat-viz-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.chat-viz-titles { min-width: 0; }
.chat-viz-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text);
}
.chat-viz-meta {
  font-size: 0.75rem;
  color: var(--color-faint);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* Right-hand viz actions: copy / download icons + Table/Chart toggle */
.chat-viz-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.chat-icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-muted);
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.chat-icon-btn:hover { color: var(--color-accent); border-color: var(--color-accent); }
.chat-icon-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.chat-copied {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-success);
  white-space: nowrap;
}
.chat-copied[hidden] { display: none; }

/* Per-turn Table/Chart toggle */
.chat-view-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 9px;
  flex-shrink: 0;
}
.chat-view-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-faint);
  background: transparent;
  transition: color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
.chat-view-btn:hover { color: var(--color-text); }
.chat-view-btn.active {
  color: var(--color-accent);
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
}
.chat-view-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.chat-table-slot[hidden],
.chat-chart-slot[hidden] { display: none; }
.chat-table-slot { min-width: 0; max-width: 100%; }
.chat-chart-slot { min-height: 0; }

/* Chat consolidates chart export into the per-turn viz-head Download button
   (CSV for the table, PNG for the chart), so the shared Save PNG / Copy chart
   toolbar is redundant when the chart view is relocated into a chat turn. */
.chat-chart-slot #chart-actions-toolbar { display: none !important; }

/* Compact static result table (non-interactive; sorting lives in Ask mode) */
.chat-table-scroll {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: 10px;
}
.chat-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.chat-table th,
.chat-table td {
  padding: 8px 12px;
  text-align: start;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
}
.chat-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface-2);
  color: var(--color-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.chat-table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--color-surface-2) 55%, transparent); }
.chat-table tbody tr:last-child td { border-bottom: 0; }
.chat-table tbody tr:hover { background: var(--color-surface-2); }
.chat-table td:not(.chat-num) {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-table .chat-num {
  text-align: end;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}
.chat-table .chat-null { color: var(--color-faint); }
.chat-table-more {
  padding: 8px 2px 0;
  font-size: 0.75rem;
  color: var(--color-faint);
}
.chat-no-data {
  padding: 16px;
  color: var(--color-faint);
  font-size: 0.8125rem;
}

/* Per-turn insights — reuse the InsightsManager markup, drop the nested chrome */
.chat-insights-slot {
  border-top: 1px solid var(--color-border);
  padding-top: 16px;
}
.chat-insights-slot:empty {
  display: none;
  border: 0;
  padding: 0;
}
.chat-insights-slot .ins-card {
  border: 0;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  background: transparent;
  gap: 16px;
}
/* The chat card is wider than the Ask insights panel — let the follow-up chips
   reflow to fill the available width. Wider min track (2 roomy columns on a wide
   card, 1 full-width column when narrow) gives each question space to wrap on one
   or two lines instead of being cramped/truncated. `min(100%, …)` prevents the
   track from ever overflowing the card on small screens. */
.chat-insights-slot .ins-followups {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 10px;
}

/* Conversational (no-SQL) answer + error card */
.chat-answer-text {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--color-text);
}
.chat-answer-text.chat-muted { color: var(--color-faint); }

/* Agent tool proposal — generic confirm card (Phase 3) */
.chat-tool-card {
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface-2, var(--color-surface));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-tool-head { display: flex; align-items: baseline; gap: 8px; }
.chat-tool-icon { font-size: 1.05rem; }
.chat-tool-title { font-weight: 600; font-size: 0.9375rem; color: var(--color-text); }
.chat-tool-sub { margin-inline-start: auto; font-size: 0.75rem; color: var(--color-faint); }
.chat-tool-label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.75rem; color: var(--color-faint);
}
.chat-tool-input {
  padding: 7px 10px; border: 1px solid var(--color-border); border-radius: 7px;
  background: var(--color-bg, #fff); color: var(--color-text); font-size: 0.875rem;
}
.chat-tool-input:focus { outline: none; border-color: var(--color-primary, #4f46e5); }
textarea.chat-tool-input { resize: vertical; min-height: 2.2rem; font-family: inherit; }
.chat-tool-summary {
  font-size: 0.8125rem; line-height: 1.55; color: var(--color-text);
  background: var(--color-bg, rgba(0,0,0,0.02)); border-radius: 7px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.chat-tool-warn { color: var(--color-error, #b91c1c); font-weight: 500; }
.chat-tool-msg { font-size: 0.8125rem; }
.chat-tool-msg.error { color: var(--color-error, #b91c1c); }
.chat-tool-msg.ok { color: var(--color-success, #15803d); }
.chat-tool-answer {
  font-size: 0.875rem; line-height: 1.6; color: var(--color-text);
  background: var(--color-bg, rgba(0,0,0,0.02));
  border: 1px solid var(--color-border); border-radius: 7px; padding: 10px 12px;
}
.chat-tool-actions { display: flex; gap: 8px; justify-content: flex-end; }
.chat-tool-btn {
  padding: 6px 14px; border-radius: 7px; border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  font-size: 0.8125rem; cursor: pointer;
}
.chat-tool-btn:disabled { opacity: 0.5; cursor: default; }
.chat-tool-btn.ghost { background: transparent; color: var(--color-faint); }
.chat-tool-btn.primary { background: var(--color-primary, #4f46e5); border-color: var(--color-primary, #4f46e5); color: #fff; }
.chat-card.chat-error {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  color: var(--color-error);
  border-color: var(--color-error-bg);
}
.chat-error-icon { flex-shrink: 0; }
.chat-error-body { min-width: 0; flex: 1; }
.chat-error-message { line-height: 1.55; overflow-wrap: anywhere; }
.chat-error-details { margin-top: 10px; color: var(--color-muted); }
.chat-error-details summary {
  width: max-content;
  cursor: pointer;
  color: var(--color-accent);
  font-size: var(--text-xs);
}
.chat-error-details pre {
  max-height: 180px;
  margin: 8px 0 0;
  padding: 10px 12px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--code-text);
  font: 0.75rem/1.45 var(--font-mono);
}

/* ── Thinking pipeline indicator ─────────────────────────────── */
.chat-thinking {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px 16px 16px 16px;
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadeUp 220ms ease both;
}
.chat-think-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8125rem;
  color: var(--color-faint);
  transition: color 160ms ease, opacity 160ms ease;
}
.chat-think-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
  flex-shrink: 0;
  transition: background 160ms ease;
}
.chat-think-step.is-pending { opacity: 0.5; }
.chat-think-step.is-active { color: var(--color-text); font-weight: 500; }
.chat-think-step.is-active .chat-think-dot {
  background: var(--color-accent);
  animation: mc-pulse 1s ease-in-out infinite;
}
.chat-think-step.is-done { color: var(--color-muted); }
.chat-think-step.is-done .chat-think-dot { background: var(--color-success); }

/* ── Empty state (first chat) ────────────────────────────────── */
.chat-empty {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  color: var(--color-faint);
}
.chat-empty[hidden] { display: none; }
.chat-empty-mark {
  width: 52px;
  height: 52px;
  border-radius: 15px;
  background: var(--color-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 26px;
  box-shadow: var(--shadow-md);
  margin-bottom: 8px;
}
.chat-empty-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-medium);
  letter-spacing: 0;
  color: var(--color-text);
  line-height: 1.2;
}
.chat-empty-sub {
  font-size: 0.9rem;
  color: var(--color-faint);
  margin-bottom: 12px;
}
.chat-empty-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 640px;
}
.chat-empty-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  box-shadow: none;
  transition: border-color 120ms ease, background 120ms ease;
}
.chat-empty-chip:hover {
  border-color: var(--color-accent);
  background: var(--color-surface-2);
}
.chat-empty-chip svg { flex-shrink: 0; color: var(--color-accent); }
.chat-empty-chip:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* ── Pinned composer ─────────────────────────────────────────── */
.chat-composer-wrap {
  flex-shrink: 0;
  padding: 14px clamp(16px, 3vw, 40px) 18px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 1100px;
  margin: 0;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-bg-tertiary);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.chat-composer:focus-within {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
.chat-input {
  flex: 1;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: 0.9375rem;
  line-height: 1.5;
  max-height: 160px;
  padding: 6px 0;
  outline: none;
}
.chat-input::placeholder { color: var(--color-faint); }
.chat-send-btn {
  flex-shrink: 0;
  cursor: pointer;
  border: 0;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms ease, opacity 120ms ease;
}
.chat-send-btn:hover { background: var(--btn-primary-hover); filter: none; }
.chat-send-btn:active { background: var(--btn-primary-active); filter: none; }
.chat-send-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.chat-send-btn:disabled { opacity: 0.55; cursor: default; filter: none; }
.ask-btn-kbd { font-family: var(--font-mono); font-size: 0.8em; opacity: 0.85; }

/* ── Connector / Integration platform ──────────────────────────── */
.sp-switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.sp-switch input { opacity: 0; width: 0; height: 0; }
.sp-switch-slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--color-border-2, var(--color-border)); border-radius: 999px;
  transition: background 140ms ease;
}
.sp-switch-slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 140ms ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.sp-switch input:checked + .sp-switch-slider { background: var(--color-accent); }
.sp-switch input:checked + .sp-switch-slider::before { transform: translateX(18px); }
.sp-switch input:disabled + .sp-switch-slider { opacity: 0.5; cursor: not-allowed; }

.sp-conn-item {
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-4); margin-bottom: var(--space-3); background: var(--color-surface);
}
.sp-conn-head { display: flex; align-items: center; gap: var(--space-3); }
.sp-conn-title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
.sp-conn-sub { font-size: var(--text-xs); color: var(--color-faint); margin-top: 2px; }
.sp-conn-actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--space-2); }
.sp-conn-body { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--color-border); }
.sp-conn-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--space-3); }
.sp-conn-field label { font-size: var(--text-xs); color: var(--color-muted); font-weight: var(--weight-medium); }
.sp-conn-row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.sp-conn-input {
  height: 34px; padding: 0 10px; font-size: 0.85rem; flex: 1; min-width: 180px;
  background: var(--color-bg); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: 8px;
}
.sp-conn-input:focus { outline: none; border-color: var(--color-accent); }
.sp-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 10px; border-radius: 999px; font-size: 0.75rem;
  background: var(--color-surface-2); border: 1px solid var(--color-border); color: var(--color-text);
}
.sp-chip button {
  border: none; background: none; cursor: pointer; color: var(--color-faint);
  font-size: 1rem; line-height: 1; padding: 0;
}
.sp-chip button:hover { color: var(--color-danger, #d33); }
.sp-conn-pill {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
}
.sp-conn-pill.on { background: var(--color-success-bg, #e6f6ec); color: var(--color-success, #1a7f37); }
.sp-conn-pill.off { background: var(--color-surface-2); color: var(--color-muted); }
.sp-conn-pill.warn { background: var(--color-warning-bg, #fff4e5); color: var(--color-warning, #b45309); }
.sp-conn-health-txt { font-size: 0.72rem; font-weight: 600; color: var(--color-faint); }
.sp-conn-health-txt.ok { color: var(--color-success, #1a7f37); }
.sp-conn-health-txt.warn { color: var(--color-warning, #b45309); }
.sp-conn-empty { font-size: 0.85rem; color: var(--color-faint); padding: var(--space-3) 0; }
.sp-audit-row {
  display: grid; grid-template-columns: 150px 1fr auto; gap: var(--space-3);
  padding: 8px 0; border-bottom: 1px solid var(--color-border); font-size: 0.78rem;
}
.sp-audit-row:last-child { border-bottom: 0; }
.sp-audit-ts { color: var(--color-faint); font-family: var(--font-mono); font-size: 0.72rem; }
.sp-audit-ev { color: var(--color-text); font-weight: 500; }
.sp-audit-out { color: var(--color-muted); }

/* Send / Share result modal */
.sr-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.sr-modal {
  width: 100%; max-width: 480px;
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: flex; flex-direction: column; max-height: 90vh;
}
.sr-head { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); }
.sr-head h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.sr-body { padding: var(--space-5); overflow-y: auto; }
.sr-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.sr-field label { font-size: 0.78rem; font-weight: 600; color: var(--color-muted); }
.sr-field textarea.sp-conn-input { height: auto; padding: 8px 10px; resize: vertical; }
.sr-hint { font-size: 0.72rem; color: var(--color-faint); }
.sr-note { font-size: 0.85rem; color: var(--color-muted); line-height: 1.5; }
.sr-summary {
  font-size: 0.8rem; color: var(--color-muted); line-height: 1.5;
  background: var(--color-surface-2); border-radius: 8px; padding: 10px 12px;
}
.sr-error { color: var(--color-danger, #d33); font-size: 0.8rem; margin-top: 10px; min-height: 1em; }
.sr-warn {
  font-size: 0.82rem; line-height: 1.5; color: #92400e;
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px;
  padding: 10px 12px; margin-bottom: 12px;
}
[data-theme="dark"] .sr-warn { color: #fbbf24; background: rgba(251,191,36,.08); border-color: rgba(251,191,36,.3); }
.sr-recips { display: flex; flex-wrap: wrap; gap: 6px; }
.sr-recip {
  font-size: 0.8rem; padding: 3px 8px; border-radius: 999px;
  background: var(--color-surface-2); border: 1px solid var(--color-border);
}
.sr-recip-ext { color: #92400e; background: #fff7ed; border-color: #fed7aa; }
[data-theme="dark"] .sr-recip-ext { color: #fbbf24; background: rgba(251,191,36,.08); border-color: rgba(251,191,36,.3); }
.sr-foot {
  padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border);
  display: flex; justify-content: flex-end; gap: var(--space-2);
}

/* ── RTL (dir="rtl" on <html>) ──────────────────────────────────────────────
   Layout above uses logical properties, so panels, toolbars and text mirror on
   their own. These rules cover transforms and glyphs that are direction-blind:
   slide-in drawers/toasts, the toggle knob, and code/identifier islands. */
[dir="rtl"] .dev-drawer:not(.open),
[dir="rtl"] .history-drawer:not(.open) { transform: translateX(-100%); }
[dir="rtl"] .toast { transform: translateX(-20px); }
[dir="rtl"] .toast.show { transform: translateX(0); }
[dir="rtl"] .sp-switch-slider::before { left: auto; right: 3px; }
[dir="rtl"] .sp-switch input:checked + .sp-switch-slider::before { transform: translateX(-18px); }
[dir="rtl"] .follow-up-chip:hover .follow-up-chip-arrow { transform: translateX(-2px) scaleX(-1); }
[dir="rtl"] .follow-up-chip-arrow,
[dir="rtl"] .connection-pill-caret,
[dir="rtl"] .sp-prompt-row-chev,
[dir="rtl"] .sp-header-back-btn svg,
[dir="rtl"] .table-expand-arrow { transform: scaleX(-1); }
/* Code, SQL, identifiers and machine text keep their own (LTR) order. */
[dir="rtl"] pre,
[dir="rtl"] code,
[dir="rtl"] kbd,
[dir="rtl"] .sql-editor-wrapper,
[dir="rtl"] #sql-editor,
[dir="rtl"] .prompt-text,
[dir="rtl"] .trace-panel,
[dir="rtl"] .mc-result-code,
[dir="rtl"] .sp-prompt-textarea,
[dir="rtl"] .sp-prompt-view,
[dir="rtl"] .sp-about-value,
[dir="rtl"] .user-dropdown-email,
[dir="rtl"] .connection-panel-item-type,
[dir="rtl"] .table-name,
[dir="rtl"] .col-ctx-icon-mono {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}
[dir="rtl"] .user-dropdown-email { text-align: right; }
/* Numeric table cells stay an LTR island aligned to the trailing edge. */
[dir="rtl"] td.numeric,
[dir="rtl"] .cell-numeric,
[dir="rtl"] .stats-table td:last-child { direction: ltr; unicode-bidi: isolate; text-align: end; }
/* The settings language picker: option labels are in their own script. */
.sp-lang-picker { display: inline-flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--color-border); border-radius: var(--radius-pill); background: var(--color-surface); }
.sp-lang-option { border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--color-muted); font: inherit; font-size: var(--text-sm); padding: 5px 12px; cursor: pointer; transition: background 120ms ease, color 120ms ease; }
.sp-lang-option:hover { color: var(--color-text); background: var(--color-surface-2); }
.sp-lang-option.is-active,
.sp-lang-option[aria-checked="true"] { background: var(--color-text); color: var(--color-bg, #fff); }
.sp-lang-option:disabled { opacity: .6; cursor: progress; }
.sp-lang-status { display: block; margin-top: 4px; font-size: var(--text-xs); color: var(--color-muted); min-height: 1em; }
