:root {
  color-scheme: light;
  --page: #f4f3f0;
  --surface: #fcfcfb;
  --border: #e3e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --grid: #e9e8e3;
  /* Series colours follow the entity, in a fixed order */
  --grid-import: #2a78d6;
  --consumption: #eb6834;
  --grid-export: #1baf7a;
  --solar: #eda100;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --ok: #0ca30c;
  --bad: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #111110;
    --surface: #1a1a19;
    --border: #2e2e2b;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --grid: #2a2a27;
    --grid-import: #3987e5;
    --consumption: #d95926;
    --grid-export: #199e70;
    --solar: #c98500;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: inherit; }

.top {
  display: flex; align-items: baseline; gap: 24px;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { font-weight: 700; font-size: 20px; letter-spacing: -0.02em; text-decoration: none; }
nav { display: flex; gap: 16px; }
nav a { color: var(--text-2); text-decoration: none; }
nav a[aria-current], nav a:hover { color: var(--text); }
nav a[aria-current] { font-weight: 600; }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px; }
footer { max-width: 980px; margin: 0 auto; padding: 0 16px 24px; color: var(--text-2); font-size: 13px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.tile, .card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.tile { padding: 14px 16px; }
.tile-label { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 7px; }
.tile-value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.tile-value.muted { color: var(--text-2); }
.tile-sub { color: var(--text-2); font-size: 13px; min-height: 1.45em; }
code { font-size: 0.93em; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.swatch.consumption { background: var(--consumption); }
.swatch.solar { background: var(--solar); }
.swatch.grid-import { background: var(--grid-import); }
.swatch.grid-export { background: var(--grid-export); }

.meta { color: var(--text-2); font-size: 13px; margin: 8px 2px 0; }
.sep { margin: 0 4px; }
.state.ok { color: var(--ok); }
.state.bad { color: var(--bad); font-weight: 600; }

.card { margin-top: 16px; padding: 14px 16px 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 10px; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }

.ranges { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.ranges button {
  font: inherit; font-size: 13px; padding: 4px 11px; border: 0; background: none;
  color: var(--text-2); cursor: pointer;
}
.ranges button + button { border-left: 1px solid var(--border); }
.ranges button[aria-pressed="true"] { background: var(--page); color: var(--text); font-weight: 600; }

.chart { width: 100%; min-height: 300px; }
.u-legend { font-size: 13px; color: var(--text-2); text-align: left; }
.u-legend .u-value { color: var(--text); font-variant-numeric: tabular-nums; }

svg.daily { display: block; width: 100%; height: auto; }
svg.daily .gridline { stroke: var(--grid); stroke-width: 1; }
svg.daily .axis { fill: var(--text-2); font-size: 11px; }
svg.daily .grid { fill: var(--grid-import); }
svg.daily .solar { fill: var(--solar); }
svg.daily .hit { fill: transparent; }
svg.daily .day:hover .hit { fill: var(--grid); }

details { margin-top: 10px; font-size: 13px; }
summary { cursor: pointer; color: var(--text-2); }
table { border-collapse: collapse; width: 100%; margin-top: 8px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
.dim { color: var(--text-2); font-size: 12px; margin-left: 6px; }
.scroll { overflow-x: auto; }
.stats { display: flex; flex-wrap: wrap; gap: 10px 32px; margin: 4px 0 0; }
.stats dt { color: var(--text-2); font-size: 13px; }
.stats dd { margin: 0; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
h2 .dim { font-weight: 400; }
.card-head .meta { margin: 0; }
td { white-space: nowrap; }
th { color: var(--text-2); font-weight: 500; }

/* signing in and out */
.signout { margin-left: auto; }
.signout button {
  border: 0; padding: 0; background: none; color: var(--text-2); font: inherit; cursor: pointer;
}
.signout button:hover { color: var(--text); }
.login { max-width: 340px; margin: 12vh auto 0; padding: 22px 22px 24px; display: grid; gap: 10px; }
.login h1 { margin: 0 0 6px; font-size: 20px; }
.login label { color: var(--text-2); font-size: 13px; }
.login input[type="password"] {
  width: 100%; padding: 9px 10px; font: inherit; color: var(--text);
  background: var(--page); border: 1px solid var(--border); border-radius: 6px;
}
.login input[aria-invalid] { border-color: var(--consumption); }
.login button {
  margin-top: 6px; padding: 9px 10px; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--surface); background: var(--text); border: 0; border-radius: 6px;
}
.login .error { margin: 0; font-size: 13px; }

/* devices */
.devices td { vertical-align: middle; }
.devices td.action { width: 1%; white-space: nowrap; }
.switch {
  padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; border-radius: 6px;
  color: var(--text); background: var(--page); border: 1px solid var(--border);
}
.switch[aria-pressed="true"] { font-weight: 600; }
.switch:disabled { opacity: 0.5; cursor: wait; }
.alert {
  margin: 0 0 12px; padding: 12px 16px; border-radius: 10px; font-weight: 600;
  color: var(--bad); background: var(--surface); border: 2px solid var(--bad);
}

.weather-now { margin: 0 0 12px; }
.weather-now strong { font-size: 1.4rem; margin-right: 6px; }

/* opened from the home screen: keep clear of the notch and the home indicator */
.top { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
main, footer { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
footer { padding-bottom: max(24px, env(safe-area-inset-bottom)); }

/* sortable table headings */
th a.sort { color: inherit; text-decoration: none; white-space: nowrap; }
th a.sort:hover { color: var(--text); text-decoration: underline; }
th[aria-sort="ascending"] a.sort, th[aria-sort="descending"] a.sort { color: var(--text); font-weight: 600; }
