:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s7: #4a3aa7;
  --acc-offer: #d03b3b;
  --acc-bid: #15407a;
  --acc-system: #fab219;
  --up: #006300;
  --down: #d03b3b;
  --good: #0ca30c;
  --critical: #d03b3b;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s7: #9085e9;
    --acc-offer: #e66767;
    --acc-bid: #2f6fc4;
    --acc-system: #fab219;
    --up: #0ca30c;
    --down: #e66767;
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s7: #9085e9;
  --acc-offer: #e66767;
  --acc-bid: #2f6fc4;
  --acc-system: #fab219;
  --up: #0ca30c;
  --down: #e66767;
  --accent: #3987e5;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 16px; }
h2 { font-size: 18px; }
h3 { font-size: 14px; }
.muted { color: var(--ink-2); margin: 2px 0 0; }
.small { font-size: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--s1), var(--s3)); }
.sub { margin: 0; color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.tabs button {
  border: 0; background: transparent; color: var(--ink-2);
  font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 7px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px var(--border); }

main { max-width: 1280px; margin: 0 auto; padding: 20px 24px 40px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.controls { display: flex; gap: 6px; align-items: center; }
.controls.wrap { flex-wrap: wrap; }
input[type="date"], #asset-input {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 9px; min-height: 34px;
}
#asset-input { width: 230px; max-width: 100%; }
.icon-btn {
  font: inherit; font-size: 18px; line-height: 1; width: 34px; height: 34px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--ink); cursor: pointer;
}
.icon-btn:hover, .seg button:hover { background: var(--surface-2); }


.status { min-height: 0; color: var(--ink-2); font-size: 13px; }
.status:not(:empty) { margin-bottom: 10px; }
.status.error { color: var(--critical); }

.badge { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.badge:empty { display: none; }
.badge.ok { color: var(--up); background: color-mix(in srgb, var(--good) 14%, var(--surface)); font-weight: 600; }
.tiles-title:not(:empty) { font-size: 13px; color: var(--ink-2); font-weight: 500; margin: 0 0 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.tile .label { color: var(--ink-2); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.tile .swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.tile .value .unit { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.tile .delta { font-size: 12px; color: var(--muted); }
.tile .delta.up { color: var(--up); }
.tile .delta.down { color: var(--down); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 14px; }
.chart-box { position: relative; height: 220px; }
.chart-box.tall { height: 320px; }

.seg { display: inline-flex; background: var(--surface-2); padding: 2px; border-radius: 7px; }
.seg button { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 5px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px var(--border); }

.table-card summary { cursor: pointer; font-weight: 600; }
.table-card[open] summary { margin-bottom: 10px; }
.table-wrap { overflow: auto; }
.table-wrap.short { max-height: 280px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: right; padding: 9px 12px; border-bottom: 1px solid var(--grid); white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.sr td { background: color-mix(in srgb, var(--s7) 13%, transparent); }
tr.sr td:first-child { box-shadow: inset 3px 0 0 var(--s7); }
/* Accepted rows carry a marker on the "Accepted" cell, so colour is never the only cue */
tr.acc-offer td:nth-child(8) { color: var(--acc-offer); font-weight: 600; }
tr.acc-bid td:nth-child(8) { color: var(--acc-bid); font-weight: 600; }
tr.acc-sys td:nth-child(8) { color: var(--acc-system); font-weight: 600; }
/* Renewables: the run that is current carries the marker, so colour is never the only cue */
tr.ren-latest td { background: color-mix(in srgb, var(--s1) 10%, transparent); }
tr.ren-latest td:first-child { box-shadow: inset 3px 0 0 var(--s1); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--ink-2); font-weight: 500; position: sticky; top: 0; background: var(--surface); }
td.neg { color: var(--down); }
.empty { color: var(--muted); padding: 14px 0; text-align: left; }

.asset-info { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-bottom: 14px; color: var(--ink-2); }
.asset-info b { color: var(--ink); font-weight: 600; }
.asset-info .name { font-size: 16px; color: var(--ink); font-weight: 600; width: 100%; }
.chip { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); margin-left: 4px; }

/* Filters */
.filter-row { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-bottom: 14px; }
.filter-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-label { font-size: 12px; color: var(--muted); }
.inline-field { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.inline-field input[type="number"] {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; min-height: 34px; width: 72px;
}
.sr-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--s7); margin-right: 3px; }
.sr-dot.acc { background: var(--acc-offer); }
.inline-field select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; min-height: 34px;
}
/* Each forecast-run chip carries its own line colour */
.chip-btn .run-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.chip-btn:not(.on) .run-dot { opacity: 0.35; }
.chip-btn:not(.on) .sr-dot { opacity: 0.45; }
.card-head-right { display: flex; align-items: center; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  font: inherit; font-size: 12px; cursor: pointer;
  color: var(--ink-2); background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px;
}
.chip-btn:hover { background: var(--surface-2); }
.chip-btn.on { color: var(--ink); border-color: var(--axis); background: var(--surface-2); font-weight: 600; }
.chip-btn .chip-mw { color: var(--muted); font-weight: 400; margin-left: 4px; }
.chip-btn:not(.on) .chip-mw { opacity: 0.6; }

/* Sign-in gate */
body.locked main, body.locked .tabs, body.locked .account { display: none; }
.auth-gate {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: var(--page); overflow: auto;
}
.auth-gate[hidden] { display: none; }
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 22px; display: flex; flex-direction: column; gap: 12px;
}
.auth-card .brand { margin-bottom: 4px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.auth-card input {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; min-height: 40px;
}
.auth-card .source { margin-top: 4px; }
.primary-btn {
  font: inherit; font-weight: 600; color: #fff; background: var(--accent);
  border: 0; border-radius: 7px; padding: 10px 14px; min-height: 40px; cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: 0.6; cursor: default; }
.auth-error:empty { display: none; }
.auth-error { font-size: 12px; color: var(--critical); margin: 0; }

.account { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-2); }
.account #auth-who { font-weight: 600; color: var(--ink); }
.chip.warn { color: var(--down); }

.users-dialog {
  width: min(680px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 12px; padding: 18px;
}
.users-dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.users-dialog .table-wrap { max-height: 300px; }
.users-dialog td .text-btn:disabled { color: var(--muted); cursor: default; }

.opt-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 14px; margin: 10px 0 12px; }
.opt-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.opt-form label span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.opt-form input, .opt-form select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; min-height: 32px; width: 100%;
}
.opt-form label span input { width: 100%; }
.opt-advanced { grid-column: 1 / -1; font-size: 12px; color: var(--ink-2); }
.opt-advanced summary { cursor: pointer; }
.opt-advanced .opt-form { margin-bottom: 0; }
.opt-actions { display: flex; align-items: flex-end; }
.text-btn { font: inherit; font-size: 12px; color: var(--accent); background: none; border: 0; padding: 6px 0; cursor: pointer; }
.chart-sub { font-size: 12px; font-weight: 500; color: var(--ink-2); margin: 14px 0 6px; }
.source { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

@media (max-width: 640px) {
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  /* Seven tabs cannot share a phone's width, so the strip swipes instead of widening the page */
  .tabs { width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 0 0 auto; padding: 7px 10px; white-space: nowrap; }
  .chart-box.tall { height: 260px; }
  #asset-input { width: 100%; }
}
