/* =============================================================================
   AIBO — design system
   Warm, friendly, token-driven stylesheet. Cream paper surfaces, teal primary,
   amber accents, rounded geometry throughout. Logo: hand-sketched robot in a
   mirror (cropped from the readme header illustration).
   All structural selectors that drive behaviour (radio :checked tab toggles,
   .is-open / .is-active state classes, modal, footer groups) are preserved.
   ============================================================================= */

/* ----------------------------------------------------------------------------
   1. Design tokens
   ---------------------------------------------------------------------------- */
:root {
  /* Brand — friendly teal */
  --brand:          #0f766e;
  --brand-strong:   #115e59;
  --brand-soft:     rgba(15, 118, 110, 0.10);
  --brand-softer:   rgba(15, 118, 110, 0.06);
  --on-brand:       #ffffff;

  /* Accent — warm amber */
  --accent:         #de994b;
  --accent-deep:    #a16022;
  --accent-soft:    rgba(222, 153, 75, 0.18);
  --accent-softer:  rgba(222, 153, 75, 0.10);

  /* Surfaces & neutrals — warm paper */
  --bg:             #faf5ec;
  --surface:        #ffffff;
  --surface-2:      #faf7f1; /* subtle insets */
  --surface-3:      #f2ecdf;
  --border:         #e9e1d2;
  --border-strong:  #d5c9b4;

  /* Text — warm near-blacks, tuned for contrast/readability */
  --text:           #33302a;
  --text-muted:     #5f584b;
  --text-subtle:    #837a69;
  --placeholder:    #a89e8c;

  /* Semantic */
  --success:        #157347; --success-bg: rgba(34, 170, 108, 0.14);
  --warning:        #a16022; --warning-bg: rgba(222, 153, 75, 0.18);
  --danger:         #c2402f; --danger-bg:  rgba(216, 84, 62, 0.12);
  --info:           #0f766e; --info-bg:    rgba(15, 118, 110, 0.10);

  /* Focus ring */
  --ring:           0 0 0 3px rgba(15, 118, 110, 0.22);

  /* Radii — generous and soft */
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 999px;

  /* Shadows — warm-tinted */
  --shadow-xs: 0 1px 2px rgba(90, 70, 40, 0.06);
  --shadow-sm: 0 1px 3px rgba(90, 70, 40, 0.09), 0 1px 2px rgba(90, 70, 40, 0.05);
  --shadow-md: 0 6px 16px rgba(90, 70, 40, 0.09), 0 2px 4px rgba(90, 70, 40, 0.05);
  --shadow-lg: 0 18px 42px rgba(90, 70, 40, 0.16);

  /* Layout */
  --content-max-width: 1500px;
  --sidebar-width: 320px;

  /* ---- Legacy variable aliases (so any leftover references stay coherent) ---- */
  --color-primary: var(--brand);
  --color-primary-dark: var(--brand-strong);
  --color-primary-light: #14b8a6;
  --color-success: var(--success);
  --color-warning: var(--warning);
  --color-error: var(--danger);
  --color-bg: var(--bg);
  --color-surface: var(--surface);
  --color-border: var(--border);
  --color-text: var(--text);
  --color-text-muted: var(--text-muted);
  --color-text-light: var(--text-subtle);
  --brand-blue: var(--brand);
  --brand-blue-dark: var(--brand-strong);
  --accent-red: var(--danger);
  --border-color: var(--border);
  --bg-muted: var(--bg);
}

/* ----------------------------------------------------------------------------
   2. Base / reset
   ---------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  /* Flex column so the footer sits at the viewport bottom without forcing a scrollbar */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 85% -10%, rgba(222, 153, 75, 0.10), transparent 60%),
    radial-gradient(800px 460px at -10% 0%, rgba(15, 118, 110, 0.05), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--text); line-height: 1.25; }

a { color: var(--brand); }

::selection { background: rgba(222, 153, 75, 0.35); }

/* Shared focus-visible treatment */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Utility */
.hidden { display: none !important; }
.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; }
.muted { color: var(--text-muted); font-size: 0.875rem; }

/* Custom scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-pill); border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); background-clip: content-box; }

/* ----------------------------------------------------------------------------
   3. Layout shell
   ---------------------------------------------------------------------------- */
main {
  padding: 1.5rem 1.5rem 3rem;
  max-width: 1760px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.main-column {
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

.page-title { margin: 0; font-size: 1.75rem; font-weight: 800; }
.title-divider { height: 1px; background: var(--border); }

/* Legacy two-column shell (benchmark.html) */
.app-shell {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  max-width: calc(var(--sidebar-width) + var(--content-max-width) + 64px);
  margin: 0 auto;
  width: 100%;
}
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
  position: sticky;
  top: 96px;
  max-height: calc(100vh - 128px);
  overflow-y: auto;
  padding-right: 4px;
}
.sidebar details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-sm); }
.sidebar summary { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; font-weight: 700; cursor: pointer; list-style: none; }
.sidebar summary::marker { display: none; }
.sidebar summary::after { content: "▾"; font-size: 1.1rem; color: var(--text-subtle); transition: transform 0.2s ease; }
.sidebar details[open] summary::after { transform: rotate(180deg); }
.sidebar form { padding: 0 1.25rem 1rem; display: flex; flex-direction: column; gap: 1rem; }
.sidebar label { display: flex; flex-direction: column; font-size: 0.875rem; font-weight: 700; color: var(--text); gap: 0.375rem; }
.sidebar .setting-help { margin: 0; font-size: 0.78rem; color: var(--text-muted); }
.sidebar .settings-control { display: flex; flex-direction: column; gap: 0.5rem; }
.sidebar button { width: 100%; }

/* ----------------------------------------------------------------------------
   4. Global header — a single, slim bar
   ---------------------------------------------------------------------------- */
.global-header {
  position: sticky;
  top: 0;
  z-index: 60;
  background: rgba(255, 253, 248, 0.88);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(90, 70, 40, 0.03);
}

