/* Power — instrument-panel dark. Powder-steel surfaces, LCD-amber accent,
   monospace numerals. Committed dark theme: this is a status screen. */

:root {
  --surface: #12161c;
  --panel: #1a2028;
  --panel-edge: #242c37;
  --ink: #e8edf2;
  --ink-2: #93a1b0;
  /* Was #5c6a78 (2.96:1 on --panel) — below the large-text floor while carrying
     every label in the app. #7d8b9a measures ~4.7:1. */
  --ink-3: #7d8b9a;
  --amber: #ffb454;          /* accent + warning; always paired with a word */
  --good: #4ad07e;
  --critical: #ff5c5c;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--surface); }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--surface);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

/* ---------- sign-in ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  padding: 32px 28px;
  text-align: center;
}
.brand-mark { color: var(--amber); font-size: 28px; line-height: 1; }
.login-card h1 { font-size: 22px; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 10px; }
.login-sub { color: var(--ink-2); font-size: 13px; margin: 6px 0 24px; }
.login-card label { display: block; text-align: left; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.login-card input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  color: var(--ink);
  font-size: 16px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.login-card input:focus-visible, button:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.login-card button[type="submit"] {
  width: 100%;
  background: var(--amber);
  color: #201505;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  padding: 11px;
  cursor: pointer;
}
.login-msg { margin-top: 14px; font-size: 13px; color: var(--ink-2); min-height: 1.2em; }

/* ---------- shell ---------- */
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 14px 40px;
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 2px 16px;
}
.brand { font-size: 14px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; }
.brand .host { color: var(--ink-3); letter-spacing: 0.05em; text-transform: none; font-weight: 400; margin-left: 6px; }
.top-actions { display: flex; gap: 8px; }
button.ghost {
  background: none;
  border: 1px solid var(--panel-edge);
  border-radius: 7px;
  color: var(--ink-2);
  font-size: 12px;
  padding: 6px 10px;
  min-height: 44px;      /* iOS touch target */
  cursor: pointer;
}
button.ghost:hover { color: var(--ink); border-color: var(--ink-3); }

/* ---------- hero ---------- */
.hero {
  background: linear-gradient(180deg, var(--panel) 0%, #171d25 100%);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  padding: 22px 20px 18px;
  margin-bottom: 14px;
}
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); }
.dot.ol { background: var(--good); box-shadow: 0 0 8px rgba(74, 208, 126, 0.6); }
.dot.ob { background: var(--amber); box-shadow: 0 0 8px rgba(255, 180, 84, 0.7); animation: pulse 1.2s ease-in-out infinite; }
.dot.lb, .dot.err { background: var(--critical); box-shadow: 0 0 8px rgba(255, 92, 92, 0.7); animation: pulse 0.7s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none !important; } }
.status-word { letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; }
.data-age { margin-left: auto; color: var(--ink-3); font-size: 11px; font-family: var(--mono); }

.status-detail { color: var(--ink-2); font-size: 13px; line-height: 1.45; margin-top: 8px; }
/* When readings stop arriving, the numbers must stop looking authoritative. */
.hero.stale .gauges, .hero.stale .vmeter, .hero.stale .hero-stats { opacity: 0.4; filter: saturate(0.3); }
.hero.stale .status-detail { color: var(--critical); }

/* ---------- outage takeover ---------- */
.outage {
  border: 1px solid rgba(255, 180, 84, .45);
  background: rgba(255, 180, 84, .08);
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 14px;
}
.outage h2 { font-size: 15px; letter-spacing: 0.04em; color: var(--amber); }
.outage-elapsed { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); margin-top: 5px; }
.outage-steps { list-style: none; margin-top: 10px; display: grid; gap: 8px; }
.outage-steps li {
  font-size: 13px; line-height: 1.45; color: var(--ink-2);
  padding-left: 14px; position: relative;
}
.outage-steps li::before { content: '·'; position: absolute; left: 3px; color: var(--amber); }

.runtime-note { color: var(--ink-3); font-size: 11.5px; margin-top: 10px; text-align: center; }

/* ---------- technical disclosure ---------- */
.tech { margin-top: 14px; border-top: 1px solid var(--panel-edge); padding-top: 10px; }
.tech summary {
  font-size: 12px; color: var(--ink-3); cursor: pointer;
  letter-spacing: 0.05em; text-transform: uppercase;
  padding: 6px 0; min-height: 30px;
}
.tech summary:hover { color: var(--ink-2); }
.tech[open] summary { margin-bottom: 10px; }
.tech-line {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  line-height: 1.6; margin-top: 12px; word-break: break-word;
  user-select: all;   /* tap to select the whole line for pasting */
}
.specs dd.warn-value { color: var(--amber); }

