/*
 * Valor Insights: the one stylesheet (spec 019).
 *
 * The look is Feasibility's. Every value in :root, the body font, and the
 * card, KPI and table rules are taken from valor-studies'
 * templates/study-template-v2.html at origin/main (its <style> block), so
 * Valor's two tools look like one product. --red is Feasibility's warning
 * red. To change the look, change a value here; no page carries a colour of
 * its own (app/tests/unit/design-tokens.test.ts checks both).
 */

:root {
  --bg: #0d0f10;
  --surface: #16191c;
  --surface2: #1c2024;
  --surface3: #22272b;
  --line: #2a2f34;
  --ink: #f2f4f3;
  --ink2: #b7bfba;
  --muted: #8a938e;
  --green: #39b54a;
  --green2: #7ed957;
  --green-deep: #1e7c2b;
  --amber: #c98500;
  --blue: #3987e5;
  --radius: 12px;
  --red: #d9534f;
  /* Spec 024: the chart's fourth and fifth line colours (Feasibility has
     three). Each at least 3:1 against --surface: 6.5:1 and 10.8:1. */
  --violet: #a78bfa;
  --yellow: #f5c518;
  --grad: linear-gradient(135deg, #2e9e3e, #7ed957);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 32px 40px 64px;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
@media (max-width: 640px) { body { padding: 20px 16px 48px; } }

img { max-width: 100%; }
a { color: var(--green2); }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 27px; font-weight: 800; letter-spacing: 0.02em; margin: 0 0 16px; }
h1.brand { color: var(--green2); }
h2 {
  font-size: 15px; text-transform: uppercase; letter-spacing: 0.14em;
  margin: 28px 0 10px; font-weight: 800; color: var(--ink);
}
h3 { font-size: 16px; margin: 20px 0 8px; font-weight: 700; }
#reference h4, #reference h5, #reference h6 { font-size: 14px; margin: 16px 0 6px; color: var(--ink2); }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13.5px; }
code { color: var(--ink2); }
pre {
  margin: 0; padding: 12px 14px; background: var(--surface2);
  border: 1px solid var(--line); border-radius: 8px;
}
pre code { color: var(--ink); }

/* ---------- The staging banner (spec 009) ---------- */
.env-banner {
  margin: -32px -40px 24px; padding: 10px 40px;
  background: #f5c518; color: var(--bg); font-weight: bold;
}
@media (max-width: 640px) { .env-banner { margin: -20px -16px 20px; padding: 10px 16px; } }

/* ---------- Text ---------- */
.muted { color: var(--muted); }
.alert { color: var(--red); }

/* ---------- Sign in ---------- */
.logo { display: block; height: 28px; width: auto; margin: 0 0 20px; }
.sign-in { max-width: 360px; }
.form-stack { display: grid; gap: 12px; }
.form-stack label { display: grid; gap: 4px; color: var(--ink2); font-size: 13.5px; }

/* ---------- Controls ---------- */
input, button {
  font: inherit; color: var(--ink);
  background: var(--surface2); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 12px;
}
input { width: 100%; }
input:focus { outline: 2px solid var(--green); outline-offset: 0; border-color: var(--green); }
button { cursor: pointer; }
button:hover { border-color: var(--green); }
button.primary { background: var(--grad); color: #06230b; font-weight: 800; border-color: transparent; }

/* ---------- Panels (Feasibility's .card and .kpi) ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 0 0 16px;
}
.card h2:first-child { margin-top: 0; }
.card section > :last-child { margin-bottom: 0; }
.kpi {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 14px 12px; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--grad); }
.kpi .l { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.kpi .v { font-size: 21px; font-weight: 800; letter-spacing: 0.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- Data states (R5): one colour each, for later orders ---------- */
.state-live { color: var(--green2); }
.state-delayed { color: var(--amber); }
.state-offline { color: var(--red); }
.state-no-data { color: var(--muted); }
.state-unknown { color: var(--muted); }

/* ---------- Tables (Feasibility's table.data) ---------- */
.scroll-x { overflow-x: auto; margin: 0 0 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th {
  color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  white-space: nowrap; font-weight: 700;
}
tr:hover td { background: rgba(57, 181, 74, 0.04); }
td code { white-space: nowrap; overflow-wrap: normal; }

/* ---------- Lists and pages ---------- */
.sites { list-style: none; padding: 0; margin: 0; }
.sites li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.sites li:last-child { border-bottom: 0; }
.doc { max-width: 960px; overflow-wrap: anywhere; }

/* ---------- The page frame (spec 020) ---------- */
/* One header on every signed-in page. No script: the site menu is a
   <details>. From 360 px up nothing in it scrolls sideways; below 720 px
   the site menu and the menu each take a row under the header. */
.frame { margin: 0 0 24px; padding: 0 0 14px; border-bottom: 1px solid var(--line); }
.frame-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.frame-brand { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; flex: 1 1 0; min-width: 0; }
.frame-logo { display: block; height: 18px; width: auto; }
.frame-name { font-size: 12px; font-weight: 800; letter-spacing: 0.16em; color: var(--green2); }
.frame-sign-out { margin: 0; }
.frame-sign-out button { padding: 6px 12px; font-size: 13.5px; }
/* The open site list is placed against this row, which spans the page's
   content width, not against its button: a long customer name can push the
   button far right, and a list hung from there would run off the page
   (review F1). */
.frame-context { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 14px; }
.frame-org { margin: 0; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.frame-menu { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
.frame-menu a { color: var(--ink2); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.frame-menu a:hover { color: var(--ink); background: var(--surface2); }
.frame-menu a[aria-current="page"] { color: var(--green2); background: var(--surface2); }
#data-status { margin: 0; }
#data-status:empty { display: none; }

.site-menu { min-width: 0; max-width: 100%; }
.site-menu summary {
  list-style: none; cursor: pointer; display: inline-block; max-width: 100%;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface2); color: var(--ink); font-size: 13.5px; overflow-wrap: anywhere;
}
.site-menu summary::-webkit-details-marker { display: none; }
.site-menu summary::after { content: " \25BE"; color: var(--muted); }
.site-menu[open] summary, .site-menu summary:hover { border-color: var(--green); }
.site-menu-list {
  position: absolute; z-index: 10; left: 0; top: 100%;
  width: max-content; min-width: min(220px, 100%); max-width: min(360px, 100%);
  list-style: none; margin: 6px 0 0; padding: 6px;
  background: var(--surface2); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.site-menu-list.scroll { max-height: 320px; overflow-y: auto; }
.site-menu-list a, .site-menu-list .muted { display: block; padding: 7px 10px; border-radius: 8px; overflow-wrap: anywhere; }
.site-menu-list a { color: var(--ink); text-decoration: none; }
.site-menu-list a:hover { background: var(--surface3); }
.site-menu-list a[aria-current="page"] { color: var(--green2); font-weight: 700; }

@media (max-width: 719px) {
  .site-menu, .frame-menu { flex-basis: 100%; }
  .frame-menu { margin-left: 0; }
}

/* ---------- The Overview (spec 021) ---------- */
/* The status line under the frame, coloured by its .state-* class above,
   and the live-value cards: as many columns as fit, one on a phone. */
#data-status { margin-top: 12px; font-weight: 700; font-size: 13.5px; letter-spacing: 0.04em; }
#data-status .status-extra { margin-left: 8px; font-weight: 400; color: var(--ink2); letter-spacing: 0; }
.overview-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.overview-head h1 { overflow-wrap: anywhere; min-width: 0; }
.refresh-control { margin: 0 0 16px; font-size: 13.5px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.kpi h2.l, .kpi h3.l { margin: 0; font-weight: 400; }
.kpi .v { margin: 2px 0 0; }
.kpi-word { margin: 2px 0 0; color: var(--ink2); font-size: 13.5px; }
.kpi-note { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.kpi-note:empty { display: none; }

/* ---------- The live energy flow (spec 022) ---------- */
/* Written for this app (not copied): a slowly moving dashed line for a LIVE
   value, in the live green; a still line in the delayed colour for DELAYED;
   a grey dashed still line for a stopped source. Lines are drawn in the
   direction power goes, so the dashes move that way. The movement stops
   under prefers-reduced-motion. From 640 px the drawing shows; below, the
   list with the same values. Whichever is hidden is hidden from a screen
   reader too (display: none). */
.flow-panel { margin-top: 16px; }
.flow-panel h2 { margin-top: 0; }
.flow-svg { display: block; width: 100%; max-width: 800px; height: auto; margin: 0 auto; }
.flow-box { fill: var(--surface2); stroke: var(--line); stroke-width: 1; }
.flow-site .flow-box { stroke: var(--green-deep); }
.flow-svg text { fill: var(--ink); font-size: 14px; }
.flow-svg .flow-title { fill: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; }
.flow-svg .flow-name { fill: var(--ink); font-size: 13px; font-weight: 700; }
.flow-svg .flow-row { font-size: 16px; font-weight: 800; }
.flow-svg .flow-k { fill: var(--muted); font-size: 12px; font-weight: 400; }
.flow-svg .flow-word { fill: var(--ink2); font-size: 12.5px; }
.flow-svg .flow-note { fill: var(--muted); font-size: 11px; }
.stream { fill: none; stroke-width: 3; stroke-linecap: round; }
.stream.live { stroke: var(--green2); stroke-dasharray: 10 8; animation: dashmove 2.4s linear infinite; }
.stream.delayed { stroke: var(--amber); }
.stream.dim { stroke: var(--muted); stroke-dasharray: 4 6; opacity: 0.6; }
@keyframes dashmove { to { stroke-dashoffset: -36; } }
.flow-arrow.live { fill: var(--green2); }
.flow-arrow.delayed { fill: var(--amber); }
.flow-list { display: none; list-style: none; margin: 0; padding: 0; }
.flow-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.flow-item:last-child { border-bottom: 0; }
.flow-list .flow-title { display: block; color: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; }
.flow-list .flow-name { display: block; font-weight: 700; overflow-wrap: anywhere; }
.flow-list .flow-row { display: block; }
.flow-list .flow-k { color: var(--muted); font-size: 13px; margin-right: 4px; }
.flow-list .flow-value { font-weight: 800; }
.flow-list .flow-word { margin-left: 6px; color: var(--ink2); font-size: 13.5px; }
.flow-list .flow-note { display: block; color: var(--muted); font-size: 12.5px; }
.flow-caption { margin: 12px 0 0; color: var(--muted); font-size: 12.5px; }
@media (max-width: 639.98px) {
  .flow-svg { display: none; }
  .flow-list { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  .stream.live { animation: none; }
}

/* ---------- Today's performance (spec 023) ---------- */
/* A panel like the energy flow's, below it, holding 019's .kpi tiles in the
   cards' grid. */
.today { margin-top: 16px; }
.today h2 { margin: 0; }
.today-since { margin: 2px 0 12px; font-size: 13px; }

/* ---------- Power today (spec 024) ---------- */
/* The chart's look: plain SVG, drawn by /assets/power-today.js. Grid lines
   in the line colour, labels muted and small (.viz-lab), a tooltip on the
   raised surface (.viz-tip). One colour per line, set by its line-<key>
   class and used by the line, its dots, its button and its tooltip row. */
/* Spec 026: the Energy page's chart (.energy-chart-*) is the same chart, drawn by the shared /assets/chart.js. */
.power-today, .energy-chart { margin-top: 16px; }
.power-today h2, .energy-chart h2 { margin: 0; }
.power-today-since, .energy-chart-grouping { margin: 2px 0 12px; font-size: 13px; }
.energy-chart-grouping:empty { display: none; }
.power-today-message, .energy-chart-message { margin: 8px 0 0; color: var(--ink2); }
.power-today-failed, .energy-chart-failed { color: var(--amber); }
.power-today-signs, .energy-chart-signs { margin: 8px 0 0; font-size: 12.5px; }
.power-today-controls, .energy-chart-controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.series-btn {
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 5px 10px; font-size: 13px; border-radius: 999px; max-width: 100%;
}
.series-btn[aria-pressed="false"] { color: var(--muted); background: var(--bg); }
.series-btn[aria-pressed="false"] .swatch { opacity: 0.35; }
.series-btn:disabled { cursor: default; color: var(--muted); border-color: var(--line); }
.series-btn:disabled .swatch { opacity: 0.35; }
.series-note { font-size: 12px; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.line-grid { --c: var(--blue); }
.line-battery { --c: var(--green2); }
.line-ev { --c: var(--amber); }
.line-siteLoad { --c: var(--violet); }
.line-solar { --c: var(--yellow); }
.power-today-chart, .energy-chart-chart { position: relative; width: 100%; min-width: 0; overflow: hidden; }
.viz { display: block; max-width: 100%; touch-action: pan-y; }
.viz:focus { outline: 2px solid var(--green); outline-offset: 2px; }
.viz-grid { stroke: var(--line); stroke-width: 1; }
.viz-grid-x { stroke-dasharray: 2 4; }
.viz-zero { stroke: var(--muted); stroke-width: 1; }
.viz-now { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.6; }
.viz-lab { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-dot { fill: var(--c); }
.viz-marker { stroke: var(--ink2); stroke-width: 1; }
.viz-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 140px;
  padding: 8px 10px; background: var(--surface2); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.viz-tip[hidden] { display: none; }
.viz-tip-time { font-weight: 700; margin: 0 0 4px; }
.viz-tip-note { color: var(--muted); font-size: 12px; margin: -2px 0 4px; }
.viz-tip-row { display: flex; align-items: center; gap: 6px; }
.viz-tip-label { color: var(--ink2); }
.viz-tip-value { margin-left: auto; padding-left: 12px; font-weight: 700; }
@media (max-width: 519.98px) { .viz-lab { font-size: 10px; } }

/* ---------- The Energy page (spec 025) ---------- */
/* A panel holding the period links (a row of buttons, the chosen one
   marked), one plain form for the client's own dates, the period in words
   and 023's .kpi tiles in the cards' grid. Everything wraps: from 360 px
   nothing scrolls sideways. */
.energy h2 { margin: 0 0 12px; }
.period-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.period-link {
  color: var(--ink2); text-decoration: none; padding: 7px 14px; font-size: 13.5px;
  background: var(--surface2); border: 1px solid var(--line); border-radius: 9px;
}
.period-link:hover { color: var(--ink); border-color: var(--green); }
.period-link[aria-current="true"] { color: var(--green2); border-color: var(--green); font-weight: 700; }
.period-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin: 0 0 12px; }
.period-form label { display: grid; gap: 4px; flex: 1 1 140px; min-width: 0; max-width: 220px; color: var(--ink2); font-size: 13.5px; }
.period-form input { min-width: 0; }
.energy-period { margin: 0 0 12px; font-size: 13px; }

/* ---------- The EV Charging page (spec 027) ---------- */
/* The figures are 023's .kpi tiles in the cards' grid; each charger is a
   .kpi card in a panel below, one column on a phone. A card's top stripe
   says its charger's state in 021's colours: the green gradient only for a
   live, reporting charger. */
.chargers { margin-top: 16px; }
.chargers h2 { margin: 0 0 12px; }
#ev-figures { margin-bottom: 0; }
.charger-name { margin: 0; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.charger-power { margin: 2px 0 0; color: var(--ink2); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.charger.stripe-delayed::before { background: var(--amber); }
.charger.stripe-offline::before { background: var(--red); }
.charger.stripe-unknown::before { background: var(--muted); }
#chargers-more { margin: 12px 0 0; }

/* ---------- Recent sessions (spec 028) ---------- */
/* Under the charger cards, a panel holding a real table (Feasibility's
   table rules above). Below 640 px each row is a stacked block: the header
   row is hidden from sight (kept for screen readers) and each cell shows
   its column's name from its data-label. Long names wrap, so nothing
   scrolls sideways. */
.recent-sessions { margin-top: 16px; }
.recent-sessions h2 { margin: 0; }
#recent-sessions-period, #recent-sessions-read { margin: 2px 0 0; font-size: 13px; }
#recent-sessions-no-data, #recent-sessions-none { margin: 12px 0 0; }
#recent-sessions-more { margin: 12px 0 0; }
.sessions { margin-top: 12px; }
.sessions caption { text-align: left; caption-side: top; color: var(--muted); font-size: 12.5px; padding: 0 0 8px; }
.sessions td { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
@media (max-width: 639.98px) {
  .sessions, .sessions caption, .sessions tbody, .sessions tr, .sessions td { display: block; width: 100%; }
  .sessions thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .sessions tr.session { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .sessions tr.session:last-child { border-bottom: 0; }
  .sessions td { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; border-bottom: 0; text-align: right; }
  .sessions td::before {
    content: attr(data-label); flex: none; text-align: left;
    color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  }
}
