:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, sans-serif;
  --page: #e8eff7;
  --background: linear-gradient(155deg, #d8e6f8, #edf2f8 58%, #f4e7d8);
  --surface: #ffffffdb;
  --solid: #f7f9fc;
  --text: #101b2a;
  --muted: #46566c;
  --line: #cbd7e4;
  --accent: #895000;
  --amber: #ffac32;
  --soft-amber: #fff0d0;
  --green: #22683c;
  --coral: #963c2b;
  --green-track: #9ed9b7;
  --coral-track: #ec947f;
  --shadow: 0 12px 30px #29466a12;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b1019;
  --background: linear-gradient(155deg, #101a2b, #0b1019 65%, #201912);
  --surface: #172131;
  --solid: #131c29;
  --text: #f4f6fa;
  --muted: #b9c6d7;
  --line: #34445a;
  --accent: #ffce7c;
  --soft-amber: #402e18;
  --green: #87e1a7;
  --coral: #ffab97;
  --green-track: #367953;
  --coral-track: #d76f59;
  --shadow: 0 12px 30px #0003;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--background) fixed var(--page);
  line-height: 1.45;
}
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: clamp(1.35rem, 5vw, 1.7rem); letter-spacing: -.035em; }
h2 { font-size: 1.18rem; letter-spacing: -.02em; }
h3 { font-size: 1.15rem; overflow-wrap: anywhere; }
h4 { font-size: .94rem; }
.muted { color: var(--muted); font-size: .875rem; }

.shell {
  max-width: 680px;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.top, .toolbar, .section-head, .brand, .order { display: flex; align-items: center; gap: 12px; }
.top, .toolbar, .section-head { justify-content: space-between; }
.brand img { border-radius: 14px; box-shadow: var(--shadow); }
.toolbar { margin: 13px 0; }
.locations, #overview-list { display: grid; gap: 12px; margin-top: 12px; }
.panel, dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.location, .empty, .install { padding: 16px; }
.empty p, .install p { margin-top: 4px; }
.install { margin-top: 12px; }
.install p { color: var(--muted); }
.footer { margin-top: 20px; text-align: center; font-size: .78rem; }
.identity { min-width: 0; }

button, input, select { font: inherit; color: inherit; }
button {
  min-height: 44px;
  padding: 7px 13px;
  color: var(--text);
  background: var(--solid);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: .875rem;
  font-weight: 650;
  cursor: pointer;
}
button:disabled { opacity: .48; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.primary { color: #271600; background: var(--amber); border-color: transparent; }
.square { flex: 0 0 44px; width: 44px; padding: 0; font-size: 1.4rem; }
.full-button { width: 100%; min-height: 50px; margin-top: 14px; font-size: 1rem; }

.timer {
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  background: var(--solid);
  border: 1px solid var(--line);
  text-align: center;
  --state-color: var(--muted);
}
.timer[data-state="on"] { --state-color: var(--green); }
.timer[data-state="off"] { --state-color: var(--coral); }
.power-state { color: var(--state-color); font-size: .875rem; font-weight: 700; margin-bottom: 4px; }
.digits { font-size: clamp(2rem, 10vw, 3rem); line-height: 1.14; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
progress {
  display: block;
  appearance: none;
  width: 100%;
  height: 7px;
  margin-top: 10px;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: var(--line);
  color: var(--state-color);
}
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--state-color); border-radius: 10px; }
progress::-moz-progress-bar { background: var(--state-color); border-radius: 10px; }

.day { margin-top: 14px; }
.timeline {
  position: relative;
  height: 12px;
  overflow: hidden;
  margin: 6px 0 4px;
  border-radius: 5px;
  background: var(--green-track);
}
.outage-band { position: absolute; height: 100%; background: var(--coral-track); }
.scale { display: flex; justify-content: space-between; font-size: .75rem; font-variant-numeric: tabular-nums; }
.summary { margin-top: 4px; font-size: .875rem; }
.off-text, .danger { color: var(--coral); }
.on-text { color: var(--green); }

dialog {
  width: min(calc(100% - 28px), 510px);
  max-height: calc(100% - 40px);
  color: var(--text);
  background: var(--solid);
  padding: 16px;
}
dialog::backdrop { background: #08121e9c; }
label { display: grid; gap: 5px; margin: 12px 0; font-size: .875rem; font-weight: 650; }
input, select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1rem;
  background-color: var(--surface);
}
select {
  appearance: none;
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 15px center, right 10px center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.order { margin: 0 0 14px; flex-wrap: wrap; }
.save { margin-left: auto; }
.tabs { display: flex; gap: 8px; }
.tabs button { flex: 1; }
.tabs [aria-pressed="true"] { background: var(--soft-amber); color: var(--accent); border-color: var(--accent); }
.group-row {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: var(--surface);
}
.group-row.saved { border-color: var(--accent); }
