/* ── Analytics dashboard styles ───────────────────────────── */
/* Dark walnut/amber theme, tokens from tokens.css             */

/* ── Reset / Base ─────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
}

body.analytics-body {
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-size: var(--text-base);
  -webkit-font-smoothing: antialiased;
  /* Share UI zoom with editor */
  zoom: var(--ui-zoom, 1);
  width: calc(100vw / var(--ui-zoom, 1));
  height: calc(100vh / var(--ui-zoom, 1));
}

/* ── Layout ───────────────────────────────────────────────── */

.analytics-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */

.analytics-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-scale-select {
  display: block;
  margin-top: 8px;
  background: var(--bg-primary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
}

.sidebar-back {
  display: inline-block;
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: var(--space-2);
  transition: color var(--transition);
}

.sidebar-back:hover {
  color: var(--accent);
}

.sidebar-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-3) var(--space-2);
  gap: var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: 'Nunito', sans-serif;
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  border-left: 2px solid transparent;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-left-color: var(--accent);
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  background: var(--bg-input);
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}

.nav-badge:empty {
  display: none;
}

.nav-badge.has-warnings {
  background: var(--warning-dim);
  color: var(--warning);
}

.nav-badge.all-clear {
  background: var(--success-dim);
  color: var(--success);
}

.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* ── Main content area ────────────────────────────────────── */

.analytics-content {
  flex: 1;
  padding: var(--space-6) var(--space-6) var(--space-12);
  max-width: 1100px;
  min-width: 0;
  margin: 0 auto;
  width: 100%;
}

/* ── Empty state ──────────────────────────────────────────── */

.analytics-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12);
  gap: var(--space-4);
  color: var(--text-secondary);
}

.analytics-empty h2 {
  margin: 0;
  font-size: var(--text-xl);
  color: var(--text);
}

.analytics-empty p {
  margin: 0;
  font-size: var(--text-md);
  color: var(--text-muted);
  max-width: 360px;
}

/* ── KPI Cards ────────────────────────────────────────────── */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.kpi-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Insight Cards ────────────────────────────────────────── */

.insight-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: filter var(--transition), border-color var(--transition);
  margin-bottom: var(--space-2);
}

.insight-card:hover {
  filter: brightness(1.08);
  border-color: var(--accent);
}

.insight-icon {
  font-size: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}

.insight-content {
  flex: 1;
  min-width: 0;
}

.insight-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-1);
}

.insight-message {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}

.insight-arrow {
  font-size: var(--text-lg);
  color: var(--text-muted);
  flex-shrink: 0;
  align-self: center;
  transition: color var(--transition), transform var(--transition);
}

.insight-card:hover .insight-arrow {
  color: var(--accent);
  transform: translateX(3px);
}

.insight-empty {
  text-align: center;
  padding: var(--space-6);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.insight-show-more {
  width: 100%;
  margin-top: var(--space-2);
  text-align: center;
}

/* ── Insight Drill-Down (inline row table) ── */
.insight-card-wrapper { margin-bottom: 6px; }
.insight-drilldown {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 0;
  max-height: 300px;
  overflow-y: auto;
}
.insight-drilldown-count {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.insight-drilldown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.insight-drilldown-table th {
  padding: 4px 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-input);
}
.insight-drilldown-table td {
  padding: 4px 10px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.insight-drilldown-table tr:hover td { background: var(--bg-hover); }
.insight-hl-cell {
  color: var(--accent) !important;
  font-weight: 600;
}

/* ── Chart Grid ───────────────────────────────────────────── */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}

.chart-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-6);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chart-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chart-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text);
  margin: 0 0 var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chart-title .drill-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 400;
  margin-left: auto;
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.chart-card-header .chart-title { margin: 0; }

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
}

/* ── Empty States ─────────────────────────────────────────── */
.analytics-empty-msg,
.analytics-empty-state {
  color: var(--text-muted);
  font-style: italic;
  padding: var(--space-6);
  text-align: center;
}

/* ── Mini Charts (overview) ───────────────────────────────── */

.mini-chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.mini-chart-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}

.mini-chart-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Drill-down ───────────────────────────────────────────── */

.drill-down-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: var(--space-4);
  background: none;
  border: none;
  padding: 0;
  font-family: 'Nunito', sans-serif;
  transition: color var(--transition);
}

