/* Modern EMS Dashboard Styles */

:root {
  color-scheme: dark;
  /* === Brand colors === */
  --primary:        #60a5fa;
  --primary-rgb:    96, 165, 250;
  --primary-hover:  #93c5fd;
  --primary-action: #2563eb;
  --primary-action-hover: #1d4ed8;
  --primary-light:  #dbeafe;
  --primary-soft:   rgba(var(--primary-rgb), 0.12);
  --primary-border: rgba(var(--primary-rgb), 0.32);
  --primary-dim:    var(--primary-soft); /* alias for primary-soft */
  --solar-panel:      #3b82f6;
  --solar-panel-dark: #2563eb;

  --accent:        #10b981;

  /* === Backgrounds === */
  --bg-page:      #101a2a;
  --bg-surface:   #16212f;
  --bg-card:      #16212f;
  --bg-card-soft: #131d2b;
  --bg-inset:     rgba(8, 13, 24, 0.55);
  --bg-elevated:  #1e2d42;
  --bg-overlay:   rgba(15, 23, 42, 0.88);
  --bg-input: #0f172a;
  --bg-control: var(--bg-input);
  --bg-passive: var(--bg-input);
  --bg-chart: transparent;
  --checkbox-size: 15px;

  /* === Borders === */
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border:        #1c2a3d;
  --border-strong: #2a3850;
  --border-focus:  #3b82f6;

  /* === Text === */
  --text-primary:   #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted:     #94a3b8;
  --text-disabled:  #8492a6;
  --text-on-primary: #ffffff;
  --hover:          rgba(148, 163, 184, 0.08);

  /* === Semantic colors === */
  --success:        #10b981;
  --success-rgb:    16, 185, 129;
  --success-text:   #34d399;
  --success-soft:   rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.28);

  --warning:        #f59e0b;
  --warning-rgb:    245, 158, 11;
  --warning-soft:   rgba(245, 158, 11, 0.12);
  --warning-border: rgba(245, 158, 11, 0.28);
  --warning-surface: #332713;

  --danger:        #f87171;
  --danger-rgb:    248, 113, 113;
  --danger-soft:   rgba(248, 113, 113, 0.12);
  --danger-border: rgba(248, 113, 113, 0.32);

  --color-info:     #38bdf8;
  --color-info-dim: rgba(56, 189, 248, 0.12);

  /* === Energy flow colors === */
  --flow-pv:      #10b981;
  --flow-battery: #f59e0b;
  --flow-grid:    #3b82f6;
  --flow-export:  #38bdf8;
  --flow-import:  #E63946;
  --flow-load:    #38bdf8;
  --green:        var(--success);

  /* === Border radius === */
  --radius-xs:   6px;
  --radius-sm:   10px;
  --radius:      12px;
  --radius-md:   14px;
  --radius-lg:   16px;
  --radius-xl:   24px;
  --radius-pill: 999px;

  /* === Shadows === */
  --shadow-card: 0 2px 8px rgba(0,0,0,0.38);
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.45);
  --shadow-lg:   0 10px 28px rgba(0,0,0,0.55);
  --shadow-xl:   0 20px 48px rgba(0,0,0,0.65);

  /* === Spacing scale === */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  /* === Shared layout and controls === */
  --content-standard: 1600px;
  --content-wide: 1600px;
  --content-gutter: clamp(16px, 2.2vw, 32px);
  --control-height-sm: 32px;
  --control-height: 40px;

  /* === Transitions === */
  --transition-fast: 0.1s ease;
  --transition-base: 0.18s ease;

  /* === Typography === */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg-page);
}

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

:where(button, a, input, select, textarea, summary, [tabindex="0"]):focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Sidebar */
.sidebar {
  width: 244px;
  flex: 0 0 244px;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  background: rgba(15, 23, 42, 0.98);
  border-right: 1px solid var(--border);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
  padding: 1.5rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  align-self: flex-start;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

.sidebar[data-nav-loading="true"] {
  visibility: hidden;
}

@media (min-width: 769px) {
  #nav-slot {
    flex: 0 0 244px;
  }
  #nav-slot:has(.sidebar.collapsed) {
    flex-basis: 72px;
  }
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}

