/* ==========================================================================
   Ianus — frontend styles (static/styles.css)

   Main page layout (top → bottom):
   .page              Root column wrapper (#app in index.html)
   .header            Top bar: brand, meta badges, action buttons
   .toolbar           Control panels (window/metrics, MOL)
   .status-bar        Subtle line above table: last refreshed time
   .grid-shell        Bordered container around the data table
   .plot-shell        Chart section below the table

   Analytics / Strategy tester pages reuse: .page, .header, .brand-row,
   .brand.brand-home, .site-nav, .logo, .title
   ========================================================================== */

/* --- Theme tokens (colors, spacing, grid/chart dimensions) --- */
:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, sans-serif;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #52606d;
  --border: #d9e2ec;
  --border-strong: #bcccdc;
  --accent: #243b53;
  --accent-action: #2563eb;
  --on-accent: #ffffff;
  --live-on-bg: #e3f9e5;
  --live-on-border: #27ab83;
  --live-on-text: #147d64;
  --live-off-bg: #f0f4f8;
  --live-off-border: #9fb3c8;
  --current-bg: #e3f9e5;
  --current-header-bg: #b2f2bb;
  --current-row-even: #c8eed0;
  --current-row-hover: #d4ebdd;
  --row-alt: #eef2f6;
  --row-hover: #e8f0f8;
  --metric-frozen-bg: #f8fafc;
  --metric-frozen-alt: #e4e9ef;
  --table-header-bg: #f0f4f8;
  --panel-subtle-bg: #f8fafc;
  --panel-subtle-bg-alt: #fafbfc;
  --analytics-overview-month-bg: #e4ecf4;
  --field-label: #334e68;
  --field-input-text: #102a43;
  --nav-hover-bg: rgba(36, 59, 83, 0.06);
  --nav-active-bg: rgba(36, 59, 83, 0.08);
  --status-muted: #829ab1;
  --btn-secondary-bg: #486581;
  --btn-live-stop: #9b2226;
  --btn-live-start: #147d64;
  --positive: #147d64;
  --negative: #9b2226;
  --gap-filled: #9aa5b1;
  --gap-filled-current: #7a8b7a;
  --plot-grid: #e4e9ef;
  --plot-grid-zero: #829ab1;
  --plot-zero-line: #334e68;
  --plot-axis-zero: #243b53;
  --plot-crosshair-stroke: #627d98;
  --plot-crosshair-fill: #ffffff;
  --tooltip-bg: rgba(255, 255, 255, 0.97);
  --disabled-text: #7b8794;
  --disabled-bg: #eef2f6;
  --hour-preset-bg: #f0f4f8;
  --hour-preset-hover: #eef2f6;
  --legend-off-swatch: #9aa5b1;
  --grid-col-width: 98px;
  --grid-metric-width: 280px;
  --plot-height: 360px;
  --grid-row-height: 32px;
  --header-height: 40px;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(16, 42, 67, 0.12);
  --balancing-price: #7048e8;
  --spread-line: #495057;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e8eef4;
  --muted: #9fb3c8;
  --border: #2d3a4d;
  --border-strong: #3d4f66;
  --accent: #bcccdc;
  --accent-action: #5c7cfa;
  --on-accent: #0f1419;
  --live-on-bg: #133d2e;
  --live-on-border: #27ab83;
  --live-on-text: #63e6be;
  --live-off-bg: #1a2332;
  --live-off-border: #3d4f66;
  --current-bg: #1a3d2e;
  --current-header-bg: #1f5c40;
  --current-row-even: #1f4d35;
  --current-row-hover: #255c40;
  --row-alt: #151e2b;
  --row-hover: #243447;
  --metric-frozen-bg: #1a2332;
  --metric-frozen-alt: #1f2a3a;
  --table-header-bg: #1f2a3a;
  --panel-subtle-bg: #151e2b;
  --panel-subtle-bg-alt: #1a2332;
  --analytics-overview-month-bg: #243044;
  --field-label: #9fb3c8;
  --field-input-text: #e8eef4;
  --nav-hover-bg: rgba(255, 255, 255, 0.06);
  --nav-active-bg: rgba(255, 255, 255, 0.08);
  --status-muted: #627d98;
  --btn-secondary-bg: #3d4f66;
  --btn-live-stop: #c92a2a;
  --btn-live-start: #2b8a3e;
  --positive: #63e6be;
  --negative: #ff8787;
  --gap-filled: #627d98;
  --gap-filled-current: #829ab1;
  --plot-grid: #2d3a4d;
  --plot-grid-zero: #627d98;
  --plot-zero-line: #9fb3c8;
  --plot-axis-zero: #e8eef4;
  --plot-crosshair-stroke: #627d98;
  --plot-crosshair-fill: #1a2332;
  --tooltip-bg: rgba(26, 35, 50, 0.97);
  --disabled-text: #627d98;
  --disabled-bg: #1f2a3a;
  --hour-preset-bg: #1f2a3a;
  --hour-preset-hover: #243447;
  --legend-off-swatch: #627d98;
  --spread-line: #adb5bd;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* --- Page shell --- */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

/* Main Vue app column: header → toolbar → status → grid → chart */
.page {
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}

/* --- Header: logo + title (.brand), info pills (.meta .badge), buttons (.actions) --- */
.header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

/* Logo + "Ianus" title row, optionally with primary site nav beside it */
.brand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 20px;
  margin-bottom: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-row .brand {
  margin-bottom: 0;
}

/* Clickable brand link (returns to Overview / home) */
.brand-home {
  text-decoration: none;
  color: inherit;
  width: fit-content;
}

.brand-home:hover .title {
  color: var(--accent);
}

/* Primary page links beside the brand */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 2px;
}

.site-nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  line-height: 1.2;
}

.site-nav-link:hover {
  color: var(--text);
  background: var(--nav-hover-bg);
}

.site-nav-link.is-active {
  color: var(--accent);
  background: var(--nav-active-bg);
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* Logo image in .brand / .brand-home */
.logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

:root[data-theme="dark"] .logo {
  /* logo.png is primarily dark; invert to keep it visible in dark mode */
  filter: invert(1) brightness(1.6);
}

/* "Ianus" heading next to the logo */
.title {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.5rem);
  line-height: 1.2;
}

/* Row of rounded info pills under the title */
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.875rem;
}

/* Single meta pill; .live-on / .live-off color the Live/Paused badge */
.badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.badge.live-on {
  background: var(--live-on-bg);
  border-color: var(--live-on-border);
  color: var(--live-on-text);
}

.badge.live-off {
  background: var(--live-off-bg);
  border-color: var(--live-off-border);
  color: var(--muted);
}

/* Header button group: page actions left; theme/logout pinned right via .header-utils */
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.header-utils {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  order: 100;
}

.download-menu {
  position: relative;
}

.download-menu-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 150px;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.download-menu-panel button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: var(--surface);
  color: var(--field-input-text);
  border: 1px solid var(--border);
}

.download-menu-panel button:hover {
  border-color: var(--border-strong);
  background: var(--bg);
}

/* Theme toggle: real switch with sun/moon buttons */
.theme-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.theme-switch-btn {
  width: 38px;
  height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: background-color 0.12s ease, color 0.12s ease;
}

.theme-switch-btn svg {
  display: block;
}

.theme-switch-btn.is-active {
  background: var(--accent);
  color: var(--on-accent);
}

/* Discrete site logout (injected by theme.js; not a primary action button) */
button.site-logout {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 6px 8px;
  margin: 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  border-radius: 6px;
}

button.site-logout:hover,
button.site-logout:focus-visible {
  background: transparent;
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

button.site-logout:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* --- Toolbars: window/metrics panel, then MOL panel --- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.toolbar-mol {
  margin-top: -4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Label + input/select stack (Start, End, Metrics, MOL pricing, quantities) */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--field-label);
}

.field input,
.field select {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: var(--surface);
  color: var(--field-input-text);
  min-width: 0;
}

.field-mol-quantities {
  width: 9.5rem;
}

.field-mol-quantities input {
  width: 100%;
}

/* Shared button styles; .secondary = gray, .live-start/.live-stop = green/red */
button,
a.button {
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--accent);
  color: var(--on-accent);
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}