.header-shell {
  max-width: 1760px;
  margin: 0 auto;
  padding: 0.55rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
}

/* Kept for any legacy markup that still wraps rows */
.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.logo { display: flex; align-items: center; gap: 0.65rem; color: var(--text); }
.logo-icon {
  width: 38px; height: 38px;
  display: block;
  border-radius: 12px;
  box-shadow: 0 3px 8px rgba(58, 68, 84, 0.25);
}
.logo-wordmark {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  font-weight: 900;
  font-size: 1.18rem;
  letter-spacing: 0.01em;
}
.logo-wordmark small {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
}

.header-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
/* The import form only hosts a hidden file input — keep it out of the flex flow
   so it doesn't add a phantom gap between the upload and key buttons. */
.settings-import-form { display: none; }

/* Header tab pills (analyzer / benchmark) */
.global-header .app-tab-buttons[data-header-tabs="true"] {
  display: inline-flex;
  align-items: center;
  align-self: center;
  gap: 4px;
  background: var(--surface-3);
  padding: 4px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}
.global-header .app-tab-buttons[data-header-tabs="true"] label {
  padding: 0.42rem 1.05rem;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
}
.global-header .app-tab-buttons[data-header-tabs="true"] label:hover:not(.active) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
}
.global-header .app-tab-buttons[data-header-tabs="true"] label.active,
#app-tab-analyzer:checked ~ header .app-tab-buttons[data-header-tabs="true"] label[for="app-tab-analyzer"],
#app-tab-analysis:checked ~ header .app-tab-buttons[data-header-tabs="true"] label[for="app-tab-analysis"],
#app-tab-benchmark:checked ~ header .app-tab-buttons[data-header-tabs="true"] label[for="app-tab-benchmark"] {
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}

#apiKeyButton[data-has-keys="false"] {
  color: var(--danger);
  border-color: rgba(194, 64, 47, 0.4);
  background: var(--danger-bg);
}
#apiKeyButton[data-has-keys="false"]:hover { background: rgba(194, 64, 47, 0.16); }

/* ----------------------------------------------------------------------------
   5. App tabs (analyzer / benchmark panes) — open layout, no heavy card frame
   ---------------------------------------------------------------------------- */
.app-tabs {
  position: relative;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: none;
  min-width: 0;
}
.app-tab-toggle { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.app-tab-buttons { display: inline-flex; gap: 4px; background: var(--surface-3); padding: 4px; border-radius: var(--radius-pill); align-self: flex-start; }
.app-tab-buttons label { padding: 0.5rem 1.1rem; border-radius: var(--radius-pill); font-weight: 700; color: var(--text-muted); cursor: pointer; transition: all 0.18s ease; user-select: none; }
.app-tab-panels { display: grid; min-width: 0; }
.app-pane { display: none; flex-direction: column; gap: 2rem; min-width: 0; }
#app-tab-analyzer:checked ~ main .app-tab-panels #app-pane-analyzer,
#app-tab-analysis:checked ~ main .app-tab-panels #app-pane-analysis,
#app-tab-benchmark:checked ~ main .app-tab-panels #app-pane-benchmark { display: flex; }

/* ----------------------------------------------------------------------------
   6. Zones & run bar — the design → run → results flow
   ---------------------------------------------------------------------------- */
.footer-form { margin: 0; }

.zone { display: flex; flex-direction: column; gap: 1rem; min-width: 0; scroll-margin-top: 148px; }

.zone-header { display: flex; align-items: flex-start; gap: 0.85rem; flex-wrap: wrap; }
.zone-step {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 900;
  font-size: 0.95rem;
  box-shadow: 0 2px 6px rgba(15, 118, 110, 0.25);
}
.zone-heading { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.zone-heading h2 { margin: 0; font-size: 1.25rem; font-weight: 800; }
.zone-sub { margin: 0; color: var(--text-muted); font-size: 0.85rem; }
.zone-actions { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; flex-wrap: wrap; }

/* Sticky command bar: run settings + the Run button in one place, always in reach */
.run-bar {
  position: sticky;
  top: 66px;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  padding: 0.55rem 0.75rem 0.55rem 1rem;
  /* Cancel the left padding + border so the step badge inside the bar
     lines up with the other zones' step numbers. */
  margin-left: calc(-1rem - 1px);
}
.run-bar-inner { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.run-bar-lead { display: flex; align-items: center; gap: 0.6rem; }
.run-bar-title { font-weight: 800; font-size: 1rem; }
.run-bar-settings { display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap; margin: 0; }
.run-field { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.run-field label {
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  white-space: nowrap;
}
.run-field .form-input,
.run-field .form-select {
  padding: 0.38rem 0.55rem;
  font-size: 0.84rem;
  border-radius: var(--radius-sm);
  width: auto;
}
.run-field input[type="number"] { width: 74px; }
.run-field .form-select { width: 200px; }
.run-bar-actions { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; }
.btn-run { padding: 0.6rem 1.7rem; font-size: 0.95rem; }

/* Benchmark data zone: dataset + subset side by side when there's room */
.data-grid { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: stretch; }
/* Cards stretch to the row height; anchor each card's status line to its bottom
   edge so the two columns finish on the same visual baseline. */
.data-grid .analysis-card > :last-child { margin-top: auto; }

/* ----------------------------------------------------------------------------
   7. Buttons — pill-shaped and friendly
   ---------------------------------------------------------------------------- */
.btn[hidden] { display: none; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.06s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary { background: var(--brand); color: var(--on-brand); border-color: var(--brand); box-shadow: 0 1px 2px rgba(15, 118, 110, 0.35); }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); border-color: var(--brand-strong); box-shadow: 0 4px 12px rgba(15, 118, 110, 0.3); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-subtle); }

.btn-ghost { background: transparent; color: var(--brand); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--brand-soft); }

.btn-outline { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn-outline:hover:not(:disabled) { background: var(--brand-soft); }

.btn-text { background: none; border: none; color: var(--danger); padding: 0; font-weight: 700; cursor: pointer; }

.btn-sm { padding: 0.4rem 0.9rem; font-size: 0.825rem; }
.btn-xs { padding: 0.35rem 0.8rem; font-size: 0.8rem; font-weight: 700; }
.btn-icon { width: 40px; height: 40px; padding: 0; }
.btn-icon-sm { width: 34px; height: 34px; padding: 0; flex: none; }
.btn-icon-sm svg { width: 18px; height: 18px; }

/* Lightweight CSS tooltip (pair with aria-label for accessibility) */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-2px);
  background: var(--text);
  color: var(--bg);
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 100;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.btn .icon-arrow { display: inline-flex; align-items: center; font-size: 1.05em; }

.link-button { background: none; border: none; padding: 0; font-size: 0.875rem; color: var(--brand); cursor: pointer; font-weight: 700; }
.link-button.destructive { color: var(--danger); }
.link-button:hover { text-decoration: underline; }

/* ----------------------------------------------------------------------------
   8. Forms
   ---------------------------------------------------------------------------- */
.form-input, .form-select, .form-textarea,
.text-input,
.sidebar input[type="password"], .sidebar input[type="text"], .sidebar input[type="number"], .sidebar select,
.dataset-quick-select select, .subset-input input,
.model-preferences select, .model-preferences input[type="number"],
.critical-field .form-input, .critical-field .form-select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus,
.text-input:focus,
.sidebar input:focus, .sidebar select:focus,
.dataset-quick-select select:focus, .subset-input input:focus,
.model-preferences select:focus, .model-preferences input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.form-input::placeholder, .form-textarea::placeholder, .text-input::placeholder, input::placeholder, textarea::placeholder {
  color: var(--placeholder);
}

.form-textarea, .text-input {
  resize: vertical;
  min-height: 88px;
  line-height: 1.55;
}

/* File upload */
.file-upload { display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.85rem; font-weight: 700; color: var(--text); }
.file-upload input[type="file"] {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: var(--surface-2);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}
.file-upload input[type="file"]::-webkit-file-upload-button,
.file-upload input[type="file"]::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.compact-file-upload { max-width: 280px; }
.compact-file-upload input[type="file"] { min-height: 38px; }

/* Toggle switch */
.toggle-row { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; color: var(--text); }
.toggle-input { position: relative; appearance: none; width: 44px; height: 24px; border-radius: var(--radius-pill); background: var(--border-strong); transition: background 0.2s ease; cursor: pointer; border: none; flex-shrink: 0; }
.toggle-input::before { content: ""; position: absolute; top: 3px; left: 4px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.2s ease; box-shadow: var(--shadow-xs); }
.toggle-input:checked { background: var(--brand); }
.toggle-input:checked::before { transform: translateX(18px); }

.toggle-group { display: flex; align-items: center; gap: 0.75rem; }
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input[type="checkbox"] { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; cursor: pointer; background: var(--border-strong); border-radius: var(--radius-pill); transition: background 0.2s ease; }
.toggle-slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s ease; box-shadow: var(--shadow-xs); }
.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }

