/* =====================================================================
   PowerFlow theme — Edgecom portal design system (portal/src)
   Light default mirrors portal/src/index.scss + tailwind.config.js;
   dark remains as the alternate terminal look.
   ===================================================================== */
@font-face {
  font-family: SF-Pro;
  src: local('SF-Pro-Regular'), url(fonts/SFPRODISPLAYREGULAR.OTF) format('opentype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: SF-Pro;
  src: local('SF-Pro-Medium'), url(fonts/SFPRODISPLAYMEDIUM.OTF) format('opentype');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: SF-Pro;
  src: local('SF-Pro-Medium'), url(fonts/SFPRODISPLAYMEDIUM.OTF) format('opentype');
  font-weight: 600; font-display: swap;
}
@font-face {
  font-family: SF-Pro;
  src: local('SF-Pro-Bold'), url(fonts/SFPRODISPLAYBOLD.OTF) format('opentype');
  font-weight: 700; font-display: swap;
}
:root {
  color-scheme: dark;
  --page: #0c0e12;
  --surface-1: #12151b;
  --surface-2: #191d25;
  --surface-3: #21262f;
  --ink-1: #f2f4f8;
  --ink-2: #aab2c0;
  --ink-3: #6e7787;
  --grid: #232833;
  --axis: #333a47;
  --ring: rgba(255, 255, 255, 0.08);
  --focus: #3987e5;
  /* Fuel palette — CVD-validated order (do not re-order without re-validating) */
  /* Portal palette (chartUtils.ts), brightened only where dark contrast demands */
  --fuel-nuclear: #2fa3f2;
  --fuel-gas: #ffa500;
  --fuel-hydro: #00d5e6;
  --fuel-wind: #2f9e58;
  --fuel-solar: #c2c04a;
  --fuel-other: #a05ab8;
  --fuel-biofuel: #99d211;
  /* Status — reserved, never series */
  --st-good: #46bd62;
  --st-warn: #ffa500;
  --st-serious: #f64a3f;
  --st-critical: #ff4d4d;
  --accent: #2fa3f2;
  --up: #46bd62;
  --down: #ff6b6b;
  /* Series accents (portal chart palette) */
  --s-blue: #2fa3f2;
  --s-orange: #ffa500;
  --s-aqua: #00d5e6;
  --s-yellow: #c2c04a;
  --s-magenta: #f760ae;
  --s-red: #f64a3f;
  /* Component surfaces */
  --side-bg: #0a0c10;
  --meter-track: #24365a;
  --chip-on-bg: #1d2b45;
  --chip-on-br: #2a4a7a;
  --edge: #232833;
  --card-shadow: rgba(0, 0, 0, 0.35);
  --seg-track: rgba(255, 255, 255, 0.08);
  --seg-thumb: #2a303b;
  --tag-good-bg: #12301c;
  --tag-good-ink: #5ecb79;
  --tag-warn-bg: #33270e;
  --tag-warn-ink: #ffb340;
  --pill-bg: #21262f;
  --pill-ink: #aab2c0;
  --pillblue-bg: #1d2b45;
  --nav-on-bg: #1d2b45;
  --nav-on-ink: #7db4ee;
  --shadow: rgba(0, 0, 0, 0.45);
  --font: 'SF-Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---------- Light theme (default) — matched to portal.edgecomenergy.net ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f5f5f5;
  --surface-1: #ffffff;
  --surface-2: #fafafa;
  --surface-3: #f0f0f0;
  --ink-1: rgba(0, 0, 0, 0.88);
  --ink-2: rgba(0, 0, 0, 0.65);
  --ink-3: rgba(0, 0, 0, 0.45);
  --grid: #f0f0f0;
  --axis: #d9d9d9;
  --edge: #e7e7e7;
  --ring: #f0f0f0;
  --focus: #006dd1;
  /* Portal palette — portal/src/utils/chartUtils.ts + p-track charts */
  --fuel-nuclear: #1975f2;
  --fuel-gas: #ffa500;
  --fuel-hydro: #00d5e6;
  --fuel-wind: #007536;
  --fuel-solar: #adab30;
  --fuel-other: #6e1980;
  --fuel-biofuel: #99d211;
  --st-good: #46bd62;
  --st-warn: #ffa500;
  --st-serious: #f64a3f;
  --st-critical: #dc0f0f;
  --accent: #006dd1;
  --up: #46bd62;
  --down: #dc0f0f;
  --s-blue: #1975f2;
  --s-orange: #ffa500;
  --s-aqua: #00d5e6;
  --s-yellow: #adab30;
  --s-magenta: #f760ae;
  --s-red: #f64a3f;
  --side-bg: #ffffff;
  --meter-track: #e6f2fc;
  --chip-on-bg: #e6f7ff;
  --chip-on-br: #91caff;
  --card-shadow: rgba(0, 0, 0, 0.08);
  --seg-track: rgba(0, 0, 0, 0.06);
  --seg-thumb: #ffffff;
  --tag-good-bg: #eef8f4;
  --tag-good-ink: #2f9e4f;
  --tag-warn-bg: #fff8e6;
  --tag-warn-ink: #c07f00;
  --pill-bg: #f2f2f2;
  --pill-ink: #252525;
  --pillblue-bg: #e2f1ff;
  --nav-on-bg: #e6f7ff;
  --nav-on-ink: #006dd1;
  --shadow: rgba(0, 0, 0, 0.1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
[hidden] { display: none !important; }
body {
  font-family: var(--font);
  background: var(--page);
  color: var(--ink-1);
  font-size: 13px;
  line-height: 1.45;
  display: grid;
  grid-template-columns: 216px 1fr;
  grid-template-rows: 48px 1fr;
  grid-template-areas: "side top" "side main";
  height: 100vh;
  overflow: hidden;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-radius: 6px; }
*::-webkit-scrollbar { width: 3px; height: 4px; border-radius: 10px; background: transparent; }
*::-webkit-scrollbar-track { background: transparent; border-radius: 10px; }
*::-webkit-scrollbar-thumb { background-color: #aeacacbf; border-radius: 10px; }
#top-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; margin-right: 4px; white-space: nowrap; }

/* ---------- Sidebar ---------- */
.side {
  grid-area: side; background: var(--side-bg); border-right: 1px solid var(--edge);
  display: flex; flex-direction: column; padding: 14px 10px; gap: 2px;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 8px 16px; }
.brand-img { width: 30px; height: auto; flex: none; }
.theme-btn { border: 1px solid var(--ring); background: var(--surface-1); color: var(--ink-2); border-radius: 7px; width: 30px; height: 30px; cursor: pointer; display: grid; place-items: center; font-size: 14px; }
.theme-btn:hover { background: var(--surface-2); color: var(--ink-1); }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, #2a78d6, #1c5cab);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff;
}
.brand-name { font-weight: 650; font-size: 14px; letter-spacing: -0.01em; }
.brand-sub { font-size: 10px; color: var(--ink-3); letter-spacing: 0.06em; text-transform: uppercase; }
.nav-label { font-size: 10px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); padding: 12px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 12px; border-radius: 8px; font-size: 13.5px;
  color: var(--ink-2); text-decoration: none; font-weight: 480; border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface-3); color: var(--ink-1); }
.nav-item.active { background: var(--nav-on-bg); color: var(--nav-on-ink); border-color: transparent; font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-item svg { width: 15px; height: 15px; flex: none; opacity: 0.85; }
.nav-kbd { margin-left: auto; font-size: 10px; color: var(--ink-3); background: var(--surface-2); border: 1px solid var(--ring); border-radius: 4px; padding: 0 5px; }
.side-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--grid); font-size: 11px; color: var(--ink-3); display: flex; flex-direction: column; gap: 6px; }
.side-foot a { color: var(--ink-3); text-decoration: none; }
.side-foot a:hover { color: var(--ink-2); }

