/* Base styles of the EMS cloud. Tokens follow the EcoEnergy design draft A5 (same set as
   the cockpit and the box). Three switchable design variants set the tokens:
   tag (light, scale model), nacht (dark), plan (drawing sheet). */
@font-face {
  font-family: 'Questrial'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/static/questrial-latin.woff2') format('woff2');
}

:root {
  --ground: #f2f2f2; --paper: #ffffff; --ink: #000000; --ink-2: #4b4f54;
  --rule: #d4d4d4; --rule-soft: #e6e6e6; --hover: #f7f7f7;
  --accent: #a8c800; --accent-text: #4d5c00; --warn: #ffec1f; --err: #c31005; --err-text: #a50d04;
  --btn: #000000; --btn-text: #ffffff;
  --head: 'Questrial', 'Helvetica Neue', Arial, sans-serif;
  --body: 'Helvetica Neue', Arial, sans-serif;
  --stage: #e7e6e3; --devstage: #efefef; --grid: #c0c0c0;
  --c-pv: #a8c800; --c-feed: #d3e37f; --c-load: #000000; --c-grid: #7a828b; --c-batt: #8a7a00;
  --chip: rgba(255, 255, 255, .92); --chip-line: transparent;
  --radius: 10px; --card-line: transparent;
}
:root[data-design="nacht"] {
  --ground: #000000; --paper: #121212; --ink: #f2f2f2; --ink-2: #a6aaae;
  --rule: #333333; --rule-soft: #222222; --hover: #1b1b1b;
  --accent-text: #c4e03a; --err: #e0291c; --err-text: #ff6a5e;
  --btn: #f2f2f2; --btn-text: #000000;
  --stage: #060807; --devstage: #010101; --grid: #454545;
  --c-feed: #56660a; --c-load: #f2f2f2; --c-grid: #8d96a0; --c-batt: #ffec1f;
  --chip: rgba(18, 18, 18, .88); --chip-line: #333333;
  color-scheme: dark;
}
:root[data-design="plan"] {
  --ground: #e6e4e5; --paper: #efeeee; --ink: #111111; --ink-2: #4b4f54;
  --rule: #111111; --rule-soft: #c9c7c8; --hover: #dddbdc;
  --stage: #e6e4e5; --devstage: #efefec; --grid: #a9a7a8;
  --c-feed: #cfdc8a; --c-load: #111111; --c-grid: #6b7178; --c-batt: #6f6200;
  --chip: #efeeee; --chip-line: #111111;
  --radius: 2px; --card-line: #111111;
  --body: ui-monospace, 'Cascadia Mono', 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.5 var(--body); background: var(--ground); color: var(--ink);
       min-height: 100vh; }