.sidebar-toggle-wrap {
  padding: 0 0.4rem 0.25rem;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

.brand-logo {
  height: 38px;
  width: 38px;
  object-fit: contain;
  display: block;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 1.1rem;
  color: var(--text-primary);
  line-height: 1.05;
}

.brand-name span {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.view-toggle {
  padding: 0.25rem;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  display: flex;
}

.mode-pill {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: 600 0.8rem var(--font-sans);
  padding: 0.4rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.mode-pill[aria-pressed="true"] {
  background: var(--primary-action);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.nav-system-select {
  margin-top: 0.5rem;
}

.nav-system-select select {
  width: 100%;
  padding: 0.4rem 0.6rem;
  background: var(--bg-control);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font: 600 0.8rem var(--font-sans);
  cursor: pointer;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.5rem;
}

.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius);
  transition: background-color 0.12s ease, color 0.12s ease;
  font-weight: 500;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.nav a:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.nav a[data-nav].active {
  background: var(--primary-dim);
  box-shadow: inset 3px 0 0 var(--primary);
  color: var(--text-primary);
}

.nav-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 100%;
  height: 100%;
}

.nav-text {
  white-space: nowrap;
}

.nav-events-link {
  position: relative;
}

.nav-event-badge {
  margin-left: auto;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.38rem;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 3px var(--danger-soft);
  font: 700 0.75rem/1 var(--font-mono);
}

.nav-events-link.has-events .nav-icon {
  color: #ff8a93;
}

.nav-group {
  display: flex;
  flex-direction: column;
}

.chev {
  margin-left: auto;
  opacity: 0.6;
  transition: transform 0.18s ease;
}

.nav-group.open > a .chev {
  transform: rotate(90deg);
}

.nav-sub {
  display: none;
  flex-direction: column;
  gap: 0.05rem;
  padding: 0.15rem 0 0.25rem 2.4rem;
  border-left: 1px dashed var(--border-subtle);
  margin: 0.1rem 0 0.1rem 1.45rem;
}

.nav-group.open .nav-sub {
  display: flex;
}

.nav-sub-link {
  font-size: 0.82rem;
  padding: 0.3rem 0.6rem;
  color: var(--text-muted);
}

.nav-sub-link:hover {
  color: var(--text-primary);
  background: transparent;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding-top: 0.5rem;
}

.logout-btn {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius);
  cursor: pointer;
  font: 500 0.9rem var(--font-sans);
  display: flex;
  align-items: center;
  gap: 0.7rem;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.logout-btn:hover {
  background: rgba(230, 57, 70, 0.08);
  color: #ff8a93;
  border-color: rgba(230, 57, 70, 0.3);
}

.sidebar.collapsed {
  width: 72px;
  padding: 1rem 0.5rem;
  align-items: center;
}

.sidebar.collapsed .sidebar-header {
  width: 100%;
}

.sidebar.collapsed .brand-name,
.sidebar.collapsed .view-toggle,
.sidebar.collapsed .nav-system-select,
.sidebar.collapsed .sidebar-build {
  display: none;
}

.sidebar.collapsed .nav {
  align-items: center;
}

.sidebar.collapsed .nav a {
  justify-content: center;
}

.sidebar.collapsed .nav-group > a {
  justify-content: center;
}

.sidebar.collapsed .chev,
.sidebar.collapsed .nav-sub {
  display: none;
}

.sidebar.collapsed .nav-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sidebar.collapsed .nav-event-badge {
  position: absolute;
  top: 0.12rem;
  right: 0.05rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.2rem;
  font-size: 0.75rem;
}

.sidebar-build {
  padding: 0 0.4rem;
}

.sidebar-build-id {
  color: var(--text-disabled);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.4;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.sidebar.collapsed .sidebar-build {
  display: none;
}

/* Content */
.content {
  flex: 1 1 0;
  min-width: 0;
  padding: var(--space-7) var(--content-gutter) var(--space-8);
  max-width: calc(var(--content-standard) + (2 * var(--content-gutter)));
  width: auto;
  margin: 0 auto;
}

.content--wide {
  max-width: calc(var(--content-wide) + (2 * var(--content-gutter)));
}

.workbench {
  --content-gutter: clamp(12px, 1.5vw, 24px);
  max-width: none;
  font-size: 0.875rem;
}

/* Shared page anatomy */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}

@media (min-width: 769px) {
  .page-header {
    align-items: center;
  }
}

.page-header--surface {
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: none;
}

.page-header__copy {
  min-width: 0;
}

.page-header__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.page-title {
  margin: 0;
  color: var(--text-primary);
  font-size: clamp(1.7rem, 2.5vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.page-subtitle {
  margin: var(--space-2) 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.55;
}

.page-section {
  min-width: 0;
  margin-bottom: var(--space-6);
}

.content > :last-child,
.content > .page-section:last-of-type {
  margin-bottom: 0;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.section-title,
.card-title {
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.section-description {
  margin-top: var(--space-1);
  color: var(--text-muted);
  font-size: 0.84rem;
}

/* EMS Page */

.metric-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.metric-sub {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.panel {
  padding: 1.75rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.panel-title { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }

.range-header { margin-bottom: var(--space-2); }
.range-bar,
.range-custom { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 0.65rem; }

/* Shared by the electricity plan and strategy price charts. */
.price-block-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-2) 0 var(--space-3);
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.price-block-legend-title {
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
}

.price-block-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 1.6rem;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  color: var(--text-primary);
  font-weight: 700;
  white-space: nowrap;
}

.price-block-chip-swatch {
  width: 1.2rem;
  height: 0.26rem;
  border-radius: var(--radius-pill);
  background: var(--block-color, var(--text-muted));
}

.history-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.history-summary-grid > .card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
}

.history-summary-grid > .card > span {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.history-summary-grid > .card > strong {
  margin-top: auto;
  color: var(--text-primary);
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.history-summary-grid > .card > strong.positive { color: var(--success-text); }
.history-summary-grid > .card > strong.negative { color: var(--danger); }

.range-toolbar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-5); }
.range-toolbar > .range-bar { margin-left: auto; }
.range-date-field,
.range-select-field { display: grid; min-width: 0; gap: var(--space-1); }
.range-date-field { width: 10rem; }
.range-date-field--wide { width: 13.75rem; }
.range-select-field { width: 17rem; }
.range-select-field > select { min-width: 0; width: 100%; }
.range-date-field .ems-date-picker,
.range-date-field .ems-date-trigger { min-width: 0; }
.range-date-field > label,
.range-select-field > .label {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.range-step { min-width: var(--control-height); padding-inline: var(--space-2); }

.segmented {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 3px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 0.32rem 0.6rem;
  font: 600 0.78rem var(--font-sans);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  font-variant-numeric: tabular-nums;
}
.segmented button:hover  { color: var(--text-primary); }
.segmented button.active { background: var(--primary-action); color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.5); }

.reset-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font: 500 0.78rem var(--font-sans);
  cursor: pointer;
  padding: 0.32rem 0.55rem;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.reset-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.04); }

.details-block {
  background: rgba(15, 23, 42, 0.4);
  border-radius: var(--radius);
  border: 1px solid rgba(51, 65, 85, 0.5);
  padding: 0.75rem 1rem;
}

.details-block summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.details-block pre {
  margin-top: 0.5rem;
  white-space: pre-wrap;
  color: var(--text-muted);
}

.device-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.device {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  gap: 0.25rem;
  grid-template-columns: 1fr auto;
}

.device[data-tree-depth="1"] { margin-left: 1.5rem; }
.device[data-tree-depth="2"] { margin-left: 3rem; }
.device[data-tree-depth="3"] { margin-left: 4.5rem; }
.device.is-tree-hidden { display: none; }
.device-tree-toggle {
  width: 1.75rem;
  min-width: 1.75rem;
  padding: 0.1rem;
  margin-right: 0.35rem;
}
.device-hierarchy-state {
  color: var(--text-muted);
}

.device small {
  color: var(--text-muted);
}

.device .actions {
  justify-content: flex-end;
  gap: 0.5rem;
}

.btn.tiny {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.device-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  justify-self: end;
  grid-column: 2;
  grid-row: 1;
}

.device-debug {
  display: grid;
  grid-column: 1 / -1;
  margin-top: 0.5rem;
  padding: 0.85rem;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(2, 6, 23, 0.55);
  gap: 0.65rem;
}

.device-debug pre {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.price-curve-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

#price-home-row {
  align-items: end;
}

#price-home-row .form-row {
  justify-content: flex-end;
}

.price-curve {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 6px;
  height: 180px;
  background: var(--bg-chart);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.price-bar {
  background: var(--primary);
  border-radius: 6px;
  align-self: end;
  min-height: 6px;
  cursor: default;
  position: relative;
  transition: height 0.08s ease;
}

.price-bar::after {
  content: attr(data-value);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.price-bar:hover::after {
  opacity: 1;
}

.price-curve-labels {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.battery-glance {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.summary-stat {
  padding: 1rem 1.1rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.5);
  box-shadow: var(--shadow-sm);
}

.summary-stat.info {
  border-color: rgba(59, 130, 246, 0.35);
}

.summary-stat.primary {
  border-color: rgba(16, 185, 129, 0.35);
}

.summary-stat.accent {
  border-color: rgba(245, 158, 11, 0.35);
}

.summary-stat.ok {
  border-color: rgba(16, 185, 129, 0.35);
}

.summary-stat.caution,
.summary-stat.warn {
  border-color: rgba(245, 158, 11, 0.45);
}

.summary-stat.danger {
  border-color: rgba(239, 68, 68, 0.45);
}

.summary-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-value {
  margin-top: 0.45rem;
  font-size: 1.2rem;
  font-weight: 700;
}

.summary-note {
  margin-top: 0.35rem;
  color: var(--text-secondary);
  font-size: 0.84rem;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip-list.compact {
  gap: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.55);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
}

.chip.ok {
  border-color: rgba(46, 196, 182, 0.4);
  background: rgba(46, 196, 182, 0.12);
  color: #9ee8e2;
}

.chip.info {
  border-color: rgba(0, 119, 182, 0.4);
  background: rgba(0, 119, 182, 0.14);
  color: #99d4f0;
}

.chip.primary {
  border-color: rgba(46, 196, 182, 0.4);
  background: rgba(46, 196, 182, 0.12);
  color: #9ee8e2;
}

.chip.caution,
.chip.warn {
  border-color: rgba(255, 176, 0, 0.45);
  background: rgba(255, 176, 0, 0.12);
  color: #ffe099;
}

.chip.danger {
  border-color: rgba(230, 57, 70, 0.45);
  background: rgba(230, 57, 70, 0.12);
  color: #f5b0b5;
}

.chip.muted {
  border-color: rgba(30, 75, 107, 0.4);
  background: rgba(6, 20, 38, 0.42);
  color: var(--text-muted);
}

.card-title.small {
  font-size: 0.95rem;
  margin-bottom: 0.8rem;
}

.protocol-inline-note {
  margin-top: 0.95rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.card--interactive {
  cursor: pointer;
}

.card--interactive:hover,
.card--interactive:focus-within {
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
}

.card--panel {
  background: var(--bg-card);
}

.card--kpi {
  background: var(--bg-card);
}

.card--warning {
  border-color: var(--warning-border);
  background: var(--bg-card);
}

.card--danger {
  border-color: var(--danger-border);
  background: var(--bg-card);
}

.card-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Hero Section */
.hero {
  text-align: center;
  margin-bottom: 2rem;
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.hero p {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* Form Elements */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.subsection {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
}

.subsection__header {
  margin-bottom: var(--space-4);
}

.subsection__header h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 0.92rem;
}

.subsection__header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.subsection__header h3 + p {
  margin-top: var(--space-1);
}

.subsection > .metric-sub {
  margin-top: var(--space-3);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  align-items: start;
}

.field-grid--five {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

@media (max-width: 1050px) {
  .field-grid--five {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.progress-wrap progress {
  width: 100%;
  height: 12px;
}

.code-block {
  margin: 0;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(2, 6, 23, 0.55);
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 7.5rem;
}

body[data-page="login"] .grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 400px;
  margin: 0 auto;
}

body[data-page="login"] .row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.label {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input {
  background: var(--bg-control);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  color: var(--text-primary);
  font-size: 0.925rem;
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.input::placeholder {
  color: var(--text-muted);
}

.input:disabled,
.input[readonly] {
  background: var(--bg-control);
  border-color: rgba(148, 163, 184, 0.22);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

select.input:disabled {
  opacity: 1;
  -webkit-text-fill-color: var(--text-muted);
}

.input:disabled::placeholder,
.input[readonly]::placeholder {
  color: rgba(148, 163, 184, 0.7);
}

/* Buttons */
.btn {
  min-height: var(--control-height);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

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

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

.btn.small {
  min-height: var(--control-height-sm);
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}

.btn.icon-only {
  width: var(--control-height);
  padding: 0;
}

.btn.primary {
  border-color: var(--primary-action);
  background: var(--primary-action);
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.btn.danger {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.btn.danger:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--text-primary);
}

.btn.primary:hover {
  border-color: var(--primary-action-hover);
  background: var(--primary-action-hover);
  box-shadow: 0 5px 16px rgba(37, 99, 235, 0.34);
}

.btn.primary:active {
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.btn.ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn.auto-refresh[aria-pressed="true"] {
  border-color: var(--success-border);
  background: var(--success-soft);
  color: var(--success);
}

.check-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-inset);
  color: var(--text-secondary);
  cursor: pointer;
}

.check-card--compact {
  align-items: center;
  padding: var(--space-2) var(--space-3);
}

.check-card > span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: var(--space-1);
}

.check-card strong {
  color: var(--text-primary);
  font-size: 0.86rem;
}

.check-card small {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.45;
}

.check-toggle {
  display: inline-flex;
  min-height: var(--control-height);
  flex: 0 0 auto;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.check-toggle--sm {
  min-height: var(--control-height-sm);
  padding: var(--space-1) var(--space-3);
  font-size: 0.75rem;
}

.check-card:has(input:checked),
.check-toggle:has(input:checked) {
  border-color: var(--primary-border);
  background: var(--primary-soft);
}

.check-toggle:has(input:checked) {
  color: var(--text-primary);
}

.check-card input,
.check-toggle input {
  flex: 0 0 auto;
  width: var(--checkbox-size);
  height: var(--checkbox-size);
  accent-color: var(--primary);
}

.check-card input {
  margin: 0;
  transform: translateY(1px);
}

/* Shared tabs and segmented controls */
.tabs {
  display: flex;
  align-items: flex-end;
  gap: var(--space-1);
  overflow-x: auto;
  margin-bottom: var(--space-6);
  padding: var(--space-2) var(--space-2) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--bg-card);
  box-shadow:
    inset 0 -1px 0 var(--border),
    var(--shadow-sm);
  scrollbar-width: thin;
}

.tab {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  margin-bottom: 0;
  padding: 0.58rem 1rem 0.65rem;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-muted);
  font: 600 0.86rem var(--font-sans);
  white-space: nowrap;
  cursor: pointer;
  transition:
    color var(--transition-fast),
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
  transform: translateY(-1px);
}

.tab:is(.active, [aria-selected="true"]) {
  z-index: 1;
  margin-bottom: -1px;
  padding-bottom: calc(0.65rem + 1px);
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow:
    inset 0 3px 0 var(--primary-action),
    0 -5px 14px rgba(2, 8, 23, 0.18);
  transform: translateY(-1px);
}

.tab:is(.active, [aria-selected="true"]) .tab__icon {
  color: var(--primary-action);
}

.tab__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  color: currentColor;
}

.tab__icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Shared status and severity mapping */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  width: fit-content;
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--hover);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.3;
}

.status-pill:is(.selected, .blue, .info) {
  border-color: var(--primary-border);
  background: var(--primary-soft);
  color: var(--primary);
}

.status-pill:is(.ok, .success, .healthy) {
  border-color: var(--success-border);
  background: var(--success-soft);
  color: var(--success);
}

.status-pill:is(.warning, .alarm) {
  border-color: var(--warning-border);
  background: var(--warning-soft);
  color: var(--warning);
}

.status-pill:is(.danger, .fault, .critical) {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.muted {
  color: var(--text-muted);
}

/* uPlot dims disabled series with opacity; keep its legend text readable. */
.u-legend .u-off > * {
  opacity: 0.8;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table :is(th, td) {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.data-table th {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table tbody tr:last-child :is(th, td) {
  border-bottom: 0;
}

.table-wrap--inset {
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.data-table--compact {
  font-size: 0.76rem;
  line-height: 1.45;
}

.data-table--compact :is(th, td) {
  padding: var(--space-2) var(--space-3);
  vertical-align: top;
  overflow-wrap: anywhere;
}

.data-table--compact thead th {
  position: sticky;
  z-index: 1;
  top: 0;
  background: var(--bg-elevated);
}

.data-table--compact tbody th {
  width: 40%;
  background: var(--bg-inset);
  line-height: 1.35;
}

.data-table--compact tbody td {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.data-table--compact code {
  color: var(--color-info);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.empty-state {
  padding: var(--space-7);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-inset);
  color: var(--text-muted);
  text-align: center;
}

.empty-state--compact {
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
}

.empty-state--clear {
  border-color: var(--success-border);
  background: var(--success-soft);
  color: var(--success);
}

.empty-state--chart {
  display: grid;
  min-height: 300px;
  place-items: center;
}

.data-table td.empty-state {
  padding: var(--space-6);
  border: 0;
  border-radius: 0;
  color: var(--text-muted);
  text-align: center;
}

.btn.ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--primary);
}

.actions {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
}

.actions .btn {
  flex: 1;
}

/* ===== Utility classes ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.text-muted     { color: var(--text-muted); }
.text-sm        { font-size: 0.8rem; }
.font-mono      { font-family: var(--font-mono); }

/* Status */
.status {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  display: none;
  animation: slideIn 0.3s ease;
}

.status:not(:empty) {
  display: block;
}

.status.error {
  background: rgba(230, 57, 70, 0.1);
  color: #f5b0b5;
  border: 1px solid rgba(230, 57, 70, 0.3);
}

.status.success {
  background: rgba(46, 196, 182, 0.1);
  color: #9ee8e2;
  border: 1px solid rgba(46, 196, 182, 0.3);
}

.status--page:not(:empty) {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
}

.status--page:is(.ok, .success) {
  border-color: var(--success-border);
  background: var(--success-soft);
  color: var(--success);
}

.status--page.warn {
  border-color: var(--warning-border);
  background: var(--warning-soft);
  color: var(--warning);
}

.status--page.error {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Footer */
.nav-hamburger-icon { display: none; }
.nav-close-icon     { display: none; }
.nav-mobile-btn     { display: none; }
.nav-overlay        { display: none; }

.brand[data-nav-toggle] { cursor: pointer; }

/* Responsive */
@media (max-width: 768px) {
  .page {
    flex-direction: column;
  }

  /* ── Mobile top-bar navigation ──────────────────────────────────── */
  .sidebar {
    width: 100%;
    height: auto;
    overflow: visible;
    position: sticky;
    top: 0;
    z-index: 200;
    padding: 0;
    flex-direction: column;
    gap: 0;
    align-self: auto;
  }

  .sidebar-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    padding: 0.6rem 1rem;
    gap: 0.55rem 0.75rem;
  }

  .sidebar-toggle-wrap {
    grid-column: 1 / -1;
    padding: 0;
  }

  .sidebar-header .view-toggle,
  .sidebar-header .nav-system-select {
    min-width: 0;
    margin: 0;
  }

  .brand-row {
    width: 100%;
    justify-content: space-between;
  }

  /* Nav and footer: hidden by default, shown when mobile-open */
  .nav, .sidebar-foot {
    display: none;
  }

  .sidebar.mobile-open .nav {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.25rem 0.75rem 0.5rem;
    border-top: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.98);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }

  .sidebar.mobile-open .sidebar-foot {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem 0.75rem;
    border-top: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.98);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    margin-top: 0;
  }

  /* Hamburger button shown only on mobile */
  .nav-mobile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    min-width: 36px;
    min-height: 36px;
  }

  .nav-mobile-btn:hover { background: var(--hover); }

  .nav-hamburger-icon { display: block; }
  .nav-close-icon     { display: none;  }
  .sidebar.mobile-open .nav-hamburger-icon { display: none;  }
  .sidebar.mobile-open .nav-close-icon     { display: block; }

  /* Overlay backdrop */
  .nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 190;
    background: rgba(0, 0, 0, 0.45);
  }

  .sidebar.mobile-open ~ .nav-overlay {
    display: block;
  }

  /* Desktop collapsed → revert on mobile */
  .sidebar.collapsed {
    width: 100%;
    padding: 0;
    align-items: stretch;
  }

  .sidebar.collapsed .brand-name,
  .sidebar.collapsed .view-toggle,
  .sidebar.collapsed .nav-system-select,
  .sidebar.collapsed .sidebar-build {
    display: revert;
  }

  .sidebar.collapsed .nav-text {
    display: inline;
  }

  .sidebar.collapsed .chev {
    display: inline-flex;
  }

  .content {
    width: 100%;
    padding: var(--space-4) var(--content-gutter) var(--space-7);
  }

  .page-header,
  .page-header__actions {
    justify-content: flex-start;
  }

  .page-header {
    flex-direction: column;
    gap: var(--space-4);
  }

  .page-header--surface {
    padding: var(--space-5);
  }

  .card {
    padding: 1.25rem;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .actions {
    flex-direction: column;
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

  /* Range-bar / panel header overflow fix */
  .panel-header,
  .panel-head {
    flex-wrap: wrap;
  }
  .range-bar {
    width: 100%;
    flex-wrap: wrap;
  }
  .range-custom {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) auto;
    width: 100%;
  }
  .range-date-field {
    width: auto;
  }
  .segmented {
    flex: 1;
    min-width: 0;
  }
  .segmented button {
    flex: 1;
    padding: 0.4rem 0.25rem;
    font-size: 0.75rem;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Small phones (≤480px) ──────────────────────────────────────── */
@media (max-width: 480px) {
  /* Price curve: horizontal scroll so 24 bars remain usable */
  .price-curve-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .price-curve,
  .price-curve-labels {
    min-width: 420px;
  }

  /* Slightly tighter card padding on very small screens */
  .card {
    padding: 1rem;
  }
}

/* Additional polish */
::selection {
  background: var(--primary-action);
  color: white;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-elevated) inset;
  -webkit-text-fill-color: var(--text-primary);
  border-color: var(--primary);
}

/* Device Debug Layout */
.device-debug-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

@media (max-width: 980px) {
  .device-debug-header {
    flex-direction: column;
  }

}

/* Forecast decision-log debug table (admin only) */
.forecast-debug-summary {
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.4rem 0;
  list-style: none;
}
.forecast-debug-summary::-webkit-details-marker { display: none; }
.forecast-debug-summary::before {
  content: "▸ ";
  font-size: 0.7em;
}
details[open] > .forecast-debug-summary::before { content: "▾ "; }

.forecast-debug-spread-ok { color: var(--green, #4ade80); }

.forecast-debug-reason .reason-why { display: block; color: var(--text-muted); font-size: 0.75rem; font-weight: 400; }

/* --- Skeleton Loader --- */

/* --- UI Mode Gating --- */
[data-ui-mode="simple"] [data-advanced] { display: none !important; }

/* --- Accessibility Focus Rings --- */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ================================================================
   DASHBOARD — index.html
   All classes unique to the standalone dashboard page.
   ================================================================ */

.strategy-chart-tooltip {
  position: absolute;
  z-index: 10;
  min-width: 220px;
  max-width: 300px;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid rgba(51, 65, 85, 0.75);
  background: rgba(2, 6, 23, 0.94);
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.45);
  color: var(--text-primary);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.strategy-chart-tooltip.visible { opacity: 1; transform: translateY(0); }
.strategy-chart-tooltip-time { font-size: 0.82rem; font-weight: 700; color: var(--text-secondary); margin-bottom: 0.55rem; }
.strategy-chart-tooltip-grid { display: grid; grid-template-columns: 1fr auto; gap: 0.35rem 0.75rem; align-items: center; }
.strategy-chart-tooltip-label { display: flex; align-items: center; gap: 0.45rem; font-size: 0.82rem; color: var(--text-secondary); }
.strategy-chart-tooltip-swatch { width: 10px; height: 10px; border-radius: 999px; display: inline-block; }
.strategy-chart-tooltip-value { font-size: 0.82rem; font-weight: 700; color: var(--text-primary); text-align: right; }

.ems-chart-fullscreen-target { position: relative; }
.ems-chart-fullscreen-btn {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(2, 6, 23, 0.68);
  color: rgba(226, 232, 240, 0.92);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32);
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.ems-chart-fullscreen-target:hover > .ems-chart-fullscreen-btn,
.ems-chart-fullscreen-btn:focus-visible,
.ems-chart-fullscreen-target.is-fullscreen > .ems-chart-fullscreen-btn {
  opacity: 1;
}
.ems-chart-fullscreen-btn:hover { transform: translateY(-1px); border-color: rgba(96, 165, 250, 0.75); }
.ems-chart-fullscreen-target:fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 1rem !important;
  border-radius: 0 !important;
  overflow: hidden !important;
  background: #020617 !important;
}
.ems-chart-fullscreen-target:fullscreen .uplot-host,
.ems-chart-fullscreen-target:fullscreen .strategy-uplot-host {
  width: 100% !important;
  height: calc(100vh - 4.5rem) !important;
}
.ems-chart-fullscreen-target:fullscreen .uplot {
  max-width: none;
}

/* --- SVG utility --- */
.icon-stroke { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* --- Footer and canvas (dashboard overrides) --- */
.footer { background: rgba(30, 41, 59, 0.6); border-top: 1px solid var(--border); padding: 1.25rem 2rem; text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-top: 1.5rem; }
.footer-build { margin-top: 0.35rem; color: var(--text-muted); font-family: var(--font-mono); font-size: 0.8rem; overflow-wrap: anywhere; }
canvas { max-width: 100%; }

/* Persistent setup affordance shown until the guided checklist is finished. */

.setup-wizard-launcher {
  position: fixed;
  z-index: 900;
  right: max(1.25rem, env(safe-area-inset-right));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  min-width: 240px;
  max-width: min(340px, calc(100vw - 2rem));
  padding: 0.72rem 0.82rem;
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--bg-surface), var(--bg-card-soft));
  box-shadow: var(--shadow-xl);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.setup-wizard-launcher:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-xl), 0 0 0 3px var(--primary-soft);
  transform: translateY(-2px);
}

.setup-wizard-launcher:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.setup-wizard-launcher__icon {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-action);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 800;
}

.setup-wizard-launcher__copy {
  display: grid;
  min-width: 0;
  gap: 0.12rem;
}

.setup-wizard-launcher__copy strong {
  font-size: 0.86rem;
  line-height: 1.2;
}

.setup-wizard-launcher__copy span {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.setup-wizard-launcher__arrow {
  color: var(--primary);
  font-size: 1.15rem;
  line-height: 1;
}

body.setup-wizard-open .setup-wizard-launcher { display: none; }

.setup-wizard-return {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-md);
}

.setup-wizard-return__copy {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.setup-wizard-return__copy strong {
  color: var(--text-primary);
  font-size: 0.95rem;
}

.setup-wizard-return__copy span {
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.setup-wizard-return__button { flex: 0 0 auto; }

.cluster-banner {
  --accent-color: var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding: var(--space-3) var(--space-5);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-color);
  border-radius: 4px var(--radius-lg) var(--radius-lg) 4px;
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.cluster-banner[data-tone="success"] { --accent-color: var(--success); }
.cluster-banner[data-tone="info"] { --accent-color: var(--primary); }
.cluster-banner[data-tone="warning"] { --accent-color: var(--warning); }
.cluster-banner[data-tone="danger"] { --accent-color: var(--danger); }
.cluster-banner[data-refused] { border-color: var(--warning-border); border-left-color: var(--accent-color); }

.cluster-banner__copy {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.cluster-banner__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.cluster-banner__head strong {
  color: var(--text-primary);
  font-size: 0.92rem;
}

.cluster-banner__meta {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.cluster-banner__detail {
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.4;
}

.cluster-banner__alert {
  color: var(--warning);
  font-size: 0.82rem;
  font-weight: 600;
}

.cluster-banner > .btn { flex: 0 0 auto; }

@media (max-width: 640px) {
  .setup-wizard-launcher {
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    min-width: 0;
    width: calc(100vw - 1.5rem);
  }

  .setup-wizard-return {
    align-items: stretch;
    flex-direction: column;
    padding: var(--space-4);
  }

  .setup-wizard-return__button { width: 100%; }

  .cluster-banner {
    align-items: stretch;
    flex-direction: column;
    padding: var(--space-3) var(--space-4);
  }

  .cluster-banner > .btn { width: 100%; }
}

/* Shared chart legend chips (rendered by forecast-chart.js below the plot) */
.ems-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  padding: 0.65rem 0.25rem 0.15rem;
  justify-content: center;
}

.ems-chart-legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.26rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.55);
  color: var(--text-primary, #e2e8f0);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: opacity 0.15s, border-color 0.15s;
}

.ems-chart-legend-chip:hover {
  border-color: rgba(148, 163, 184, 0.5);
}

.ems-chart-legend-chip.off {
  opacity: 0.4;
}

.ems-chart-legend-chip.off .ems-chart-legend-swatch {
  background: rgba(148, 163, 184, 0.4) !important;
}

.ems-chart-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

[data-status] {
  white-space: pre-line;
}

/* uPlot drag selection and cursor lines, shared by every zoomable chart */
.uplot .u-select {
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-radius: 8px;
}
.uplot .u-cursor-x,
.uplot .u-cursor-y { border-color: rgba(184, 199, 214, 0.16) !important; }
