/* ==========================================================================
   Global Macro & Cross-Asset Strategic Terminal — Component Language
   Direct Task Hierarchy · Statistical Distribution Primitives · Calendar Grid
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Optical Inline SVG Icon System (20x20 Coordinate Space)
   -------------------------------------------------------------------------- */
.icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  vertical-align: -0.18em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm {
  width: 14px;
  height: 14px;
}

.icon-lg {
  width: 18px;
  height: 18px;
}

.theme-icon-moon {
  display: none;
}

:root[data-theme="light"] .theme-icon-sun {
  display: none;
}

:root[data-theme="light"] .theme-icon-moon {
  display: inline-block;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   2. Topbar Controls (#as-of-badge, Search, Unit Mode, View Nav, Toggles)
   -------------------------------------------------------------------------- */
#as-of-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  background-color: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  max-width: 100%;
}

#as-of-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--status-good);
  flex-shrink: 0;
}

#as-of-badge[data-status="warning"] .status-indicator {
  background-color: var(--status-warn);
}

#as-of-badge[data-status="error"] .status-indicator {
  background-color: var(--status-critical);
}

.global-search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 210px;
  max-width: 290px;
  flex: 1 1 210px;
}

.global-search-wrap .search-icon {
  position: absolute;
  left: 9px;
  color: var(--text-muted);
  pointer-events: none;
}

#global-search-input {
  width: 100%;
  height: 31px;
  padding: 0 32px 0 30px;
  background-color: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}

#global-search-input::placeholder {
  color: var(--text-muted);
}

#global-search-input:focus {
  background-color: var(--surface-2);
  border-color: var(--accent-primary);
  outline: none;
}

.search-shortcut-kbd {
  position: absolute;
  right: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background-color: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-muted);
  pointer-events: none;
}

#global-search-input:focus + .search-shortcut-kbd,
.global-search-wrap.has-value .search-shortcut-kbd {
  display: none;
}

/* Segmented Control Group (#unit-mode-group & Chart Mode Switchers) */
.segmented-group {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  background-color: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  gap: 2px;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}

.segmented-group::-webkit-scrollbar {
  display: none;
}

.seg-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 25px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}

.seg-btn:hover {
  color: var(--text-primary);
  background-color: var(--surface-hover);
}

.seg-btn.is-active,
.seg-btn.active,
.seg-btn[aria-pressed="true"],
.seg-btn[aria-selected="true"] {
  background-color: var(--surface-3);
  color: var(--text-primary);
  border-color: var(--accent-border);
  font-weight: 600;
}

.terminal-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 31px;
  padding: 0 10px;
  background-color: var(--surface-1);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

.portal-back-link {
  height: 28px;
  padding: 0 9px;
  font-weight: 600;
}

.terminal-btn:hover {
  background-color: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.terminal-btn.is-active,
.terminal-btn.active,
.terminal-btn[aria-pressed="true"] {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border-color: var(--accent-border);
  font-weight: 600;
}

/* View Navigation Bar (#view-nav) */
#view-nav {
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

#view-nav::-webkit-scrollbar {
  display: none;
}

.view-nav-btn {
  appearance: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}

.view-nav-btn:hover {
  color: var(--text-primary);
  background-color: var(--surface-hover);
}

.view-nav-btn.is-active,
.view-nav-btn.active,
.view-nav-btn[aria-current="page"],
.view-nav-btn[aria-selected="true"] {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom-color: var(--accent-primary);
}