button.secondary,
a.button.secondary {
  background: var(--btn-secondary-bg);
}

button.live-stop {
  background: var(--btn-live-stop);
}

button.live-start {
  background: var(--btn-live-start);
}

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

/* --- Status line above the table (last refreshed; spinner while .is-refreshing) --- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 1rem;
  margin: -4px 0 -2px;
  padding: 0 2px;
  color: var(--status-muted);
  font-size: 0.78rem;
  line-height: 1.3;
}

.status-bar.is-refreshing::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--border);
  border-top-color: var(--status-muted);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* --- Data table container (.grid-host is filled by VirtualGrid in app.js) --- */
.grid-shell {
  width: 100%;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.grid-shell.is-initial-load {
  opacity: 0.72;
  pointer-events: none;
}

/* --- Price chart section below the table --- */
.plot-shell {
  width: 100%;
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--border-strong);
}

/* "Balancing price on same Y axis" checkbox under the chart legend */
.plot-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.85rem;
  color: var(--field-label);
  cursor: pointer;
  user-select: none;
}

/* Legend row + axis checkbox wrapper */
.plot-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  padding: 0 2px;
}

.plot-control input {
  margin: 0;
  width: 15px;
  height: 15px;
  accent-color: var(--balancing-price);
  cursor: pointer;
}

/* Vue mounts PriceChart here (.plot-panel is created inside app.js) */
.plot-host {
  width: 100%;
}

/* Chart card: title, subtitle, SVG canvas, empty-state message */
.plot-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
}

/* "Key prices" heading and loaded-window subtitle */
.plot-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 10px;
}

/* "Key prices" chart title (inside .plot-panel, created in app.js) */
.plot-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
}

/* Period range subtitle under the chart title */
.plot-subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Relative wrapper for SVG + hover tooltip */
.plot-canvas-wrap {
  position: relative;
  width: 100%;
  min-height: var(--plot-height);
}

/* --- Chart SVG internals (classes applied in PriceChart, app.js) --- */
.plot-svg {
  display: block;
  width: 100%;
  height: var(--plot-height);
}

/* Horizontal grid lines and Y-axis tick labels */
.plot-grid-line,
.plot-grid line {
  stroke: var(--plot-grid);
  stroke-width: 1;
}

.plot-grid-line-zero {
  stroke: var(--plot-grid-zero);
  stroke-width: 1.5;
  stroke-dasharray: none;
}

.plot-zero-line {
  stroke: var(--plot-zero-line);
  stroke-width: 2.5;
  stroke-dasharray: none;
  opacity: 1;
  pointer-events: none;
}

.plot-axis-label-zero {
  fill: var(--plot-axis-zero);
  font-weight: 700;
  font-size: 11px;
}

.plot-axis-label {
  fill: var(--muted);
  font-size: 10px;
  text-anchor: end;
  dominant-baseline: middle;
}

/* Right Y-axis labels when balancing price uses its own scale */
.plot-axis-label-right {
  text-anchor: start;
  fill: var(--balancing-price);
  font-weight: 600;
}

/* Zero line on the balancing (right) axis */
.plot-zero-line-balancing {
  stroke: var(--balancing-price);
  stroke-width: 2.5;
  stroke-dasharray: none;
  opacity: 1;
  pointer-events: none;
}

/* "(right)" hint next to Balancing Price in the legend */
.plot-legend-axis {
  font-size: 0.75rem;
  color: var(--balancing-price);
  font-weight: 600;
}

.plot-axis-label-x {
  text-anchor: middle;
  dominant-baseline: auto;
}

/* Vertical dashed line at the current quarter-hour */
.plot-current-marker {
  stroke: var(--live-on-border);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  opacity: 0.85;
}

/* Series lines; .plot-line-dashed = incentives, .plot-line-emphasis = balancing */
.plot-line {
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plot-line-dashed {
  stroke-dasharray: 7 5;
}

.plot-line-emphasis {
  stroke-width: 3;
}

.plot-hover-crosshair {
  stroke: var(--plot-crosshair-stroke);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  pointer-events: none;
}

.plot-hover-dot {
  stroke: var(--plot-crosshair-fill);
  stroke-width: 1.5;
  pointer-events: none;
}

.plot-hover-dot-emphasis {
  stroke-width: 2;
}

/* Mouse-follow tooltip over the chart */
.plot-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 220px;
  max-width: min(320px, 90vw);
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--tooltip-bg);
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 0.82rem;
  color: var(--field-label);
}

.plot-tooltip-period {
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.85rem;
}

.plot-tooltip-row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 2px 0;
}

/* Balancing Price row uses purple emphasis in the tooltip */
.plot-tooltip-row-emphasis .plot-tooltip-name,
.plot-tooltip-row-emphasis .plot-tooltip-value {
  font-weight: 600;
  color: var(--balancing-price);
}

.plot-tooltip-swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

.plot-tooltip-swatch-dashed {
  background: transparent;
  height: 0;
  border-top: 3px dashed;
}

.plot-tooltip-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* --- Chart legend (toggle series visibility; below the chart in index.html) --- */
.plot-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  font-size: 0.82rem;
  color: var(--field-label);
}

/* One legend pill; .is-hidden = faded + struck-through when series toggled off */
.plot-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--surface);
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

.plot-legend-item:hover {
  border-color: var(--border-strong);
}

.plot-legend-item.is-hidden {
  opacity: 0.45;
}

.plot-legend-item.is-hidden .plot-legend-swatch {
  opacity: 0.35;
}

.plot-legend-item.is-hidden span:last-child {
  text-decoration: line-through;
}

.plot-legend-swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

.plot-legend-swatch-dashed {
  background: transparent;
  height: 0;
  border-top: 3px dashed;
}

.plot-legend-swatch-emphasis {
  width: 18px;
  height: 4px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(112, 72, 232, 0.25);
}

/* Balancing Price legend pill (purple text + thicker swatch) */
.plot-legend-item-emphasis {
  font-weight: 600;
  color: var(--balancing-price);
}

/* Shown inside chart when no plottable values exist */
.plot-empty {
  padding: 20px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* "No data available" message inside .grid-shell */
.grid-empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

/* --- Data table (built by VirtualGrid; sticky header + frozen metric column) --- */
.virtual-grid {
  width: 100%;
}

/* Horizontally scrollable table body */
.grid-body {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
}

.grid-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}

.grid-table th,
.grid-table td {
  padding: 6px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}

.grid-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-header-bg);
  font-weight: 600;
  height: var(--header-height);
}

.grid-table thead th.period-col {
  height: auto;
  min-height: var(--header-height);
  padding-top: 4px;
  padding-bottom: 4px;
  line-height: 1.2;
  vertical-align: middle;
  font-size: inherit;
}

.grid-table thead th.period-col .period-header-date,
.grid-table thead th.period-col .period-header-time {
  display: block;
  white-space: nowrap;
}

.grid-table thead th.period-col .period-header-date {
  font-size: 1em;
  font-weight: 600;
}

.grid-table thead th.period-col .period-header-time {
  font-size: 0.94em;
  font-weight: 500;
  color: var(--muted);
}

/* Left frozen column (metric names); .period-col = quarter-hour value cells */
.grid-table th.metric-col,
.grid-table td.metric-col {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--grid-metric-width);
  min-width: 140px;
  max-width: 520px;
  font-weight: 500;
  text-align: left;
  background: var(--metric-frozen-bg);
}

.grid-table thead th.metric-col {
  z-index: 3;
  background: var(--table-header-bg);
}