.drill-down-back:hover {
  color: var(--accent);
}

.drill-down-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text);
  margin: 0 0 var(--space-4);
}

.drill-down-insights {
  margin-bottom: var(--space-6);
}

.drill-down-chart {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-6);
}

.drill-down-chart canvas {
  max-height: 400px;
  width: 100%;
}

.drill-down-table {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ── Data Table ───────────────────────────────────────────── */

.data-table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table th {
  background: var(--bg-panel);
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th.sortable-th {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}

.data-table th.sortable-th:hover {
  color: var(--accent);
}

.data-table td {
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text);
  vertical-align: middle;
}

.data-table .row-highlighted {
  background: var(--warning-dim);
}

.data-table tbody tr:hover {
  background: var(--bg-elevated);
}

/* ── Mapping Dialog ───────────────────────────────────────── */

.mapping-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.mapping-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.mapping-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
}

.mapping-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-6);
}

.mapping-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.mapping-table th {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.mapping-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.mapping-col-name {
  font-weight: 600;
  color: var(--text);
}

.mapping-classified {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.mapping-role-select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-family: 'Nunito', sans-serif;
  font-size: var(--text-sm);
  cursor: pointer;
  width: 100%;
}

.mapping-role-select:focus {
  outline: none;
  border-color: var(--accent);
}

.conf-high {
  color: var(--success);
}

.conf-med {
  color: var(--accent);
}

.conf-low {
  color: var(--text-muted);
}

/* ── Extraction Section (inside mapping dialog) ──────────── */
.extraction-section {
  border-top: 1px solid var(--border);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
}

.extraction-header {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--accent);
  margin-bottom: var(--space-3);
}

.extraction-subheader {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin: var(--space-3) 0 var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.extraction-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
  cursor: pointer;
}

.extraction-item input[type="checkbox"] {
  accent-color: var(--accent);
  flex-shrink: 0;
}

.extraction-item strong {
  color: var(--text);
  min-width: 80px;
}

.extraction-freq {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.extraction-sample {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.extraction-role {
  color: var(--accent);
  font-size: var(--text-xs);
  margin-left: auto;
  flex-shrink: 0;
}

.extraction-empty {
  color: var(--text-muted);
  font-style: italic;
  padding: var(--space-3) 0;
}

/* ── Simulation ───────────────────────────────────────────── */

.sim-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}

.sim-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-6);
}

.sim-input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.sim-input-group label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 600;
}

.sim-input-group input,
.sim-input-group select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-family: 'Nunito', sans-serif;
  font-size: var(--text-base);
  width: 100%;
}

.sim-input-group input:focus,
.sim-input-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.sim-result {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Nunito', sans-serif;
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-light);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  color: #12110F;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #12110F;
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}

/* ── Analytics Toolbar ────────────────────────────────────── */

.analytics-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.analytics-toolbar .analytics-tab-bar {
  display: flex;
  gap: 2px;
}

.analytics-toolbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-bottom: var(--space-2);
}

.analytics-sensitivity-label {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.analytics-sensitivity-select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-family: 'Nunito', sans-serif;
  font-size: var(--text-xs);
  cursor: pointer;
}

/* ── Balance OK (empty state for no-issue sections) ──────── */

.balance-ok {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-3) 0;
  background: var(--success-dim);
  border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.balance-ok-icon {
  color: var(--success);
  font-size: var(--text-md);
  flex-shrink: 0;
}

/* ── Overview Synthesis ──────────────────────────────────── */

