:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1b1f24; --muted: #66707c; --line: #e3e6ea;
  --accent: #2563eb; --ok: #15803d; --off: #9aa3ad; --warn: #b45309; --bad: #b91c1c;
  --bar: #dbe7fd; --bar-fill: #2563eb; --row-hover: #f1f4f8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #1a1e24; --text: #e6e9ed; --muted: #8b95a1; --line: #2a3038;
    --accent: #60a5fa; --ok: #4ade80; --off: #5b6470; --warn: #fbbf24; --bad: #f87171;
    --bar: #1e2a3d; --bar-fill: #60a5fa; --row-hover: #20252c;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* top navigation */
.topnav { position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line); }
.navin { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; height: 52px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { width: 22px; height: 22px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tabs a { color: var(--muted); padding: 15px 12px 13px; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.navin .sp { flex: 1; }
.who { white-space: nowrap; font-size: 13px; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px; }
@media (max-width: 560px) { .brand span, .who .muted { display: none; } .navin { gap: 8px; } }

.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
header.page { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 16px; }
header.page h1 { font-size: 22px; margin: 0; }
header.page .sp { flex: 1; }
.updated, .muted { color: var(--muted); }
.updated { font-size: 13px; }

button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
select { font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); max-width: 100%; }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; min-width: 0; }
.tile .k { color: var(--muted); font-size: 12px; }
.tile .v { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.tile .v small { font-size: 14px; font-weight: 400; color: var(--muted); }
.tile .s { font-size: 12px; color: var(--muted); }
.tile.warnv .v { color: var(--warn); }

/* section cards on the overview */
.sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 20px; }
.scard { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--text); }
.scard:hover { border-color: var(--accent); text-decoration: none; }
.scard h3 { margin: 0 0 8px; font-size: 15px; display: flex; justify-content: space-between; }
.scard h3::after { content: "→"; color: var(--muted); }
.scard .big { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.scard .s { font-size: 12px; color: var(--muted); }
.scard .alert { color: var(--warn); font-size: 13px; margin-top: 4px; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 12px; margin-bottom: 20px; min-width: 0; }
.phead { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.phead h2 { font-size: 16px; margin: 0; }
.phead .sp { flex: 1; }
.note { font-size: 12px; color: var(--muted); margin-top: 8px; }
details.rules { margin-top: 10px; font-size: 12px; color: var(--muted); }
details.rules summary { cursor: pointer; }
.gh { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }

/* tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel); }
th.sort { cursor: pointer; user-select: none; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th .arr { opacity: .6; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: var(--row-hover); }
.name { font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
input[type=search] { font: inherit; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); min-width: 0; flex: 1 1 220px; max-width: 320px; }
.chip { border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.on { background: var(--ok); } .dot.off { background: var(--off); }
.pw { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar { width: 70px; height: 6px; border-radius: 3px; background: var(--bar); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--bar-fill); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.on { color: var(--ok); border-color: currentColor; }
.badge.bad { color: var(--bad); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.ok { color: var(--ok); } .bad { color: var(--bad); }
.err { background: var(--panel); border: 1px solid var(--bad); color: var(--bad); padding: 12px 16px; border-radius: 12px; margin-bottom: 12px; }

/* device details */
tr.detail td { background: var(--bg); white-space: normal; padding: 14px 16px; }
.dgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; min-width: 0; }
.dgrid > div { min-width: 0; }
tr.detail .dgrid { position: sticky; left: 16px; width: calc(var(--cardw, 100%) - 32px); }
.dgrid h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span { overflow-wrap: anywhere; }
.wide { grid-column: 1 / -1; }

/* charts */
.spark { width: 100%; height: 120px; display: block; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark path.g { stroke: var(--warn); }
.axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.mnav { display: inline-flex; align-items: center; gap: 6px; }
.mnav button { padding: 2px 10px; }
.mlabel { min-width: 110px; text-align: center; font-variant-numeric: tabular-nums; }
.mtotal { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.mchart svg { display: block; }
.mchart .b { fill: var(--accent); }
.mchart .b.calc { opacity: .55; }
.mchart .b:hover { opacity: .8; }
.mchart .g { stroke: var(--line); }
.mchart text { fill: var(--muted); font-size: 11px; }

/* categorical series colours (stations) */
:root { --c0: #2563eb; --c1: #0d9488; --c2: #d97706; --c3: #9333ea; }
@media (prefers-color-scheme: dark) { :root { --c0: #60a5fa; --c1: #2dd4bf; --c2: #fbbf24; --c3: #c084fc; } }
.lines .s0, .legend i.s0 { --c: var(--c0); background: var(--c0); }
.lines .s1, .legend i.s1 { --c: var(--c1); background: var(--c1); }
.lines .s2, .legend i.s2 { --c: var(--c2); background: var(--c2); }
.lines .s3, .legend i.s3 { --c: var(--c3); background: var(--c3); }
.lines path { fill: none; stroke: var(--c); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.lines path.dash { stroke-dasharray: 4 4; }
.lines circle { fill: var(--c); stroke: var(--panel); stroke-width: 1.5; }
.lines circle.cur { fill: var(--panel); stroke: var(--c); stroke-width: 2; }
.lines circle:hover { r: 6; }
.legend i.s0, .legend i.s1, .legend i.s2, .legend i.s3 { height: 3px; width: 14px; border-radius: 2px; }

/* group analytics (komory, pidvaly) */
.gcols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.gmonths svg { display: block; }
.gmonths .b { fill: var(--accent); } .gmonths .fc { fill: var(--accent); opacity: .25; }
.gmonths text { fill: var(--muted); font-size: 11px; }
.gtable { min-width: 640px; }
.gtable td { vertical-align: top; }
.gtable tr.anom td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.gtable tr.anom { background: color-mix(in srgb, var(--warn) 7%, transparent); }
.strip { display: flex; gap: 2px; padding-top: 2px; }
.strip i { width: 9px; height: 16px; border-radius: 2px; background: var(--bar); position: relative; flex: none; }
.strip i b { position: absolute; inset: 0; border-radius: 2px; background: var(--accent); }
.strip i.sp { outline: 2px solid var(--bad); outline-offset: -1px; }
.strip i.na { background: transparent; border: 1px dashed var(--line); }
.flags { margin-top: 4px; white-space: normal; font-size: 12px; color: var(--warn); }
.flags div::before { content: "⚠ "; }

/* inverters */
.invgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-bottom: 20px; }
.invc { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.invc.offline { opacity: .7; border-style: dashed; }
.invh { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin-bottom: 10px; }
.invh b { font-size: 18px; }
.invh .sp { flex: 1; }
.flow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.flow div { background: var(--bg); border-radius: 8px; padding: 6px 8px; font-size: 11px; color: var(--muted); min-width: 0; }
.flow b { display: block; font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.flow small { display: block; font-size: 11px; overflow-wrap: anywhere; }
@media (max-width: 420px) { .flow { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.socbar { height: 4px; border-radius: 2px; background: var(--bar); margin-top: 4px; overflow: hidden; }
.socbar i { display: block; height: 100%; background: var(--ok); }
.socbar i.low { background: var(--bad); }
.kv2 { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; font-size: 12px; margin-bottom: 8px; }
.kv2 span:nth-child(odd) { color: var(--muted); }
.kv2 span:nth-child(even) { font-variant-numeric: tabular-nums; }
.invc .spark { height: 70px; }
.dbars { display: flex; align-items: flex-end; gap: 2px; height: 46px; margin-top: 4px; }
.dbars i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 1px; }
.dbars i.today { opacity: .55; }
.dbars i.nodata { background: var(--bar); }
.legend { font-size: 11px; color: var(--muted); display: flex; gap: 10px; }
.legend i { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 4px; background: var(--accent); }
.legend i.g { background: var(--warn); }

/* DAH */
.dahcard table { min-width: 720px; }
.dahcard .warn { color: var(--warn); font-size: 12px; white-space: normal; }