.grid-table th.period-col,
.grid-table td.period-col {
  width: var(--grid-col-width);
  min-width: var(--grid-col-width);
  max-width: var(--grid-col-width);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.grid-table tbody tr:nth-child(even) td {
  background: var(--row-alt);
}

.grid-table tbody tr:nth-child(even) td.metric-col {
  background: var(--metric-frozen-alt);
}

.grid-table tbody tr:hover td {
  background: var(--row-hover);
}

.grid-table tbody tr:hover td.metric-col {
  background: var(--row-hover);
}

/* Green highlight for the current quarter-hour column */
.grid-table th.period-current,
.grid-table td.period-current {
  background: var(--current-bg);
  font-weight: 600;
}

.grid-table thead th.period-current {
  background: var(--current-header-bg);
}

.grid-table tbody tr:nth-child(even) td.period-current {
  background: var(--current-row-even);
}

.grid-table tbody tr:hover td.period-current {
  background: var(--current-row-hover);
}

/* Values carried forward because MOL XML was missing for that period */
.grid-table td.period-col.value-gap-filled {
  color: var(--gap-filled);
  font-style: italic;
}

.grid-table td.period-col.value-gap-filled.period-current {
  color: var(--gap-filled-current);
}

/* --- Metrics visibility dropdown (toolbar "Metrics" field) --- */
.column-dropdown {
  position: relative;
  z-index: 40;
}

/* Button showing "N of M metrics visible" */
.dropdown-toggle {
  min-width: 220px;
  text-align: left;
  background: var(--surface);
  color: var(--field-input-text);
  border: 1px solid var(--border-strong);
}

/* Floating checkbox list of metrics */
.dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 100;
  box-sizing: border-box;
  width: max(220px, min(360px, calc(100vw - 32px)));
  max-width: calc(100vw - 32px);
  max-height: min(320px, 50vh);
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* Select all / Clear buttons at top of metrics dropdown */
.dropdown-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.dropdown-actions button {
  padding: 6px 10px;
  font-size: 0.85rem;
}

/* One metric checkbox row inside the dropdown */
.dropdown-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  column-gap: 8px;
  padding: 4px 0;
  font-size: 0.9rem;
  color: var(--accent);
  cursor: pointer;
}

.dropdown-option input {
  margin: 0.2rem 0 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.dropdown-option span {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
}

.dropdown-option-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.dropdown-option-label .strategy-table-family-swatch {
  flex-shrink: 0;
  margin: 0;
}

/* Refresh spinner keyframes (status bar) */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Analytics --- */
.analytics-page {
  gap: 14px;
  min-width: 0;
}

.analytics-status {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.analytics-status.error {
  color: var(--negative);
}

.analytics-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.analytics-card-title {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--accent);
}

.analytics-card-title--flush {
  margin-bottom: 6px;
}

.analytics-card-desc {
  margin: 0 0 12px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--muted);
}

.analytics-overview-period-cell.is-month {
  padding-left: 1.35rem;
}

.analytics-table-row-clickable {
  cursor: pointer;
}

.analytics-table-row-clickable:hover td {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.analytics-overview-chevron {
  display: inline-block;
  margin-right: 0.35rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.analytics-overview-chevron.is-expanded {
  transform: rotate(90deg);
}

.analytics-scroll-table .strategy-table tbody tr.analytics-overview-month-row td,
.analytics-scroll-table .strategy-table tbody tr.analytics-overview-month-row td:first-child {
  background: var(--analytics-overview-month-bg);
}

.analytics-scroll-table .strategy-table tbody tr.analytics-overview-month-row .analytics-overview-period-cell {
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--accent) 55%, var(--border));
}

.analytics-scroll-table .strategy-table tbody tr.analytics-overview-month-row:hover td,
.analytics-scroll-table .strategy-table tbody tr.analytics-overview-month-row:hover td:first-child {
  background: color-mix(in srgb, var(--accent) 10%, var(--analytics-overview-month-bg));
}

.analytics-table-row-clickable.is-expanded td {
  border-bottom-color: transparent;
}

.analytics-card-placeholder {
  opacity: 0.92;
}

.analytics-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.analytics-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.analytics-table th,
.analytics-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.analytics-table th {
  background: var(--panel-subtle-bg);
  color: var(--muted);
  font-weight: 600;
}

.analytics-table th:first-child,
.analytics-table td.analytics-col-month {
  text-align: left;
}

.analytics-table tbody tr:nth-child(even) td {
  background: var(--panel-subtle-bg-alt);
}

.analytics-col-up {
  color: var(--positive);
}

.analytics-col-down {
  color: var(--negative);
}

.analytics-table-empty {
  text-align: center !important;
  color: var(--muted);
  padding: 16px !important;
}

.analytics-section2-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: flex-end;
  margin-bottom: 8px;
}

.analytics-section2-panel .analytics-section2-toolbar {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 0;
}

.analytics-section2-panel .analytics-field {
  min-width: 0;
  width: 100%;
}

.analytics-section2-panel .analytics-field-input {
  width: 100%;
  box-sizing: border-box;
}

.analytics-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.analytics-field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.analytics-field-input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--surface);
}

.analytics-field-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.analytics-section2-summary {
  margin: 10px 0 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
}

.analytics-section2-visual {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 14px;
  margin-bottom: 8px;
  min-width: 0;
}

.analytics-section2-panel {
  flex: 0 1 240px;
  min-width: min(100%, 200px);
  max-width: 100%;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-subtle-bg);
}

@media (max-width: 680px) {
  .analytics-section2-panel,
  .analytics-profile-host {
    flex: 1 1 100%;
    width: 100%;
  }
}

.analytics-profile-host {
  flex: 1 1 420px;
  min-width: 0;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}

.analytics-profile-host .analytics-profile-plot {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.analytics-hour-filter {
  width: 100%;
  margin: 0 0 14px;
}

.analytics-section2-kpi-title {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--muted);
  text-transform: uppercase;
}

.analytics-kpi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.analytics-kpi-table th,
.analytics-kpi-table td {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: baseline;
}

.analytics-kpi-table tr:last-child th,
.analytics-kpi-table tr:last-child td {
  border-bottom: none;
}

.analytics-kpi-table th {
  padding-right: 12px;
  font-weight: 600;
  text-align: left;
  color: var(--muted);
  line-height: 1.3;
}

.analytics-kpi-label-row {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.analytics-kpi-hint-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.analytics-kpi-hint {
  width: 14px;
  height: 14px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  cursor: help;
}

.analytics-kpi-hint:hover,
.analytics-kpi-hint:focus-visible {
  color: var(--text);
  border-color: var(--accent);
  outline: none;
}

.analytics-kpi-hint-tip {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 30;
  width: max-content;
  max-width: min(240px, 70vw);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--tooltip-bg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 500;
  font-style: normal;
  line-height: 1.4;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease, visibility 0.12s ease;
}

.analytics-kpi-hint-wrap:hover .analytics-kpi-hint-tip,
.analytics-kpi-hint-wrap:focus-within .analytics-kpi-hint-tip {
  opacity: 1;
  visibility: visible;
}

.analytics-kpi-table td {
  text-align: left;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
}

.analytics-kpi-empty {
  padding: 12px 0 !important;
  text-align: center !important;
  color: var(--muted);
  font-weight: 500;
}

.analytics-profile-plot .plot-canvas-wrap {
  flex: 1 1 auto;
  min-height: 360px;
  position: relative;
}

.analytics-profile-plot .plot-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
}

.analytics-profile-legend {
  margin-top: 8px;
}

.analytics-axis-title {
  font-size: 10px;
  fill: var(--muted);
  font-weight: 600;
}

.analytics-unit {
  font-weight: 500;
  font-size: 0.72em;
  color: var(--muted);
}

.analytics-scroll-table {
  min-width: 0;
  max-width: 100%;
}

.analytics-scroll-table-meta {
  margin: 0 0 8px;
  text-align: right;
}

.analytics-page .strategy-table-split {
  margin-top: 0;
}

.analytics-scroll-table col.analytics-col-month,
.analytics-scroll-table th.analytics-col-month,
.analytics-scroll-table td.analytics-col-month {
  white-space: nowrap;
  text-align: left;
  min-width: 7rem;
}

.analytics-scroll-table col.analytics-col-time,
.analytics-scroll-table th.analytics-col-time,
.analytics-scroll-table td.analytics-col-time {
  white-space: nowrap;
  text-align: left;
  min-width: 5.5rem;
}

/* --- Strategy tester --- */
.strategy-page {
  gap: 14px;
  min-width: 0;
}

.strategy-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0;
  min-width: 0;
}

.strategy-mode-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex: 0 0 auto;
}

.strategy-mode-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.strategy-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius, 8px);
  background: var(--surface);
  color: var(--field-input-text);
  border: 1px solid var(--border-strong);
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.strategy-mode-btn:hover {
  border-color: var(--accent);
}