/* ---------- gauges ---------- */
.gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 4px; }
@media (max-width: 420px) { .gauges { grid-template-columns: 1fr; gap: 20px; } }
.gauge { position: relative; }
.gauge-arc svg { display: block; width: 100%; height: auto; max-width: 230px; margin: 0 auto; }
.g-track { fill: none; stroke: var(--panel-edge); stroke-linecap: round; }
.g-value {
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 600ms ease, stroke 400ms ease;
}
@media (prefers-reduced-motion: reduce) { .g-value { transition: none; } }
/* Caption sits inside the arc's open middle. */
.gauge figcaption {
  position: absolute;
  left: 50%; bottom: 2px;
  transform: translateX(-50%);
  /* Bounded in px, not %, so it can't outgrow the arc's inner span when the
     figure is full width on a phone. */
  width: max-content;
  max-width: 148px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0;
  line-height: 1.1;
}
/* Both captions must be exactly three single lines, or the bottom-anchored
   stacks sit at different heights and the two gauges read as misaligned. */
.gauge figcaption > * { white-space: nowrap; }
.runtime-num {
  font-family: var(--mono);
  font-size: clamp(26px, 7vw, 34px);
  font-weight: 300;
  line-height: 0.95;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}
.runtime-num.sm { color: var(--ink); }
.runtime-unit { color: var(--ink-2); font-size: 12px; }
.gauge-sub { color: var(--ink-3); font-size: 11px; margin-top: 3px; }
.gauge-sub b { color: var(--ink-2); font-family: var(--mono); font-weight: 500; }

/* ---------- input voltage meter ---------- */
.vmeter { margin: 20px 0 16px; }
.vmeter-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3);
}
.vmeter-now { text-transform: none; letter-spacing: 0; }
.vmeter-now b { font-family: var(--mono); font-size: 14px; color: var(--ink); font-weight: 500; }
/* The whole track is transfer territory; the safe band is positioned over it
   from the UPS's real thresholds by app.js. */
.vmeter-track {
  position: relative;
  height: 8px;
  margin: 8px 0 6px;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(255, 92, 92, .45);
}
.vmeter-safe {
  position: absolute; top: 0; bottom: 0;
  left: 18%; right: 18%;          /* replaced at runtime */
  background: rgba(74, 208, 126, .30);
}
.vmeter-marker {
  position: absolute; top: -3px; width: 3px; height: 14px;
  border-radius: 2px; background: var(--ink);
  transform: translateX(-50%);
  transition: left 500ms ease;
}
@media (prefers-reduced-motion: reduce) { .vmeter-marker { transition: none; } }
.vmeter-scale {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 10px; color: var(--ink-3);
}
.vmeter-nominal { color: var(--ink-3); }
.vmeter-note { color: var(--ink-3); font-size: 11px; margin-top: 6px; }

.hero-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 8px; }
.hero-stats.three { grid-template-columns: repeat(3, 1fr); }
.hstat { text-align: center; }
.hstat-num { display: block; font-family: var(--mono); font-size: 19px; font-variant-numeric: tabular-nums; }
.hstat-label { color: var(--ink-3); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; }

/* ---------- range filter ---------- */
.ranges { display: flex; gap: 6px; margin-bottom: 12px; }
.ranges button {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 7px;
  color: var(--ink-2);
  font-size: 12.5px;
  font-family: var(--mono);
  padding: 7px 0;
  min-height: 44px;      /* iOS touch target */
  cursor: pointer;
}
.ranges button.active { color: #201505; background: var(--amber); border-color: var(--amber); font-weight: 600; }

/* ---------- charts ---------- */
.charts { display: grid; gap: 12px; margin-bottom: 14px; }
@media (min-width: 640px) { .charts { grid-template-columns: 1fr 1fr; } }
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 14px 14px 8px;
}
.panel figcaption, .panel-head h2 {
  font-size: 12.5px;
  letter-spacing: 0.05em;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 7px;
}
.swatch { width: 8px; height: 8px; border-radius: 2px; background: var(--c, var(--ink-3)); display: inline-block; }
.panel .cur { margin-left: auto; font-family: var(--mono); color: var(--ink); font-size: 13px; }
.plot { margin-top: 6px; }
/* touch-action stays default: scrolling over a chart is never intercepted */
.plot svg { display: block; width: 100%; height: auto; }
.plot .gridline { stroke: var(--panel-edge); stroke-width: 1; }
.plot .axis-label { fill: var(--ink-3); font-size: 9.5px; font-family: var(--mono); }
.plot .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot .area { opacity: 0.12; }
.plot .cross { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.plot .crossdot { stroke: var(--surface); stroke-width: 2; }

.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: #0d1116;
  border: 1px solid var(--panel-edge);
  border-radius: 7px;
  padding: 6px 9px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
}
.tooltip .t-time { color: var(--ink-3); font-size: 10.5px; display: block; }

