:root {
  color-scheme: dark;
  --bg: #0e1217;
  --surface: #161b22;
  --surface-2: #1d242d;
  --surface-3: #252e39;
  --border: #2c3643;
  --text: #e8edf2;
  --text-2: #a5b0bc;
  --muted: #74808d;
  --accent: #3987e5;
  --accent-2: #2a78d6;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --roof: #5c5347;
  --roof-line: #7b7061;
  --panel-off: #2a3038;
  --sel: #f2f5f8;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f4f6; --surface: #ffffff; --surface-2: #f5f6f8; --surface-3: #e8ebef;
    --border: #d9dee4; --text: #14181d; --text-2: #4b5561; --muted: #7a8490;
    --roof: #cbbfae; --roof-line: #a89984; --panel-off: #d4d8de; --sel: #0b0b0b;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f4f6; --surface: #ffffff; --surface-2: #f5f6f8; --surface-3: #e8ebef;
  --border: #d9dee4; --text: #14181d; --text-2: #4b5561; --muted: #7a8490;
  --roof: #cbbfae; --roof-line: #a89984; --panel-off: #d4d8de; --sel: #0b0b0b;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 var(--font); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
h4 { margin: 8px 0; font-size: 13px; font-weight: 600; }
input, select, button { font: inherit; color: inherit; }
input, select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-2); }
label:has(> input[type=checkbox]) { flex-direction: row; align-items: center; gap: 6px; }

.btn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.active { outline: 2px solid var(--accent); }