.range-wrapper { display: flex; align-items: center; gap: 0.75rem; }
.range-wrapper input[type="range"] { flex-grow: 1; accent-color: var(--brand); }
.range-value { min-width: 48px; text-align: right; font-size: 0.82rem; color: var(--text-muted); }

.settings-divider { height: 1px; background: var(--border); margin: 0.75rem 0 1rem; border: 0; }

/* Control row (legacy grid) */
.control-row { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(0,1fr) minmax(0,1fr) minmax(0,1.5fr); gap: 0.75rem; align-items: stretch; }
.control-row form { margin: 0; }
.control-row .btn { width: 100%; }
.control-placeholder { border: 1px dashed transparent; border-radius: var(--radius-xs); }

/* ----------------------------------------------------------------------------
   9. Cards (analysis / benchmark sections)
   ---------------------------------------------------------------------------- */
.analysis-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card-header { display: flex; flex-direction: column; gap: 0.3rem; }
.card-title { margin: 0; font-size: 1.2rem; font-weight: 800; }

.benchmark-pane { display: flex; flex-direction: column; gap: 1.5rem; }
.dataset-actions { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-items: start; }
.dataset-quick-select { display: flex; flex-direction: column; gap: 0.6rem; font-size: 0.85rem; font-weight: 700; color: var(--text); }
.subset-input { display: flex; flex-direction: column; gap: 0.6rem; }
.subset-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.subset-row input { flex: 1 1 200px; }
.subset-row .btn { white-space: nowrap; }