/* ---------- Top bar ---------- */
.top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--edge); background: var(--surface-1); box-shadow: 0 2px 6px var(--shadow); position: relative; z-index: 2; }
.top-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.seg {
  display: flex; align-items: center; gap: 8px; background: var(--surface-1);
  border: 1px solid var(--ring); border-radius: 7px; padding: 5px 10px; font-weight: 550; cursor: pointer;
}
.seg:hover { background: var(--surface-2); }
.seg .caret { color: var(--ink-3); font-size: 10px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.mode-tabs { display: flex; background: var(--seg-track); border: none; border-radius: 6px; padding: 2px; }
.mode-tab { padding: 4px 12px; border-radius: 4px; color: var(--ink-2); font-weight: 400; cursor: pointer; border: none; background: transparent; font-size: 13px; font-family: var(--font); transition: color 0.15s; }
.mode-tab.on { background: var(--seg-thumb); color: var(--ink-1); font-weight: 500; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); }
.top-spacer { flex: 1; }
.tag { display: inline-flex; align-items: center; gap: 6px; border-radius: 4px; padding: 3px 10px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.tag-live { background: var(--tag-good-bg); color: var(--tag-good-ink); font-variant-numeric: tabular-nums; }
.tag-warn { background: var(--tag-warn-bg); color: var(--tag-warn-ink); cursor: help; }
.live-pill .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--st-good); box-shadow: 0 0 0 0 rgba(70,189,98,0.5); animation: pulse 2.4s infinite; flex: none; }
.live-pill.snapshot { background: var(--tag-warn-bg); color: var(--tag-warn-ink); }
.live-pill.snapshot .pulse { background: var(--st-warn); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(12,163,12,0.45); } 70% { box-shadow: 0 0 0 7px rgba(12,163,12,0); } 100% { box-shadow: 0 0 0 0 rgba(12,163,12,0); } }


