/* Analytics tab (Daily electricity / Forward curves / Vol surfaces), desk-only.
   static/market-analytics.js builds every pane from document.createElement + textContent
   (tests/test_static_security.py convention) and composes the house classes: .panel,
   .panel-title, .data-table, .empty-state, .skeleton-* , .btn-ghost, rather than carrying
   copies. What follows is only what the house does not already define: toolbar layout, the
   per-region KPI card grid, table wrappers, change colouring, flag badges and chart chrome.
   Every colour is a token. Chrome is --font-sans; every number is --font-mono. Hierarchy comes
   from size, colour and tracking, never weight (house rule). */

.ma-pane {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding-top: var(--sp-4);
}

/* ----- Toolbar: date / lookback / refresh, the as-of + partial-day context line, notes ----- */
.ma-toolbar-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.ma-toolbar label,
.ma-chart-controls label {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--track-normal);
  color: var(--text-dim);
}
.ma-toolbar select,
.ma-chart-controls select {
  background: var(--bg-primary);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-2);
  min-height: 32px;
  max-width: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}
.ma-toolbar-row > .btn-ghost {
  margin-left: auto;
}
.ma-toolbar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-4);
  padding-top: var(--sp-3);
  margin-top: var(--sp-3);
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.ma-toolbar-meta strong {
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--text);
}
.ma-toolbar-status {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--amber);
}

.ma-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-tight);
  line-height: 1.6;
}
.ma-badge-warn {
  color: var(--amber);
  background: color-mix(in srgb, var(--amber) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent);
}
.ma-badge-muted {
  color: var(--text-muted);
  background: var(--surface-tint-1);
  border: 1px solid var(--border-subtle);
}
.ma-badge-neg {
  color: var(--negative);
  background: color-mix(in srgb, var(--negative) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--negative) 45%, transparent);
}

.ma-notes {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  margin-top: var(--sp-3);
}
.ma-notes > summary {
  cursor: pointer;
  padding: var(--sp-1) 0;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--track-tight);
  color: var(--text-muted);
}
.ma-notes ul {
  margin: var(--sp-2) 0 0;
  padding-left: var(--sp-5);
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.6;
}
.ma-notes li {
  margin-bottom: var(--sp-1);
}

/* ----- Sections: full-width house panels stacked with even air ----- */
.ma-section-sub {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-dim);
  font-weight: 400;
}
.ma-section-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.ma-section-actions select {
  background: var(--bg-primary);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-2);
  min-height: 30px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}
.ma-section-note {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 var(--sp-3);
}

/* ----- KPI cards: one per region, a metric-tile grid inside ----- */
.ma-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--sp-3);
}
.ma-kpi-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  min-width: 0;
}
.ma-kpi-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.ma-kpi-card-head strong {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: var(--track-tight);
}
.ma-kpi-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: var(--sp-3) var(--sp-2);
}
.ma-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ma-metric-label {
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--track-normal);
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ma-metric-value {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}
.ma-metric-sub {
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  color: var(--text-muted);
}

/* ----- Tables: the house table, wrapped so every wide table scrolls its own axis ----- */
.ma-table-wrap {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}
.ma-table-wrap > .data-table {
  min-width: 100%;
}
.data-table.ma-table th,
.data-table.ma-table td {
  white-space: nowrap;
}
.data-table.ma-table td.ma-num,
.data-table.ma-table th.ma-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.data-table.ma-table td.ma-text {
  white-space: normal;
  font-family: var(--font-sans);
  min-width: 160px;
}
/* Row-label header cells (<th scope="row">, e.g. a tenor or region name in the first
   column) get no house rule (style.css only left-aligns td:first-child, not th). Left
   here explicitly so a row label reads like the rest of the house tables instead of
   falling back to the browser's centred <th> default. */
.data-table.ma-table tbody th[scope="row"] {
  text-align: left;
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
}
.ma-pos { color: var(--positive); }
.ma-neg { color: var(--negative); }
.ma-muted { color: var(--text-dim) !important; font-style: italic; }
.ma-row-flagged td {
  color: var(--text-dim);
}
.ma-row-flagged td.ma-num,
.ma-row-flagged td.ma-text {
  opacity: 0.75;
}
.ma-flag-tag {
  display: inline-block;
  margin-left: var(--sp-1);
  padding: 0 4px;
  border-radius: 3px;
  font-family: var(--font-sans);
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--amber);
  background: color-mix(in srgb, var(--amber) 16%, transparent);
  vertical-align: middle;
}
.ma-shade-hi { background: color-mix(in srgb, var(--positive) 16%, transparent) !important; }
.ma-shade-lo { background: color-mix(in srgb, var(--negative) 16%, transparent) !important; }

/* ----- Chips: breadth (curves) and similar small tallies ----- */
.ma-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.ma-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
}
.ma-chip strong {
  font-family: var(--font-sans);
  color: var(--text);
}
.ma-chip .ma-chip-up { color: var(--positive); font-family: var(--font-mono); }
.ma-chip .ma-chip-down { color: var(--negative); font-family: var(--font-mono); }
.ma-chip .ma-chip-flat { color: var(--text-dim); font-family: var(--font-mono); }
.ma-chip-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
}

/* ----- Charts ----- */
.ma-chart-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-2);
}
.ma-chart {
  width: 100%;
  min-width: 0;
  height: 360px;
}
.ma-chart--tall { height: 440px; }
.ma-chart--short { height: 260px; }
.ma-legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding-top: var(--sp-2);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.ma-legend-row .ma-chip-swatch { border-radius: 2px; }
.ma-loading {
  display: grid;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
}
.ma-loading .skeleton-bar:nth-child(2) { width: 78%; }
.ma-loading .skeleton-bar:nth-child(3) { width: 60%; }

.ma-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: var(--sp-4);
}

@media (max-width: 900px) {
  .ma-toolbar-row { gap: var(--sp-2); }
  .ma-toolbar-row label { flex: 1; min-width: 130px; }
  .ma-two-col { grid-template-columns: 1fr; }
  .ma-chart { height: 300px; }
}

@media (max-width: 480px) {
  .ma-kpi-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .ma-pane * { transition: none !important; }
}