/* Benchmark controls read poorly at full page width — cap them and let buttons hug their label */
.dataset-actions .file-upload input[type="file"],
.dataset-quick-select select,
.subset-input input { max-width: 420px; }
.dataset-actions .file-upload .btn,
.dataset-quick-select .btn { align-self: flex-start; }
.run-benchmark-form { display: flex; justify-content: flex-start; }
.dataset-status, .subset-status, .benchmark-status { display: flex; flex-direction: column; gap: 0.75rem; }
.dataset-manager { display: flex; flex-direction: column; gap: 1rem; }
/* Default <p>/<pre> margins double up with the flex gap and read as huge blank rows */
.dataset-status > p { margin: 0; }
.dataset-status .dataset-preview { margin-top: 0; }
.dataset-status .dataset-preview pre { margin: 0; }
/* The last-child bottom-pinning in .data-grid would shove the whole manager down */
.data-grid .analysis-card > .dataset-manager:last-child { margin-top: 0; }
.dataset-loaded-alert { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.dataset-clear-form { flex-shrink: 0; }

/* ----------------------------------------------------------------------------
   10. Experiment cards (prompt workspace + benchmark experiments)
   ---------------------------------------------------------------------------- */
.prompt-grid-wrapper, #prompts-container, .experiments-viewport { max-width: 100%; min-width: 0; }

.experiments-grid { display: flex; gap: 1.25rem; align-items: stretch; overflow-x: auto; padding: 0.25rem 0 1rem; }

.experiments-scroll-container {
  display: flex;
  gap: 1.25rem;
  overflow-x: auto;
  overflow-y: visible;
  padding: 0.25rem 0 1rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* A lone card grows to fill the row; multiple cards keep a comfortable width and scroll. */
.experiment-card {
  flex: 1 1 460px;
  min-width: 360px;
  max-width: 640px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}
/* Ghost card: the add-experiment affordance sits where the next card will appear */
.ghost-card {
  flex: 0 0 230px;
  min-width: 230px;
  align-self: stretch;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text-subtle);
  font-family: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}
.ghost-card:hover, .ghost-card:focus-visible { border-color: var(--brand); color: var(--brand); background: var(--brand-softer); }
.ghost-plus { font-size: 1.9rem; line-height: 1; }
.ghost-hint { font-size: 0.75rem; font-weight: 600; color: inherit; opacity: 0.75; }

.experiment-card-header { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }
.experiment-card-header h3 { margin: 0; font-size: 1.15rem; font-weight: 800; }
.section-divider { height: 1px; background: var(--border); margin: 0; }

.card-section { display: flex; flex-direction: column; gap: 0.5rem; }
.section-label { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-size: 0.875rem; color: var(--text); gap: 0.5rem; }
.label-metadata { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--text-subtle); font-size: 0.75rem; font-weight: 500; }
.char-count { font-size: 0.75rem; color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.duplicate-badge { display: inline-flex; align-items: center; background: var(--danger-bg); color: var(--danger); border-radius: var(--radius-pill); padding: 0.1rem 0.5rem; font-size: 0.68rem; font-weight: 800; }

.field-group.is-duplicate > .text-input:first-of-type,
.text-input.duplicate-field { border: 2px solid var(--danger); background: var(--danger-bg); box-shadow: none; }

.markdown-preview { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); padding: 0.75rem; font-size: 0.82rem; color: var(--text-muted); line-height: 1.55; }
.markdown-preview p { margin: 0 0 0.5rem; }
.markdown-preview .empty-preview { color: var(--text-subtle); font-style: italic; margin: 0; }

.inline-warning { background: var(--danger-bg); color: var(--danger); border-radius: var(--radius-xs); padding: 0.5rem 0.75rem; font-size: 0.78rem; }

/* Prompt turns */
.prompt-turns { display: flex; flex-direction: column; gap: 0.75rem; }
.turn-group { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; transition: box-shadow 0.2s ease; }
.turn-group:hover { box-shadow: var(--shadow-sm); }
.prompt-turn { display: flex; flex-direction: column; gap: 0.5rem; }
.prompt-turn-header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.prompt-turn-header .section-label { flex: 1; }
.turn-actions { display: flex; justify-content: flex-end; align-items: center; gap: 0.5rem; margin-top: 0.25rem; }

/* Attachments */
.attachment-upload { margin: 0; }
.attachment-upload input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.attachment-chip { display: inline-flex; align-items: center; gap: 0.4rem; max-width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface); padding: 0.25rem 0.6rem; font-size: 0.75rem; color: var(--text); }
.attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-remove { border: 0; background: transparent; color: var(--text-subtle); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 2px; }
.attachment-remove:hover { color: var(--danger); }

/* Model preferences */
.model-preferences { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.model-preferences label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.85rem; font-weight: 700; color: var(--text); }

/* Model select with custom-ID override (pencil swaps the select for free text) */
.model-select { position: relative; display: block; min-width: 0; }
.model-select select { width: 100%; padding-right: 3.1rem; text-overflow: ellipsis; }
.model-select-edit {
  position: absolute; top: 50%; right: 1.75rem; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem; padding: 0;
  border: none; border-radius: var(--radius-xs);
  background: transparent; color: var(--text-subtle); cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease;
}
.model-select-edit:hover, .model-select-edit:focus-visible { color: var(--brand); background: var(--brand-soft); }
.model-select-edit:focus-visible { outline: none; box-shadow: var(--ring); }
.model-select-edit svg { width: 0.9rem; height: 0.9rem; }
.model-select.is-editing select, .model-select.is-editing .model-select-edit { display: none; }
.model-override-input {
  width: 100%; padding: 0.6rem 0.75rem;
  border: 1px solid var(--brand); border-radius: var(--radius-sm);
  font-size: 0.9rem; font-family: inherit;
  background: var(--surface); color: var(--text);
  box-shadow: var(--ring); outline: none;
}
.run-field .model-select { width: 200px; flex-shrink: 0; }

/* Prompts actions */
.prompts-actions { display: flex; justify-content: flex-start; padding: 0.5rem 0 0; }
.prompts-actions .add-experiment-btn, .add-experiment-btn { display: inline-flex; align-items: center; gap: 0.5rem; }

/* Evaluation rubric — quiet, styled like the other sections; the star is the only marker */
.card-section.rubric-section .section-label > span:first-child::before { content: "⭐"; margin-right: 0.35rem; }
.card-section.rubric-section textarea { min-height: 113px; }

/* ----------------------------------------------------------------------------
   11. Advanced settings panel
   ---------------------------------------------------------------------------- */
.advanced-settings-wrapper {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.26s ease, opacity 0.26s ease;
  width: 100%;
  padding: 0 1.5rem;
  box-sizing: border-box;
}
.advanced-settings-wrapper.is-open { max-height: 1600px; opacity: 1; padding-top: 0.5rem; padding-bottom: 1.25rem; }

