:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef1f5; --border: #dbe0e7;
  --text: #17202c; --muted: #5b6676; --accent: #0f6fcf; --accent-soft: #e2eefb;
  --ok: #1f8a4c; --warn: #c27a00; --alarm: #c8352e; --offline: #6b7686; --charge: #2f6fd6; --discharge: #1f8a4c;
  --shadow: 0 1px 2px rgba(18,28,45,.06), 0 3px 12px rgba(18,28,45,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --surface: #171e27; --surface-2: #1f2832; --border: #2c3744;
    --text: #e6ebf1; --muted: #98a3b3; --accent: #5aa2f0; --accent-soft: #1b2e45;
    --ok: #47c47e; --warn: #f0ab3c; --alarm: #ef6f67; --offline: #8a95a6; --charge: #6ea2ff; --discharge: #47c47e;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14.5px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 500; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.topbar .right { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid currentColor; white-space: nowrap; }
.badge.live { color: var(--warn); } .badge.stored { color: var(--ok); }

main { max-width: 1500px; margin: 0 auto; padding: 18px 20px 40px; }
main.narrow { max-width: 460px; padding-top: 60px; }
.note { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--warn);
  border-radius: 8px; padding: 9px 12px; margin-bottom: 14px; font-size: 13.5px; }
.error { color: var(--alarm); }
section { margin-top: 22px; }
section > h2 { font-size: 15px; margin-bottom: 10px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* site cards */
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 16px; }
@media (max-width: 560px) { .sites { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 16px; }
.card-head .meta { font-size: 12.5px; color: var(--muted); }
.card-head .status { margin-left: auto; }
.card-body { display: grid; grid-template-columns: 1fr; }
.block { padding: 12px 14px; }
.block + .block { border-top: 1px solid var(--border); }
.block h4 { margin: 0 0 8px; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px 14px; }
.fact .k { font-size: 12px; color: var(--muted); }
.fact .v { font-size: 17px; font-weight: 650; }
.fact .v small { font-size: 12px; font-weight: 500; color: var(--muted); }

.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 650; background: var(--surface-2); }
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.s-ok { color: var(--ok); } .s-warning { color: var(--warn); } .s-alarm { color: var(--alarm); } .s-offline { color: var(--offline); }

/* cabinet rows */
.cab { display: grid; grid-template-columns: minmax(110px, 1.3fr) 1.4fr 1fr 1fr; gap: 10px; align-items: center;
  padding: 8px 0; border-top: 1px dashed var(--border); }
.cab:first-of-type { border-top: 0; }
.cab .name { font-weight: 600; }
.socbar { position: relative; height: 18px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.socbar i { position: absolute; inset: 0 auto 0 0; background: var(--ok); opacity: .85; }
.socbar.low i { background: var(--warn); } .socbar.empty i { background: var(--alarm); }
.socbar span { position: relative; font-size: 12px; font-weight: 650; padding-left: 6px; line-height: 18px; }
.power.dis { color: var(--discharge); } .power.chg { color: var(--charge); }
.chip { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 5px; background: var(--surface-2); }
.chip.fault { color: #fff; background: var(--alarm); }
.stale { color: var(--offline); }
@media (max-width: 560px) { .cab { grid-template-columns: 1fr 1fr; } }

.alarm-line { display: flex; gap: 8px; align-items: baseline; font-size: 13px; padding: 3px 0; }
.sev { display: inline-block; min-width: 62px; text-align: center; font-size: 11.5px; font-weight: 700;
  padding: 1px 6px; border-radius: 5px; color: #fff; text-transform: uppercase; }
.sev.critical { background: var(--alarm); } .sev.major { background: var(--warn); }
.sev.minor { background: var(--charge); } .sev.info { background: var(--offline); }

/* tables */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.cleared td { color: var(--muted); }

/* filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
select, input, button { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 6px 10px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }

/* chart */
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; box-shadow: var(--shadow); }
.chart svg { width: 100%; height: 240px; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* login */
.login { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; box-shadow: var(--shadow); }
.login h1 { font-size: 20px; margin-bottom: 4px; }
.login form { display: grid; gap: 12px; margin-top: 16px; }
.login label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* sites: layout switch, chart, list */
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.section-head h2 { margin: 0; font-size: 15px; }
.section-head .seg { margin: 0 0 0 auto; }
.site-chart { width: 100%; height: auto; display: block; color: var(--text); }
th.r, td.r { text-align: right; }
#site-list td { white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--surface); padding: 5px 14px; font-size: 13px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; }

/* site card: seven metrics + day chart */
.site-card { cursor: pointer; transition: border-color .15s; }
.site-card:hover { border-color: var(--accent); }
.site-card h3 a, .site-row a { color: inherit; text-decoration: none; }
.site-card h3 a:hover, .site-row a:hover { color: var(--accent); }
.site-card .status { display: flex; gap: 6px; align-items: center; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; padding: 12px 14px; }
@media (max-width: 560px) { .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.metric { cursor: help; min-width: 0; }
.metric .k { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .v { font-size: 19px; font-weight: 650; white-space: nowrap; }
.metric .v small { font-size: 12px; font-weight: 500; color: var(--muted); }
.metric .s { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.chart-wrap { border-top: 1px solid var(--border); padding: 8px 14px 12px; }
.chart-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 13px; }
.chart-date { font-weight: 600; min-width: 130px; text-align: center; }
.nav-btn { padding: 1px 9px; line-height: 1.4; cursor: pointer; }
.nav-btn:disabled { opacity: .35; cursor: default; }
.nav-btn.today { font-size: 12px; }
.info { margin-left: auto; color: var(--muted); cursor: help; font-size: 15px; }
.chart-empty { padding: 30px 0; text-align: center; color: var(--muted); font-size: 13px; }
.c-axis { font-size: 10px; fill: var(--muted); }
.c-soc-t { fill: var(--warn); }
.c-zero { stroke: var(--border); }
.c-peak { fill: var(--accent-soft); opacity: .8; }
.c-imp { fill: var(--accent); } .c-imp.dim { opacity: .4; }
.c-exp { fill: var(--ok); }
.c-md { stroke: var(--alarm); stroke-dasharray: 4 3; stroke-width: 1.2; }
.c-soc { fill: none; stroke: var(--warn); stroke-width: 2; }
.alarm-badge { text-decoration: none; min-width: 0; }
.site-row { cursor: pointer; }
.site-row:hover td { background: var(--surface-2); }
