/* MeuWatt health board.
   One job: from across the room, is anything red?
   Dark-only on purpose — this sits on a second monitor all day. */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2129;
  --border: #272e38;
  --text: #e6edf3;
  --muted: #8b949e;

  --ok: #2ea043;
  --warn: #d29922;
  --down: #f85149;
  --unknown: #6e7681;
  --asleep: #3f6ba8;

  --ok-dim: #10331b;
  --warn-dim: #3a2d08;
  --down-dim: #48191a;
  --unknown-dim: #21262d;
  --asleep-dim: #14243a;
}

* { box-sizing: border-box; }

/* The UA stylesheet's `[hidden] { display: none }` loses to ANY author-level
   display rule, so `.gate { display: grid }` and `.sheet { display: flex }`
   stayed on screen after JS set `.hidden = true` — the board rendered fine and
   was simply covered by the login overlay. Anything toggled via the `hidden`
   property needs this to actually hide. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: env(safe-area-inset-bottom); }

.muted { color: var(--muted); }

/* ── token gate ─────────────────────────────────────────────────────────── */

.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: var(--bg); padding: 16px;
}
.gate-card {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.gate-card h1 { margin: 0; font-size: 20px; font-weight: 650; }
.gate-card p { margin: 0; font-size: 13px; }
.gate-card input, .gate-card button {
  font: inherit; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border);
}
.gate-card input { background: var(--bg); color: var(--text); }
.gate-card input:focus { outline: 2px solid var(--asleep); outline-offset: 1px; }
.gate-card button {
  background: var(--ok); color: #fff; border: none;
  font-weight: 600; cursor: pointer;
}
.gate-error { color: var(--down); font-size: 13px; }

/* ── banner ─────────────────────────────────────────────────────────────── */

