/* Energy board. No external fonts, images or requests.
   Where a card sits and how big it is: layout.js. This file is only how things look. */
:root {
  color-scheme: light;
  --brand: #0b7a3b; --on-brand: #ffffff;
  --page: #eef2ef; --surface: #ffffff; --border: #d9e0dc;
  --ink: #14181a; --ink-2: #4d5450; --muted: #5f6762;   /* small print: 5.2:1 on a tile, 5.8:1 on a card */
  --grid: #e4e8e5; --track: #e4e8e5;
  --series: #008300; --series-soft: #bfe3bf;
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #c98500; --c0: #9aa29d;   /* c4: 3:1 on a card, as a bar must be */
  /* The four subjects of the board (layout.js `group`): the line on top of a card and its chart. */
  --g-meters: #55677d; --g-consumption: #008300; --g-vending: #2a78d6; --g-generation: #c98500;
  --warn-bg: #fff4d6; --warn-ink: #5c4300;
  --gap: 6px;
}
/* Light is the default, as the owner's report; ?theme=dark switches (app.js). */
:root[data-theme="dark"] {
    color-scheme: dark;
    --brand: #0b7a3b; --on-brand: #ffffff;
    --page: #0f1211; --surface: #191d1b; --border: #2b312e;
    --ink: #f2f4f2; --ink-2: #c3c9c5; --muted: #98a19c;
    --grid: #272c29; --track: #2b312e;
    --series: #0ca30c; --series-soft: #1d4a1d;
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c0: #6f7772;
    --g-meters: #8fa3bb; --g-consumption: #0ca30c; --g-vending: #3987e5; --g-generation: #c98500;
    --warn-bg: #3a2f10; --warn-ink: #f3dfa6;
}
* { box-sizing: border-box; }
/* Text grows with the window height, so a large screen is not filled with small print.
   Everything is sized in rem from here; charts.js scales its margins by the same factor. */
html { font-size: clamp(12.5px, 1.45vh, 15.5px); }
html, body { height: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); overflow: hidden;
       display: flex; flex-direction: column;
       font: 1rem/1.3 system-ui, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }

/* ── header ─────────────────────────────────────────────────────────────── */
header { flex: none; display: flex; align-items: center; gap: 18px; min-height: 3.2rem; padding: 4px 12px;
         background: var(--brand); color: var(--on-brand); }
.wordmark { font-size: 1.36rem; font-weight: 300; letter-spacing: .04em; text-transform: lowercase; white-space: nowrap; opacity: .92; }
h1 { font-size: 1.44rem; font-weight: 500; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .right { margin: 0 0 0 auto; display: flex; align-items: center; gap: 8px; font-size: 0.92rem; min-width: 0; }
#meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .92; }
.chip { flex: none; padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .55); cursor: help; white-space: nowrap; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; font-weight: 600; }
.message { background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
           padding: 28px 16px; text-align: center; margin: 24px auto; max-width: 560px; font-size: 1.12rem; }

/* ── the grid: fills the window, never scrolls the page ─────────────────── */
#grid { flex: 1; min-height: 0; display: grid; gap: var(--gap); padding: var(--gap);
        grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
        grid-template-rows: repeat(var(--rows), minmax(0, 1fr)); }
.card { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column;
        background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px 4px; }
