/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f5f7fa;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #1a202c;
  --text-muted:#718096;
  --primary:   #3b82f6;
  --primary-hover: #2563eb;
  --danger:    #ef4444;
  --danger-hover: #dc2626;
  --warning:   #f59e0b;
  --warning-hover: #d97706;
  --success:   #10b981;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ── Dark mode overrides ─────────────────────────────────── */
:root.dark {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --border:    #334155;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --shadow:    0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.2);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Navbar ──────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand a {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.navbar-menu {
  display: flex;
  gap: 8px;
}

.navbar-item {
  padding: 6px 14px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.navbar-item:hover {
  background: var(--bg);
  color: var(--text);
}

/* ── Content ─────────────────────────────────────────────── */
.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
  overflow-x: hidden;
}

/* ── Buttons ─────────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.4;
}

button:hover, .btn:hover {
  background: var(--bg);
  border-color: var(--border-strong);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary, button.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover, button.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-danger, button.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn-danger:hover, button.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn-warning, button.btn-warning {
  background: var(--warning);
  color: white;
  border-color: var(--warning);
}
.btn-warning:hover, button.btn-warning:hover {
  background: var(--warning-hover);
  border-color: var(--warning-hover);
}

.btn-google {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  padding: 10px 24px;
  font-size: 1rem;
}
.btn-google:hover {
  background: var(--bg);
  box-shadow: var(--shadow-md);
}

/* ── Tables ──────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 12px;
}

thead {
  background: var(--surface-2);
}

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

td {
  padding: 10px 16px;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--surface-2); }

td a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
td a:hover { text-decoration: underline; }

.alarm-row td {
  background: var(--danger-wash) !important;
}

/* ── State badges ────────────────────────────────────────── */
.state-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.state-draft       { background: var(--surface-3); color: var(--text-secondary); }
.state-scheduled   { background: var(--accent-wash); color: var(--accent); }
.state-collecting  { background: var(--accent-wash); color: var(--accent); }
.state-alarmed     { background: var(--danger-wash); color: var(--danger); }
.state-analyzing   { background: var(--warn-wash); color: var(--warn); }
.state-decided     { background: var(--accent-wash); color: var(--accent); }
.state-cancelled   { background: var(--surface-3); color: var(--text-muted); }
.state-default     { background: var(--surface-3); color: var(--text-secondary); }

/* ── Dashboard ───────────────────────────────────────────── */
.dashboard h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.dashboard > a.btn {
  margin-bottom: 20px;
}

.dashboard > p {
  color: var(--text-muted);
  padding: 40px 0;
  text-align: center;
}

/* ── Test detail ─────────────────────────────────────────── */
.test-detail h1 {
  font-size: 1.5rem;
  font-weight: 700;
  display: inline;
  margin-right: 12px;
}

.test-detail > .state-badge {
  vertical-align: middle;
}

.test-detail h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.config-section,
.groups-section,
.decisions-section,
.monitoring-section {
  background: var(--surface);
  padding: 20px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
}

.config-section dl {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 6px 16px;
}

.config-section dt {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.config-section dd {
  font-size: 0.9rem;
}

/* ── Actions ─────────────────────────────────────────────── */
.actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.cancel-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.cancel-form input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  min-width: 250px;
}

/* ── Forms / Wizard ──────────────────────────────────────── */
.new-test-wizard {
  max-width: 640px;
  margin: 0 auto;
}

.new-test-wizard h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.step-indicator {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.step {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--border);
  color: var(--text-muted);
  transition: all 0.2s;
}

.step.active {
  background: var(--primary);
  color: white;
}

.wizard-step {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.wizard-step h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.button-group {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-preview {
  margin-top: 8px;
  margin-bottom: 12px;
}

.preview-table {
  margin-top: 12px;
  font-size: 0.85rem;
}

.preview-table th {
  font-size: 0.7rem;
  padding: 8px 12px;
}

.preview-table td {
  padding: 8px 12px;
  font-variant-numeric: tabular-nums;
}

.preview-diff {
  margin-top: 10px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

#preview_container .loading {
  padding: 16px 0;
}

#preview_container .error {
  margin-top: 8px;
}

#preview_container .info {
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.preview-power {
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--accent-wash);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
}