.advanced-settings-card {
  max-width: 1760px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.advanced-settings-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.advanced-settings-title h2 { margin: 0; font-size: 1.2rem; font-weight: 800; }
.advanced-settings-title p { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.9rem; }
.advanced-settings-status { display: inline-flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.advanced-settings-toolbar { display: flex; align-items: flex-start; gap: 0.75rem; flex-wrap: wrap; margin-left: auto; }
.advanced-settings-body { display: flex; flex-direction: column; gap: 1.25rem; }
.advanced-settings-form { display: flex; flex-direction: column; gap: 1.25rem; }
.advanced-settings-grid { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.advanced-control label { font-weight: 700; color: var(--text); }
.advanced-control .setting-help { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.8rem; }
.advanced-form-actions, .advanced-form-submit { display: flex; justify-content: flex-end; }

.advanced-settings-close {
  border: none; background: transparent; color: var(--text-subtle);
  font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 0.25rem;
  border-radius: var(--radius-sm); transition: background 0.18s ease, color 0.18s ease;
}
.advanced-settings-close:hover, .advanced-settings-close:focus-visible { background: var(--surface-3); color: var(--text); outline: none; }

.key-status-chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.25rem 0.65rem; border-radius: var(--radius-pill); background: var(--surface-3); color: var(--text-muted); font-size: 0.72rem; font-weight: 800; transition: background 0.18s ease, color 0.18s ease; }
.key-status-chip--active { background: var(--success-bg); color: var(--success); }

/* Import summary */
.import-summary { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1rem 1.25rem; background: var(--surface-2); display: flex; flex-direction: column; gap: 1rem; }
.import-summary-header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.import-summary-header h3 { margin: 0; font-size: 1rem; }
.import-summary-pill { padding: 0.25rem 0.65rem; border-radius: var(--radius-pill); background: var(--brand-soft); color: var(--brand); font-weight: 800; font-size: 0.78rem; }
.import-summary-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.import-summary-grid dt { margin: 0; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-subtle); }
.import-summary-grid dd { margin: 0.25rem 0 0; font-weight: 700; color: var(--text); }
.import-summary-warnings { border-top: 1px dashed var(--border-strong); padding-top: 0.75rem; }
.import-summary-warnings ul { margin: 0.5rem 0 0; padding-left: 1rem; }

/* ----------------------------------------------------------------------------
   12. Alerts
   ---------------------------------------------------------------------------- */
.alert { background: var(--info-bg); border-left: 4px solid var(--brand); padding: 0.75rem 1rem; border-radius: var(--radius-sm); color: var(--info); font-size: 0.875rem; }
.alert.error { background: var(--danger-bg); border-left-color: var(--danger); color: var(--danger); }
.alert.warning { background: var(--warning-bg); border-left-color: var(--warning); color: var(--warning); }

.advanced-alert, .api-keys-alert { border-radius: var(--radius-sm); padding: 0.85rem 1rem; font-size: 0.9rem; line-height: 1.45; }
.advanced-alert--success, .api-keys-alert--success { background: var(--success-bg); color: var(--success); }
.advanced-alert--warning { background: var(--warning-bg); color: var(--warning); }
.advanced-alert--error, .api-keys-alert--error { background: var(--danger-bg); color: var(--danger); }

.sidebar-alert { margin: 0 1.25rem 0.75rem; padding: 0.6rem 0.9rem; border-radius: var(--radius-sm); font-size: 0.82rem; background: var(--info-bg); color: var(--info); }
.sidebar-alert.error { background: var(--danger-bg); color: var(--danger); }
.sidebar-alert.warning { background: var(--warning-bg); color: var(--warning); }

.toast-alert { display: flex; align-items: center; gap: 0.5rem; border-radius: var(--radius-sm); padding: 0.6rem 0.9rem; font-size: 0.875rem; font-weight: 500; }
.toast-alert.success { background: var(--success-bg); color: var(--success); border-left: 4px solid var(--success); }
.toast-alert.error { background: var(--danger-bg); color: var(--danger); border-left: 4px solid var(--danger); }
.toast-alert.warning { background: var(--warning-bg); color: var(--warning); border-left: 4px solid var(--warning); }

.inline-alert { background: var(--danger-bg); color: var(--danger); border-radius: var(--radius-xs); padding: 0.6rem 0.9rem; font-size: 0.78rem; }

.analysis-cost-warning-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.analysis-cost-warning-title { font-weight: 800; margin: 0 0 0.25rem; }
.analysis-cost-warning-breakdown, .analysis-cost-warning-estimate { margin: 0.25rem 0; }

/* ----------------------------------------------------------------------------
   13. Analysis results
   ---------------------------------------------------------------------------- */
.panel { min-width: 0; }
.analysis-panel, .analysis-module { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }
.analysis-results, .analysis-summary, .analysis-transcripts { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

.summary-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 1rem; }
.summary-title { display: flex; flex-direction: column; gap: 0.4rem; }
.summary-cost-badge { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0.8rem; border-radius: var(--radius-pill); background: var(--brand-soft); color: var(--brand); font-size: 0.8rem; font-weight: 800; }

.summary-table-wrapper { border: 1px solid var(--border); border-radius: var(--radius-md); overflow-x: auto; background: var(--surface); box-shadow: var(--shadow-sm); }
.analysis-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.analysis-table th, .analysis-table td { padding: 0.7rem 1rem; text-align: left; font-size: 0.82rem; border-bottom: 1px solid var(--border); }
.analysis-table thead th { background: var(--surface-3); text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 800; }
.analysis-table tbody tr:last-child th, .analysis-table tbody tr:last-child td { border-bottom: none; }
.summary-table { min-width: 560px; }
.summary-table .metric-cell { font-weight: 700; background: var(--surface-2); position: sticky; left: 0; }
.summary-table tbody tr:nth-child(even) td, .summary-table tbody tr:nth-child(even) th { background: var(--surface-2); }
.summary-table .value-cell { font-variant-numeric: tabular-nums; }

.analysis-status { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1rem; background: var(--surface-2); display: flex; flex-direction: column; gap: 0.75rem; }
.analysis-status.success { border-color: var(--success); background: var(--success-bg); }
.analysis-status.error { border-color: var(--danger); background: var(--danger-bg); }
.analysis-status.warning { border-color: var(--warning); background: var(--warning-bg); }
.status-headline { font-weight: 700; font-size: 0.95rem; display: flex; justify-content: space-between; align-items: center; }
.status-iterations { font-size: 0.82rem; color: var(--text-muted); }
.status-label { font-weight: 700; }
.status-line { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-muted); }
.progress-wrapper { width: 100%; height: 8px; border-radius: var(--radius-pill); background: rgba(90, 70, 40, 0.10); overflow: hidden; }
.progress-bar { height: 100%; border-radius: var(--radius-pill); background: linear-gradient(90deg, var(--brand), #14b8a6); transition: width 0.3s ease; }
.status-spinner { flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(15, 118, 110, 0.25); border-top-color: var(--brand); animation: spin 0.8s linear infinite; }
.status-hint { font-size: 0.8rem; margin: 0; }
.status-elapsed { margin-left: auto; font-size: 0.8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.status-counts { display: flex; gap: 0.75rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-muted); }
.status-count { font-variant-numeric: tabular-nums; }

.badge { background: var(--brand); color: var(--on-brand); border-radius: var(--radius-pill); padding: 0.2rem 0.6rem; font-size: 0.72rem; font-weight: 700; }
.rating-badge { background: var(--success-bg); color: var(--success); }

/* Plots */
.analysis-plots, .benchmark-plots { display: flex; flex-direction: column; gap: 1.1rem; }
.plot-grid { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.plot-card { margin: 0; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.plot-card img { width: 100%; border-radius: var(--radius-sm); }
.plot-card figcaption { margin: 0; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-subtle); }

/* Experiment accordion (analysis) */
.analysis-experiment { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1rem 1.1rem; background: var(--surface); }
.analysis-experiment summary { cursor: pointer; font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; list-style: none; }
.analysis-experiment summary::-webkit-details-marker { display: none; }
.analysis-experiment summary::after { content: "▸"; font-size: 1.1rem; color: var(--text-subtle); transition: transform 0.2s ease; }
.analysis-experiment[open] summary::after { transform: rotate(90deg); }
.experiment-summary { display: flex; flex-direction: column; gap: 0.4rem; width: 100%; }
.experiment-label { font-size: 0.95rem; font-weight: 800; color: var(--text); }
.experiment-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; font-size: 0.75rem; color: var(--text-subtle); font-weight: 500; }
.experiment-chip { display: inline-flex; align-items: center; gap: 0.25rem; border-radius: var(--radius-pill); padding: 0.2rem 0.65rem; background: var(--surface-3); color: var(--text); font-weight: 700; }
.experiment-chip[data-chip-type="temperature"] { background: var(--accent-soft); color: var(--accent-deep); }
.experiment-chip[data-chip-type="ratings"] { background: var(--success-bg); color: var(--success); }
.experiment-body { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.75rem; }

.analysis-iteration { border-top: 1px solid var(--border); padding: 1rem 0; display: flex; flex-direction: column; gap: 0.75rem; }
.analysis-iteration:first-of-type { border-top: none; }
.iteration-header { display: flex; justify-content: space-between; align-items: center; font-size: 0.875rem; font-weight: 700; }

/* Transcripts */
.transcript-block { display: flex; flex-direction: column; gap: 0.625rem; }
.transcript-line { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; background: var(--surface-2); }
.role-badge { display: inline-flex; align-items: center; border-radius: var(--radius-pill); padding: 0.1rem 0.6rem; font-size: 0.68rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; align-self: flex-start; background: var(--surface-3); color: var(--text-muted); }
.transcript-user .role-badge { background: var(--brand-soft); color: var(--brand); }
.transcript-assistant .role-badge { background: var(--surface-3); color: var(--text-muted); }
.transcript-line pre { margin: 0; white-space: pre-wrap; font-family: inherit; font-size: 0.875rem; color: var(--text); }
.rating-text { margin: 0; font-size: 0.82rem; color: var(--text-muted); }

.benchmark-results { display: flex; flex-direction: column; gap: 1.5rem; margin-top: 1.5rem; }
.benchmark-summary, .benchmark-transcripts { display: flex; flex-direction: column; gap: 1.1rem; }
.transcript-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 1rem; }
.transcript-item { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1rem; background: var(--surface); box-shadow: var(--shadow-xs); }
.transcript-item ol { margin: 0.75rem 0 0; padding-left: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.transcript-item li { line-height: 1.6; color: var(--text); }

/* Dataset preview */
.dataset-preview { margin-top: 1rem; }
.dataset-preview h3 { margin: 0 0 0.75rem; font-size: 1rem; font-weight: 800; }
.dataset-preview pre { padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); overflow-x: auto; font-size: 0.82rem; }

/* Downloads / export menu */
.analysis-downloads { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.download-button { display: inline-flex; align-items: center; justify-content: center; padding: 0.6rem 1.25rem; border-radius: var(--radius-pill); border: 1px solid var(--border-strong); color: var(--brand); text-decoration: none; font-weight: 700; background: var(--surface); transition: background 0.18s ease; cursor: pointer; }
.download-button:hover { background: var(--brand-soft); }
.export-menu { position: relative; }
.export-menu-panel { margin-top: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.75rem; background: var(--surface); box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: 0.75rem; max-height: 320px; overflow-y: auto; }
.export-menu-option { display: flex; flex-direction: column; gap: 0.625rem; padding: 0.75rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); }
.export-menu-option.is-latest { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand-soft); }
.export-menu-title-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.export-menu-title { font-size: 0.875rem; font-weight: 800; color: var(--text); }
.export-menu-badge { background: var(--brand); color: var(--on-brand); padding: 0.1rem 0.5rem; border-radius: var(--radius-pill); font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase; }
.export-menu-meta { display: grid; gap: 0.25rem 0.75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); font-size: 0.75rem; color: var(--text-muted); }
.export-menu-meta div { display: flex; flex-direction: column; gap: 0.125rem; }
.export-menu-meta dt { font-weight: 700; color: var(--text); }
.export-menu-meta dd { margin: 0; }
.export-menu-links { display: inline-flex; gap: 0.75rem; font-weight: 700; }
.download-link { color: var(--brand); text-decoration: none; }
.download-link:hover { text-decoration: underline; }
.download-link.disabled { opacity: 0.4; cursor: not-allowed; }