.card h2 { flex: none; margin: 0 0 3px; font-size: 1rem; font-weight: 600; color: var(--ink-2);
           white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .body { flex: 1; min-height: 0; min-width: 0; position: relative; overflow: hidden; }
/* A group: its colour on top of the card, and as the colour of the card's own series. */
.card[data-group] { border-top: 3px solid var(--group); padding-top: 3px; }
.card[data-group="meters"] { --group: var(--g-meters); --series: var(--g-meters); --series-soft: color-mix(in srgb, var(--g-meters) 28%, var(--surface)); }
.card[data-group="consumption"] { --group: var(--g-consumption); }
.card[data-group="vending"] { --group: var(--g-vending); --series: var(--g-vending); --series-soft: color-mix(in srgb, var(--g-vending) 28%, var(--surface)); }
.card[data-group="generation"] { --group: var(--g-generation); }
.card .note { flex: none; margin: 2px 0 0; font-size: 0.84rem; line-height: 1.2; color: var(--muted);
              display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.none { margin: 0; height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.flag { margin-left: 6px; padding: 0 5px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink);
        font-size: 0.8rem; font-weight: 600; white-space: nowrap; }

/* Narrow or low windows: the cards stack in the order of layout.js and the page scrolls. */
body.stacked { overflow: auto; display: block; height: auto; }
body.stacked header { flex-wrap: wrap; }
body.stacked header .right { flex-wrap: wrap; margin-left: 0; }
body.stacked #meta, body.stacked h1 { white-space: normal; }
body.stacked #grid { display: flex; flex-direction: column; }
body.stacked .card.chart .body { height: 220px; flex: none; }

/* ── tiles ──────────────────────────────────────────────────────────────── */
.tiles { height: 100%; display: flex; gap: var(--gap); }
.tile { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: center;
        background: var(--page); border-radius: 5px; padding: 3px 8px; overflow: hidden; }
.tile .flag { margin: 0 5px 0 0; }
.tile .label { font-size: 0.88rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value { font-size: clamp(1.35rem, 2.6vh, 2.1rem); font-weight: 600; line-height: 1.15; white-space: nowrap; }
.tile .sub { font-size: 0.84rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ── the two controls ───────────────────────────────────────────────────── */
.period { height: 100%; display: flex; flex-direction: column; justify-content: space-evenly; gap: 3px; min-width: 0; }
.period .row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.period .steps { margin-left: auto; display: flex; gap: 3px; flex: none; }
.period .span { margin: 0; min-width: 0; display: flex; flex-direction: column; color: var(--ink-2); font-size: 0.88rem; }
.period .span strong { color: var(--ink); font-weight: 600; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The granularity slider (datestrip.js): four stops on a line, a knob on the chosen one, its name under it. */
.grain { flex: none; width: 6.6rem; padding: 0 0.7rem; cursor: pointer; touch-action: none; border-radius: 4px;
         user-select: none; -webkit-user-select: none; }
.grain .rail { position: relative; height: 1.75rem; }
.grain .rail::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0.3rem; height: 2px; background: var(--ink-2); }
.grain .stop { position: absolute; top: 0; transform: translateX(-50%); font-size: 0.8rem; line-height: 1.1rem; color: var(--ink-2); }
.grain .stop::after { content: ""; position: absolute; left: 50%; bottom: -0.45rem; width: 2px; height: 0.4rem; margin-left: -1px; background: var(--ink-2); }
.grain .stop.on { color: var(--ink); font-weight: 700; }
.grain:focus-visible .knob { box-shadow: 0 0 0 2px var(--c1); }
.grain .knob { position: absolute; top: -2px; bottom: 0; width: 1.25rem; transform: translateX(-50%);
               border: 2px solid var(--brand); border-radius: 5px; background: color-mix(in srgb, var(--brand) 10%, transparent); }
.grain .name { display: block; text-align: center; font-size: 0.8rem; color: var(--ink-2); line-height: 1.1; }
/* The strip of cells (datestrip.js). One cell is --cell wide whatever the number of buckets: the strip scrolls. */
.strip { --cell: 2.3rem; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
         scrollbar-width: thin; scrollbar-color: var(--muted) var(--track); outline: none; }
.strip .inner { margin: 0 0.6rem; }
.strip .groups { display: flex; height: 1.05rem; font-size: 0.76rem; line-height: 1.05rem; color: var(--ink-2); }
.strip .groups span { flex: none; min-width: 0; overflow: clip; border-left: 2px solid var(--ink-2); white-space: nowrap; }
.strip .groups b { position: sticky; left: 0; display: inline-block; padding: 0 5px; font-weight: 600; background: var(--surface); }
.strip .cells { position: relative; display: flex; height: 1.9rem; margin: 2px 0 5px; border-right: 1px solid var(--muted);
                cursor: pointer; touch-action: pan-x; user-select: none; -webkit-user-select: none; }
.strip .cell { flex: 0 0 var(--cell); min-width: 0; border: 1px solid var(--muted); border-right: 0; background: var(--surface);
               display: flex; align-items: center; justify-content: center; font-size: 0.74rem; color: var(--muted); }
.strip .cell.empty { background: repeating-linear-gradient(135deg, var(--surface) 0 4px, var(--grid) 4px 6px); color: transparent; }
.strip .cell.filling { background: var(--warn-bg); color: var(--warn-ink); font-weight: 600; }
.strip .cell.on { background: color-mix(in srgb, var(--brand) 32%, var(--surface)); color: var(--ink); }
.strip .cell.on.empty { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--brand) 32%, var(--surface)) 0 4px,
                                                               color-mix(in srgb, var(--brand) 14%, var(--surface)) 4px 6px); }
.strip .cell.on.filling { background: color-mix(in srgb, var(--brand) 32%, var(--warn-bg)); }
.strip .cell:hover { box-shadow: inset 0 0 0 1px var(--ink-2); }
.strip .dragging, .strip .dragging .cell { cursor: grabbing; }
.strip .handle { position: absolute; top: -3px; bottom: -3px; width: 0.72rem; min-height: 0; padding: 0; transform: translateX(-50%);
                 border: 0; border-radius: 0.4rem; background: var(--ink-2); cursor: ew-resize; touch-action: none; }
.strip .handle::after { content: ""; position: absolute; inset: -6px -8px; }       /* a finger-sized target */
button { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border);
                 border-radius: 4px; padding: 2px 8px; min-height: 1.9rem; }
