/* ===================== Font (lokal, tanpa CDN) ===================== */
@font-face { font-family: "Barlow SC"; src: url("vendor/fonts/barlow-semi-condensed-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Barlow SC"; src: url("vendor/fonts/barlow-semi-condensed-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow SC"; src: url("vendor/fonts/barlow-semi-condensed-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Barlow SC"; src: url("vendor/fonts/barlow-semi-condensed-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

/* ===================== Token ===================== */
:root {
  --bg: #eef1f3;
  --panel: #ffffff;
  --ink: #16222d;
  --muted: #5b6b78;
  --line: #d3dbe1;
  --grid: #e3e8ec;
  --focus: #1b5fd1;

  /* warna seri — sama dengan grafik matplotlib yang sudah dipakai */
  --c-v: #1b5fd1;   /* tegangan: biru  */
  --c-ih: #cf6a06;  /* arus highside: oranye */
  --c-il: #c53030;  /* arus lowside: merah */
  --c-p: #1d8a43;   /* daya: hijau */
  --c-e: #7a3eb5;   /* energi: ungu */

  --ok: #1d8a43;
  --warn: #b7791f;
  --off: #9aa7b2;

  --font: "Barlow SC", "Barlow Semi Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111a21;
    --panel: #172229;
    --ink: #e3e9ed;
    --muted: #93a3b0;
    --line: #2b3a45;
    --grid: #22303a;
    --focus: #7fb0ff;

    --c-v: #6ea3ff;
    --c-ih: #f0a04b;
    --c-il: #f07470;
    --c-p: #56c27a;
    --c-e: #b58ae6;

    --ok: #56c27a;
    --warn: #e0b04f;
    --off: #5d6b76;
    color-scheme: dark;
  }
}

/* ===================== Dasar ===================== */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  padding: env(safe-area-inset-top, 0) max(16px, env(safe-area-inset-right, 0)) max(24px, env(safe-area-inset-bottom, 0)) max(16px, env(safe-area-inset-left, 0));
  max-width: 1440px;
  margin-inline: auto;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ===================== Header ===================== */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 0 14px;
}
.brand h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.95rem; }

.server-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.95rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); flex: none; }
.server-state[data-state="ok"] .dot { background: var(--ok); }
.server-state[data-state="bad"] .dot { background: var(--c-il); }

/* ===================== Tab ===================== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--line);
  overflow-x: auto;
}
.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 9px;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tab:hover { color: var(--ink); }
.tab .t-state { font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.tab[data-online="true"] .dot { background: var(--ok); }
.tab[data-online="true"][data-stale="true"] .dot { background: var(--warn); }

.boot-note { color: var(--muted); padding: 32px 0; }

/* ===================== Panel ===================== */
.panel { padding-top: 18px; }
.panel[hidden] { display: none; }
.panel:focus { outline: none; }

/* Pembacaan nilai terkini — elemen utama halaman, meniru OLED joulemeter */
.readouts {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.readout {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "label label" "val unit";
  align-items: baseline;
  column-gap: 6px;
  padding: 14px 18px 12px;
  border-left: 1px solid var(--line);
  position: relative;
}
.readout:first-child { border-left: 0; }
.readout::before {
  content: "";
  position: absolute;
  left: 18px; right: 18px; top: 0;
  height: 3px;
  background: var(--series);
}
.r-label { grid-area: label; color: var(--muted); font-size: 0.95rem; font-weight: 500; }
.r-val { grid-area: val; font-size: clamp(2rem, 3.4vw, 3rem); font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
.r-unit { grid-area: unit; font-size: 1.1rem; color: var(--muted); font-weight: 500; }
.readout-energy .r-val { color: var(--series); }

[data-key="v"]  { --series: var(--c-v); }
[data-key="ih"] { --series: var(--c-ih); }
[data-key="il"] { --series: var(--c-il); }
[data-key="p"]  { --series: var(--c-p); }
[data-key="e"]  { --series: var(--c-e); }

/* ===================== Toolbar ===================== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  padding: 14px 2px;
}
.meta { display: flex; gap: 6px 22px; flex-wrap: wrap; color: var(--muted); font-size: 0.95rem; }
.meta b { color: var(--ink); font-weight: 600; }
.m-age[data-stale="true"] { color: var(--warn); font-weight: 600; }
.m-drop:empty, .m-rate:empty { display: none; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; background: var(--panel); }
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 5px;
  padding: 6px 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn-live { border-color: var(--warn); color: var(--warn); font-weight: 600; }

.empty-note {
  margin: 0 0 14px;
  padding: 12px 16px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
}

/* ===================== Grafik ===================== */
.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.chart {
  position: relative;
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 10px 4px;
  min-width: 0;
}
.chart-wide { grid-column: 1 / -1; }
.chart figcaption {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1rem;
  padding: 0 4px 6px;
}
.chart figcaption::before {
  content: "";
  width: 14px; height: 3px;
  background: var(--series);
  flex: none;
}
.plot { width: 100%; min-height: 230px; }

/* uPlot */
.uplot { font-family: var(--font); color: var(--ink); }
.u-legend {
  position: absolute;
  top: 9px;
  right: 12px;
  width: auto;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: right;
}
.u-legend .u-series { padding: 0 0 0 10px; }
.u-legend .u-label { font-weight: 500; }
.u-legend th::after { content: "" !important; }
.uplot:not(.is-hover) .u-legend { visibility: hidden; }
.u-legend .u-series + .u-series .u-label { display: none; }   /* cukup penanda warna + nilai */
.u-legend td { font-weight: 600; color: var(--ink); padding-left: 4px; }
.u-legend .u-marker { border-radius: 1px; }
.u-select { background: color-mix(in srgb, var(--focus) 14%, transparent); }

/* ===================== Responsif ===================== */
@media (max-width: 1000px) {
  .readouts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .readout:nth-child(4) { border-left: 0; }
  .readout:nth-child(n + 4) { border-top: 1px solid var(--line); }
}
@media (max-width: 720px) {
  .charts { grid-template-columns: 1fr; }
  .readouts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .readout:nth-child(odd) { border-left: 0; }
  .readout:nth-child(4) { border-left: 1px solid var(--line); }
  .readout:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .readout-energy { grid-column: 1 / -1; }
  .brand h1 { font-size: 1.45rem; }
  .tab { padding: 10px 12px 9px; }
  .u-legend { position: static; text-align: left; padding: 2px 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
