:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7973;
  --grid: #e9e8e3;
  --accent: #2a78d6;
  /* chart series, fixed order (validated palette) */
  --s-load: #2a78d6;
  --s-grid: #eb6834;
  --s-batt: #1baf7a;
  --s-pv: #eda100;
  --warn-bg: #fdf3d8;
  --warn-text: #5c4300;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2e2e2b;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e85;
    --grid: #2a2a27;
    --accent: #3987e5;
    --s-load: #3987e5;
    --s-grid: #d95926;
    --s-batt: #199e70;
    --s-pv: #c98500;
    --warn-bg: #3a2e0c;
    --warn-text: #f3dc9a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 13px; margin: 0 0 10px; color: var(--text-2); font-weight: 600;
     text-transform: uppercase; letter-spacing: 0.05em; }
.grow { flex: 1; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-2);
}
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 8px; }
section { margin-bottom: 28px; }
footer { max-width: 1100px; margin: 0 auto; padding: 0 16px 28px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.row h2 { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; white-space: nowrap; }
.tile .sub { font-size: 13px; color: var(--text-3); line-height: 1.3; margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-top: 10px; }
.chart { width: 100%; height: 620px; }
.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 8px 12px; margin: 10px 0 0; font-size: 14px; }

.datenav { display: flex; gap: 6px; align-items: center; }
button, input[type="date"] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; min-height: 34px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--text-3); }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, input:focus-visible, tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
th { font-size: 13px; font-weight: 600; color: var(--text-2); }
.num { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr[aria-selected="true"] { background: var(--bg); }
tbody tr:last-child td { border-bottom: 0; }
td.partial { color: var(--text-3); }

.status { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.status li { display: flex; gap: 10px; align-items: baseline; font-size: 14px; }
.status .name { min-width: 110px; color: var(--text-2); }
.status .state { min-width: 70px; font-weight: 600; }

@media (max-width: 600px) {
  .chart { height: 560px; }
  .tile .value { font-size: 20px; }
}

.login { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
.login h1 { font-size: 22px; margin-bottom: 18px; }
.login form { display: grid; gap: 10px; }
.login label { font-size: 14px; color: var(--text-2); }
.login input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
               border-radius: 8px; padding: 9px 10px; width: 100%; }
.login button { padding: 9px 10px; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.login pre { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.linkbutton { border: 0; background: none; color: var(--text-2); padding: 4px 6px; min-height: 0; text-decoration: underline; }

/* sortable table: scrolls inside its card, header stays in view */
.tablewrap { max-height: 560px; overflow-y: auto; }
thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; box-shadow: 0 1px 0 var(--border); padding: 4px 6px; }
button.sort { border: 0; background: none; font-size: 13px; font-weight: 600; color: var(--text-2);
              padding: 6px; min-height: 0; white-space: nowrap; }
button.sort:hover { color: var(--text); }
th[aria-sort="ascending"] button.sort, th[aria-sort="descending"] button.sort { color: var(--text); }

.caption { margin: 0; padding: 0 14px 14px; font-size: 13px; color: var(--text-3); }

/* full-width mode: use the whole screen; on very wide screens the day and the
   table of days sit side by side */
body.wide main, body.wide footer { max-width: none; padding-left: 24px; padding-right: 24px; }
@media (min-width: 2400px) {
  body.wide main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 28px; align-items: start; }
  body.wide .s-live, body.wide .s-sum, body.wide .s-status { grid-column: 1 / -1; }
  body.wide .s-day { grid-column: 1; }
  body.wide .s-days { grid-column: 2; }
  body.wide .tablewrap { max-height: 880px; }
}
@media (max-width: 700px) { #wide { display: none; } }

.noteform { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.noteform label { font-size: 13px; color: var(--text-2); }
.noteform input { flex: 1 1 280px; min-width: 0; font: inherit; color: var(--text); background: var(--surface);
                  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-height: 34px; }
#days td:first-child { white-space: normal; min-width: 150px; }

.login section, .login details { margin-top: 14px; }
.login summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.login .cancel { margin-top: 18px; display: flex; gap: 14px; align-items: center; }
.login .cancel .linkbutton { background: none; color: var(--text-2); font-weight: 400; padding: 4px 0; }
.seclist { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.seclist li { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.seclist .name { min-width: 160px; }
button.small { font-size: 13px; padding: 2px 8px; min-height: 26px; }

main.after { padding-top: 0; }
body.wide main.after { display: block; }
h3 { margin: 12px 0 6px; font-weight: 600; }