.strategy-mode-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.strategy-panels {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  width: 100%;
  margin: 0;
}

.strategy-panels-bess {
  grid-template-columns:
    minmax(280px, 420px)
    minmax(280px, 420px)
    minmax(24rem, 1fr);
  align-items: stretch;
  gap: 12px;
}

@media (max-width: 1280px) {
  .strategy-panels-bess {
    grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  }

  .strategy-panels-bess-kpi {
    grid-column: 1 / -1;
  }
}

.strategy-panels-bess > .strategy-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.strategy-panels-bess-left,
.strategy-panels-bess-mid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
  align-self: stretch;
  height: 100%;
}

.strategy-panels-bess-kpi {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
  align-items: stretch;
  align-self: stretch;
  height: 100%;
}

.strategy-panels-bess-kpi > .strategy-card {
  /* Share column height by KPI row count so field rows stay equal height. */
  flex: var(--kpi-rows, 1) 1 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
}

.strategy-panels-bess-left > .strategy-card,
.strategy-panels-bess-mid > .strategy-card,
.strategy-panels-bess-kpi > .strategy-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.strategy-panels-bess-mid > .strategy-card-strategy-params {
  flex: 0 0 auto;
}

.strategy-panels-bess-mid > .strategy-card-soc-plot {
  flex: 1 1 0;
  min-height: 14rem;
  overflow: hidden;
}

.strategy-card-soc-plot .strategy-card-head {
  flex: 0 0 auto;
}

.strategy-card-head-soc {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.strategy-soc-day-stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.strategy-soc-day-btn {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-subtle-bg, transparent);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.strategy-soc-day-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.strategy-soc-day-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.strategy-soc-day-select {
  min-width: 0;
  max-width: 9.5rem;
  height: 1.75rem;
  padding: 0 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--field-input-text);
  font-size: 0.8rem;
  color-scheme: inherit;
}

.strategy-soc-day-select option {
  background: var(--surface);
  color: var(--field-input-text);
}

.strategy-soc-plot {
  position: relative;
  flex: 1 1 0;
  min-height: 12rem;
  width: 100%;
  align-self: stretch;
}

.strategy-soc-plot-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.strategy-soc-plot-frame {
  fill: var(--panel-subtle-bg, rgba(0, 0, 0, 0.03));
  stroke: var(--border);
  stroke-width: 1;
}

.strategy-soc-plot-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-opacity: 0.55;
  stroke-dasharray: 3 3;
}

.strategy-soc-plot-area {
  fill: color-mix(in srgb, var(--accent) 18%, transparent);
  stroke: none;
}

.strategy-soc-plot-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.strategy-soc-plot-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: inherit;
}

.strategy-card-soc-plot > .strategy-empty {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 8rem;
}

.strategy-param-toggle-only {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto;
  align-items: center;
  gap: 8px;
}

.strategy-param-toggle-only .strategy-param-label {
  grid-column: 1;
  margin: 0;
}

.strategy-param-toggle-only .strategy-toggle {
  grid-column: 2;
  justify-self: end;
}

.strategy-param-dual-toggle {
  grid-template-rows: auto auto;
  grid-template-columns: 1fr;
  align-content: center;
  gap: 10px;
}

.strategy-param-toggle-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
}

.strategy-param-toggle-label {
  font-size: 0.78rem;
  line-height: 1.2;
  color: var(--muted);
}

.strategy-param-dual-toggle .strategy-toggle {
  grid-column: auto;
  grid-row: auto;
  justify-self: end;
}

.strategy-param-soft-sep {
  grid-column: 1 / -1;
  height: 1px;
  margin: 0;
  background: var(--border);
  opacity: 0.55;
}

.strategy-param-toggle-pair-row,
.strategy-param-field-pair-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
  min-width: 0;
}

.strategy-param-toggle-pair-row {
  margin-top: 2px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.strategy-param-field-pair-row > .strategy-param {
  min-width: 0;
}

.strategy-param-toggle-pair-row .strategy-param-toggle-row {
  grid-column: auto;
  min-height: 0;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-subtle-bg);
  box-sizing: border-box;
}

.strategy-card-kpi {
  min-width: 0;
}

.strategy-card-kpi-compact {
  padding: 12px 14px;
}

.strategy-card-kpi-compact .strategy-card-title {
  margin-bottom: 8px;
  font-size: 0.88rem;
}

.strategy-card-kpi-compact .strategy-table-empty {
  font-size: 0.8rem;
}

.strategy-hour-filter {
  min-width: 0;
  margin: 2px 0 4px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.strategy-hour-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.strategy-hour-presets {
  display: flex;
  flex-shrink: 0;
  gap: 4px;
  padding-right: 8px;
  border-right: 1px solid var(--border);
}

.strategy-hour-preset {
  height: 1.65rem;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--field-label);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.strategy-hour-preset:hover {
  background: var(--hour-preset-hover);
}

.strategy-hour-preset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.strategy-hour-digits {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
}

.strategy-hour-btn {
  flex: 1 1 0;
  min-width: 1.75rem;
  height: 1.65rem;
  padding: 0 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--hour-preset-bg);
  color: var(--muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.strategy-hour-btn:hover {
  background: var(--hour-preset-hover);
  color: var(--field-label);
}

.strategy-hour-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.strategy-hour-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.strategy-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.strategy-apply-button {
  height: 1.75rem;
  padding: 0 10px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.strategy-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.strategy-card-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.strategy-apply-hint {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.2;
  color: var(--muted);
  white-space: nowrap;
}

.strategy-apply-hint.error {
  color: var(--negative);
  white-space: normal;
  text-align: right;
}

.strategy-card-head .strategy-card-title {
  margin-bottom: 0;
}

.strategy-card-title {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--accent);
}

.strategy-param-label .strategy-param-note {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.72rem;
}

.strategy-param input.strategy-param-syncable {
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.strategy-param input.strategy-param-syncable.is-synced-flash {
  background-color: color-mix(in srgb, var(--accent-action) 50%, var(--surface)) !important;
  border-color: var(--accent-action) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-action) 45%, transparent);
}

.strategy-param-field-pair-row.is-grid-max-synced {
  border-radius: 8px;
  outline: 2px solid var(--accent-action);
  outline-offset: 3px;
  transition: outline-color 0.2s ease;
}

.strategy-params,
.strategy-kpi-grid {
  flex: 1;
  display: grid;
  gap: 10px;
}

.strategy-params {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(3.65rem, auto);
  align-content: start;
}

.strategy-params-fill {
  align-content: start;
  grid-auto-rows: minmax(3.65rem, auto);
}

/**
 * BESS: equal-height panel cards, but param rows keep natural height (same as PV/GM).
 */
.strategy-panels-bess .strategy-params-fill {
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
  grid-auto-rows: auto;
}

.strategy-panels-bess .strategy-kpi-grid.strategy-kpi-grid-bess,
.strategy-panels-bess .strategy-kpi-grid.strategy-kpi-grid-pv {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  align-content: stretch;
  grid-auto-rows: 1fr;
}

.strategy-panels-bess .strategy-params-fill > .strategy-param-toggle-pair-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: auto;
  min-height: 0;
  height: auto;
  align-content: center;
  align-self: start;
}

.strategy-panels-bess .strategy-params-fill > .strategy-param.strategy-param-eff-group {
  min-height: 3.65rem;
}

.strategy-panels-bess .strategy-params-fill > .strategy-param,
.strategy-panels-bess .strategy-params-fill > .strategy-param-pair-group {
  min-height: 3.65rem;
  height: auto;
  align-content: start;
  grid-template-rows: auto auto;
}

.strategy-panels-bess .strategy-params-fill > .strategy-param-field-pair-row {
  min-height: 3.65rem;
  height: auto;
  align-content: start;
  grid-template-rows: auto;
  row-gap: 0;
}

.strategy-panels-bess .strategy-params-fill > .strategy-param.strategy-param-input-bottom {
  grid-template-rows: 1fr auto;
  align-content: stretch;
  height: 100%;
}

.strategy-kpi-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(2.65rem, 1fr);
  align-content: start;
}

.strategy-kpi-grid.strategy-kpi-grid-bess {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: none;
  grid-auto-rows: minmax(2.65rem, 1fr);
  align-content: stretch;
}

