/* Energy Monitor. Calm surfaces, system type, one accent. Light and dark. */

:root {
  color-scheme: light;
  --page: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f2f2f4;
  --fill: rgba(118, 118, 128, 0.12);
  --fill-strong: rgba(118, 118, 128, 0.2);
  --ink: #1d1d1f;
  --ink-2: #515154;
  --muted: #86868b;
  --grid: rgba(0, 0, 0, 0.07);
  --border: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --accent-ink: #ffffff;
  --good: #34c759;
  --warn: #ff9f0a;
  --bad: #ff3b30;
  --c-power: #007aff;
  --c-volt: #ff9500;
  --c-curr: #34c759;
  --c-freq: #ff2d55;
  --c-pf: #af52de;
  --c-app: #ffcc00;
  --bar: rgba(255, 255, 255, 0.72);
  --shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.05);
  --shadow-pop: 0 0 0 0.5px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.08);
  --radius: 20px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(118, 118, 128, 0.36);
    --ink: #f5f5f7;
    --ink-2: #c7c7cc;
    --muted: #8e8e93;
    --grid: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.1);
    --accent: #0a84ff;
    --good: #30d158;
    --bad: #ff453a;
    --c-power: #0a84ff;
    --c-volt: #ff9f0a;
    --c-curr: #30d158;
    --c-freq: #ff375f;
    --c-pf: #bf5af2;
    --c-app: #ffd60a;
    --bar: rgba(22, 22, 24, 0.72);
    --shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.08);
    --shadow-pop: 0 0 0 0.5px rgba(255, 255, 255, 0.14), 0 2px 8px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --fill: rgba(118, 118, 128, 0.24);
  --fill-strong: rgba(118, 118, 128, 0.36);
  --ink: #f5f5f7;
  --ink-2: #c7c7cc;
  --muted: #8e8e93;
  --grid: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.1);
  --accent: #0a84ff;
  --good: #30d158;
  --bad: #ff453a;
  --c-power: #0a84ff;
  --c-volt: #ff9f0a;
  --c-curr: #30d158;
  --c-freq: #ff375f;
  --c-pf: #bf5af2;
  --c-app: #ffd60a;
  --bar: rgba(22, 22, 24, 0.72);
  --shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  --shadow-pop: 0 0 0 0.5px rgba(255, 255, 255, 0.14), 0 2px 8px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.47 var(--font);
  letter-spacing: -0.01em;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--accent);
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}
h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 19px;
}
h3 {
  font-size: 15px;
}
code {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--fill);
  padding: 1px 5px;
  border-radius: 5px;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
.mono {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
}
.num {
  font-variant-numeric: tabular-nums;
}
.spacer {
  flex: 1;
}