.topbar-benchmark-readout {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-2xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .topbar-benchmark-readout {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   3. Panel Cards, Chart Stages, Legends & Statistical Summary Strips
   -------------------------------------------------------------------------- */
.panel-card {
  display: flex;
  flex-direction: column;
  background-color: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border-hairline);
  background-color: var(--surface-1);
}

/* Direct Content Title */
.panel-title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: var(--leading-snug);
  color: var(--text-primary);
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-2xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chart-host {
  position: relative;
  padding: 10px 12px 12px;
  width: 100%;
  min-width: 0;
  min-height: 280px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chart-host-compact {
  min-height: 240px;
}

.chart-host-tall {
  min-height: 340px;
}

.chart-host-xl {
  min-height: 390px;
}

.chart-visual {
  position: relative;
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chart-visual svg,
.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Statistical Aggregation Header Strip Inside Charts (Median / IQR / Win-Rate) */
.stat-summary-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: 5px 9px;
  background-color: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
  font-size: var(--text-2xs);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.stat-summary-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-kv {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.stat-kv strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Chart Toolbar & Legend */
.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 5px 12px;
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.legend-item {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  cursor: pointer;
}

.legend-item:hover {
  color: var(--text-primary);
  background-color: var(--surface-hover);
}

.legend-item.is-muted,
.legend-item[aria-pressed="false"] {
  opacity: 0.36;
}

.legend-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-circle {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-line {
  display: inline-block;
  width: 14px;
  height: 2.5px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Series Color Utility Classes */
.swatch-s1 { background-color: var(--series-1); }
.swatch-s2 { background-color: var(--series-2); }
.swatch-s3 { background-color: var(--series-3); }
.swatch-s4 { background-color: var(--series-4); }
.swatch-s5 { background-color: var(--series-5); }
.swatch-s6 { background-color: var(--series-6); }
.swatch-s7 { background-color: var(--series-7); }
.swatch-s8 { background-color: var(--series-8); }
.swatch-other { background-color: var(--series-other); }

.swatch-good { background-color: var(--status-good); }
.swatch-warn { background-color: var(--status-warn); }
.swatch-serious { background-color: var(--status-serious); }
.swatch-critical { background-color: var(--status-critical); }

/* Diverging Scale Ramp Bar */
.diverging-legend-bar {
  display: inline-grid;
  grid-template-columns: repeat(9, 13px);
  height: 8px;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid var(--border-hairline);
}

.div-step-n4 { background-color: var(--div-neg-4); }
.div-step-n3 { background-color: var(--div-neg-3); }
.div-step-n2 { background-color: var(--div-neg-2); }
.div-step-n1 { background-color: var(--div-neg-1); }
.div-step-0  { background-color: var(--div-zero); }
.div-step-p1 { background-color: var(--div-pos-1); }
.div-step-p2 { background-color: var(--div-pos-2); }
.div-step-p3 { background-color: var(--div-pos-3); }
.div-step-p4 { background-color: var(--div-pos-4); }

/* Interactive SVG Primitives */
.viz-interactive {
  cursor: pointer;
  transition: opacity var(--dur-fast) ease;
}

.viz-interactive:hover {
  opacity: 0.92;
}

/* --------------------------------------------------------------------------
   4. Compact Graphical KPI & Micro-Gauge Tiles
      (#compass-kpi-strip, #liquidity-kpi-strip, #politician-kpi-strip)
   -------------------------------------------------------------------------- */
.kpi-tile {
  background-color: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 5px;
  min-width: 0;
}

.kpi-tile.is-clickable {
  cursor: pointer;
  transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}

.kpi-tile.is-clickable:hover {
  border-color: var(--accent-border);
  background-color: var(--surface-2);
}

.kpi-tile-accent {
  border-left: 3px solid var(--accent-primary);
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

/* Sentence-case KPI label */
.kpi-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Standalone KPI Value: Proportional Figures per Dataviz Spec */
.kpi-value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.kpi-value {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: proportional-nums;
  line-height: 1.12;
}

.kpi-unit {
  font-size: var(--text-2xs);
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 2px;
}

.kpi-change {
  font-size: var(--text-2xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.kpi-gauge-svg {
  display: block;
  width: 100%;
  height: 14px;
  overflow: visible;
}

.kpi-detail {
  margin: 0;
  font-size: var(--text-2xs);
  color: var(--text-muted);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   5. Seven-Column Interactive Macro Calendar Grid & Scenario Impact Matrix
      (#chart-calendar-grid)
   -------------------------------------------------------------------------- */
.cal-split-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.15fr) minmax(290px, 1fr);
  gap: var(--space-3);
  align-items: stretch;
  min-width: 0;
}

@media (max-width: 1080px) {
  .cal-split-layout {
    grid-template-columns: 1fr;
  }
}

.cal-board-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.cal-weekday-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.cal-weekday-cell {
  padding: 4px 2px;
  text-align: center;
  font-size: var(--text-2xs);
  font-weight: 600;
  color: var(--text-muted);
  background-color: var(--surface-2);
  border-radius: var(--radius-xs);
}

.cal-days-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.cal-day-cell {
  appearance: none;
  text-align: left;
  min-height: 78px;
  padding: 5px 6px;
  background-color: var(--cal-heat-0);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  font-family: var(--font-sans);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}

.cal-day-cell:hover {
  border-color: var(--border-strong);
}

.cal-day-cell.is-outside {
  opacity: 0.34;
  background-color: var(--surface-1);
}

.cal-day-cell.heat-1 { background-color: var(--cal-heat-1); }
.cal-day-cell.heat-2 { background-color: var(--cal-heat-2); }
.cal-day-cell.heat-3 { background-color: var(--cal-heat-3); }

.cal-day-cell.is-today {
  border-color: var(--accent-primary);
  box-shadow: inset 0 0 0 1px var(--accent-primary);
}

.cal-day-cell.is-selected {
  border-color: var(--accent-primary);
  background-color: var(--surface-selected);
}

.cal-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
}

.cal-day-num {
  font-weight: 600;
  color: var(--text-secondary);
}

.cal-day-cell.is-today .cal-day-num,
.cal-day-cell.is-selected .cal-day-num {
  color: var(--accent-primary);
  font-weight: 700;
}

.cal-more-badge {
  padding: 0 4px;
  border-radius: var(--radius-xs);
  background-color: var(--surface-3);
  color: var(--text-secondary);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.cal-event-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  background-color: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-left: 2.5px solid var(--series-1);
  border-radius: var(--radius-xs);
  font-size: 10.5px;
  line-height: 1.22;
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
}

.cal-event-chip.imp-high {
  border-left-color: var(--status-warn);
  font-weight: 600;
}

.cal-chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

@media (max-width: 680px) {
  .cal-day-cell {
    min-height: 54px;
    padding: 3px 4px;
    gap: 2px;
  }

  .cal-event-chip {
    padding: 1px 3px;
    font-size: 9.5px;
  }
}

/* Selected Date Scenario Impact Symbol Matrix Panel */
.cal-impact-panel {
  background-color: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.cal-impact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-hairline);
}

.cal-impact-title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.cal-reading-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.cal-reading-box {
  padding: 5px 7px;
  background-color: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
  font-variant-numeric: tabular-nums;
}

.cal-reading-label {
  font-size: 10px;
  color: var(--text-muted);
}

.cal-reading-val {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-primary);
}

.impact-matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-2xs);
  font-variant-numeric: tabular-nums;
}

.impact-matrix-table th,
.impact-matrix-table td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--border-hairline);
  text-align: center;
}

.impact-matrix-table th:first-child,
.impact-matrix-table td:first-child {
  text-align: left;
  font-weight: 600;
}

.imp-glyph-up {
  color: var(--status-good-text);
  font-weight: 700;
}

.imp-glyph-down {
  color: var(--status-critical-text);
  font-weight: 700;
}

.imp-glyph-flat {
  color: var(--text-muted);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   6. Graphical Micro-Chart Matrix Tables (.table-host, .data-table)
   -------------------------------------------------------------------------- */
.table-host {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-host-compact {
  max-height: 460px;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: var(--text-xs);
  color: var(--text-primary);
}

.data-table th,
.data-table td {
  padding: 6px 9px;
  border-bottom: 1px solid var(--border-hairline);
  text-align: left;
  vertical-align: middle;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--surface-2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: var(--text-2xs);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  user-select: none;
}

.data-table th.num,
.data-table td.num,
.num {
  text-align: right;
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
}

.tabular {
  font-variant-numeric: tabular-nums lining-nums;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.th-sort-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.th-sort-btn:hover {
  color: var(--text-primary);
}

.data-table thead th[aria-sort="ascending"],
.data-table thead th[aria-sort="descending"],
.th-sort-btn.is-sorted {
  color: var(--accent-primary);
}

.data-table tbody tr {
  transition: background-color var(--dur-fast) ease;
}

.data-table tbody tr:hover {
  background-color: var(--surface-hover);
}

.data-table tbody tr.is-clickable,
.data-table tbody tr[data-drilldown],
.data-table tbody tr[tabindex] {
  cursor: pointer;
}

.data-table tbody tr.is-selected,
.data-table tbody tr[aria-selected="true"] {
  background-color: var(--surface-selected);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tfoot td {
  background-color: var(--surface-2);
  font-weight: 600;
  border-top: 1px solid var(--border-subtle);
  border-bottom: none;
}

.entity-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 112px;
}

.entity-primary {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text-primary);
}

.ticker-pill {
  display: inline-block;
  padding: 1px 5px;
  background-color: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 600;
  color: var(--text-primary);
}

.entity-sub {
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

/* Inline Graphical Micro-Chart Cells (Drawdown Bar, RSI Ruler, 60D Sparkline) */
.micro-meter-cell {
  width: 102px;
  min-width: 92px;
}

.micro-meter-cell svg {
  display: block;
  width: 94px;
  height: 22px;
  overflow: visible;
}

.sparkline-cell {
  width: 92px;
  min-width: 84px;
}

.sparkline-cell svg {
  display: block;
  width: 86px;
  height: 22px;
  overflow: visible;
}

/* --------------------------------------------------------------------------
   7. Reserved Status Badges & Signed Value Tokens (Icon + Label Mandatory)
   -------------------------------------------------------------------------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--status-neutral-border);
  background-color: var(--status-neutral-bg);
  color: var(--status-neutral-text);
  font-size: var(--text-2xs);
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
}

.status-good,
.stance-overweight {
  background-color: var(--status-good-bg);
  border-color: var(--status-good-border);
  color: var(--status-good-text);
}

.status-warn {
  background-color: var(--status-warn-bg);
  border-color: var(--status-warn-border);
  color: var(--status-warn-text);
}

.status-serious {
  background-color: var(--status-serious-bg);
  border-color: var(--status-serious-border);
  color: var(--status-serious-text);
}

.status-critical,
.stance-underweight {
  background-color: var(--status-critical-bg);
  border-color: var(--status-critical-border);
  color: var(--status-critical-text);
}

.status-neutral,
.stance-neutral {
  background-color: var(--status-neutral-bg);
  border-color: var(--status-neutral-border);
  color: var(--status-neutral-text);
}

.val-pos { color: var(--status-good-text); }
.val-neg { color: var(--status-critical-text); }
.val-warn { color: var(--status-warn-text); }
.val-muted { color: var(--text-muted); }

.party-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 700;
}

.party-d {
  background-color: var(--series-1-wash);
  color: var(--accent-primary);
  border: 1px solid var(--accent-border);
}

.party-r {
  background-color: var(--series-2-wash);
  color: var(--series-2);
  border: 1px solid var(--series-2);
}

.party-i {
  background-color: var(--status-neutral-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* --------------------------------------------------------------------------
   8. Filter Controls (Selects, Filter Chips, Result Counters)
   -------------------------------------------------------------------------- */
.filter-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.filter-select {
  height: 27px;
  padding: 0 22px 0 8px;
  background-color: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  cursor: pointer;
}

.filter-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 25px;
  padding: 0 8px;
  background-color: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

.filter-chip:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.filter-chip.is-active,
.filter-chip.active,
.filter-chip[aria-pressed="true"] {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border-color: var(--accent-border);
  font-weight: 600;
}

/* Empty & Loading Continuity States */
.empty-state {
  padding: var(--space-5) var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-xs);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  background-color: var(--surface-1);
}

.loading-placeholder {
  padding: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* --------------------------------------------------------------------------
   9. Shared Interactive Crosshair Tooltip (#chart-tooltip)
   -------------------------------------------------------------------------- */
#chart-tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-tooltip);
  min-width: 196px;
  max-width: 340px;
  padding: 9px 11px;
  background-color: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-float);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  will-change: transform;
}

#chart-tooltip[hidden],
#chart-tooltip.is-hidden {
  display: none !important;
}

.tooltip-header {
  padding-bottom: 5px;
  margin-bottom: 5px;
  border-bottom: 1px solid var(--border-hairline);
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.tooltip-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.tooltip-series-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  min-width: 0;
}

.tooltip-value {
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.tooltip-note {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--border-hairline);
  font-size: var(--text-2xs);
  color: var(--text-secondary);
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   10. Right-Side Deep Drill-Down Drawer (#detail-drawer)
   -------------------------------------------------------------------------- */
#detail-drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer-backdrop);
  pointer-events: none;
  visibility: hidden;
}

#detail-drawer.is-open,
#detail-drawer[data-open="true"],
#detail-drawer[aria-hidden="false"] {
  pointer-events: auto;
  visibility: visible;
}

#detail-drawer-backdrop {
  position: absolute;
  inset: 0;
  background-color: var(--backdrop-dim);
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease-out-quart);
}

#detail-drawer.is-open #detail-drawer-backdrop,
#detail-drawer[data-open="true"] #detail-drawer-backdrop,
#detail-drawer[aria-hidden="false"] #detail-drawer-backdrop {
  opacity: 1;
}