.preview-power h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent);
}

.preview-power dl {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 4px 12px;
  font-size: 0.85rem;
}

.preview-power dt {
  font-weight: 600;
  color: var(--text-muted);
}

.preview-power dd {
  color: var(--text);
}

.summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 16px 0;
}

.summary h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.summary p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 2px 0;
}

.info {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ── Login ───────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.login-card {
  background: var(--surface);
  padding: 40px 48px;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  text-align: center;
  max-width: 400px;
}

.login-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.login-card a.btn {
  display: block;
  margin-bottom: 16px;
}

.login-hint {
  font-size: 0.75rem !important;
  color: var(--text-muted) !important;
}

/* ── Checkbox / form-row helpers ─────────────────────────── */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 6px 0;
}

.checkbox-group .checkbox-label,
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.checkbox-group input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.form-row label {
  display: inline;
  margin-bottom: 0;
  white-space: nowrap;
}

.form-row select,
.form-row input {
  width: auto;
  flex: 1;
  min-width: 100px;
}

.form-help {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.alarm-kpis-section {
  background: var(--surface);
  padding: 20px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
}

/* ── Histogram ───────────────────────────────────────────── */
.histogram-container { margin-top: 20px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.histogram-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 12px; }
.histogram-container svg { display: block; max-width: 100%; height: auto; }

/* ── Observed cumulative curve ───────────────────────────── */
.cumulative-curve-container { margin-top: 1rem; padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.cumulative-curve-container .cumulative-curve-container { margin-top: 0; padding: 0; border: none; }
.cumulative-curve-container .chart-title { font-size: 0.9rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 0.5rem; }
.cumulative-curve-container svg { display: block; max-width: 100%; height: auto; }
.cumulative-legend { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; font-size: 0.8rem; color: var(--text-secondary); }
.cumulative-legend-item { padding-left: 0.5rem; }
.cumulative-legend-item strong { color: var(--text); }

/* ── Error / Loading ─────────────────────────────────────── */
.error {
  background: var(--danger-wash);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin: 12px 0;
}

.loading {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

/* ── Confirm Dialog ──────────────────────────────────────── */
.confirm-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-md);
  margin-top: 12px;
}

.confirm-dialog h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.confirm-dialog input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 12px;
}

/* ── Help Button ────────────────────────────────────────── */
.help-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
}
.help-btn:hover {
  background: var(--primary-hover);
}

/* ── Help Modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover {
  color: var(--text);
  background: none;
}
.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.7;
}
.modal-body h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 16px;
  margin-bottom: 4px;
}
.modal-body h3:first-child {
  margin-top: 0;
}
.modal-body ul {
  padding-left: 20px;
  margin: 4px 0 8px;
}
.modal-body li {
  margin-bottom: 4px;
}

/* ── Conclusion section (test detail) ────────────────────── */
.conclusion-section {
  background: var(--surface);
  padding: 16px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
}
.conclusion-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.conclusion-decided { border-left: 4px solid var(--primary); }
.conclusion-decided h2 { color: var(--accent); }
.conclusion-collecting-section { border-left: 4px solid var(--primary); }
.conclusion-collecting-section h2 { color: var(--primary); }
.conclusion-alarmed-section { border-left: 4px solid var(--danger); }
.conclusion-alarmed-section h2 { color: var(--danger); }
.conclusion-cancelled-section { border-left: 4px solid var(--border-strong); }
.conclusion-cancelled-section h2 { color: var(--text-muted); }

.progress-info {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.progress-bar-track {
  height: 14px;
  background: var(--surface-3);
  border-radius: 7px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 7px;
  transition: width 0.3s;
  min-width: 0;
}

.power-progress-detail {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: monospace;
}

/* ── Conclusion column (dashboard) ──────────────────────── */
.conclusion-cell { min-width: 120px; }
.conclusion-draft      { color: var(--text-muted); }
.conclusion-cancelled  { color: var(--text-muted); }
.conclusion-decided    { color: var(--accent); font-weight: 600; }
/* Multi-arm: one verdict chip per decision pair in the list's conclusion cell. */
.conclusion-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.conclusion-chip {
    display: inline-block; padding: 1px 6px; border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); background: var(--accent-wash); font-size: 0.85em; white-space: nowrap;
}

