/* talo.css: the look of the summary page, taken from the approved mockup (data_local/visualizations/talo-yhteenveto.html).
   Colours are tokens on :root with a dark variant; the page never sets a colour directly. Tones: ok, warn, alert
   (data flow broken), off (no reading / stale). Phone width: two columns under 640 px, one under 400 px. */
:root {
  --bg: #f3f5f2;
  --panel: #ffffff;
  --panel-2: #eaeeea;
  --ink: #1f2925;
  --muted: #5d6b64;
  --line: #d5ddd7;
  --accent: #2b5f8a;
  --accent-soft: #e2ecf4;
  --ok: #2f7a4f;
  --ok-bg: #e3f1e7;
  --warn: #8a5a10;
  --warn-bg: #f8eed8;
  --alert: #9c2f2f;
  --alert-bg: #f6e0e0;
  --off: #8a948e;
  --off-bg: #eef0ee;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;   /* system stack: no font download */
  --mono: ui-monospace, "SF Mono", Menlo, "Cascadia Mono", Consolas, monospace;
  /* Chart series (categorical, in this fixed order; validated for colour vision on both surfaces). The status
     tones above are never used as series colours. */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161b19; --panel: #1f2624; --panel-2: #283130; --ink: #e6ece8; --muted: #a4b0aa; --line: #37423d;
    --accent: #8fbfe6; --accent-soft: #24384a; --ok: #8fd0a6; --ok-bg: #223a2c; --warn: #efc57a; --warn-bg: #3e3320;
    --alert: #f0a0a0; --alert-bg: #47282a; --off: #8c968f; --off-bg: #2a302d;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  }
}
:root[data-theme="dark"] {
  --bg: #161b19; --panel: #1f2624; --panel-2: #283130; --ink: #e6ece8; --muted: #a4b0aa; --line: #37423d;
  --accent: #8fbfe6; --accent-soft: #24384a; --ok: #8fd0a6; --ok-bg: #223a2c; --warn: #efc57a; --warn-bg: #3e3320;
  --alert: #f0a0a0; --alert-bg: #47282a; --off: #8c968f; --off-bg: #2a302d;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; }
.wrap { max-width: 880px; margin: 0 auto; padding-block: 20px 40px; padding-inline: 16px; }
header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.brand { font-size: 17px; font-weight: 600; letter-spacing: .01em; }
.who { font-size: 12px; color: var(--muted); display: flex; gap: 12px; align-items: baseline; }
h1 { font-size: 26px; font-weight: 600; margin: 0; text-wrap: balance; }
.when { color: var(--muted); margin: 4px 0 18px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 0 10px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
h2 small { font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 12px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

button, .btn { font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
button.link { border: 0; background: transparent; color: var(--accent); padding: 0; font-size: 12px; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Connection lost / status line above the content */
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; background: var(--warn-bg); color: var(--warn); }
.banner[data-tone="alert"] { background: var(--alert-bg); color: var(--alert); }
.banner[data-tone="ok"] { background: var(--panel-2); color: var(--muted); }

/* Yhteys */
.health { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.health-top { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.health[data-state="warn"] .dot { background: var(--warn); }
.health[data-state="alert"] .dot { background: var(--alert); }
.health[data-state="off"] .dot { background: var(--off); }
.health-top strong { font-weight: 600; }
.health-top .sub { color: var(--muted); }
.health-top .more { color: var(--warn); font-size: 13px; margin-top: 2px; }
.sources { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.src { padding: 12px 16px; border-right: 1px solid var(--line); min-width: 0; }
.src:last-child { border-right: 0; }
.src .name { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.src .age { color: var(--muted); font-size: 13px; margin-top: 2px; }
.pill { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 2px 7px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); }
.pill[data-k="warn"] { background: var(--warn-bg); color: var(--warn); }
.pill[data-k="alert"] { background: var(--alert-bg); color: var(--alert); }
.pill[data-k="off"] { background: var(--off-bg); color: var(--off); }
.pipe { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); background: var(--panel-2); }
.pipe div { padding: 10px 16px; font-size: 13px; color: var(--muted); min-width: 0; }
.pipe b { color: var(--ink); font-weight: 500; }
.pipe [data-tone="warn"] b { color: var(--warn); }
.pipe [data-tone="alert"] b { color: var(--alert); }

/* Tiles */
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-size: 28px; font-weight: 500; line-height: 1.15; margin-top: 6px; }
.tile .value .unit { font-size: 15px; font-weight: 400; color: var(--muted); margin-left: 3px; font-family: var(--font); }
.tile .state { font-size: 14px; }
.tile .meta { color: var(--muted); font-size: 12px; margin-top: 6px; overflow-wrap: anywhere; }
.tile[data-tone="warn"] { border-style: dashed; }
.tile[data-tone="warn"] .value { color: var(--off); }
.tile[data-tone="warn"] .meta { color: var(--warn); }
.tile[data-tone="off"] .value { color: var(--off); }
.tile[data-tone="off"] .state { color: var(--muted); }
.tile.later { background: transparent; border-style: dashed; color: var(--muted); justify-content: flex-start; }
.tile.later .label { color: var(--ink); font-weight: 500; }
.tile.later .why { font-size: 12px; margin-top: 4px; }

/* Lämmitys */
.rows { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding-inline: 16px; }
.rows[data-tone="warn"] { border-style: dashed; }
.rows[data-tone="warn"] .r { color: var(--off); }
.rows[data-tone="warn"] .l .meta { color: var(--warn); }
.rows[data-tone="off"] .r { color: var(--off); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row .l { min-width: 0; }
.row .l .meta { color: var(--muted); font-size: 12px; }
.row .r { text-align: right; flex-shrink: 0; font-size: 18px; font-weight: 500; }
.row .r .unit { font-size: 13px; color: var(--muted); font-family: var(--font); font-weight: 400; }
.row .r .meta { display: block; font-size: 12px; color: var(--muted); font-weight: 400; font-family: var(--font); }

details { margin-top: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
summary { padding: 13px 16px; font-weight: 500; cursor: pointer; }
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }
.detail { padding: 0 16px 14px; color: var(--muted); font-size: 14px; }
.detail ul { margin: 0; padding-left: 20px; }
.detail li + li { margin-top: 6px; }
.detail b { color: var(--ink); font-weight: 500; }
.foot { margin-top: 16px; color: var(--muted); font-size: 12px; }

/* Login */
.login { max-width: 420px; margin: 40px auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px 20px; }
.login h1 { font-size: 22px; margin-bottom: 6px; }
.login p { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.login form { display: flex; flex-direction: column; gap: 10px; }
.login label { font-size: 13px; color: var(--muted); }
.login input { font: inherit; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; }
.login .msg { font-size: 14px; margin-top: 12px; }
.login .msg[data-tone="alert"] { color: var(--alert); }
.login .msg[data-tone="ok"] { color: var(--ok); }

/* Tabs in the header (Talous | Yhteenveto) */
.tabs { display: flex; gap: 2px; background: var(--panel-2); border-radius: 8px; padding: 3px; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 6px; font-size: 13px; }
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }

/* Talous: head, day picker, controls */
.t-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.t-head .when { margin-bottom: 0; }
.t-pick label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
select { font: inherit; font-size: 14px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); max-width: 100%; }
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.t-empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 18px 16px; }
.t-empty .meta { color: var(--muted); margin-top: 4px; }
.meta { color: var(--muted); font-size: 12px; }
.meta.warn { color: var(--warn); }
.t-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.seg { display: inline-flex; gap: 2px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--bg); max-width: 100%; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 4px 10px; border-radius: 6px; font-size: 12px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }

/* Talous: KPI cards and the strip under them */
.t-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.t-kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.t-kpi[data-kpi="balance"] { background: var(--accent-soft); }
.t-kpi .label { font-size: 13px; }
.t-kpi .value { font-size: 28px; font-weight: 500; line-height: 1.15; margin: 6px 0 4px; white-space: nowrap; }
.t-kpi .sub { font-size: 12px; color: var(--muted); }
.t-kpi .note { font-size: 12px; color: var(--warn); margin-top: 4px; }
.t-strip { display: flex; justify-content: space-between; align-items: center; gap: 8px 18px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 10px 2px 0; }
.t-strip .items { display: flex; gap: 6px 18px; flex-wrap: wrap; }
.t-strip b { color: var(--ink); font-weight: 500; }
.t-strip button.link { font-size: 13px; }

/* Talous: panels, rows, tables */
.t-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.t-panel + .t-panel { margin-top: 10px; }
.t-panel h3 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.t-panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.t-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.t-row:first-of-type { border-top: 0; }
.t-row .l { min-width: 0; }
.t-row .r { flex-shrink: 0; text-align: right; }
.t-row.total { font-weight: 600; }
.t-row.total + .t-row { border-top-width: 2px; }
.t-two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.t-details summary { padding: 13px 16px; }
.t-details .t-two { padding: 0 16px 14px; }
.t-details .seg { margin: 6px 0; }
.t-tablewrap { overflow-x: auto; margin-top: 10px; }
.t-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.t-table caption { text-align: left; color: var(--muted); padding-bottom: 4px; }
.t-table th, .t-table td { text-align: right; padding: 4px 5px; border-top: 1px solid var(--line); white-space: nowrap; }
.t-table th { color: var(--muted); font-weight: 500; }
.t-table th:first-child, .t-table td:first-child { text-align: left; }
.t-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; padding-top: 10px; margin-top: 8px; border-top: 1px solid var(--line); font-size: 13px; }
.t-totals div { display: flex; justify-content: space-between; gap: 10px; }
.t-totals span { color: var(--muted); }
.t-totals b { font-weight: 500; }
.detail ul { margin: 4px 0 10px; padding-left: 20px; }
.detail b { color: var(--ink); font-weight: 500; }

/* Talous: the hour slider and the selected hour */
.t-scrub { display: flex; align-items: center; gap: 12px; margin: 8px 0 10px; flex-wrap: wrap; }
.t-scrub label { font-size: 12px; color: var(--muted); }
.t-scrub label .num { color: var(--ink); margin-left: 4px; }
.t-scrub input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--accent); }
.t-selected { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px 14px; background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.t-selected .lbl { font-size: 11px; color: var(--muted); }
.t-selected .val { font-size: 15px; }

/* Talous: charts (inline SVG built by talous.js; colours only through classes) */
.chartbox { min-width: 0; }
.chart { display: block; width: 100%; max-width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-family: var(--font); font-size: 11px; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--off); stroke-width: 1; }
.chart .cut { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .sel { fill: var(--accent); opacity: .12; }
.chart .note { fill: var(--muted); }
.chart .b-actual { fill: var(--s1); } .chart .b-solar { fill: var(--s2); } .chart .b-house { fill: var(--s3); }
.chart .l-actual { stroke: var(--s1); fill: none; stroke-width: 2.5; stroke-linejoin: round; }
.chart .l-solar { stroke: var(--s2); fill: none; stroke-width: 2; stroke-dasharray: 6 4; stroke-linejoin: round; }
.chart .l-house { stroke: var(--s3); fill: none; stroke-width: 2; stroke-dasharray: 2 4; stroke-linejoin: round; }
.chart .d-actual { fill: var(--s1); } .chart .d-solar { fill: var(--s2); } .chart .d-house { fill: var(--s3); }
.chart .b-buy { fill: var(--s2); } .chart .b-sell { fill: var(--s1); }
.chart .l-buy { stroke: var(--s2); fill: none; stroke-width: 2; } .chart .l-sell { stroke: var(--s1); fill: none; stroke-width: 2; }
.chart .l-pv { stroke: var(--s4); fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .l-price { stroke: var(--s1); fill: none; stroke-width: 2; }
.chart .l-price-future { stroke: var(--muted); fill: none; stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .b-charge { fill: var(--s2); } .chart .b-discharge { fill: var(--s1); }
.chart .b-hp { fill: var(--s3); }
.chart .l-temp { stroke: var(--s2); fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .d-temp { fill: var(--s2); }
.chart rect, .chart circle { cursor: default; }
.legend { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 16px; height: 3px; background: currentColor; }
.sw.box { width: 10px; height: 10px; border-radius: 2px; }
.sw.dashed { background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px); }
.sw.dotted { background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 5px); }
.sw.s-actual, .sw.s-sell, .sw.s-price, .sw.s-discharge { color: var(--s1); }
.sw.s-solar, .sw.s-buy, .sw.s-charge, .sw.s-temp { color: var(--s2); }
.sw.s-house, .sw.s-hp { color: var(--s3); }
.sw.s-pv { color: var(--s4); }
.sw.s-future { color: var(--muted); }

/* Visually hidden, still read by assistive technology (the hour table behind the charts) */
.vh { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sources { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .src:nth-child(2) { border-right: 0; }
  .src:nth-child(n+3) { border-top: 1px solid var(--line); }
  .pipe { grid-template-columns: 1fr; }
  .pipe div + div { border-top: 1px solid var(--line); }
  .tile .value { font-size: 24px; }
  .t-kpis { grid-template-columns: 1fr; }
  .t-kpi .value { font-size: 24px; }
  .t-two { grid-template-columns: 1fr; }
  .t-selected { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .t-totals { grid-template-columns: 1fr; }
  header { align-items: center; }
  .tabs { order: 3; width: 100%; }
  .tabs button { flex: 1; }
}
@media (max-width: 400px) {
  .grid { grid-template-columns: 1fr; }
}
@media (pointer: coarse) {
  .seg button, .tabs button, select { min-height: 40px; }
  .t-scrub input[type="range"] { min-height: 40px; }
}