/* ----------------------------------------------------------------------------
   14. Flash toast (floating status message, formerly in the sticky footer)
   ---------------------------------------------------------------------------- */
.footer-flash {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  display: none;
  align-items: center;
  gap: 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.6rem 1.2rem;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  color: var(--text);
}
.footer-flash.is-visible { display: inline-flex; }
.footer-flash--success { color: var(--success); border: 1px solid var(--success); }
.footer-flash--warning { color: var(--warning); border: 1px solid var(--warning); }
.footer-flash--error { color: var(--danger); border: 1px solid var(--danger); }

/* Site footer — quiet credit line */
.site-footer { text-align: center; padding: 0 1.5rem 1.75rem; }
.site-footer p { margin: 0; font-size: 0.78rem; color: var(--text-subtle); }
.site-footer a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.site-footer a:hover { color: var(--brand); }

/* ----------------------------------------------------------------------------
   15. Modal + API keys
   ---------------------------------------------------------------------------- */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; opacity: 0; transition: opacity 0.22s ease; z-index: 80; }
.modal.is-open { pointer-events: auto; opacity: 1; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(51, 40, 24, 0.45); backdrop-filter: blur(2px); }
.modal-dialog { position: relative; z-index: 1; width: min(720px, 92vw); max-height: 90vh; overflow-y: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 1.75rem; }
.modal-close { position: absolute; top: 0.75rem; right: 0.75rem; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-subtle); line-height: 1; }
.modal-close:hover { color: var(--text); }