/* ---------- consumption ---------- */
.energy-panel { margin-bottom: 14px; }
.energy-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 8px; margin-top: 12px; }
.estat { text-align: center; }
.estat-num { display: block; font-family: var(--mono); font-size: 18px; font-variant-numeric: tabular-nums; }
/* Marks a total built from an incompletely observed window. */
.estat-num.partial::after { content: '*'; color: var(--amber); font-size: 13px; vertical-align: 2px; }
.estat-label { color: var(--ink-3); font-size: 10.5px; letter-spacing: 0.05em; text-transform: uppercase; }

.daily { margin-top: 18px; }
.daily figcaption {
  font-size: 12.5px; color: var(--ink-2);
  display: flex; align-items: baseline; gap: 8px;
}
.daily .cur { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.daily .bar { fill: #3987e5; }
/* Hollow = incomplete day, so a short bar isn't misread as low usage. */
.daily .bar.partial { fill: none; stroke: #3987e5; stroke-width: 1.5; stroke-dasharray: 3 2; }
.daily .bar:hover { fill: #5a9ff0; }
.daily .bar.partial:hover { fill: none; stroke: #5a9ff0; }

/* ---------- alerts ---------- */
.alerts { width: 100%; border-collapse: collapse; margin-top: 6px; }
.alerts th {
  font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 500; text-align: center; padding-bottom: 6px;
}
.alerts th:first-child { text-align: left; }
.alerts td { border-top: 1px solid var(--panel-edge); padding: 9px 2px; font-size: 13px; }
.alerts td:not(:first-child) { text-align: center; width: 62px; }
.a-label { color: var(--ink-2); }
.a-crit {
  display: inline-block; margin-left: 7px; font-size: 9.5px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--critical); border: 1px solid rgba(255,92,92,.35);
  border-radius: 4px; padding: 1px 5px; vertical-align: 1px;
}

/* toggle switch */
.sw { display: inline-block; cursor: pointer; }
.sw input { position: absolute; opacity: 0; width: 0; height: 0; }
.sw span {
  display: block; width: 38px; height: 22px; border-radius: 11px;
  background: var(--panel-edge); position: relative; transition: background 160ms ease;
}
.sw span::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink-3); transition: transform 160ms ease, background 160ms ease;
}
.sw input:checked + span { background: rgba(74, 208, 126, .35); }
.sw input:checked + span::after { transform: translateX(16px); background: var(--good); }
.sw input:focus-visible + span { outline: 2px solid var(--amber); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .sw span, .sw span::after { transition: none; } }

/* ---------- specs ---------- */
.specs { display: grid; grid-template-columns: 1fr auto; gap: 0; margin-top: 4px; }
.specs dt, .specs dd {
  padding: 8px 2px;
  border-top: 1px solid var(--panel-edge);
  font-size: 12.5px;
}
.specs dt { color: var(--ink-3); }
.specs dd { font-family: var(--mono); text-align: right; color: var(--ink-2); }

/* ---------- lists ---------- */
.list-panel { margin-bottom: 14px; padding-bottom: 6px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-note { color: var(--ink-3); font-size: 12px; margin: 8px 0 4px; line-height: 1.45; }
.warn-note {
  color: var(--ink-2);
  border-left: 2px solid var(--amber);
  padding-left: 10px;
  margin-top: 12px;
}
.rows { list-style: none; margin-top: 8px; }
.rows li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 9px 2px;
  border-top: 1px solid var(--panel-edge);
  font-size: 13px;
}
.rows .when { font-family: var(--mono); color: var(--ink-3); font-size: 11.5px; min-width: 88px; }
.rows .tag {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid var(--panel-edge);
  color: var(--ink-2);
}
.rows .tag.pass, .rows .tag.ONLINE, .rows .tag.COMMOK { color: var(--good); border-color: rgba(74,208,126,.35); }
.rows .tag.ONBATT, .rows .tag.SELFTEST { color: var(--amber); border-color: rgba(255,180,84,.35); }
.rows .tag.fail, .rows .tag.LOWBATT, .rows .tag.FSD, .rows .tag.SHUTDOWN, .rows .tag.COMMBAD,
.rows .tag.NOCOMM, .rows .tag.REPLBATT { color: var(--critical); border-color: rgba(255,92,92,.35); }
.rows .msg { color: var(--ink-2); line-height: 1.4; }
.rows .empty { color: var(--ink-3); }
