:root {
  --bg: #0b0e14;
  --panel: rgba(14, 18, 27, 0.92);
  --panel-solid: #0e121b;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e8ecf3;
  --muted: #8b95a7;
  --dim: #5b6577;
  --lit: #ffcf5c;
  --lit-soft: rgba(255, 207, 92, 0.14);
  --off: #3a4459;
  --out: #ff5a52;
  --out-soft: rgba(255, 90, 82, 0.14);
  --accent: #ffcf5c;
  --radius: 14px;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

#map { position: fixed; inset: 0; }

/* ---------- panel ---------- */
.panel {
  position: fixed; top: 16px; left: 16px; bottom: 16px; width: 380px;
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 20px;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 18px 8px; z-index: 5;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  scrollbar-width: thin; scrollbar-color: #2a3242 transparent;
}
.sheet-handle { display: none; }

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; color: #1a1300;
  background: radial-gradient(circle at 35% 30%, #fff1c2, var(--lit) 55%, #f29e1f);
  box-shadow: 0 0 24px rgba(255, 207, 92, 0.45);
}
h1 { font-size: 20px; line-height: 1.1; margin: 0; font-weight: 800; letter-spacing: -0.01em; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.35; }
h2 { font-size: 13px; margin: 0; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); }

.now-card {
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
  background: linear-gradient(160deg, rgba(255, 207, 92, 0.07), rgba(255, 255, 255, 0.02));
}
.now-card.dark { background: linear-gradient(160deg, rgba(90, 110, 160, 0.12), rgba(255, 255, 255, 0.02)); }
.now-top { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.clock { color: var(--text); font-size: 15px; }
.day-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6); animation: pulse 2s infinite; flex: none; }
.live-dot.paused { background: var(--dim); animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(61, 220, 132, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); } }
.now-main { font-size: 19px; font-weight: 700; line-height: 1.3; margin: 10px 0 10px; letter-spacing: -0.01em; }
.now-main b { color: var(--lit); font-weight: 800; }
.now-main .off { color: #9fb0d0; }
.now-main .o { color: #ff8a84; }
.now-sub { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.now-sub .o { color: var(--out); font-weight: 700; }
.meter { height: 8px; border-radius: 99px; background: var(--lit-soft); overflow: hidden; margin: 2px 0 10px; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, #2d3850, #56688f); transition: width .4s ease; border-radius: 99px; }

.my-home {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; font-size: 13px;
}
.my-home .addr { font-weight: 700; font-size: 14px; }
.my-home .st { color: var(--muted); grid-column: 1 / -1; line-height: 1.45; }
.my-home .st b { color: var(--text); }
.my-home .x { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 16px; padding: 2px 4px; }

/* актуальність даних */
.brand-text { flex: 1; min-width: 0; }
.fresh-pill {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px 4px 5px; border-radius: 99px;
  border: 1px solid var(--line-strong); background: #141a25; cursor: pointer; font-size: 12px; color: var(--muted);
}
.fresh-pill:hover { border-color: var(--lit); color: var(--text); }
.fresh-pill svg { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, 0.1); stroke-width: 4; }
.ring { fill: none; stroke: var(--lit); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset .6s ease; }
.fresh-pill.done .ring { stroke: #3ddc84; }

.fresh { font-size: 12.5px; color: var(--muted); }
.fresh.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { border-color: var(--lit); box-shadow: 0 0 0 3px rgba(255, 207, 92, .15); } }
.fresh-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.fresh-count { font-size: 13px; color: var(--text); }
.fresh-count b { font-size: 15px; color: var(--lit); font-weight: 600; }
.bar { position: relative; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, .07); overflow: hidden; margin: 8px 0 7px; }
.bar-fill, .bar-map { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; transition: width .6s ease; width: 0; }
.bar-fill { background: rgba(255, 207, 92, .35); }
.bar-map { background: var(--lit); }
.fresh-sub { line-height: 1.5; }
.fresh-sub .warn { color: #f2a33a; }
.collector { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.collector::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.collector.on { color: #3ddc84; }
.collector.on::before { background: #3ddc84; animation: pulse 2s infinite; }
.collector.ok { color: #3ddc84; }
.collector.ok::before { background: #3ddc84; }
.collector.off { color: #f2a33a; }
.collector.off::before { background: #f2a33a; }
.fresh-rows { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 9px 0 0; padding-top: 9px; border-top: 1px solid var(--line); }
.fresh-rows dt { color: var(--dim); }
.fresh-rows dd { margin: 0; color: var(--muted); }
.fresh-rows dd b { color: var(--text); font-weight: 600; }
.fresh-rows .stale { color: #f2a33a; }

.block { border-top: 1px solid var(--line); padding: 14px 0; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.note { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.note:empty { display: none; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--out-soft); color: var(--out); }

select {
  background: #161c28; border: 1px solid var(--line-strong); border-radius: 10px; padding: 6px 10px; font-size: 13px; max-width: 210px;
}

/* search */
.search { display: flex; align-items: center; gap: 8px; background: #141a25; border: 1px solid var(--line-strong); border-radius: 12px; padding: 0 12px; color: var(--muted); }
.search:focus-within { border-color: rgba(255, 207, 92, 0.6); box-shadow: 0 0 0 3px rgba(255, 207, 92, 0.12); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; padding: 11px 0; font-size: 14px; color: var(--text); min-width: 0; }
.suggest { list-style: none; margin: 6px 0 0; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: #121722; }
.suggest li { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; display: flex; justify-content: space-between; gap: 10px; }
.suggest li span { color: var(--dim); font-size: 12px; white-space: nowrap; }
.suggest li:hover, .suggest li.on { background: #1d2534; }
.houses { margin-top: 10px; }
.houses .h-title { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; }
.houses .grid { display: flex; flex-wrap: wrap; gap: 5px; max-height: 168px; overflow-y: auto; }
.hbtn {
  border: 1px solid var(--line-strong); background: #151b27; border-radius: 8px; padding: 4px 7px; font-size: 12.5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums;
}
.hbtn i { width: 7px; height: 7px; border-radius: 2px; display: inline-block; }
.hbtn.nomap { opacity: .65; border-style: dashed; }
.hbtn:hover { border-color: var(--lit); }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--dim); border-top-color: var(--lit); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* timeline */
.timeline { position: relative; user-select: none; touch-action: none; cursor: ew-resize; }
.timeline svg { display: block; width: 100%; height: auto; overflow: visible; }
.tl-row { cursor: pointer; }
.tl-row:hover .tl-label { fill: var(--text); }
.tl-label { fill: var(--muted); font: 600 10.5px var(--mono); }
.tl-label.on { fill: var(--lit); }
.tl-track { fill: rgba(255, 207, 92, 0.12); }
.tl-off { fill: #3c4b6b; }
.tl-off.now { fill: #6f86b8; }
.tl-row.focus .tl-track { fill: rgba(255, 207, 92, 0.3); }
.tl-tick { fill: var(--dim); font: 500 9.5px var(--mono); }
.tl-grid { stroke: rgba(255, 255, 255, 0.06); }
.tl-cursor { stroke: var(--lit); stroke-width: 1.5; }
.tl-cursor-dot { fill: var(--lit); }
.tl-now { stroke: #3ddc84; stroke-width: 1; stroke-dasharray: 2 2; }

.scrub { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.scrub input[type=range] { flex: 1; accent-color: var(--lit); min-width: 0; }
.t-label { font-size: 13px; width: 44px; text-align: right; }

.chip {
  border: 1px solid var(--line-strong); background: #171e2b; border-radius: 99px; padding: 5px 11px; font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--lit); }
.chip.ghost { background: transparent; padding: 2px 9px; color: var(--lit); border-color: rgba(255, 207, 92, 0.4); }
#btn-play { width: 34px; height: 30px; padding: 0; display: grid; place-items: center; font-size: 12px; }

/* ключ кольорів — лише те, що зараз є на мапі */
.key { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.key:empty { display: none; }
.key span { display: inline-flex; align-items: center; gap: 6px; }
.key i { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* лінзи: одна тема на мапі за раз */
.search-wrap { margin-bottom: 12px; }
.lenses { margin-bottom: 6px; }
.lens-row { display: flex; gap: 4px; padding: 3px; background: #121722; border: 1px solid var(--line); border-radius: 12px; }
.lens { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 7px 6px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.lens:hover { color: var(--text); }
.lens.on { background: #222b3b; color: var(--text); box-shadow: inset 0 0 0 1px rgba(255, 207, 92, 0.35); }
.lens-note { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 7px 2px 4px; }
.lens-note:empty { display: none; }
.lens-note .grid { display: grid; grid-template-columns: repeat(6, auto); gap: 4px 8px; margin-top: 6px; justify-content: start; }
.lens-note .grid span { display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 11px; }
.lens-note i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; vertical-align: -1px; margin-right: 4px; }

/* згорнуті деталі */
.fold { border-top: 1px solid var(--line); }
.fold > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 12px 2px; user-select: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--dim); border-bottom: 2px solid var(--dim); transform: rotate(-45deg); transition: transform .15s; margin-left: 2px; flex: none; }
.fold[open] > summary::after { transform: rotate(45deg); }
.fold > summary:hover .fold-title { color: var(--text); }
.fold-title { font-size: 13px; font-weight: 700; color: var(--muted); flex: 1; }
.fold-hint { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.fold-hint b { color: var(--muted); font-weight: 600; }
.fold-body { padding: 0 0 14px; }
.fold-tools { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.chip.more { width: 100%; margin-top: 8px; border-radius: 10px; color: var(--muted); }
.sources { font-size: 11.5px; color: var(--dim); line-height: 1.5; margin: 10px 0 0; }

/* 3D — кнопка на мапі */
.ctl-3d { font: 700 11px var(--font) !important; color: #1b2230 !important; width: 29px; }
.ctl-3d[aria-pressed=false] { opacity: .55; }

/* outages */
.outages { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.outages li {
  border: 1px solid var(--line); border-left: 3px solid var(--out); border-radius: 10px; padding: 9px 11px; cursor: pointer; font-size: 13px; line-height: 1.4;
  background: rgba(255, 255, 255, 0.015);
}
.outages li:hover { background: rgba(255, 255, 255, 0.04); }
.outages .o-street { font-weight: 700; }
.outages .o-city { color: var(--dim); font-weight: 500; }
.outages .o-meta { color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; }
.outages .o-houses { color: var(--muted); font-size: 12px; margin-top: 3px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.outages .o-kind { font-weight: 700; }
.outages .empty { border-left-color: #3ddc84; cursor: default; color: var(--muted); }

.foot { border-top: 1px solid var(--line); padding: 12px 2px 10px; font-size: 11.5px; color: var(--dim); line-height: 1.5; }
.foot a { color: var(--muted); }

/* overlays */

.big-time {
  position: fixed; top: 22px; left: 50%; transform: translateX(calc(-50% + 200px)); z-index: 4; pointer-events: none;
  font-size: 44px; font-weight: 500; color: var(--lit); text-shadow: 0 0 30px rgba(255, 207, 92, 0.5); letter-spacing: 0.02em;
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(calc(-50% + 200px)); z-index: 6;
  background: #1a2130; border: 1px solid var(--line-strong); border-radius: 12px; padding: 10px 14px; font-size: 13px; max-width: min(420px, calc(100vw - 32px));
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}

/* popup */
.maplibregl-popup-content {
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--line-strong); border-radius: 14px;
  padding: 13px 15px 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, .5); font-family: var(--font); min-width: 230px;
}
.maplibregl-popup-tip { border-top-color: var(--panel-solid) !important; border-bottom-color: var(--panel-solid) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; right: 6px; top: 4px; }
.pp-addr { font-weight: 800; font-size: 15px; padding-right: 16px; line-height: 1.25; }
.pp-city { color: var(--dim); font-size: 12px; margin-top: 1px; }
.pp-status { margin: 10px 0 8px; padding: 8px 10px; border-radius: 10px; font-weight: 700; font-size: 13.5px; line-height: 1.35; }
.pp-status.lit { background: var(--lit-soft); color: var(--lit); }
.pp-status.off { background: rgba(110, 134, 184, .16); color: #b8c6e6; }
.pp-status.out { background: var(--out-soft); color: #ff8a84; }
.pp-status.sh { background: rgba(90, 209, 230, .14); color: #8fe3f1; }
.pp-status small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: 2px; }
.pp-kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12.5px; color: var(--muted); }
.pp-kv b { color: var(--text); font-weight: 600; }
.pp-g { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); color: var(--text); }
.pp-g i { width: 9px; height: 9px; border-radius: 2px; }
.pp-actions { margin-top: 10px; display: flex; gap: 6px; }
.pp-actions button { font-size: 12px; }

.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--line); }
.maplibregl-ctrl-group button { filter: invert(.9); }
.maplibregl-ctrl-attrib { background: rgba(10, 13, 20, .7) !important; color: var(--dim); }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }

/* ---------- mobile: bottom sheet ---------- */
@media (max-width: 760px) {
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh; border-radius: 20px 20px 0 0;
    padding: 6px 16px calc(8px + env(safe-area-inset-bottom)); transition: max-height .25s ease;
  }
  .panel.collapsed { max-height: 168px; overflow: hidden; }
  .sheet-handle { display: grid; place-items: center; width: 100%; height: 22px; background: none; border: 0; cursor: pointer; margin-bottom: 4px; }
  .sheet-handle span { width: 42px; height: 4px; border-radius: 99px; background: var(--line-strong); }
  .brand { margin-bottom: 10px; }
  .brand-mark { width: 34px; height: 34px; }
  h1 { font-size: 18px; }
  .sub { display: none; }
  .big-time, .toast { transform: translateX(-50%); }
  .big-time { font-size: 34px; top: 70px; }
  .toast { bottom: auto; top: 12px; }
  .maplibregl-ctrl-bottom-right { bottom: 62vh; transition: bottom .25s ease; }
  body.sheet-collapsed .maplibregl-ctrl-bottom-right { bottom: 168px; }
}
