/*
 * 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;
  --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; }