.api-keys-modal { display: flex; flex-direction: column; gap: 1.25rem; }
.api-keys-header { display: flex; flex-direction: column; gap: 0.5rem; }
.api-keys-heading { display: flex; flex-direction: column; gap: 0.25rem; }
.api-keys-header h2 { margin: 0; font-size: 1.3rem; font-weight: 800; }
.api-keys-header p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.api-keys-assurance { margin: 0; color: var(--success); font-weight: 700; font-size: 0.875rem; }
.api-keys-tabs { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.5rem; }
.api-keys-tab { border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--text); padding: 0.7rem 1rem; font-family: inherit; font-weight: 700; font-size: 0.9rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; transition: all 0.18s ease; }
.api-keys-tab:hover, .api-keys-tab:focus-visible { border-color: var(--brand); color: var(--brand); outline: none; }
.api-keys-tab.is-active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.api-keys-tab[data-has-value="true"]::after { content: "Stored"; margin-left: 0.4rem; font-size: 0.65rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--success); }
.api-keys-panels { position: relative; }
.api-key-panel, .api-key-guide-panel { display: none; flex-direction: column; gap: 0.75rem; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.api-key-panel.is-active, .api-key-guide-panel.is-active { display: flex; }
.api-key-panel h3 { margin: 0; font-size: 1rem; }
.api-key-field { display: flex; flex-direction: column; gap: 0.5rem; }
.api-key-label { font-weight: 700; color: var(--text); font-size: 0.9rem; }
.api-key-input-group { position: relative; display: flex; align-items: center; }
.api-key-input { width: 100%; padding: 0.7rem 3rem 0.7rem 0.9rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 0.9rem; font-family: inherit; background: var(--surface); color: var(--text); transition: border-color 0.16s ease, box-shadow 0.16s ease; }
.api-key-input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.api-key-visibility { position: absolute; right: 0.5rem; background: none; border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0.25rem; border-radius: var(--radius-sm); color: var(--text-subtle); transition: background 0.18s ease, color 0.18s ease; }
.api-key-visibility:hover, .api-key-visibility:focus-visible { background: var(--surface-3); color: var(--text); outline: none; }
.api-key-visibility svg { width: 20px; height: 20px; }
.api-key-visibility.is-active { color: var(--brand); }
.api-key-status { margin: 0; font-size: 0.78rem; color: var(--success); font-weight: 700; }
.api-key-hint { font-size: 0.78rem; color: var(--text-subtle); margin: 0; }
.api-key-aux-field .api-key-input { padding-right: 0.9rem; }
.api-key-guide { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font-size: 0.82rem; }
.api-key-guide summary { cursor: pointer; padding: 0.55rem 0.8rem; font-weight: 700; color: var(--brand); list-style-position: inside; }
.api-key-guide summary:hover { color: var(--brand-strong); }
.api-key-guide[open] summary { border-bottom: 1px solid var(--border); }
.api-key-guide-body { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.7rem 0.9rem; color: var(--text-muted); }
.api-key-guide-body p { margin: 0; }
.api-key-guide-body ol { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.3rem; }
.api-key-guide-help { font-size: 0.78rem; color: var(--text-subtle); }
.api-keys-form-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }
.api-keys-guides { border-top: 1px solid var(--border); padding-top: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.api-keys-guides h3 { margin: 0; font-size: 1rem; }
.api-keys-guide-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.api-key-guide { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1rem; background: var(--surface-2); display: flex; flex-direction: column; gap: 0.75rem; }
.api-key-guide h4 { margin: 0; font-size: 0.9rem; }
.api-key-guide ol { margin: 0; padding-left: 1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.api-key-guide-help { margin: 0; color: var(--text-subtle); font-size: 0.82rem; }

/* Readme / about overlay */
.readme-modal { display: flex; flex-direction: column; gap: 1.1rem; }
.readme-header h2 { margin: 0 0 0.25rem; font-size: 1.3rem; font-weight: 800; }
.readme-header p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.readme-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.readme-tab { border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--text); padding: 0.65rem 1rem; font-family: inherit; font-weight: 700; font-size: 0.9rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; transition: all 0.18s ease; }
.readme-tab svg { width: 18px; height: 18px; flex: none; }
.readme-tab:hover, .readme-tab:focus-visible { border-color: var(--brand); color: var(--brand); outline: none; }
.readme-tab.is-active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.readme-panel { display: none; flex-direction: column; gap: 0.8rem; }
.readme-panel.is-active { display: flex; }
.readme-panel h3 { margin: 0.35rem 0 0; font-size: 1rem; }
.readme-panel p { margin: 0; color: var(--text-muted); font-size: 0.92rem; }
.readme-panel strong { color: var(--text); }
.readme-panel code { background: var(--surface-3); border-radius: var(--radius-xs); padding: 0.08rem 0.35rem; font-size: 0.85em; }
.readme-steps { margin: 0; padding-left: 1.25rem; display: flex; flex-direction: column; gap: 0.4rem; }
.readme-steps li { color: var(--text-muted); font-size: 0.92rem; }
.readme-copy-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.25rem; }
.readme-copy-hint { color: var(--text-subtle); font-size: 0.82rem; flex: 1; min-width: 200px; }
.readme-instructions { margin: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.9rem 1rem; max-height: 300px; overflow-y: auto; font-size: 0.76rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: break-word; color: var(--text-muted); }