button { cursor: pointer; }
button:disabled { color: var(--muted); cursor: default; opacity: .6; }
:focus-visible { outline: 2px solid var(--c1); outline-offset: 1px; }

/* ── charts ─────────────────────────────────────────────────────────────── */
.body svg { display: block; }
.body svg text { fill: var(--muted); font-size: 0.84rem; }
.body svg text.value { fill: var(--ink-2); }
.body svg text.centre { fill: var(--ink); font-size: 1.52rem; font-weight: 600; }
.body svg text.centre-label { fill: var(--muted); font-size: 0.84rem; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.bar { fill: var(--series); }
.bar.filling { fill: var(--series-soft); stroke: var(--series); stroke-width: 1; stroke-dasharray: 3 2; }
.area { fill: var(--series); fill-opacity: .16; }
.line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { fill: var(--series); }
.hit { fill: transparent; }
.hit:hover, .hit:focus { fill: var(--ink); fill-opacity: .07; outline: none; }
.seg { stroke: var(--surface); stroke-width: 2; }
.seg:hover, .seg:focus { opacity: .8; outline: none; }
.ring-empty { fill: none; stroke: var(--track); }
.gauge-track { fill: none; stroke: var(--track); }
.gauge-fill { fill: none; stroke: var(--series); }
.c0 { fill: var(--c0); background: var(--c0); } .c1 { fill: var(--c1); background: var(--c1); }
.c2 { fill: var(--c2); background: var(--c2); } .c3 { fill: var(--c3); background: var(--c3); }
.c4 { fill: var(--c4); background: var(--c4); }
/* Generation is drawn in the amber of the page, so it is told from consumption at a glance. */
.bar.c4 { fill: var(--c4); }
.bar.c4.filling { fill: color-mix(in srgb, var(--c4) 30%, var(--surface)); stroke: var(--c4); }
/* Energy filled from the logger's export, drawn over the bar it is part of (charts.js `hatched`). */
.hatch { stroke: var(--c4); stroke-width: 1; pointer-events: none; }
.hatch-ground { fill: var(--surface); }
.hatch-line { fill: var(--c4); }
.donut { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.donut.side { flex-direction: row; gap: 10px; }
.donut svg { flex: none; }                 /* the ring keeps its size; a long legend is cut instead */
.donut.side .legend { min-width: 0; }
.legend { list-style: none; margin: 0; padding: 0; font-size: 0.88rem; max-width: 100%; }
.legend li { display: flex; align-items: center; gap: 5px; line-height: 1.35; }
.legend i { flex: none; width: 9px; height: 9px; border-radius: 2px; }
.legend .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.legend .share { margin-left: auto; padding-left: 8px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.gauge { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge .foot { margin: 0; font-size: 0.88rem; color: var(--ink-2); text-align: center; }
.pending { height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 3px;
           border: 1px dashed var(--border); border-radius: 5px; padding: 4px 10px; color: var(--muted); font-size: 0.92rem; }
.pending strong { color: var(--ink-2); font-size: 1rem; }

/* ── table: scrolls inside its card ─────────────────────────────────────── */
.scroll { height: 100%; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 2px 6px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th[title] { cursor: help; }
/* The site choice: one radio per row, the whole name is the target. */
table.sites label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
table.sites input { margin: 0; accent-color: var(--brand); }
table.sites tr.all td { font-weight: 600; }
table.sites tr.on td { background: color-mix(in srgb, var(--brand) 13%, var(--surface)); }
table.sites tbody tr:hover td { background: color-mix(in srgb, var(--brand) 7%, var(--surface)); }
table.sites tr.on:hover td { background: color-mix(in srgb, var(--brand) 16%, var(--surface)); }
th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 600; }
th:first-child, td:first-child { text-align: left; }

.tip { position: fixed; z-index: 5; pointer-events: none; background: var(--surface); color: var(--ink);
       border: 1px solid var(--border); border-radius: 5px; padding: 5px 8px; font-size: 0.92rem;
       box-shadow: 0 4px 14px rgba(0, 0, 0, .18); max-width: 260px; }
.tip b { display: block; }