/* Per-KPI evidence: a compact bar in the collapsed summary line, so the
   secondary section can be scanned for KPIs close to resolving without
   expanding each card. Fixed 0–100 like the dashboard sparkline. */
.kpi-evidence { display: inline-flex; align-items: center; gap: 4px; cursor: help; }
.kpi-evidence-track {
  display: inline-block;
  width: 44px;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.kpi-evidence-fill { display: block; height: 100%; background: var(--primary); }
.kpi-evidence-pct { font-size: 0.72rem; color: var(--text-muted); min-width: 2.2em; }

/* Evidence sparkline: y-axis fixed 0–100, so rows are comparable. Drawn with
   vector-effect so the stroke keeps its width despite the viewBox scaling. */
.evidence-spark { display: block; margin-top: 2px; overflow: visible; }
.evidence-spark-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 1.25;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.evidence-spark-max { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 2 2; }

/* "Last refresh" column: a stale date and behind/missing KPIs are both refresh
   failures, so they share one warning style; an idle state's date is history. */
.refresh-cell { white-space: nowrap; font-size: 0.8rem; }
.refresh-ok { color: var(--text-muted); }
.refresh-idle { color: var(--text-muted); opacity: 0.7; }
.refresh-none { color: var(--text-muted); opacity: 0.6; }
.refresh-warn { color: var(--worse-3); font-weight: 600; cursor: help; }

.mini-progress { display: flex; flex-direction: column; gap: 3px; }
.mini-progress-label { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.mini-progress-track { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; min-width: 80px; }
.mini-progress-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.3s; }
.mini-progress-alarmed { background: var(--danger); }

/* ── KPI List (compact expandable) ──────────────────────── */
.kpi-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
}

.kpi-list-item {
  background: var(--surface);
  border-radius: var(--radius);
  border-left: 4px solid var(--border);
  overflow: hidden;
}

.kpi-list-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  user-select: none;
}

.kpi-list-summary:hover { background: var(--surface-2); }

.kpi-list-name {
  font-weight: 600;
  min-width: 0;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-dx-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  margin-left: 6px;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-secondary);
  vertical-align: middle;
}

.kpi-list-metrics {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

.kpi-list-change { font-weight: 600; }
.kpi-list-samples { color: var(--text-muted); }

.kpi-card-badge {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text-secondary);
}

.kpi-badge-target { background: var(--accent-wash); color: var(--accent); }
.kpi-badge-secondary { background: var(--surface-3); color: var(--text-secondary); }

.kpi-list-detail {
  border-top: 1px solid var(--border);
}

.kpi-card-body {
  padding: 12px 16px;
}

.kpi-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 0.85rem;
}