.strategy-kpi-grid.strategy-kpi-grid-pv {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: none;
  grid-auto-rows: minmax(2.65rem, 1fr);
  align-content: stretch;
}

.strategy-kpi-plot {
  margin-top: 10px;
  padding: 8px 10px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-subtle-bg);
  width: 100%;
  align-self: stretch;
}

.strategy-kpi-plot-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}

.strategy-kpi-plot-title {
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--accent);
}

.strategy-kpi-plot-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.strategy-kpi-plot-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.78rem;
  color: var(--field-label);
  margin-bottom: 6px;
}

.strategy-kpi-plot-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  margin: 0;
  padding: 2px 4px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.12s ease, background-color 0.12s ease;
}
.strategy-kpi-plot-legend-item:hover {
  background: var(--nav-hover-bg);
}
.strategy-kpi-plot-legend-item.is-off {
  opacity: 0.38;
}
.strategy-kpi-plot-legend-item.is-off .strategy-kpi-plot-swatch {
  background: var(--legend-off-swatch) !important;
}
.strategy-kpi-plot-legend-item.is-off .strategy-kpi-plot-swatch-dashed {
  background: transparent !important;
  border-color: var(--legend-off-swatch) !important;
}

.strategy-kpi-plot-swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.strategy-kpi-plot-swatch-dashed {
  height: 0;
  border-top: 2.5px dashed;
  background: transparent !important;
  border-radius: 0;
}

.strategy-kpi-plot-axis-hint {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.strategy-kpi-plot-svg {
  width: 100%;
  height: 120px;
  display: block;
}

.strategy-kpi-plot-wrap {
  position: relative;
  width: 100%;
}

.strategy-kpi-plot-tooltip {
  position: absolute;
  z-index: 10;
  left: 0;
  top: 0;
  transform: translate(0, 0);
  min-width: 190px;
  max-width: min(280px, 92vw);
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--tooltip-bg);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.strategy-kpi-plot-tooltip-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
  font-size: 0.82rem;
}

.strategy-kpi-plot-tooltip-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--field-label);
  margin: 4px 0;
}

.strategy-kpi-plot-tooltip-swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

.strategy-kpi-plot-tooltip-swatch.strategy-kpi-plot-swatch-dashed {
  height: 0;
  border-top: 2.5px dashed;
  background: transparent !important;
  border-radius: 0;
}

.strategy-kpi-plot-tooltip-value {
  margin-left: auto;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.strategy-param,
.strategy-kpi {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  min-width: 0;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-subtle-bg);
}

.strategy-param {
  grid-template-rows: auto auto;
  align-content: start;
  min-height: 3.65rem;
  height: auto;
  font-size: 0.85rem;
  color: var(--field-label);
}

/** Label on top, input + unit anchored to the bottom of the cell (e.g. price limit). */
.strategy-param.strategy-param-input-bottom {
  grid-template-rows: 1fr auto;
  align-content: stretch;
}

.strategy-param.strategy-param-input-bottom .strategy-param-label {
  align-self: start;
}

.strategy-param.strategy-param-action > button {
  grid-column: 1 / -1;
  align-self: end;
  width: 100%;
  min-height: 1.8rem;
  box-sizing: border-box;
}

.strategy-kpi {
  grid-template-rows: auto 1fr;
  align-content: stretch;
  min-height: 2.35rem;
  height: 100%;
  container-type: inline-size;
  container-name: strategy-kpi;
  padding: 3px 6px;
}

.strategy-param-wide {
  grid-column: 1 / -1;
}

.strategy-param-eff-group {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto;
  gap: 6px;
}

.strategy-param-eff-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.strategy-param-pair-fields {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.strategy-param-pair-fields > .strategy-param-eff-field:not(.strategy-param-eff-field-correction):not(.strategy-param-eff-field-sensitivity) {
  flex: 1 1 6rem;
  min-width: 0;
}

.strategy-param-pair-fields > .strategy-param-eff-field-sensitivity {
  flex: 0 0 5.25rem;
  width: 5.25rem;
  max-width: 5.25rem;
}

.strategy-param-pair-fields > .strategy-param-eff-field-correction {
  flex: 0 0 4.75rem;
  width: 4.75rem;
  max-width: 4.75rem;
}

.strategy-param-group-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.strategy-param-pair-group {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto;
  gap: 6px;
}

.strategy-param-eff-field {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 6px;
  min-width: 0;
  color: var(--field-label);
}

.strategy-param-eff-field-label {
  grid-column: 1 / -1;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--muted);
}

.strategy-param-eff-field input,
.strategy-param-eff-field select {
  grid-column: 1;
  width: 100%;
  min-width: 0;
  height: 1.8rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0 8px;
  font: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--field-input-text);
}

.strategy-param-eff-field input:disabled,
.strategy-param-eff-field select:disabled {
  cursor: not-allowed;
  background: var(--hour-preset-bg);
  color: var(--muted);
}

.strategy-param-eff-field .strategy-param-unit {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
  justify-self: end;
  margin-bottom: 0;
}

/* Percent hybrid field: fill = drag slider, click/focus to type. */
.strategy-param .strategy-param-pct-field,
.strategy-param-eff-field .strategy-param-pct-field {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  height: 1.8rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
  cursor: ew-resize;
  touch-action: none;
  user-select: none;
  box-sizing: border-box;
}

.strategy-param .strategy-param-pct-field {
  grid-column: 1 / -1;
  align-self: end;
}

.strategy-param:has(.strategy-param-unit) .strategy-param-pct-field {
  grid-column: 1;
}

.strategy-param-eff-field .strategy-param-pct-field {
  grid-column: 1;
  grid-row: 2;
}

.strategy-param-pct-field::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: clamp(0%, calc(var(--pct, 0) * 1%), 100%);
  background: color-mix(in srgb, var(--accent-action) 26%, transparent);
  pointer-events: none;
}

.strategy-param-pct-field.is-editing {
  cursor: text;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-action) 35%, transparent);
}

.strategy-param-pct-field.is-disabled {
  cursor: not-allowed;
  background: var(--hour-preset-bg);
}

.strategy-param-pct-field input[type="number"] {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  border: none !important;
  border-radius: 0;
  padding: 0 8px;
  background: transparent !important;
  font: inherit;
  font-size: 0.9rem;
  color: var(--field-input-text);
  box-shadow: none;
  align-self: stretch;
  -moz-appearance: textfield;
  appearance: textfield;
}

.strategy-param-pct-field input[type="number"]::-webkit-outer-spin-button,
.strategy-param-pct-field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.strategy-param-pct-field input[type="number"]:disabled {
  cursor: not-allowed;
  color: var(--muted);
  background: transparent !important;
}

.strategy-param-pct-field input[type="number"]:focus {
  outline: none;
}

.strategy-param-rte {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  flex-shrink: 0;
  color: var(--muted);
  line-height: 1.2;
}

.strategy-param-rte-label {
  font-size: 0.72rem;
  font-weight: 600;
}

.strategy-param-rte-value {
  font-size: 0.85rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

.strategy-param-check {
  align-items: center;
}

.strategy-param-check input[type="checkbox"] {
  grid-column: 1 / -1;
  align-self: end;
  justify-self: start;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0 0 0.35rem;
  accent-color: var(--accent);
}

.strategy-param-divert .strategy-param-label {
  grid-column: 1;
  align-self: center;
}

.strategy-toggle {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-self: end;
  align-self: center;
  width: 2.35rem;
  height: 1.25rem;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.strategy-toggle-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.strategy-toggle-ui {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--border-strong);
  border: 1px solid var(--border-strong);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.strategy-toggle-ui::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: calc(1.25rem - 4px);
  height: calc(1.25rem - 4px);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18);
  transition: transform 0.15s ease;
}

.strategy-toggle-input:checked + .strategy-toggle-ui {
  background: var(--accent);
  border-color: var(--accent);
}

.strategy-toggle-input:checked + .strategy-toggle-ui::after {
  transform: translateX(1.05rem);
}