/* ----------------------------------------------------------------------------
   16. Loading overlay (hidden by default via .hidden)
   ---------------------------------------------------------------------------- */
.analysis-loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(51, 40, 24, 0.5);
  backdrop-filter: blur(3px);
  z-index: 200;
}
.loading-spinner { width: 48px; height: 48px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.3); border-top-color: #fff; animation: spin 0.8s linear infinite; }
.loading-text { color: #fff; font-weight: 800; font-size: 1.1rem; }
.loading-progress { color: rgba(255, 255, 255, 0.85); font-size: 0.9rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Floating action button (if used) */
.fab { position: fixed; bottom: 2rem; right: 2rem; width: 60px; height: 60px; background: var(--brand); color: var(--on-brand); border: none; border-radius: 50%; box-shadow: var(--shadow-lg); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; z-index: 90; transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.3s ease; }
.fab:hover { transform: translateY(-2px) scale(1.04); background: var(--brand-strong); }
.fab.hidden { opacity: 0; pointer-events: none; transform: translateY(100px); }

/* ----------------------------------------------------------------------------
   17. Responsive
   ---------------------------------------------------------------------------- */
@media (max-width: 1279px) {
  .app-shell { flex-direction: column; gap: 1.5rem; }
  .sidebar { width: 100%; position: static; max-height: none; overflow: visible; padding-right: 0; }
  .main-column { width: 100%; }
}

@media (max-width: 1024px) {
  .control-row { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .control-placeholder { display: none; }
  /* The wrapped header gets taller than the sticky offset — let the bar flow instead */
  .run-bar { position: static; border-radius: var(--radius-lg); margin-left: 0; }
  .zone { scroll-margin-top: 90px; }
}

@media (max-width: 768px) {
  body { font-size: 14px; }
  main { padding: 1.25rem 1rem 2.5rem; }
  .header-shell { gap: 0.75rem; }
  .logo-wordmark small { display: none; }
  .control-row { grid-template-columns: 1fr; }
  .dataset-actions { grid-template-columns: 1fr; }
  .experiment-card { flex: 1 1 100%; min-width: 0; max-width: none; }
  .form-input, .form-select, .form-textarea, .text-input { font-size: 16px; } /* avoid iOS zoom */
  .footer-actions-group .add-experiment-form { margin-left: 0; }
  .analysis-downloads { flex-direction: column; align-items: stretch; }
  .download-button { width: 100%; }
}

/* ----------------------------------------------------------------------------
   18. Reduced motion
   ---------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ----------------------------------------------------------------------------
   19. Dark mode — warm charcoal, token overrides only
   ---------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --brand:          #3ec9b6;
    --brand-strong:   #5adcca;
    --brand-soft:     rgba(62, 201, 182, 0.14);
    --brand-softer:   rgba(62, 201, 182, 0.08);
    --on-brand:       #0d211d;

    --accent:         #e0a25e;
    --accent-deep:    #eebd83;
    --accent-soft:    rgba(224, 162, 94, 0.18);
    --accent-softer:  rgba(224, 162, 94, 0.10);

    --bg:             #191510;
    --surface:        #241f18;
    --surface-2:      #1e1a13;
    --surface-3:      #2e281f;
    --border:         #3a3327;
    --border-strong:  #4e4536;

    --text:           #f1ead9;
    --text-muted:     #c9c0ac;
    --text-subtle:    #9a917d;
    --placeholder:    #736b59;

    --success: #6ee7b7; --success-bg: rgba(34, 170, 108, 0.20);
    --warning: #eebd83; --warning-bg: rgba(224, 162, 94, 0.18);
    --danger:  #f0998b; --danger-bg:  rgba(216, 84, 62, 0.20);
    --info:    #8fdfd4; --info-bg:    rgba(62, 201, 182, 0.14);

    --ring: 0 0 0 3px rgba(62, 201, 182, 0.30);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 18px 42px rgba(0, 0, 0, 0.6);
  }

  body {
    background:
      radial-gradient(1100px 520px at 85% -10%, rgba(224, 162, 94, 0.07), transparent 60%),
      var(--bg);
  }
  .global-header { background: rgba(30, 26, 19, 0.88); }
  .global-header .app-tab-buttons[data-header-tabs="true"] label:hover:not(.active) { background: rgba(255, 255, 255, 0.06); }
  .btn-primary { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); }
  .btn-primary:hover:not(:disabled) { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45); }
  .logo-icon { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5); }
  .progress-wrapper { background: rgba(255, 255, 255, 0.08); }
  .modal-backdrop { background: rgba(0, 0, 0, 0.55); }
  .plot-card img { background: #fff; padding: 4px; }
}