.overview-synthesis {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.overview-synthesis strong {
  color: var(--text);
}

/* ── Mapping Weight Input ────────────────────────────────── */

.mapping-weight-cell {
  width: 70px;
}

.mapping-weight-input {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-family: 'Nunito', sans-serif;
  font-size: var(--text-sm);
  width: 60px;
  text-align: center;
}

.mapping-weight-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Simulation Presets ──────────────────────────────────── */

.sim-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.sim-preset-btn {
  font-size: var(--text-xs) !important;
  padding: 2px 8px !important;
}

/* ── Heatmap ──────────────────────────────────────────────── */

.heatmap-container {
  overflow-x: auto;
}

.heatmap-container svg {
  display: block;
}

/* ── Heatmap Tooltip ─────────────────────────────────────── */

.heatmap-tooltip {
  display: none;
  position: absolute;
  pointer-events: none;
  z-index: 10;
  background: var(--bg-panel, #1e1c18);
  color: var(--text, #fff);
  border: 1px solid var(--border, #3a3630);
  border-radius: var(--radius-sm, 4px);
  padding: 4px 8px;
  font-size: 12px;
  font-family: 'Nunito', sans-serif;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 900px) {
  body.analytics-body {
    flex-direction: column;
  }

  .analytics-sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    padding: 0 var(--space-3);
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .sidebar-brand {
    display: none;
  }

  .sidebar-nav {
    flex: 1;
    flex-direction: row;
    padding: 0;
    gap: 0;
    overflow-x: auto;
  }

  .nav-item {
    flex-shrink: 0;
    padding: var(--space-3) var(--space-3);
    border-left: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
  }

  .nav-item.active {
    background: transparent;
    border-bottom-color: var(--accent);
    color: var(--accent);
  }

  .sidebar-footer {
    display: none;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .sim-controls {
    grid-template-columns: 1fr;
  }

  .analytics-content {
    padding: var(--space-4);
    max-width: 100%;
  }
}

/* ═══════════════════════════════════════════════════════════════ */
/* BALANCE LAB v2 — New styles                                    */
/* ═══════════════════════════════════════════════════════════════ */

/* ── Grade Colors ─────────────────────────────────────────────── */
:root, [data-theme="dark"] {
  --grade-a: #34d68a;
  --grade-b: #6cabf7;
  --grade-c: #f5a623;
  --grade-d: #f0935a;
  --grade-f: #f0465a;
}

/* ── Topbar ───────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  position: sticky; top: 0; z-index: 100;
}
.topbar-brand {
  display: flex; align-items: center; gap: var(--space-2);
  text-decoration: none; color: var(--text-muted);
  font-size: var(--text-sm); font-weight: 600; flex-shrink: 0;
  transition: color var(--transition);
}
.topbar-brand:hover { color: var(--accent); }
.topbar-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }
.topbar-title {
  font-size: var(--text-lg); font-weight: 800; color: var(--text);
  letter-spacing: -0.01em;
}
.topbar-tabs {
  display: flex; gap: 2px; margin-left: var(--space-6);
  background: var(--bg-input); border-radius: var(--radius-sm); padding: 2px;
}
.topbar-tab {
  padding: var(--space-1) var(--space-4);
  background: transparent; border: none; border-radius: var(--radius-xs);
  color: var(--text-muted); font-family: 'Nunito', sans-serif;
  font-size: var(--text-sm); font-weight: 600; cursor: pointer;
  transition: all var(--transition); white-space: nowrap;
}
.topbar-tab:hover { color: var(--text); background: var(--bg-hover); }
.topbar-tab.active {
  color: var(--bg-primary); background: var(--accent); font-weight: 700;
}
.topbar-actions {
  margin-left: auto; display: flex; align-items: center; gap: var(--space-3);
}

/* ── Mapping Confirmation Bar ────────────────────────────────── */
.mapping-bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-6);
  background: var(--accent-dim);
  border-bottom: 1px solid rgba(232,145,58,0.15);
  font-size: var(--text-sm);
  animation: bar-slide-down 0.3s ease-out;
  flex-wrap: wrap;
}
@keyframes bar-slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.mapping-bar-text { color: var(--text-secondary); white-space: nowrap; }
.mapping-bar-pills { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.mapping-pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 8px; border-radius: var(--radius-pill);
  background: var(--bg-elevated); border: 1px solid var(--border);
  font-size: var(--text-xs); color: var(--text-secondary); font-weight: 600;
  white-space: nowrap;
}
.mapping-pill-role { color: var(--accent); }
.mapping-bar-actions { margin-left: auto; display: flex; gap: var(--space-2); }
.mapping-bar-btn {
  padding: 2px 12px; border-radius: var(--radius-sm);
  font-family: 'Nunito', sans-serif; font-size: var(--text-xs); font-weight: 700;
  cursor: pointer; transition: all var(--transition); border: 1px solid transparent;
}
.mapping-bar-btn.confirm { background: var(--accent); color: var(--bg-primary); border-color: var(--accent); }
.mapping-bar-btn.confirm:hover { background: var(--accent-hover); }
.mapping-bar-btn.adjust { background: transparent; color: var(--text-muted); border-color: var(--border); }
.mapping-bar-btn.adjust:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Grade Hero ──────────────────────────────────────────────── */
.grade-hero {
  display: grid; grid-template-columns: auto 1fr; gap: var(--space-8);
  align-items: center; padding: var(--space-6);
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: var(--space-6);
  position: relative; overflow: hidden;
}
.grade-hero::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 15% 50%, var(--accent-dim) 0%, transparent 60%);
  pointer-events: none;
}
.grade-gauge { position: relative; flex-shrink: 0; }
.grade-gauge svg { display: block; }
.grade-letter { font-family: 'Nunito', sans-serif; }
.grade-score {
  text-align: center; margin-top: var(--space-1);
  font-size: var(--text-xs); color: var(--text-muted); font-weight: 500;
}
.grade-detail { position: relative; z-index: 1; }
.grade-headline {
  font-size: 20px; font-weight: 800; color: var(--text);
  margin: 0 0 var(--space-2); line-height: 1.2;
}
.grade-summary {
  font-size: var(--text-md); color: var(--text-secondary);
  margin: 0 0 var(--space-4); line-height: 1.6;
}
.grade-breakdown { display: flex; gap: var(--space-6); flex-wrap: wrap; }
.grade-factor { display: flex; flex-direction: column; gap: 2px; }
.grade-factor-label {
  font-size: var(--text-xs); color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.grade-factor-value { font-size: var(--text-md); font-weight: 700; }
.grade-factor-bar {
  width: 80px; height: 4px; border-radius: 2px;
  background: var(--border); overflow: hidden; margin-top: 2px;
}
.grade-factor-bar-fill { height: 100%; border-radius: 2px; transition: width 0.8s ease-out; }

/* ── Findings ────────────────────────────────────────────────── */
.findings { margin-bottom: var(--space-6); }
.findings-header {
  display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3);
}
.findings-title { font-size: var(--text-md); font-weight: 700; color: var(--text); margin: 0; }
.findings-count {
  font-size: var(--text-xs); font-weight: 700; color: var(--bg-primary);
  background: var(--danger); border-radius: var(--radius-pill);
  padding: 0 8px; line-height: 18px;
}
.finding-card {
  display: grid; grid-template-columns: 28px 1fr auto;
  gap: var(--space-3); align-items: start;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: var(--space-2);
  cursor: pointer; transition: all var(--transition);
}
.finding-card:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.finding-card.severity-warning { border-left: 3px solid var(--warning); }
.finding-card.severity-critical { border-left: 3px solid var(--danger); }
.finding-card.severity-suggestion { border-left: 3px solid #6cabf7; }
.finding-icon {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0; margin-top: 1px;
}
.finding-icon.warning { background: var(--warning-dim); color: var(--warning); }
.finding-icon.critical { background: var(--danger-dim); color: var(--danger); }
.finding-icon.suggestion { background: rgba(108,171,247,0.12); color: #6cabf7; }
.finding-body { min-width: 0; }
.finding-title { font-size: var(--text-md); font-weight: 700; color: var(--text); }
.finding-desc { font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.5; margin-top: 2px; }
.finding-action { font-size: var(--text-xs); color: var(--accent); font-weight: 700; margin-top: var(--space-1); display: inline-block; }
.finding-badge {
  align-self: center; font-size: var(--text-xs); font-weight: 600;
  color: var(--text-muted); background: var(--bg-elevated);
  padding: 2px 8px; border-radius: var(--radius-pill); white-space: nowrap;
}

/* ── Snapshot Row ────────────────────────────────────────────── */
.snapshot-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.snapshot-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-4);
}
.snapshot-card-title {
  font-size: var(--text-xs); font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: var(--space-2);
}
.snapshot-stats {
  font-size: var(--text-sm); color: var(--text-secondary); margin-bottom: var(--space-2);
}

/* ── Accordion Sections (Deep Dive) ──────────────────────────── */
.section {
  margin-bottom: var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; transition: border-color var(--transition);
}
.section:hover { border-color: var(--border-light); }
.section.has-warnings { border-left: 3px solid var(--warning); }
.section.all-clear { border-left: 3px solid var(--success); }

.section-header {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4); cursor: pointer; user-select: none;
  background: var(--bg-secondary); transition: background var(--transition);
}
.section-header:hover { background: var(--bg-card-hover); }
.section-number {
  font-size: var(--text-xs); font-weight: 600;
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.section.has-warnings .section-number { color: var(--warning); background: var(--warning-dim); }
.section.all-clear .section-number { color: var(--success); background: var(--success-dim); }
.section-title { font-size: var(--text-md); font-weight: 800; color: var(--text); margin: 0; }
.section-status {
  font-size: var(--text-xs); font-weight: 600;
  color: var(--text-muted); margin-left: auto; flex-shrink: 0;
}
.section-chevron {
  font-size: 12px; color: var(--text-muted);
  transition: transform 0.25s ease; flex-shrink: 0;
}
.section.open .section-chevron { transform: rotate(90deg); }

.section-body {
  display: none; padding: 0 var(--space-4) var(--space-4);
  background: var(--bg-secondary);
}
.section.open .section-body { display: block; }

.section-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4);
}