/* ---------- Main / page chrome ---------- */
.main { grid-area: main; overflow-y: auto; padding: 18px 20px 40px; }
.page-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.page-head h1.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.page-head .asof { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }
.ghost-btn { border: 1px solid var(--axis); background: var(--surface-1); color: var(--ink-2); border-radius: 6px; padding: 5px 12px; font-size: 13px; font-weight: 500; cursor: pointer; font-family: var(--font); }
.ghost-btn:active { border-color: var(--accent); color: var(--accent); }
.ghost-btn:hover { background: var(--surface-2); color: var(--ink-1); }
.note { color: var(--ink-3); font-size: 11px; margin-top: 14px; text-align: center; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface-1); border: none; border-radius: 8px; padding: 13px 16px 12px; display: flex; flex-direction: column; gap: 5px; min-width: 0; box-shadow: 0 0 8px var(--card-shadow); }
.tile .lbl { align-self: flex-start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 12px; font-weight: 700; color: var(--pill-ink); background: var(--pill-bg); border-radius: 50px; padding: 2px 12px; white-space: nowrap; }
.tile .val { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.tile .val small { font-size: 11px; font-weight: 500; color: var(--ink-3); margin-left: 3px; }
.tile .sub { font-size: 11px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
.delta-up { color: var(--up); font-weight: 600; }
.delta-down { color: var(--down); font-weight: 600; }
.delta-bad { color: var(--st-serious); font-weight: 600; }
.spark { margin-top: 2px; }
.meter { height: 6px; border-radius: 3px; background: var(--meter-track); overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; border-radius: 3px; }

/* ---------- Cards & layout ---------- */
.card { background: var(--surface-1); border: 1px solid var(--ring); border-radius: 8px; min-width: 0; box-shadow: 0 0 8px var(--card-shadow); }
.card-h { display: flex; align-items: center; gap: 8px; padding: 13px 16px 0; flex-wrap: wrap; min-height: 44px; }
.card-h h2 { font-size: 16px; font-weight: 600; }
.card-h .hint { color: var(--ink-3); font-size: 11px; }
.card-h .tools { margin-left: auto; display: flex; gap: 6px; color: var(--ink-3); align-items: center; }
.icon-btn { width: 24px; height: 24px; border-radius: 6px; border: none; background: transparent; color: var(--ink-3); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-3); color: var(--ink-1); }
.card-b { padding: 8px 16px 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 10px; margin-bottom: 12px; align-items: stretch; }
.grid-6 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.grid-8-4 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 10px; margin-bottom: 12px; }
.col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