:root[data-design="plan"] body { font-size: 14px; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* Header: one line, stays on top */
.menu { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 4px;
        height: 64px; padding: 0 24px; background: var(--ground);
        border-bottom: 1px solid var(--rule); }
.menu .brand { font-family: var(--head); font-size: 21px; margin-right: 24px; white-space: nowrap;
               display: flex; align-items: center; gap: 10px; text-decoration: none; height: 100%; }
.menu .brand::before { content: ""; width: 10px; height: 26px; background: var(--accent);
                       border-radius: 2px; }
.menu nav { display: flex; height: 100%; overflow-x: auto; scrollbar-width: none; }
.menu nav a { display: flex; align-items: center; height: 100%; padding: 0 12px;
              color: var(--ink-2); text-decoration: none; font-family: var(--head); font-size: 17px;
              white-space: nowrap; border-bottom: 3px solid transparent; }
.menu nav a:hover { background: var(--hover); }
.menu nav a.active { color: var(--ink); border-bottom-color: var(--ink); }
.menu .tools { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.menu .host { font-size: 12px; color: var(--ink-2); text-align: right; white-space: nowrap;
              line-height: 1.3; }
.seg { display: inline-flex; border: 1px solid var(--ink); border-radius: 4px; overflow: hidden; }
.seg a, .seg button { min-height: 34px; padding: 0 12px; font-size: 14px; display: inline-flex;
                      align-items: center; white-space: nowrap; text-decoration: none;
                      background: transparent; color: var(--ink); border: 0; border-radius: 0;
                      font-weight: 400; cursor: pointer; font-family: var(--body); }
.seg a + a, .seg button + button { border-left: 1px solid var(--ink); }
.seg a:hover, .seg button:hover { background: var(--hover); }
.seg a[aria-current="true"], .seg button[aria-pressed="true"] { background: var(--btn);
                                                                color: var(--btn-text); font-weight: 700; }
main { padding: 24px; max-width: 1360px; margin: 0 auto; }

h1 { font-family: var(--head); font-weight: 400; font-size: 30px; line-height: 1.2; margin: 0 0 18px; }
h2 { font-family: var(--head); font-weight: 400; font-size: 21px; margin: 0 0 12px; }
h3 { font-family: var(--head); font-weight: 400; font-size: 17px; margin: 0 0 8px; }
.pagehead { display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
            flex-wrap: wrap; }
.pagehead h1 .muted { font-family: var(--body); margin-left: 8px; }
.card { background: var(--paper); border-radius: var(--radius); padding: 18px 22px;
        margin-bottom: 16px; border: 1px solid var(--card-line); }
.hint { background: var(--warn); color: #000; border-radius: 999px; padding: 5px 14px;
        text-decoration: none; display: inline-block; margin: 0 0 10px; font-size: 14px; }
.note { border-left: 4px solid var(--accent); background: var(--paper); padding: 10px 14px;
        margin: 0 0 16px; border-radius: 0 var(--radius) var(--radius) 0; }
.note.bad { border-left-color: var(--err); }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px;
         margin-bottom: 16px; }
.tile { background: var(--paper); border-radius: var(--radius); padding: 16px 22px;
        min-height: 104px; display: flex; flex-direction: column; justify-content: center;
        gap: 2px; border: 1px solid var(--card-line); }
.tile span { display: block; color: var(--ink-2); font-size: 14px; order: 2; }
.tile b { font-weight: 700; font-size: clamp(24px, 2.2vw, 34px); line-height: 1.2;
          white-space: nowrap; font-variant-numeric: tabular-nums; order: 1; }
.tile b small { font-size: .5em; font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.tile.blk { background: var(--btn); color: var(--btn-text); }
.tile.blk span, .tile.blk b small { color: inherit; opacity: .8; }
.muted { color: var(--ink-2); font-size: 13px; }
.error { color: var(--err-text); }
.ok { color: var(--accent-text); font-weight: 700; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-2); padding: 10px 12px 8px 0;
     border-bottom: 1px solid var(--ink); white-space: nowrap; }
td { padding: 9px 12px 9px 0; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
table.facts th { width: 1%; border-bottom: 1px solid var(--rule-soft); font-size: 13px; padding-right: 24px; }

.actions, form.inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: end; }
form.profile { display: grid; gap: 10px; max-width: 420px; margin-top: 14px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 15px; }
input, select { font: inherit; color: var(--ink); background: var(--paper); padding: 9px 10px;
                border: 1px solid var(--rule); border-radius: 4px; min-height: 40px; }
input[type="checkbox"] { min-height: 0; width: 18px; height: 18px; accent-color: var(--accent); }
button, .button { font: inherit; font-weight: 700; background: var(--btn); color: var(--btn-text);
                  border: 0; border-radius: 4px; padding: 9px 16px; min-height: 40px; cursor: pointer;
                  text-decoration: none; display: inline-flex; align-items: center;
                  justify-content: center; white-space: nowrap; }
button.secondary, .button.secondary { background: transparent; color: var(--ink);
                                      box-shadow: inset 0 0 0 1px var(--ink); }
button:disabled { opacity: .3; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Login */
body.login { display: grid; place-items: center; padding: 16px; }
body.login .card { width: min(380px, 100%); display: grid; gap: 14px; padding: 32px 28px; }
body.login h1 { margin: 0; font-size: 26px; }
body.login h1::before { content: ""; display: block; height: 6px; width: 56px; margin-bottom: 14px;
                        background: var(--accent); border-radius: 3px; }

/* uPlot draws its scales on canvas; the colours come from the tokens in app.js. */
div.uplot { font-family: var(--body); color: var(--ink); width: 100%; }
div.uplot .u-legend { font-size: 13px; font-variant-numeric: tabular-nums; }
div.uplot .u-legend th { font-weight: 500; color: var(--ink-2); border: 0; }
div.uplot .u-legend td { border: 0; padding: 0; }
div.uplot .u-cursor-x, div.uplot .u-cursor-y { border-color: var(--ink-2); }
div.uplot .u-select { background: var(--hover); }

body.print { display: block; padding: 24px; background: var(--paper); }
@media print { .noprint { display: none; } }

@media (max-width: 900px) {
  .menu { height: 56px; padding: 0 12px; gap: 0; }
  .menu .brand { font-size: 0; margin-right: 6px; }
  .menu .host { display: none; }
  .menu nav a { padding: 0 9px; font-size: 15px; }
  .menu .seg a { padding: 0 6px; font-size: 12px; min-height: 30px; }
  main { padding: 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 14px; min-height: 84px; }
  h1 { font-size: 24px; }
}