/* ── Strictly Better Pairs ───────────────────────────────────── */
.sb-pair {
  display: grid; grid-template-columns: 1fr 40px 1fr;
  gap: var(--space-2); align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--danger-dim);
  border: 1px solid rgba(240,70,90,0.2);
  border-radius: var(--radius); margin-bottom: var(--space-2);
}
.sb-card { text-align: center; }
.sb-card-name { font-size: var(--text-md); font-weight: 700; color: var(--text); }
.sb-card-stats { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.sb-arrow { text-align: center; font-size: 16px; color: var(--danger); font-weight: 700; }
.sb-card.winner .sb-card-name { color: var(--danger); }
.sb-card.loser .sb-card-name { color: var(--text-muted); text-decoration: line-through; opacity: 0.7; }

/* ── Design Space Coverage Grid ──────────────────────────────── */
.ds-grid { display: grid; gap: 3px; }
.ds-cell {
  aspect-ratio: 1; border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: 700;
  transition: all var(--transition); cursor: default; position: relative;
}
.ds-cell:hover { transform: scale(1.1); z-index: 1; }
.ds-cell.empty { background: var(--bg-input); color: var(--text-dim); }
.ds-cell.sparse { background: rgba(232,145,58,0.15); color: var(--accent); }
.ds-cell.filled { background: rgba(52,214,138,0.2); color: var(--success); }
.ds-cell.crowded { background: rgba(108,171,247,0.2); color: #6cabf7; }
.ds-label-row {
  font-size: var(--text-xs); color: var(--text-muted); font-weight: 600;
  display: flex; align-items: center; padding-left: 2px;
}
.ds-label-col { font-size: var(--text-xs); color: var(--text-muted); font-weight: 600; text-align: center; }

/* ── Remaining Insights Toggle ───────────────────────────────── */
.remaining-toggle {
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-2); width: 100%;
  padding: var(--space-2) var(--space-4);
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted);
  font-family: 'Nunito', sans-serif; font-size: var(--text-sm);
  font-weight: 600; cursor: pointer;
  transition: all var(--transition); margin-bottom: var(--space-6);
}
.remaining-toggle:hover { border-color: var(--accent); color: var(--text); }

/* ── Simulation Context Banner ───────────────────────────────── */
.sim-context-banner {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--accent-dim);
  border: 1px solid rgba(232,145,58,0.15);
  border-radius: var(--radius);
  margin-bottom: var(--space-6);
  font-size: var(--text-sm); color: var(--text-secondary);
}
.sim-context-banner strong { color: var(--text); }

/* ── Responsive (v2 overrides) ───────────────────────────────── */
@media (max-width: 700px) {
  .grade-hero { grid-template-columns: 1fr; text-align: center; }
  .grade-breakdown { justify-content: center; }
  .snapshot-row { grid-template-columns: 1fr; }
  .section-grid { grid-template-columns: 1fr; }
  .section-title { font-size: var(--text-sm); }
  .topbar-tabs { display: none; }
}
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; padding: var(--space-2) var(--space-4); }
}