/* ---------- Charts ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 6px 14px 0; font-size: 11px; color: var(--ink-2); }
.legend .li { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .lk { width: 12px; height: 2px; border-radius: 1px; }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; display: none;
  background: var(--surface-2); border: 1px solid var(--ring); border-radius: 8px;
  padding: 8px 10px; min-width: 150px; box-shadow: 0 8px 24px var(--shadow); font-size: 11px;
}
.tooltip .tt-t { color: var(--ink-3); margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.tooltip .tt-r { display: flex; align-items: center; gap: 7px; padding: 1.5px 0; }
.tooltip .tt-r .lk { width: 10px; height: 2.5px; border-radius: 1px; flex: none; }
.tooltip .tt-r .nm { color: var(--ink-2); }
.tooltip .tt-r .vv { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink-1); }

/* ---------- Tables ---------- */
.mixbar { display: flex; height: 18px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface-1); margin: 10px 0 4px; }
.mixbar i { display: block; height: 100%; }
.mini-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.mini-table td { padding: 5.5px 0; border-top: 1px solid var(--grid); font-size: 12px; }
.mini-table tr:first-child td { border-top: none; }
.mini-table .fuel { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.mini-table .sw { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.mini-table .mw { text-align: right; font-weight: 600; }
.mini-table .sh { text-align: right; color: var(--ink-3); width: 52px; }

.trust-row { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-top: 1px solid var(--grid); font-size: 12px; }
.trust-row:first-child { border-top: none; }
.trust-row .st { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.trust-row .nm { color: var(--ink-2); }
.trust-row .dt { margin-left: auto; color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 11px; text-align: right; }
.badge { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; border-radius: 5px; padding: 2px 7px; }
.badge.warn { color: #0c0e12; background: var(--st-warn); }
.badge.good { color: #0c0e12; background: var(--st-good); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 14px 2px; }
.chip { display: flex; align-items: center; gap: 6px; border: 1px solid var(--ring); background: var(--surface-2); color: var(--ink-2); border-radius: 16px; padding: 3.5px 11px; font-size: 12px; cursor: pointer; font-weight: 520; font-family: var(--font); }
.chip:hover { background: var(--surface-3); }
.chip.on { background: var(--chip-on-bg); border-color: var(--chip-on-br); color: var(--ink-1); }
.chip .n { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; }

.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th {
  text-align: left; font-size: 10.5px; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600; padding: 9px 14px; border-bottom: 1px solid var(--axis);
  position: sticky; top: 0; background: var(--surface-1); z-index: 2; cursor: pointer; white-space: nowrap;
}
.data-table th.r, .data-table td.r { text-align: right; }
.data-table th .arrow { color: var(--accent); }
.data-table td { padding: 7.5px 14px; border-bottom: 1px solid var(--grid); font-size: 12.5px; }
.data-table tbody tr:hover td { background: var(--surface-3); }
.data-table .strong { font-weight: 600; }
.data-table .muted { color: var(--ink-2); }
.fuel-tag { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.fuel-tag .sw { width: 8px; height: 8px; border-radius: 50%; }
.util { display: flex; align-items: center; gap: 9px; justify-content: flex-end; }
.util .bar { width: 90px; height: 5px; border-radius: 3px; background: var(--meter-track); overflow: hidden; }
.util .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.util .pc { width: 47px; text-align: right; color: var(--ink-2); }
.table-scroll { padding: 6px 0 0; max-height: 340px; overflow-y: auto; }
.table-foot { display: flex; align-items: center; padding: 9px 14px; color: var(--ink-3); font-size: 11.5px; gap: 8px; }

/* ---------- Filters / inputs ---------- */
.filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.subnav { display: flex; gap: 22px; align-items: center; border-bottom: 1px solid var(--grid); padding: 0 2px; }
.subnav .st { padding: 7px 1px 8px; font-size: 14px; font-weight: 600; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.subnav .st.on { color: var(--accent); border-bottom-color: var(--accent); background: none; }
.subnav .st:hover:not(.on) { color: var(--ink-1); }
.fdiv { width: 1px; height: 20px; background: var(--grid); margin: 0 4px; }
.preset { border: none; background: transparent; color: var(--ink-2); border-radius: 5px; padding: 5px 12px; font-size: 13px; font-weight: 500; cursor: pointer; font-family: var(--font); height: 30px; }
.preset:hover { background: var(--surface-2); }
.preset.on { background: var(--pillblue-bg); color: var(--accent); font-weight: 600; }
.sel {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--axis); border-radius: 5px;
  padding: 4.5px 11px; background: var(--surface-1); font-size: 12px; color: var(--ink-1); cursor: pointer;
  font-weight: 530; font-family: var(--font); appearance: none;
}
select.sel { padding-right: 22px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 12px) 55%, calc(100% - 8px) 55%; background-size: 4px 4px; background-repeat: no-repeat; max-width: 230px; }
.search-input {
  border: 1px solid var(--axis); border-radius: 5px; padding: 5px 11px; background: var(--surface-1);
  color: var(--ink-1); font-size: 12px; font-family: var(--font); min-width: 190px;
}
.search-input::placeholder { color: var(--ink-3); }

/* ---------- Demand page extras ---------- */
.range-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 12px; }
.rt .mm { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.rt .mm b { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.rt .mm span { color: var(--ink-3); font-size: 11px; }
.rt .rangebar { position: relative; height: 5px; border-radius: 3px; background: var(--surface-3); margin-top: 8px; }
.rt .rangebar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.cov-warn { color: var(--st-warn); font-weight: 600; }
.acc-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--grid); font-size: 12px; }
.acc-row:first-child { border-top: none; }
.acc-row .nm { color: var(--ink-2); width: 60px; flex: none; }
.acc-row .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.acc-row .bar i { display: block; height: 100%; border-radius: 3px; }
.acc-row .vv { width: 44px; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