.kpi-stat-label {
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-stat-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.sig-yes { color: var(--accent); }
.sig-no  { color: var(--text-muted); }

/* Winner color coding: blue = variant (B) wins, orange = control (A) wins
   Colorblind-safe (deuteranopia): avoids red/green distinction. */
.kpi-list-item.winner-b-nosig { background: color-mix(in srgb, var(--better-wash) 50%, transparent); border-left-color: var(--better-1); }
.kpi-list-item.winner-b-sig   { background: var(--better-wash); border-left-color: var(--better-3); }
.kpi-list-item.winner-a-nosig { background: color-mix(in srgb, var(--worse-wash) 50%, transparent); border-left-color: var(--worse-1); }
.kpi-list-item.winner-a-sig   { background: var(--worse-wash); border-left-color: var(--worse-3); }

tr.winner-b-nosig { background: color-mix(in srgb, var(--better-wash) 50%, transparent); }
tr.winner-b-sig   { background: var(--better-wash); }
tr.winner-a-nosig { background: color-mix(in srgb, var(--worse-wash) 50%, transparent); }
tr.winner-a-sig   { background: var(--worse-wash); }
.kpi-list-item.winner-neutral { background: var(--surface-2); border-left-color: var(--flat-2); }
tr.winner-neutral { background: var(--surface-2); }

/* Inline group-name highlights (control = orange, variant = blue) */
.group-a-highlight { color: var(--worse-3); font-weight: 600; }
.group-b-highlight { color: var(--better-3); font-weight: 600; }

.secondary-kpis-collapsible {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.secondary-kpis-toggle {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.95em;
  color: var(--text-secondary);
  user-select: none;
}
.secondary-kpis-toggle:hover {
  color: var(--text);
}
.secondary-kpis-content {
  padding: 0 8px 8px;
}

.kpi-history-section {
  border-top: 1px solid var(--border);
  overflow-x: auto;
}

.kpi-history-heading {
  padding: 8px 16px;
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-history-table {
  margin-top: 0;
  box-shadow: none;
  border-radius: 0;
  font-size: 0.8rem;
}

.kpi-history-table th {
  font-size: 0.65rem;
  padding: 6px 10px;
}

.kpi-history-table td {
  padding: 6px 10px;
  font-size: 0.8rem;
}

/* ── Secondary KPIs config section ──────────────────────── */
.secondary-kpis-config-section {
  background: var(--surface);
  padding: 20px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
}

/* ── Secondary KPI form rows ───────────────────────────── */
.secondary-kpi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.secondary-kpi-row select {
  min-width: 80px;
  flex: 1 1 0;
}

/* ── Table overflow ────────────────────────────────────── */
.secondary-kpis-config-section,
.config-section,
.groups-section,
.decisions-section,
.monitoring-section,
.alarm-kpis-section {
  overflow-x: auto;
}

/* ── Dark mode toggle button ───────────────────────────── */
.dark-mode-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dark-mode-btn:hover {
  background: var(--bg);
  border-color: var(--border-strong);
}

/* ── Exclusion Stats Section ────────────────────────────── */
.exclusion-summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  max-width: 400px;
  margin-bottom: 10px;
}

.exclusion-group-header {
  font-weight: 600;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 2px solid var(--border);
}

.exclusion-summary-card .kpi-stat-row:not(:last-child) {
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 4px;
}

#excluded_users_container {
  margin-top: 12px;
}

#excluded_users_container .preview-table {
  font-size: 0.85rem;
}

#load_more_excluded_btn {
  margin-top: 8px;
}

/* ── Simple Mode Toggle ──────────────────────────────── */
.mode-toggle {
  display: flex;
  margin-bottom: 20px;
}

.mode-toggle-btn {
  border-radius: 0;
}

.mode-toggle-btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.mode-toggle-btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ── Simple Mode Power Panel ─────────────────────────── */
#simple_power_panel {
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--accent-wash);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
}

#simple_power_panel dl {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 4px 12px;
  font-size: 0.85rem;
}

#simple_power_panel dt {
  font-weight: 600;
  color: var(--text-muted);
}

#simple_power_panel dd {
  color: var(--text);
}

#simple_revenue_error {
  margin-bottom: 12px;
}

/* ── Full-screen loading spinner overlay ─────────── */
.spinner-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: rgba(0,0,0,.45);
}

.spinner-ring {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.spinner-text {
  margin-top: 14px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
}

/* ── Bayesian Interpretation Panel ──────────────────── */
.bayesian-panel {
  margin: 12px 0;
  padding: 12px 16px;
  border-left: 4px solid var(--accent);
  background: var(--accent-wash);
  border-radius: 4px;
}
.bayesian-panel h4 { margin: 0 0 8px; font-size: 0.95rem; }
.bayesian-panel ul { margin: 0; padding-left: 20px; }
.bayesian-panel li { margin: 4px 0; line-height: 1.5; font-size: 0.85rem; }
.bayesian-panel .bayesian-note {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}
.bayesian-panel .btn-sm {
  margin-top: 8px;
  font-size: 0.82rem;
  padding: 4px 10px;
}
.mcmc-comparison {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--accent-wash);
  border-radius: 4px;
}
.mcmc-comparison h5 { margin: 0 0 6px; font-size: 0.85rem; }
.mcmc-progress { margin-top: 8px; }

