:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #5d6b66;
  --line: #dde3e0;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --track: #e6ebe9;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --card: #17201d;
    --text: #e8eeeb;
    --muted: #93a39d;
    --line: #2a3632;
    --accent: #2dd4bf;
    --accent-text: #052e2a;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --track: #24302c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

button {
  font: inherit; border: 0; border-radius: 10px; cursor: pointer;
  min-height: 44px; padding: 0 16px;
  background: var(--track); color: var(--text); font-weight: 600;
}
button.primary { background: var(--accent); color: var(--accent-text); }
button.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
button.link { background: none; color: var(--accent); padding: 0 4px; }
button.icon { background: none; font-size: 30px; line-height: 1; padding: 0 8px 4px; min-width: 44px; }
button:disabled { opacity: .5; cursor: default; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.big { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tap { cursor: pointer; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.pill { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--track); color: var(--muted); white-space: nowrap; }
.pill.warn { color: var(--warn); }
.pill.bad { color: var(--bad); }
.pill.ok { color: var(--ok); }

.meter { height: 12px; border-radius: 999px; background: var(--track); overflow: hidden; margin: 10px 0 6px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter.warn > i { background: var(--warn); }
.meter.bad > i { background: var(--bad); }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.actions .wide { grid-column: 1 / -1; }
.actions .wide2 { grid-column: span 2; }

.apps { list-style: none; margin: 0; padding: 0; }
.apps li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 6px 0; }
.apps .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apps .meter { grid-column: 1 / -1; height: 6px; margin: 0; }

.history { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding-top: 8px; }
.history .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; height: 100%; justify-content: flex-end; }
.history .b { width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; background: var(--accent); min-height: 2px; }
.history .b.over { background: var(--warn); }
.history .l { font-size: 11px; color: var(--muted); }

.events { list-style: none; margin: 0; padding: 0; }
.events li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.events li:last-child { border-bottom: 0; }
.events .k { font-weight: 600; }
.events .k.alert { color: var(--bad); }

label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input, textarea, select {
  font: inherit; width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
textarea { min-height: 80px; }
input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--accent); }

.days { display: grid; gap: 10px; }
.day { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.day:last-child { border-bottom: 0; }
.day .fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.day .fields label { margin: 0 0 2px; font-size: 12px; }
.day.off .fields { opacity: .4; pointer-events: none; }

pre.config {
  white-space: pre-wrap; word-break: break-all; font-size: 13px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 10px 0;
}
.empty { text-align: center; padding: 32px 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }

.login { max-width: 380px; margin: 12vh auto 0; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; scrollbar-width: none; }
.chip { min-height: 34px; padding: 0 12px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap; flex: none; }
.chip.on { background: var(--accent); color: var(--accent-text); }
.appctl { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.appctl select { width: auto; min-width: 150px; min-height: 36px; padding: 4px 10px; font-size: 14px; }
.apps li { border-bottom: 1px solid var(--line); padding: 10px 0; }
.apps li:last-child { border-bottom: 0; }
.apps .name .pill { margin-left: 6px; font-size: 12px; }

.code { font-size: 44px; font-weight: 800; letter-spacing: .12em; text-align: center; margin: 12px 0 4px; font-variant-numeric: tabular-nums; }
.steps { padding-left: 20px; margin: 16px 0; }
.steps li { margin-bottom: 12px; }
.steps a { color: var(--accent); font-weight: 600; }
code { font-size: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; word-break: break-all; }

.downloads { margin-top: 14px; }
.dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.primary-link { display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; text-decoration: none; }
.downloads a:not(.primary-link) { color: var(--accent); }

.openrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.chip.ghost { background: var(--track); color: var(--text); border: 1px solid var(--line); min-height: 32px; }