/* ------------------------------------------------------------------ bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  flex-wrap: wrap;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.02em;
}
.topbar .brand svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
}
.tabs,
.seg {
  display: inline-flex;
  gap: 2px;
  background: var(--fill);
  padding: 2px;
  border-radius: 10px;
  overflow-x: auto;
  max-width: 100%;
}
.tabs button,
.seg button {
  border: 0;
  background: transparent;
  padding: 5px 13px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s ease;
}
.tabs button {
  padding: 6px 15px;
  font-size: 14px;
}
.tabs button.active,
.seg button.active {
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  font-weight: 600;
}
:root[data-theme='dark'] .tabs button.active,
:root[data-theme='dark'] .seg button.active {
  background: #636366;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .tabs button.active,
  :root:not([data-theme='light']) .seg button.active {
    background: #636366;
  }
}

/* --------------------------------------------------------------- layout */
main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 20px 48px;
}
.view {
  display: none;
}
.view.active {
  display: block;
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row.between {
  justify-content: space-between;
}
.grid {
  display: grid;
  gap: 14px;
}
.grid > *,
.chart-wrap {
  min-width: 0;
}
.grid.tiles {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.grid.two {
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .grid.two {
    grid-template-columns: 1fr 1fr;
  }
}
.grid.three {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.card {
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card + .card,
.section {
  margin-top: 14px;
}
.grid > .card {
  margin-top: 0;
}
.card h2 {
  margin-bottom: 8px;
}

/* ---------------------------------------------------------------- tiles */
.tile {
  padding: 16px 18px;
}
.tile .label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tile.power .label::before,
.tile.volt .label::before,
.tile.curr .label::before,
.tile.freq .label::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-power);
}
.tile.volt .label::before {
  background: var(--c-volt);
}
.tile.curr .label::before {
  background: var(--c-curr);
}
.tile.freq .label::before {
  background: var(--c-freq);
}
.tile .value {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.15;
  margin-top: 6px;
  letter-spacing: -0.03em;
}
.tile .unit {
  font-size: 15px;
  color: var(--muted);
  margin-left: 3px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.tile .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

/* --------------------------------------------------------------- status */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  margin-right: 6px;
  vertical-align: 1px;
}
.dot.on {
  background: var(--good);
}
.dot.off {
  background: var(--bad);
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 14px;
  font-weight: 500;
}
.sw,
.ev-sw {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.ev-sw {
  margin-right: 7px;
  vertical-align: 0;
}
.chip .dur {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}
.banner {
  padding: 11px 16px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  margin-bottom: 14px;
  font-size: 14px;
}
.banner.info {
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
}

/* -------------------------------------------------------------- controls */
.btn {
  border: 0;
  background: var(--fill);
  color: var(--ink);
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover {
  background: var(--fill-strong);
}
.btn:active {
  transform: scale(0.98);
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn.primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}
.btn.danger {
  color: var(--bad);
}
.btn.sm {
  padding: 5px 12px;
  font-size: 13px;
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}
input[type='text'],
input[type='number'],
input[type='password'],
input[type='datetime-local'],
input[type='file'],
select,
textarea {
  background: var(--fill);
  border: 0;
  border-radius: 10px;
  padding: 7px 11px;
  min-width: 0;
  font-size: 14px;
}
select {
  padding-right: 8px;
  cursor: pointer;
}
input[type='color'] {
  padding: 2px;
  width: 40px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: var(--fill);
}
:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
}
label.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
label.field input,
label.field select {
  font-size: 15px;
  color: var(--ink);
  font-weight: 400;
}
label.inline select {
  color: var(--ink);
}
label.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

/* -------------------------------------------------------------- history */
.hist-toolbar {
  display: flex;
  align-items: center;
  gap: 10px 12px;
  flex-wrap: wrap;
}
.readout {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  padding-left: 4px;
}
.readout b {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.02em;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 6px;
  align-items: center;
}
.chip-toggle {
  border: 0;
  background: var(--fill);
  border-radius: 999px;
  padding: 6px 13px 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  transition: opacity 0.15s ease, background 0.15s ease;
  user-select: none;
}
.chip-toggle small {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chip-toggle:hover {
  background: var(--fill-strong);
}
.chip-toggle:not(.on) {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--muted);
}
.chip-toggle:not(.on) .sw {
  background: transparent !important;
  box-shadow: inset 0 0 0 1.5px var(--muted);
}
.chip-toggle:not(.on) small {
  display: none;
}
.chips .sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}
.subchart {
  margin-top: 14px;
}
.subchart .chart-title h3 {
  display: flex;
  align-items: center;
  gap: 7px;
}
.timeline-wrap {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 0.5px solid var(--border);
}
.timeline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
#timeline {
  display: block;
  width: 100%;
  height: 92px;
  border-radius: 12px;
  background: var(--surface-2);
  touch-action: none;
  cursor: crosshair;
}
.zoomable {
  cursor: grab;
  touch-action: pan-y;
}
.zoomable.dragging {
  cursor: grabbing;
}

/* --------------------------------------------------------------- charts */
.chart-wrap {
  position: relative;
  height: 220px;
}
.chart-wrap.tall {
  height: 300px;
}
.chart-wrap.hero {
  height: 400px;
}
.chart-wrap.short {
  height: 150px;
}
.chart-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.chart-title h2 {
  margin: 0;
}

/* --------------------------------------------------------------- tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  white-space: nowrap;
}
td.r,
th.r {
  text-align: right;
}
tr:last-child td {
  border-bottom: 0;
}
.table-scroll {
  overflow-x: auto;
}
.empty {
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

/* --------------------------------------------------------------- dialog */
dialog {
  border: 0;
  border-radius: 22px;
  background: var(--surface);
  color: var(--ink);
  padding: 24px;
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 0 0 0.5px var(--border), 0 30px 80px rgba(0, 0, 0, 0.3);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.32);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
dialog h2 {
  margin-bottom: 12px;
  font-size: 21px;
}
.code-box {
  background: var(--fill);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
  white-space: pre-wrap;
  user-select: all;
}
.pair-code {
  font-size: 42px;
  letter-spacing: 0.22em;
  font-weight: 600;
  text-align: center;
  padding: 14px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(40, 40, 42, 0.92);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  z-index: 50;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

/* ---------------------------------------------------------------- login */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login .card {
  width: min(380px, 100%);
  padding: 28px;
}
.login form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}
.login input {
  padding: 11px 13px;
  font-size: 16px;
}
.login .btn {
  justify-content: center;
  padding: 11px;
  font-size: 16px;
}
.err {
  color: var(--bad);
  font-size: 13px;
}

@media (max-width: 640px) {
  main {
    padding: 14px 14px 40px;
  }
  .topbar {
    padding: 10px 14px;
  }
  .card {
    padding: 16px;
    border-radius: 18px;
  }
  .tile .value {
    font-size: 28px;
  }
  .chart-wrap.hero {
    height: 300px;
  }
}

/* the card that names an event under the pointer */
.ev-tip {
  position: fixed;
  z-index: 60;
  display: none;
  pointer-events: none;
  background: rgba(40, 40, 42, 0.94);
  color: #fff;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
.ev-tip .muted {
  color: #fff;
}
.ev-tip .sub {
  font-weight: 400;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  margin-top: 2px;
}