.strategy-toggle-input:focus-visible + .strategy-toggle-ui {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.strategy-toggle-input:disabled + .strategy-toggle-ui {
  opacity: 0.55;
  cursor: not-allowed;
}

.strategy-toggle:has(.strategy-toggle-input:disabled) {
  cursor: not-allowed;
}

.strategy-gm-dropdown {
  position: relative;
  z-index: 30;
  overflow: visible;
}

.strategy-gm-dropdown .dropdown-toggle {
  grid-column: 1 / -1;
  align-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  height: 1.8rem;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1;
  background: var(--surface);
  color: var(--field-input-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strategy-gm-dropdown .dropdown-toggle:disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}

.strategy-gm-dropdown .dropdown-panel {
  width: 100%;
  max-width: none;
}

.strategy-gm-dropdown .dropdown-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.strategy-gm-dropdown .dropdown-option input,
.strategy-gm-dropdown .dropdown-option input[type="checkbox"] {
  grid-column: auto;
  align-self: center;
  width: 0.9rem;
  height: 0.9rem;
  min-width: 0.9rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.strategy-gm-dropdown .dropdown-option span {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}

.strategy-param-label,
.strategy-kpi-label {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  line-height: 1.2;
  color: var(--muted);
}

.strategy-param input:not(.strategy-toggle-input),
.strategy-param select {
  grid-column: 1 / -1;
  align-self: end;
  width: 100%;
  min-width: 0;
  height: 1.8rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0 8px;
  font: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--field-input-text);
}

.strategy-month-fallback {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
  align-self: end;
  width: 100%;
  min-width: 0;
}

.strategy-month-fallback select {
  grid-column: auto;
  width: 100%;
}

.strategy-date-range {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  align-self: end;
  width: 100%;
  min-width: 0;
}

.strategy-date-range input[type="date"] {
  grid-column: auto;
  width: 100%;
  min-width: 0;
}

.strategy-date-range-sep {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
  user-select: none;
}

.strategy-params.is-loading {
  opacity: 0.72;
  pointer-events: none;
}

.strategy-param input:not(.strategy-toggle-input):disabled,
.strategy-param select:disabled {
  cursor: not-allowed;
  background: var(--hour-preset-bg);
  color: var(--muted);
}

.strategy-param-unit {
  grid-column: 2;
  grid-row: 2;
  align-self: end;
  justify-self: end;
  margin-bottom: 0.45rem;
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
}

.strategy-param:has(.strategy-param-unit) input:not(.strategy-toggle-input) {
  grid-column: 1;
  padding-right: 6px;
}

.strategy-kpi-row-pair {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
  min-width: 0;
}

.strategy-kpi-row-trio {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
  min-width: 0;
}

.strategy-kpi-row-quad {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
  min-width: 0;
}

.strategy-kpi-row-pair > .strategy-kpi,
.strategy-kpi-row-trio > .strategy-kpi,
.strategy-kpi-row-quad > .strategy-kpi {
  min-width: 0;
  height: 100%;
}

.strategy-kpi-emphasis {
  background: var(--disabled-bg);
  border-color: var(--border-strong);
}

.strategy-kpi-wide {
  grid-column: 1 / -1;
}

.strategy-kpi-result-span {
  grid-column: 3 / 5;
}

.strategy-kpi-value {
  grid-column: 1;
  grid-row: 2;
  align-self: end;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.25rem;
  color: var(--text);
}

.strategy-kpi-unit {
  grid-column: 2;
  grid-row: 2;
  align-self: end;
  justify-self: end;
  font-size: 0.75rem;
  line-height: 1.25rem;
  color: var(--muted);
  white-space: nowrap;
}

/** Value above unit when the unit string is too long for a side-by-side layout. */
.strategy-kpi.strategy-kpi-unit-below {
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr auto auto;
  align-content: stretch;
}

.strategy-kpi.strategy-kpi-unit-below .strategy-kpi-value {
  grid-column: 1;
  grid-row: 3;
  align-self: end;
}

.strategy-kpi.strategy-kpi-unit-below .strategy-kpi-unit {
  grid-column: 1;
  grid-row: 4;
  justify-self: start;
  align-self: start;
  line-height: 1.1;
  margin-top: 1px;
}

@container strategy-kpi (max-width: 9.5rem) {
  .strategy-kpi:not(.strategy-kpi-unit-below) {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
    align-content: stretch;
  }

  .strategy-kpi:not(.strategy-kpi-unit-below) .strategy-kpi-value {
    grid-column: 1;
    grid-row: 3;
    align-self: end;
  }

  .strategy-kpi:not(.strategy-kpi-unit-below) .strategy-kpi-unit {
    grid-column: 1;
    grid-row: 4;
    justify-self: start;
    align-self: start;
    line-height: 1.1;
    margin-top: 1px;
  }
}

.strategy-kpi-value.is-positive,
.strategy-table .is-positive {
  color: var(--positive);
}

.strategy-kpi-value.is-negative,
.strategy-table .is-negative {
  color: var(--negative);
}

.strategy-status {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.strategy-status.error {
  color: var(--negative);
}

.strategy-table-card {
  min-width: 0;
  max-width: 100%;
  padding-bottom: 10px;
}

.strategy-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.strategy-table-header-main {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.strategy-table-column-dropdown {
  flex-shrink: 0;
  margin: 0;
}

.strategy-table-column-dropdown .dropdown-toggle {
  min-width: 0;
  font-size: 0.8rem;
  padding: 6px 10px;
  text-align: right;
  white-space: nowrap;
}

.strategy-table-column-dropdown .dropdown-panel {
  left: auto;
  right: 0;
  width: min(360px, calc(100vw - 32px));
  min-width: 220px;
}

.strategy-table-header .strategy-card-title {
  margin-bottom: 0;
}

.strategy-table-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.strategy-table-family-legend {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.strategy-table-family-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.strategy-table-family-swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.strategy-table-family-legend-item.is-bess .strategy-table-family-swatch,
.strategy-table-family-swatch.is-bess {
  background: color-mix(in srgb, #0f766e 45%, var(--panel-subtle-bg));
  border: 1px solid color-mix(in srgb, #0f766e 55%, transparent);
}

.strategy-table-family-legend-item.is-pv .strategy-table-family-swatch,
.strategy-table-family-swatch.is-pv {
  background: color-mix(in srgb, #b45309 45%, var(--panel-subtle-bg));
  border: 1px solid color-mix(in srgb, #b45309 55%, transparent);
}

.strategy-table-family-swatch.is-inline {
  display: inline-block;
  vertical-align: middle;
  margin-right: 2px;
}

:root[data-theme="dark"] .strategy-table-family-legend-item.is-bess .strategy-table-family-swatch,
:root[data-theme="dark"] .strategy-table-family-swatch.is-bess {
  background: color-mix(in srgb, #2dd4bf 45%, var(--panel-subtle-bg));
  border-color: color-mix(in srgb, #2dd4bf 55%, transparent);
}

:root[data-theme="dark"] .strategy-table-family-legend-item.is-pv .strategy-table-family-swatch,
:root[data-theme="dark"] .strategy-table-family-swatch.is-pv {
  background: color-mix(in srgb, #fbbf24 45%, var(--panel-subtle-bg));
  border-color: color-mix(in srgb, #fbbf24 55%, transparent);
}

/* --- MKp loader --- */
.mkp-params {
  width: 100%;
  margin: 0 0 8px;
  padding: 10px 14px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  box-sizing: border-box;
}

.mkp-params-title {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
}

.mkp-params-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px 12px;
  width: 100%;
}

.mkp-type-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding-bottom: 2px;
}

.mkp-type-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  background: var(--surface);
  color: var(--field-input-text);
  border: 1px solid var(--border-strong);
}

.mkp-type-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.mkp-type-count {
  display: inline-flex;
  min-width: 1.5rem;
  justify-content: center;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: color-mix(in srgb, currentColor 16%, transparent);
}

.mkp-field-month {
  width: 11.5rem;
  flex: 0 0 auto;
}

.mkp-month-fallback {
  grid-column: auto;
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.mkp-field-month input[type="month"] {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: var(--surface);
  color: var(--field-input-text);
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.mkp-field-asset {
  flex: 1 1 220px;
  min-width: 180px;
  max-width: 100%;
}

.mkp-checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 1px;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}

.mkp-checkbox-row input {
  margin: 0;
  accent-color: var(--accent);
}

.mkp-preview-card {
  width: 100%;
  margin-top: 0;
}

.mkp-page .strategy-status {
  margin: 0 0 6px;
}

.page.mkp-page {
  gap: 8px;
}

.mkp-placeholder {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.mkp-asset-preview {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.mkp-asset-preview ul {
  margin: 4px 0 0;
  padding-left: 1.2rem;
}

.mkp-muted {
  color: var(--muted);
}

.mkp-table-split .strategy-table th.strategy-col-value,
.mkp-table-split .strategy-table td.strategy-col-value {
  overflow: hidden;
  text-overflow: ellipsis;
}

.strategy-table-split {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.strategy-table-split.is-frozen-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.strategy-table-pane-row {
  display: flex;
  align-items: stretch;
  min-width: 0;
  width: 100%;
}

.strategy-table-frozen {
  flex: 0 0 auto;
  z-index: 4;
  overflow: hidden;
  background: var(--panel-subtle-bg);
  box-shadow: 1px 0 0 var(--border);
}

.strategy-table-frozen .strategy-table {
  width: auto;
  min-width: 0 !important;
  max-width: 100%;
  table-layout: fixed;
}

.strategy-table-body-scroller .strategy-table-frozen {
  background: var(--surface);
}

.strategy-table-split.is-frozen-pane .strategy-table-scroll {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
}

.strategy-table-head-spacer {
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.strategy-table-head-scroller {
  z-index: 20;
  overflow: visible;
  background: var(--panel-subtle-bg);
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
}

.strategy-table-split.is-frozen-pane .strategy-table-head-scroller {
  overflow: hidden;
}

.strategy-table-head-scroller.is-pinned {
  position: fixed;
  top: 0;
  z-index: 100;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
  border-radius: 0;
  box-shadow: var(--shadow);
}

.strategy-table-split.is-frozen-pane .strategy-table-head-scroller.is-pinned {
  overflow: hidden;
}

.strategy-table-head-scroller.is-pinned::-webkit-scrollbar {
  display: none;
}

.strategy-table-split.is-frozen-pane .strategy-table-head-scroller .strategy-table-scroll {
  scrollbar-width: none;
}

.strategy-table-split.is-frozen-pane .strategy-table-head-scroller .strategy-table-scroll::-webkit-scrollbar {
  display: none;
}

.strategy-table-body-scroller {
  overflow: visible;
  border-radius: 0 0 8px 8px;
}

.strategy-table-split.is-frozen-pane .strategy-table-body-scroller {
  overflow: hidden;
}

.strategy-table {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  width: 100%;
}

.strategy-table-body,
.strategy-table-head {
  width: 100%;
  min-width: 100%;
}

.strategy-col-period {
  white-space: nowrap;
  min-width: 7rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strategy-col-value,
.strategy-table thead th:not(:first-child),
.strategy-table tbody td:not(:first-child) {
  min-width: 96px;
}

.strategy-table thead th,
.strategy-table tbody td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.strategy-table th,
.strategy-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.strategy-table-head th {
  background: var(--panel-subtle-bg);
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  box-shadow: inset 0 -1px 0 var(--border);
}

/* Legacy single-table sticky first column (analytics / non dual-pane). */
.strategy-table-split:not(.is-frozen-pane) .strategy-table-head th:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  text-align: left;
  background: var(--panel-subtle-bg);
  box-shadow: inset -1px 0 0 var(--border), inset 0 -1px 0 var(--border);
}

.strategy-table-split:not(.is-frozen-pane) .strategy-table-head-scroller.is-pinned .strategy-table-head th:first-child {
  z-index: 101;
}

.strategy-table th:first-child,
.strategy-table td:first-child,
.strategy-table .strategy-col-period {
  text-align: left;
}

.strategy-table-split:not(.is-frozen-pane) .strategy-table-body td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: inset -1px 0 0 var(--border);
}

.strategy-table-frozen .strategy-table-head th,
.strategy-table-frozen .strategy-table-body td {
  text-align: left;
  background: var(--panel-subtle-bg);
  box-shadow: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-table-frozen .strategy-table-head th {
  /* Keep long period header labels inside the frozen column width. */
  max-width: 100%;
}

.strategy-cell-clip {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.strategy-table-body-scroller .strategy-table-frozen .strategy-table-body td {
  background: var(--surface);
}

.strategy-table tbody tr:nth-child(even) td {
  background: var(--panel-subtle-bg-alt);
}

.strategy-table-split:not(.is-frozen-pane) tbody tr:nth-child(even) td:first-child {
  background: var(--panel-subtle-bg-alt);
}

.strategy-table-virt tbody tr:nth-child(even) td,
.strategy-table-split:not(.is-frozen-pane) .strategy-table-virt tbody tr:nth-child(even) td:first-child {
  background: transparent;
}

.strategy-table-virt tbody tr.strategy-virt-row.is-even td {
  background: var(--panel-subtle-bg-alt);
}

.strategy-table-split:not(.is-frozen-pane) .strategy-table-virt tbody tr.strategy-virt-row.is-even td:first-child,
.strategy-table-body-scroller .strategy-table-frozen .strategy-table-virt tbody tr.strategy-virt-row.is-even td {
  background: var(--panel-subtle-bg-alt);
}

.strategy-table-virt tbody tr.strategy-virt-row td {
  height: 29px;
  max-height: 29px;
  box-sizing: border-box;
}

/* BESS table: tint BESS / PV columns only after production upload */
.strategy-table.is-col-families thead th.strategy-col-family-bess {
  background: color-mix(in srgb, #0f766e 16%, var(--panel-subtle-bg));
  color: color-mix(in srgb, #0f766e 55%, var(--muted));
  box-shadow: inset 0 -2px 0 color-mix(in srgb, #0f766e 45%, transparent),
    inset 0 -1px 0 var(--border);
}

.strategy-table.is-col-families thead th.strategy-col-family-pv {
  background: color-mix(in srgb, #b45309 16%, var(--panel-subtle-bg));
  color: color-mix(in srgb, #b45309 55%, var(--muted));
  box-shadow: inset 0 -2px 0 color-mix(in srgb, #b45309 45%, transparent),
    inset 0 -1px 0 var(--border);
}

.strategy-table.is-col-families tbody td.strategy-col-family-bess {
  background: color-mix(in srgb, #0f766e 8%, var(--surface));
}

.strategy-table.is-col-families tbody td.strategy-col-family-pv {
  background: color-mix(in srgb, #b45309 8%, var(--surface));
}

.strategy-table.is-col-families.strategy-table-virt tbody tr.strategy-virt-row.is-even td.strategy-col-family-bess {
  background: color-mix(in srgb, #0f766e 14%, var(--panel-subtle-bg-alt));
}

.strategy-table.is-col-families.strategy-table-virt tbody tr.strategy-virt-row.is-even td.strategy-col-family-pv {
  background: color-mix(in srgb, #b45309 14%, var(--panel-subtle-bg-alt));
}

:root[data-theme="dark"] .strategy-table.is-col-families thead th.strategy-col-family-bess {
  background: color-mix(in srgb, #2dd4bf 18%, var(--panel-subtle-bg));
  color: color-mix(in srgb, #99f6e4 40%, var(--muted));
}

:root[data-theme="dark"] .strategy-table.is-col-families thead th.strategy-col-family-pv {
  background: color-mix(in srgb, #fbbf24 16%, var(--panel-subtle-bg));
  color: color-mix(in srgb, #fde68a 40%, var(--muted));
}

:root[data-theme="dark"] .strategy-table.is-col-families tbody td.strategy-col-family-bess {
  background: color-mix(in srgb, #2dd4bf 10%, var(--surface));
}

:root[data-theme="dark"] .strategy-table.is-col-families tbody td.strategy-col-family-pv {
  background: color-mix(in srgb, #fbbf24 10%, var(--surface));
}

:root[data-theme="dark"] .strategy-table.is-col-families.strategy-table-virt tbody tr.strategy-virt-row.is-even td.strategy-col-family-bess {
  background: color-mix(in srgb, #2dd4bf 14%, var(--panel-subtle-bg-alt));
}

:root[data-theme="dark"] .strategy-table.is-col-families.strategy-table-virt tbody tr.strategy-virt-row.is-even td.strategy-col-family-pv {
  background: color-mix(in srgb, #fbbf24 14%, var(--panel-subtle-bg-alt));
}

.strategy-table-virt tbody tr.virt-spacer td {
  position: static !important;
  z-index: auto !important;
  padding: 0 !important;
  border: none !important;
  line-height: 0;
  background: transparent !important;
  box-shadow: none !important;
}

.strategy-table-empty {
  text-align: center !important;
  color: var(--muted);
  padding: 18px 8px !important;
}

/* --- Responsive tweaks (narrow screens) --- */
@media (max-width: 900px) {
  .page {
    padding: 12px;
  }

  .brand-row {
    width: 100%;
  }

  .actions,
  .toolbar-window,
  .toolbar-mol {
    width: 100%;
  }

  .field input {
    width: 100%;
  }

  .column-dropdown {
    width: 100%;
  }

  .dropdown-toggle {
    width: 100%;
    min-width: 0;
  }

  .dropdown-panel {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
  }

  .strategy-panels {
    grid-template-columns: 1fr;
  }

  .strategy-panels-bess {
    grid-template-columns: 1fr;
  }

  .strategy-panels-bess-kpi {
    grid-column: 1 / -1;
  }

  .strategy-panels-bess .strategy-kpi-grid.strategy-kpi-grid-bess {
    grid-template-rows: none;
    grid-auto-rows: minmax(2.65rem, auto);
  }

  .strategy-panels-bess .strategy-kpi-grid.strategy-kpi-grid-pv {
    grid-template-rows: none;
    grid-auto-rows: minmax(2.65rem, auto);
  }

  .strategy-panels-bess .strategy-params-fill > .strategy-param,
  .strategy-panels-bess .strategy-params-fill > .strategy-param-pair-group {
    height: auto;
  }

  .strategy-params,
  .strategy-kpi-grid:not(.strategy-kpi-grid-bess):not(.strategy-kpi-grid-pv) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mkp-params-row {
    align-items: stretch;
  }

  .mkp-field-month,
  .mkp-field-asset {
    flex: 1 1 100%;
    width: auto;
    max-width: none;
  }

  .mkp-month-fallback {
    width: 100%;
  }

  .mkp-type-tabs {
    width: 100%;
  }

  .strategy-kpi-wide,
  .strategy-kpi-result-span {
    grid-column: 1 / -1;
  }

  :root {
    --grid-metric-width: 200px;
    --grid-col-width: 88px;
  }
}

/* --- Site password gate (/login) --- */
.login-page {
  min-height: 100vh;
  box-sizing: border-box;
  position: relative;
}

.login-theme-bar {
  display: flex;
  justify-content: flex-end;
}

.login-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 8px 0 48px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.login-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

:root[data-theme="dark"] .login-logo {
  filter: invert(1) brightness(1.6);
}

.login-title {
  margin: 0;
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text);
}

.login-card {
  width: min(100%, 22rem);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px 22px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-heading {
  margin: 0;
  font-size: 1.15rem;
  color: var(--text);
}

.login-hint {
  margin: -4px 0 4px;
  font-size: 0.88rem;
  color: var(--muted);
}

.login-field {
  width: 100%;
}

.login-field input {
  width: 100%;
  box-sizing: border-box;
}

.login-error {
  margin: 0;
  font-size: 0.88rem;
  color: var(--negative);
}

.login-card > button[type="submit"] {
  width: 100%;
  margin-top: 4px;
}

.strategy-monthly-kpi-card {
  min-width: 0;
  max-width: 100%;
  margin-top: 4px;
  padding-top: 10px;
  padding-bottom: 10px;
  gap: 6px;
}

.strategy-monthly-kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.strategy-monthly-kpi-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.strategy-monthly-kpi-toggle:hover .strategy-card-title {
  color: var(--accent);
}

.strategy-monthly-kpi-toggle .strategy-card-title {
  margin: 0;
}

.strategy-monthly-kpi-chevron {
  flex-shrink: 0;
  width: 0.55rem;
  height: 0.55rem;
  margin-left: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.strategy-monthly-kpi-card.is-collapsed .strategy-monthly-kpi-chevron {
  transform: rotate(-45deg);
}

.strategy-monthly-kpi-scroll {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.strategy-monthly-kpi-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
}

.strategy-monthly-kpi-table th,
.strategy-monthly-kpi-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}

.strategy-monthly-kpi-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  font-weight: 600;
  text-align: right;
  color: var(--muted);
  border-bottom: 1px solid var(--border-strong);
}

.strategy-monthly-kpi-table thead th.strategy-monthly-kpi-month,
.strategy-monthly-kpi-table tbody th.strategy-monthly-kpi-month {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  background: var(--surface);
  font-weight: 600;
  color: var(--text);
  box-shadow: 1px 0 0 var(--border);
}

.strategy-monthly-kpi-table thead th.strategy-monthly-kpi-month {
  z-index: 3;
}

.strategy-monthly-kpi-table tbody td {
  text-align: right;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
}

.strategy-monthly-kpi-table tbody tr:nth-child(even) td,
.strategy-monthly-kpi-table tbody tr:nth-child(even) th.strategy-monthly-kpi-month {
  background: color-mix(in srgb, var(--muted) 6%, var(--surface));
}

.strategy-monthly-kpi-table tbody tr:last-child th,
.strategy-monthly-kpi-table tbody tr:last-child td {
  border-bottom: none;
}

.strategy-monthly-kpi-unit {
  display: block;
  margin-top: 2px;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
}

.strategy-monthly-kpi-table.is-col-families thead th.strategy-col-family-bess {
  box-shadow: inset 0 -2px 0 color-mix(in srgb, #0f766e 55%, transparent);
}

.strategy-monthly-kpi-table.is-col-families thead th.strategy-col-family-pv {
  box-shadow: inset 0 -2px 0 color-mix(in srgb, #b45309 55%, transparent);
}

.strategy-monthly-kpi-table.is-col-families tbody td.strategy-col-family-bess {
  background: color-mix(in srgb, #0f766e 6%, var(--surface));
}

.strategy-monthly-kpi-table.is-col-families tbody td.strategy-col-family-pv {
  background: color-mix(in srgb, #b45309 6%, var(--surface));
}

.strategy-monthly-kpi-table.is-col-families tbody tr:nth-child(even) td.strategy-col-family-bess {
  background: color-mix(in srgb, #0f766e 10%, var(--surface));
}

.strategy-monthly-kpi-table.is-col-families tbody tr:nth-child(even) td.strategy-col-family-pv {
  background: color-mix(in srgb, #b45309 10%, var(--surface));
}

:root[data-theme="dark"] .strategy-monthly-kpi-table.is-col-families thead th.strategy-col-family-bess {
  box-shadow: inset 0 -2px 0 color-mix(in srgb, #2dd4bf 50%, transparent);
}

:root[data-theme="dark"] .strategy-monthly-kpi-table.is-col-families thead th.strategy-col-family-pv {
  box-shadow: inset 0 -2px 0 color-mix(in srgb, #fbbf24 50%, transparent);
}

:root[data-theme="dark"] .strategy-monthly-kpi-table.is-col-families tbody td.strategy-col-family-bess {
  background: color-mix(in srgb, #2dd4bf 8%, var(--surface));
}

:root[data-theme="dark"] .strategy-monthly-kpi-table.is-col-families tbody td.strategy-col-family-pv {
  background: color-mix(in srgb, #fbbf24 8%, var(--surface));
}

:root[data-theme="dark"] .strategy-monthly-kpi-table.is-col-families tbody tr:nth-child(even) td.strategy-col-family-bess {
  background: color-mix(in srgb, #2dd4bf 12%, var(--surface));
}

:root[data-theme="dark"] .strategy-monthly-kpi-table.is-col-families tbody tr:nth-child(even) td.strategy-col-family-pv {
  background: color-mix(in srgb, #fbbf24 12%, var(--surface));
}

@media (prefers-reduced-motion: reduce) {
  .status-bar.is-refreshing::before {
    animation: none;
    border-top-color: var(--border);
  }

  .strategy-param input.strategy-param-syncable {
    transition: none;
  }
}
