/* WattWatch. One stylesheet, no build step. Colours are roles, defined once
   for light and once for dark; charts read the same variables. */

:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --raised: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-0: #898781;
  --house: #b4b2a9;
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #184f95;
  --seq-7: #0d366b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --raised: #222221;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --good-text: #0ca30c;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --house: #5f5e5a;
    --seq-1: #0d366b;
    --seq-2: #184f95;
    --seq-3: #256abf;
    --seq-4: #3987e5;
    --seq-5: #6da7ec;
    --seq-6: #9ec5f4;
    --seq-7: #cde2fb;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.hide { display: none !important; }

/* ---- frame ---- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.top-in { max-width: 1240px; margin: 0 auto; padding: 10px 16px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 17px; text-decoration: none; }
.brand svg { width: 22px; height: 22px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1 1 auto; }
.tabs a {
  padding: 8px 12px 10px; text-decoration: none; color: var(--ink-2); white-space: nowrap;
  border-bottom: 2px solid transparent; font-size: 14px;
}
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 13px; color: var(--ink-2); white-space: nowrap; margin-bottom: 8px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.good { background: var(--good); }
.dot.bad { background: var(--critical); }
.dot.warn { background: var(--warning); }
main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 64px; }
.banner {
  border: 1px solid var(--border); border-left: 3px solid var(--warning); background: var(--surface);
  border-radius: 8px; padding: 12px 14px; margin-bottom: 16px;
}
.banner.bad { border-left-color: var(--critical); }

/* ---- cards and tiles ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 12px; }
.card-head p { margin: 2px 0 0; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.section { margin-top: 16px; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.delta-good { color: var(--good-text); }
.delta-bad { color: var(--critical); }

.hero { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr); align-items: stretch; }
.hero-now { display: flex; flex-direction: column; justify-content: center; }
.hero-now .value { font-size: 56px; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
.hero-now .value small { font-size: 22px; font-weight: 500; color: var(--ink-2); margin-left: 4px; letter-spacing: 0; }
.hero-now .facts { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 10px; color: var(--ink-2); font-size: 14px; }
.hero-now .facts b { color: var(--ink); font-weight: 600; }
.hero .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; } .hero-now .value { font-size: 44px; } }
@media (max-width: 560px) { .hero .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .tile .value { font-size: 22px; } }

/* ---- controls ---- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 5px 11px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--wash); color: var(--ink); font-weight: 600; }
.btn {
  border: 1px solid var(--border); background: var(--raised); border-radius: 8px; padding: 6px 12px;
  cursor: pointer; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.danger { color: var(--critical); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
input[type="text"], input[type="number"], input[type="time"], input[type="url"], input[type="password"], input[type="date"], select {
  background: var(--raised); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; min-width: 0; max-width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.form-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }

.switch { position: relative; width: 44px; height: 26px; border: 0; border-radius: 999px; background: var(--axis); cursor: pointer; flex: none; transition: background 0.15s; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }
.switch[aria-checked="true"] { background: var(--good); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch:disabled { opacity: 0.45; cursor: default; }
.switch.busy::after { animation: pulse 0.7s infinite alternate; }
@keyframes pulse { to { opacity: 0.4; } }

/* ---- plugs ---- */
.room-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 22px 0 10px; }
.plugs { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.plug { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: grid; gap: 8px; min-width: 0; }
.plug-top { display: flex; align-items: center; gap: 10px; }
.plug-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--wash); display: grid; place-items: center; font-size: 18px; flex: none; }
.plug-name { flex: 1; min-width: 0; text-decoration: none; }
.plug-name b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plug-name:hover b { text-decoration: underline; }
.plug-mid { display: flex; align-items: end; justify-content: space-between; gap: 10px; }
.plug-w { font-size: 28px; font-weight: 600; line-height: 1; }
.plug-w small { font-size: 14px; color: var(--ink-2); font-weight: 500; margin-left: 2px; }
.plug canvas.spark { width: 110px; height: 34px; }
.plug-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--ink-2); }
.state { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* ---- charts ---- */
.chart { position: relative; height: 280px; }
.chart.short { height: 200px; }
.chart.tall { height: 340px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.empty { color: var(--muted); text-align: center; padding: 36px 12px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--ink-2); font-size: 13px; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th.right, td.right { text-align: right; }
.table-wrap { overflow-x: auto; }

.bar-row { display: grid; grid-template-columns: minmax(90px, 180px) 1fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: 14px; }
.bar-row .track { height: 12px; border-radius: 0 4px 4px 0; background: transparent; }
.bar-row .fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 11px; color: var(--muted); }
.heat .cell { aspect-ratio: 1; border-radius: 3px; background: var(--wash); min-height: 12px; }
.heat .hour { text-align: center; }
.heat .day { align-self: center; }
.heat-key { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.heat-key i { width: 16px; height: 10px; border-radius: 2px; display: inline-block; }

.facts-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; margin: 0; }
.facts-list dt { color: var(--ink-2); }
.facts-list dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.icons { display: flex; flex-wrap: wrap; gap: 6px; }
.icons button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--raised); cursor: pointer; font-size: 17px; }
.icons button.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
pre { background: var(--wash); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 13px; margin: 8px 0; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin: 6px 0; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; max-width: min(92vw, 520px);
  background: var(--ink); color: var(--plane); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* ---- sign-in ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(100%, 340px); display: grid; gap: 12px; }
.login h1 { font-size: 22px; display: flex; align-items: center; gap: 8px; }
.login .error { color: var(--critical); font-size: 14px; min-height: 20px; }

/* ---- grouping and the organise page ---- */
.fold { border: 0; background: none; cursor: pointer; padding: 0 4px 0 0; color: var(--ink-2); font-size: 14px; }
.room-head h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.group-total { font-weight: 400; }
table.organise input[type="text"] { width: 100%; min-width: 110px; }

/* ---- trends ---- */
.cal-wrap { overflow-x: auto; }
.cal { display: grid; grid-template-rows: 16px repeat(7, minmax(9px, 1fr)); gap: 3px; min-width: 620px; font-size: 11px; color: var(--muted); }
.cal .cell { border-radius: 2px; background: var(--wash); aspect-ratio: 1; }
.cal .cal-day { grid-column: 1; align-self: center; }
.cal > span:not(.cell):not(.cal-day) { grid-row: 1; white-space: nowrap; }