.power-summary {
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--accent-wash);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text);
}

/* ── Summary Panel (test detail page) ──────────────────── */
.summary-panel {
  padding: 14px 24px;
  border-radius: var(--radius);
  margin-top: 16px;
  border-left: 4px solid var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.summary-text {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text);
}

/* ── Foldable secondary KPI highlights ─────────────────── */
.secondary-summary-fold {
  margin-top: 10px;
}
.secondary-summary-toggle {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.secondary-summary-toggle:hover {
  color: var(--text);
}
.secondary-summary-list {
  margin: 6px 0 0;
  padding-left: 20px;
  font-size: 0.85rem;
  line-height: 1.5;
}
.secondary-summary-list li {
  margin: 3px 0;
}

/* ── Sort controls for secondary KPI lists ─────────────── */
.sortable-sort-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 4px;
}
.sort-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}
.sort-btn {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 500;
}
.sort-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
.sort-btn-active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.sort-btn-active:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: white;
}
.sortable-kpi-item {
  display: contents;
}

/* ── Significance split sections ───────────────────────── */
.sig-section {
  margin-top: 6px;
}
.sig-section-heading {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 4px;
  padding: 0;
  border: none;
}
.sig-section-significant .sig-section-heading {
  color: var(--accent);
}
.sig-section-toggle {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 0;
}
.sig-section-toggle:hover {
  color: var(--text);
}
.sig-section-nonsignificant {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
}

/* ── Dashboard summary tooltip ─────────────────────────── */
.summary-cell {
  width: 40px;
  text-align: center;
}
.summary-tooltip-btn {
  position: relative;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
}
.summary-tooltip-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.summary-tooltip-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  width: 320px;
  padding: 12px 16px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 400;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  white-space: normal;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}
.summary-tooltip-btn:hover::after,
.summary-tooltip-btn:focus::after {
  opacity: 1;
  visibility: visible;
}

/* Families on the dashboard: a header row led by the primary segment, children
   indented and collapsible; the family page reuses the table flat. */
.family-row td:first-child { font-weight: 600; }
.family-toggle {
    border: none; background: none; cursor: pointer; font-size: 0.95em;
    padding: 0 4px 0 0; color: var(--primary);
}
.family-name { font-weight: 600; }
.family-count { color: var(--text-muted); font-weight: 400; font-size: 0.9em; }
.family-child td:first-child { padding-left: 1.6em; }
.family-child-hidden { display: none; }
.family-indent { color: var(--text-muted); }
.segment-label {
    display: inline-block; padding: 0 6px; border-radius: 10px; font-size: 0.85em;
    background: var(--surface-3); border: 1px solid var(--border); color: var(--text-secondary);
}
.family-crumb { color: var(--text-muted); margin: 0 0 6px 0; }
.family-siblings a { margin: 0 2px; }

/* Family wizard */
.segment-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 10px 0; background: var(--surface-2); }
.segment-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.segment-head .seg-label { flex: 1; min-width: 12em; }
.segment-num { color: var(--text-muted); font-size: 0.85em; }
.seg-group-row { display: flex; gap: 6px; align-items: center; margin: 4px 0; flex-wrap: wrap; }
.seg-group-role { width: 5em; color: var(--text-muted); font-size: 0.9em; }
.seg-group-filter { max-width: 20em; margin-bottom: 4px; }
.checkbox-group.compact { max-height: 9em; overflow: auto; padding: 4px 6px; }
/* Alias pickers (advanced form + family wizard): a collapsed list of the
   game's values, sitting under its group row. */
.alias-picker { margin: 2px 0 4px; }
.alias-picker summary { cursor: pointer; font-size: 0.9em; color: var(--text-muted); }
.seg-group-row .alias-picker, .extra-group-row .alias-picker { flex-basis: 100%; }
.extra-group-row .alias-picker { margin-left: 0.5em; }
.family-edit { margin-top: 1.5em; }