.detail-drawer-surface {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-drawer-panel);
  width: var(--drawer-width);
  max-width: 100vw;
  background-color: var(--surface-1);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-drawer);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--dur-normal) var(--ease-out-quart);
}

#detail-drawer.is-open .detail-drawer-surface,
#detail-drawer[data-open="true"] .detail-drawer-surface,
#detail-drawer[aria-hidden="false"] .detail-drawer-surface {
  transform: translateX(0);
}

.detail-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 14px 18px;
  background-color: var(--surface-2);
  border-bottom: 1px solid var(--border-subtle);
}

/* Direct Drawer Title */
#detail-drawer-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text-primary);
  line-height: var(--leading-snug);
}

#detail-drawer-close {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 9px;
  background-color: var(--surface-1);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  cursor: pointer;
  flex-shrink: 0;
}

#detail-drawer-close:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

#detail-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-hairline);
}

.drawer-section:last-child {
  border-bottom: none;
}

.drawer-section h4 {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.drawer-copy {
  margin: 0;
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}

.drawer-kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: var(--space-2);
}

.drawer-kv-item {
  padding: 8px 10px;
  background-color: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
}

.drawer-kv-label {
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

.drawer-kv-val {
  margin-top: 2px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.scenario-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 720px) {
  .scenario-strip {
    grid-template-columns: 1fr;
  }
}

.scenario-cell {
  padding: 8px 10px;
  background-color: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.45;
}

.scenario-cell strong {
  display: block;
  margin-bottom: 3px;
  color: var(--text-primary);
}

/* Print Adaptation */
@media print {
  #terminal-topbar {
    position: static;
  }

  .terminal-section {
    display: flex !important;
    break-inside: avoid-page;
  }

  #detail-drawer,
  #chart-tooltip {
    display: none !important;
  }
}