/* ---- login ---- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.err { color: var(--critical); min-height: 1em; font-size: 13px; }

/* ---- header ---- */
.top {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.logo { width: 22px; height: 22px; border-radius: 5px; background:
  linear-gradient(90deg, #3fb950 0 28%, transparent 28% 36%, #3fb950 36% 64%, transparent 64% 72%, #3fb950 72%);
  box-shadow: inset 0 0 0 4px var(--surface-3); }
.tabs { display: flex; gap: 2px; }
.tabs button {
  background: transparent; border: 0; padding: 8px 12px; border-radius: 6px; cursor: pointer; color: var(--text-2);
}
.tabs button.active { background: var(--surface-3); color: var(--text); }
.tabs button:hover { color: var(--text); }
.badge { background: var(--critical); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.src { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--good); } .dot.bad { background: var(--critical); } .dot.warn { background: var(--warning); }

.view { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---- KPI ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.kpi .lbl { font-size: 12px; color: var(--text-2); }
.kpi .val { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 13px; color: var(--text-2); font-weight: 400; margin-left: 3px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.alert .val { color: var(--text); }
.kpi.alert .ico { color: var(--critical); }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 16px; padding: 4px 11px;
  cursor: pointer; font-size: 13px; color: var(--text-2);
}
.chip.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

.groups { display: flex; gap: 8px; flex-wrap: wrap; }
.gcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 12px; font-size: 13px; cursor: pointer; display: flex; gap: 10px; align-items: baseline;
}
.gcard b { font-variant-numeric: tabular-nums; }
.gcard .bar { width: 60px; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; align-self: center; }
.gcard .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.gcard.hl { outline: 2px solid var(--accent); }

/* ---- map ---- */
.map-wrap {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  height: calc(100vh - 300px); min-height: 380px; overflow: hidden;
}
#view-editor .map-wrap { height: calc(100vh - 140px); }
.map { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; cursor: grab; }
.map.panning { cursor: grabbing; }
.map .area text { pointer-events: none; }
.map .area text { fill: var(--text-2); font-size: 22px; font-weight: 600; }
.map .pnl rect.b { fill: var(--panel-off); stroke: rgba(0,0,0,.35); stroke-width: 1; }
.map .pnl text { font-size: 13px; font-weight: 600; fill: #fff; pointer-events: none; text-anchor: middle;
  paint-order: stroke; stroke: rgba(0,0,0,.55); stroke-width: 2.5px; }
.map .pnl text.v { font-weight: 500; font-size: 12px; }
.map .pnl.light text { fill: #0b0b0b; stroke: rgba(255,255,255,.5); }
.map .pnl { cursor: pointer; }
.map .pnl.off rect.b { fill: var(--panel-off); stroke: var(--critical); stroke-dasharray: 4 3; stroke-width: 2; }
.map .pnl.warn rect.ring { fill: none; stroke: var(--critical); stroke-width: 3; }
.map .pnl.dim { opacity: .25; }
.map .pnl.found rect.ring { fill: none; stroke: var(--sel); stroke-width: 4; }
.map .pnl .cell { fill: none; stroke: rgba(255,255,255,.07); stroke-width: 1; pointer-events: none; }
.editing .pnl.sel rect.b { stroke: var(--sel); stroke-width: 3; }
.map .area .sel-outline { display: none; }
.editing .area.sel .sel-outline { display: block; stroke: var(--sel); stroke-width: 3; stroke-dasharray: 8 4; }
.editing .handle { fill: var(--sel); cursor: nwse-resize; }
.editing .rubber { fill: rgba(57,135,229,.15); stroke: var(--accent); stroke-dasharray: 4 3; }
.editing .ghost rect { fill: rgba(57,135,229,.35); stroke: var(--accent); }
.editing { cursor: default; }

.legend {
  margin-left: auto; background: var(--surface); display: grid; grid-template-columns: auto 160px; column-gap: 10px; align-items: center;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 12px; font-size: 12px;
}
.legend .keys { grid-column: 1 / -1; }
.legend .grad { height: 10px; border-radius: 3px; margin: 2px 0; grid-row: 1; grid-column: 2; }
.legend .ends { grid-column: 2; }
.legend .ends { display: flex; justify-content: space-between; color: var(--text-2); font-variant-numeric: tabular-nums; }
.legend .keys { display: flex; gap: 12px; margin-top: 3px; color: var(--text-2); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -2px; margin-right: 4px; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 40px; color: var(--text-2); }

/* ---- tooltip / drawer / toast ---- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.35); min-width: 180px;
}
.tooltip table { border-collapse: collapse; width: 100%; }
.tooltip td { padding: 1px 0; font-variant-numeric: tabular-nums; }
.tooltip td:last-child { text-align: right; padding-left: 14px; color: var(--text); }
.tooltip td:first-child { color: var(--text-2); }
.tooltip .t { font-weight: 600; margin-bottom: 4px; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 40; background: var(--surface);
  border-left: 1px solid var(--border); padding: 16px; overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.3);
  display: flex; flex-direction: column; gap: 10px;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.dgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.dgrid div { background: var(--surface-2); border-radius: 6px; padding: 6px 8px; }
.dgrid span { display: block; font-size: 11px; color: var(--text-2); }
.dgrid b { font-variant-numeric: tabular-nums; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface-3);
  border: 1px solid var(--border); padding: 8px 16px; border-radius: 6px; z-index: 60;
}

/* ---- tables ---- */
.table-wrap { overflow: auto; max-height: 60vh; }
.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { padding: 5px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tbl th { color: var(--text-2); font-weight: 500; position: sticky; top: 0; background: var(--surface); cursor: pointer; }
.tbl td.n { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.sev { display: inline-flex; align-items: center; gap: 5px; }
.sev::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.sev.critical { color: var(--critical); } .sev.serious { color: var(--serious); } .sev.warning { color: var(--warning); }
.pbar { display: inline-block; width: 80px; height: 6px; background: var(--surface-3); border-radius: 3px; vertical-align: middle; margin-right: 6px; }
.pbar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }

.chart { width: 100%; min-height: 260px; }
.u-legend { font-size: 12px; }
.u-legend .u-marker { border-radius: 2px; }

/* ---- editor ---- */
.editor { display: grid; grid-template-columns: 270px 1fr 240px; gap: 12px; min-height: calc(100vh - 100px); }
.ed-side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 12px; overflow: hidden; max-height: calc(100vh - 100px); }
.ed-block { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.ed-block:first-child { flex: 1; }
.ed-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ed-list { overflow-y: auto; flex: 1; min-height: 120px; border: 1px solid var(--border); border-radius: 6px; }
.ed-item { display: flex; gap: 8px; align-items: center; padding: 4px 8px; border-bottom: 1px solid var(--border); font-size: 12px; cursor: pointer; }
.ed-item:hover { background: var(--surface-2); }
.ed-item .id { font-family: ui-monospace, monospace; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.ed-item .pw { color: var(--text-2); font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ed-props label { margin-bottom: 6px; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .ed-side { max-height: none; }
}
@media (max-width: 700px) {
  .view { padding: 10px; }
  .top { padding: 8px 10px; gap: 8px; }
  .top-right .muted { display: none; }
  .map-wrap { height: 70vh; }
  .dgrid { grid-template-columns: repeat(2, 1fr); }
  .kpi .val { font-size: 20px; }
}

.tbl th.n { text-align: right; }
.grid2 input, .ed-side input:not([type=checkbox]), .ed-side select { width: 100%; }
#view-map > .groups { align-items: center; }

/* ---- slnko ---- */
.suninfo { margin-left: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 5px 12px; font-size: 12px; line-height: 1.5; }
.suninfo + .legend { margin-left: 0; }
.sun-ring { fill: none; stroke: var(--border); }
.sun-tick { stroke: var(--muted); }
.sun-card { fill: var(--text-2); font-weight: 700; text-anchor: middle; }
.sun-card.north { fill: var(--critical); }
.sun-path { fill: none; stroke: #f5b83d; stroke-opacity: .28; stroke-linecap: round; stroke-linejoin: round; }
.sun-hour { fill: #f5b83d; fill-opacity: .7; }
.sun-hlabel { fill: var(--muted); text-anchor: middle; }
.sun-ray { stroke: #f5b83d; stroke-opacity: .35; stroke-dasharray: 10 8; }
.sun-disc { fill: #ffc940; stroke: #fff3c4; stroke-width: 2; filter: drop-shadow(0 0 12px rgba(255,190,60,.8)); }
.sun-rays { stroke: #ffc940; stroke-linecap: round; }
.sun-glyph.night .sun-disc { fill: var(--surface-3); stroke: var(--muted); filter: none; }
#view-map { height: calc(100vh - 53px); }
#view-map .map-wrap { flex: 1; height: auto; min-height: 380px; }
@media (max-width: 700px) { #view-map { height: auto; } #view-map .map-wrap { height: 70vh; flex: none; } }

.bgimg { pointer-events: none; }
.editing.bgmove { cursor: move; }
input[type=range] { width: 100%; padding: 0; }

/* ---- nastavenia ---- */
.set-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.set-grid .card { display: flex; flex-direction: column; gap: 10px; }
.set-grid .card.wide { grid-column: 1 / -1; }
.set-grid h3 { margin: 0; }
.set-grid h4 { margin: 4px 0 0; }
.set-grid p { margin: 0; }
.set-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; gap: 8px; }
.src-row { display: grid; grid-template-columns: 140px 230px 1fr 1fr auto; gap: 8px; align-items: end;
  padding: 8px 0; border-bottom: 1px solid var(--border); }
.src-row .src-st { color: var(--text-2); align-self: center; }
.set-grid code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
@media (max-width: 900px) { .set-grid { grid-template-columns: 1fr; } .src-row { grid-template-columns: 1fr 1fr; } }

.map .pnl.sleep rect.b { fill: var(--panel-off); opacity: .7; }
.night-note { color: var(--text-2); }

/* ---- vzhľad solar-roof-card ---- */

.map .area text { fill: #ffb64c; fill-opacity: .9; font-size: 22px; font-weight: 600; }
.map .pnl rect.b { fill: #0b0b0b; stroke: rgba(255,255,255,.08); stroke-width: 1; }
.map .pnl .cell { fill: none; stroke: rgba(255,255,255,.14); stroke-width: .8; pointer-events: none; }
.map .pnl .frame { fill: none; stroke: rgba(225,230,240,.55); stroke-width: 1.2; pointer-events: none; }
.map .pnl .sheen { pointer-events: none; }
.map .pnl text { fill: #fff; stroke: rgba(0,0,0,.5); stroke-width: 2px; font-weight: 600; }
.map .pnl.light text { fill: #fff; stroke: rgba(0,0,0,.5); }
.map .pnl.off rect.b { fill: #0b0b0b; stroke: #ff5252; stroke-dasharray: 4 3; stroke-width: 1.5; }
.map .pnl.off .frame { stroke: #ff5252; stroke-dasharray: 4 3; }
.map .pnl.sleep rect.b { fill: #0b0b0b; opacity: 1; }
.map .pnl.warn rect.ring { fill: none; stroke: #ff1744; stroke-width: 2.5; animation: pulse 1.6s infinite; }
.map .pnl:hover rect.b { filter: brightness(1.3); }
@keyframes pulse { 0%,100% { stroke-opacity: 1 } 50% { stroke-opacity: .35 } }
.sun-ring { stroke: #ffb64c40 !important; }
.sun-path { stroke: #ffb64c; stroke-opacity: .25; }
.sun-ray { stroke: #ffcf7a; }
/* obloha */
#view-map .map-wrap[data-sky] { transition: background .6s; }
#view-map .map-wrap[data-sky="day"] { background: linear-gradient(#123047, #1f5673); }
#view-map .map-wrap[data-sky="dusk"] { background: linear-gradient(#3a2a52, #c9663f); }
#view-map .map-wrap[data-sky="night"] { background: var(--stars) center top / cover no-repeat, linear-gradient(#02040a, #0c1c33); }
#view-map .map-wrap[data-sky] .sun-card { fill: #f7f7f2; }
#view-map .map-wrap[data-sky] .sun-card.north { fill: #ff6b6b; }
#view-map .map-wrap[data-sky] .sun-hlabel { fill: rgba(255,255,255,.55); }
.legend .tswatch { display: flex; gap: 10px; flex-wrap: wrap; grid-column: 2; }
.ebar { position: relative; height: 8px; background: #333; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.ebar i { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: linear-gradient(90deg, #ffc107, #ff9800, #ff6f00);
  box-shadow: 0 0 10px rgba(0,212,255,.45); }
.ebar i::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.5), transparent);
  width: 60px; animation: flow 1.6s linear infinite; }
@keyframes flow { from { transform: translateX(-60px) } to { transform: translateX(600px) } }

.look-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.look-grid > div { display: flex; flex-direction: column; gap: 6px; }
.look-c { flex-direction: row !important; align-items: center; gap: 8px; }
.look-c input[type=color] { width: 36px; height: 26px; padding: 0; border: 1px solid var(--border); background: none; }
.look-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.look-row input[type=number] { width: 70px; }
.look-prev { height: 10px; border-radius: 3px; }
@media (max-width: 900px) { .look-grid { grid-template-columns: 1fr; } }
.map .pnl text.v { stroke-width: .9px; stroke: rgba(0,0,0,.65); }
.ebar i { overflow: hidden; }

.ver { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; padding: 0 7px; }

.gclear { background: var(--accent-2); color: #fff; border: 0; border-radius: var(--radius); padding: 6px 12px; font-size: 13px; cursor: pointer; }
.gclear:hover { background: var(--accent); }
.gcard { user-select: none; }

/* ---- grafy ---- */
.flt { display: flex; flex-direction: column; gap: 8px; }
.flt-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.flt-l { font-size: 12px; color: var(--muted); min-width: 64px; text-transform: uppercase; letter-spacing: .03em; }
.flt-inline { flex-direction: row !important; align-items: center; gap: 6px; font-size: 12px; }
.chip.small { padding: 2px 9px; font-size: 12px; }
.plots { display: flex; flex-direction: column; gap: 12px; }
.plots .card h3 .muted { font-weight: 400; font-size: 13px; }

.bshadow { fill: rgba(0,0,0,.38); filter: blur(3px); }
.rshadow { fill: rgba(0,0,0,.42); filter: blur(2px); }

.editing.drawing { cursor: crosshair; }
.btn-group { display: inline-flex; gap: 0; }
.btn-group .btn { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group select { border-top-left-radius: 0; border-bottom-left-radius: 0; padding: 3px 6px; font-size: 13px; }

.acc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.acc-grid > div { display: flex; flex-direction: column; gap: 8px; }
label.radio { flex-direction: row !important; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
label.radio input { margin-top: 3px; }
.warnline { color: var(--warning); }
@media (max-width: 900px) { .acc-grid { grid-template-columns: 1fr; } }

.sun-halo, .sun-flare { mix-blend-mode: screen; pointer-events: none; }

.sun-solstice { fill: none; stroke: #ffcf7a; stroke-opacity: .28; stroke-dasharray: 6 6; }
.sun-slabel { fill: #ffcf7a; fill-opacity: .55; text-anchor: middle; }