.banner {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px calc(14px);
  padding-top: calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  transition: background 200ms ease;
}
.banner-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.banner-text { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.banner-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.banner-ok      { background: var(--ok-dim); }
.banner-warn    { background: var(--warn-dim); }
.banner-down    { background: var(--down-dim); }
.banner-unknown { background: var(--unknown-dim); }
.banner-asleep  { background: var(--asleep-dim); }

.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  font-size: 17px; cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.spin { animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── dots ───────────────────────────────────────────────────────────────── */

.dot {
  width: 11px; height: 11px; border-radius: 50%;
  display: inline-block; flex: none; background: var(--unknown);
}
.dot-lg { width: 18px; height: 18px; }
.dot-ok      { background: var(--ok); }
.dot-warn    { background: var(--warn); }
.dot-down    { background: var(--down); }
.dot-unknown { background: var(--unknown); }
.dot-asleep  { background: var(--asleep); }

/* A red dot pulses. Nothing else does — motion is reserved for the one state
   that should pull your eye across the room. */
.dot-down { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.55); }
  50%      { box-shadow: 0 0 0 5px rgba(248, 81, 73, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .dot-down, .icon-btn.spin { animation: none; }
}

/* ── tabs ───────────────────────────────────────────────────────────────── */

.tabs {
  display: flex; gap: 4px; padding: 10px 16px 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent; border: none; color: var(--muted);
  font: inherit; font-size: 14px; padding: 8px 12px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-active { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }

main { padding: 12px 16px 24px; max-width: 1400px; margin: 0 auto; }

/* ── plants ─────────────────────────────────────────────────────────────── */

#plants { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 720px)  { #plants { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1140px) { #plants { grid-template-columns: repeat(3, 1fr); } }

.plant {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
}
/* The left edge carries the plant's worst state, so a red plant is visible
   even when the card is scrolled half off screen. */
.plant-down    { border-left: 3px solid var(--down); }
.plant-warn    { border-left: 3px solid var(--warn); }
.plant-unknown { border-left: 3px solid var(--unknown); }
.plant-ok      { border-left: 3px solid var(--ok); }
.plant-asleep  { border-left: 3px solid var(--asleep); }

.plant-head {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 13px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.plant-name { font-weight: 620; font-size: 14.5px; flex: 1; min-width: 0;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plant-meta { font-size: 11.5px; color: var(--muted); flex: none; }

.group { padding: 9px 13px; border-bottom: 1px solid var(--border); }
.group:last-child { border-bottom: none; }
.group-head {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 11.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 7px;
}
.group-count { margin-left: auto; text-transform: none; letter-spacing: 0; }
.group-missing { color: var(--warn); text-transform: none; letter-spacing: 0; }

.devices { display: flex; flex-wrap: wrap; gap: 5px; }

.device {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px 4px 7px;
  font-size: 12.5px; cursor: pointer; max-width: 100%;
  color: var(--text); font-family: inherit;
}
.device:hover { border-color: var(--muted); }
.device-down { border-color: var(--down); background: var(--down-dim); }
.device-warn { border-color: var(--warn); }
.device-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-age { color: var(--muted); font-size: 11px; flex: none; }
.device-down .device-age { color: #ffb3ae; }

.collector-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); flex: none;
}
.collector-badge.down { border-color: var(--down); color: #ffb3ae; background: var(--down-dim); }

/* ── events ─────────────────────────────────────────────────────────────── */

.event {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 2px; border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.event-when { color: var(--muted); font-size: 11.5px; flex: none; width: 92px; }
.event-body { min-width: 0; }
.event-what { font-weight: 560; }
.event-where { color: var(--muted); font-size: 12px; }
.event-tag {
  font-size: 10.5px; padding: 1px 6px; border-radius: 999px; flex: none;
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 650;
}
.tag-down { background: var(--down-dim); color: #ffb3ae; }
.tag-ok   { background: var(--ok-dim); color: #7ee2a0; }
.tag-warn { background: var(--warn-dim); color: #e8c46a; }

.empty { color: var(--muted); text-align: center; padding: 40px 0; font-size: 14px; }

/* ── detail sheet ───────────────────────────────────────────────────────── */

.sheet {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .sheet { align-items: center; } }
.sheet-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px 14px 0 0; padding: 20px;
  width: 100%; max-width: 460px; position: relative;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .sheet-card { border-radius: 14px; } }
.sheet-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--muted);
  font-size: 26px; line-height: 1; cursor: pointer;
}
.sheet-title { font-size: 17px; font-weight: 650; margin: 0 26px 3px 0; }
.sheet-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ── footer ─────────────────────────────────────────────────────────────── */

.foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  font-size: 11.5px; border-top: 1px solid var(--border);
}
.link-btn {
  background: none; border: none; color: var(--muted);
  font: inherit; font-size: 11.5px; cursor: pointer; text-decoration: underline;
}


/* ── notifications ──────────────────────────────────────────────────────── */

.banner-actions { display: flex; gap: 6px; flex: none; }
.icon-btn.on { border-color: var(--ok); color: #7ee2a0; }

.notify-panel {
  padding: 11px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.notify-row {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; justify-content: space-between;
}
.notify-state { font-size: 13px; color: var(--muted); }
.notify-actions { display: flex; gap: 6px; flex: none; }
.btn-sm {
  font: inherit; font-size: 12.5px; padding: 5px 11px;
  border-radius: 7px; border: none; cursor: pointer;
  background: var(--ok); color: #fff; font-weight: 600;
}
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  font-weight: 500;
}
.notify-hint {
  margin: 9px 0 0; font-size: 12.5px; line-height: 1.5;
  color: var(--muted); max-width: 62ch;
}
.notify-hint strong { color: var(--text); font-weight: 600; }
.notify-hint.warn { color: #e8c46a; }


/* ── stats ──────────────────────────────────────────────────────────────── */

.stats-toolbar {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 14px; font-size: 12px;
}
.window-picker { display: flex; gap: 2px; background: var(--surface); border-radius: 8px;
                 border: 1px solid var(--border); padding: 2px; }
.win {
  background: transparent; border: none; color: var(--muted);
  font: inherit; font-size: 12px; padding: 5px 12px; border-radius: 6px; cursor: pointer;
}
.win-active { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* Fleet headline numbers. */
.kpis {
  display: grid; gap: 8px; margin-bottom: 16px;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 11px 13px;
}
.kpi-value { font-size: 21px; font-weight: 650; letter-spacing: -0.02em;
             font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 11px; color: var(--muted); margin-top: 2px;
             text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-good { color: var(--ok); }
.kpi-bad  { color: var(--down); }
.kpi-warn { color: var(--warn); }

.stats-section-title {
  font-size: 11.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.05em; margin: 18px 0 8px;
}

.srow {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); margin-bottom: 6px;
  font-size: 13px; flex-wrap: wrap;
}
.srow-name { font-weight: 560; flex: 1; min-width: 120px;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow-sub { color: var(--muted); font-size: 11.5px; font-weight: 400; }
.srow-metric { text-align: right; min-width: 66px; font-variant-numeric: tabular-nums; }
.srow-metric small { display: block; color: var(--muted); font-size: 10.5px;
                     text-transform: uppercase; letter-spacing: 0.04em; }

/* Availability bar — the quickest read of "how good was this week". */
.avail-bar {
  flex: 0 0 100%; height: 4px; border-radius: 3px;
  background: var(--down-dim); overflow: hidden; margin-top: 2px;
}
.avail-fill { height: 100%; background: var(--ok); border-radius: 3px; }
.avail-fill.warn { background: var(--warn); }
.avail-fill.bad  { background: var(--down); }

.partial-flag { color: var(--warn); font-size: 11px; }

/* Collector vitals line on each plant card. */
.vitals {
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  padding: 7px 13px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.vitals b { color: var(--text); font-weight: 600; }
.vital-hot { color: var(--warn); }


/* ── sign-in ────────────────────────────────────────────────────────────── */

.check {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer; user-select: none;
}
.check input { width: 15px; height: 15px; accent-color: var(--ok); margin: 0; }
.gate-card .link-btn { align-self: center; margin-top: 2px; }
.gate-card button[type="submit"]:disabled { opacity: 0.6; cursor: default; }

/* Who is signed in, in the footer. */
.whoami { color: var(--muted); }
.whoami b { color: var(--text); font-weight: 600; }


/* ── browser login ──────────────────────────────────────────────────────── */

.btn-primary {
  font: inherit; font-weight: 650; font-size: 14.5px;
  padding: 11px 14px; border-radius: 8px; border: none;
  background: var(--ok); color: #fff; cursor: pointer;
}
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

/* Divider that demotes the password form to the secondary option. */
.gate-or {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 11.5px; margin: 4px 0 2px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.gate-or::before, .gate-or::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.gate-code { display: flex; flex-direction: column; gap: 8px; text-align: center; }
.gate-code p { margin: 0; font-size: 12.5px; }
/* The code is read aloud and compared by eye, so it needs to be unambiguous
   and large. mw-api already excludes look-alike characters (0/O, 1/I/L). */
.code-value {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 30px; font-weight: 700; letter-spacing: 0.14em;
  color: var(--text); padding: 10px 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.gate-card .gate-code .link-btn { align-self: center; }
