:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --text: #1b1a17;
  --muted: #6f6a60;
  --line: #e0d9cb;
  --on: #e8a400;          /* світло є — тепле жовте */
  --on-soft: #fff1c4;
  --off: #2b3245;         /* немає світла — нічне */
  --off-soft: #d9dce6;
  --maybe: #c9b98f;
  --fact: #d64545;
  --good: #2f9e5b;
  --warn: #d9822b;
  --bad: #d64545;
  --soc: #2f9e5b;
  --load: #3d6fd6;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 6px 20px rgba(40, 30, 10, .06);
  --r: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #20242d; --text: #eceae4; --muted: #8e939e; --line: #262b35;
    --on: #ffc23a; --on-soft: #3a2f12; --off: #6b7590; --off-soft: #232838; --maybe: #6d6447; --fact: #ff6b6b;
    --good: #4cc27c; --warn: #f0a050; --bad: #ff6b6b; --soc: #4cc27c; --load: #6f9bff;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #20242d; --text: #eceae4; --muted: #8e939e; --line: #262b35;
  --on: #ffc23a; --on-soft: #3a2f12; --off: #6b7590; --off-soft: #232838; --maybe: #6d6447; --fact: #ff6b6b;
  --good: #4cc27c; --warn: #f0a050; --bad: #ff6b6b; --soc: #4cc27c; --load: #6f9bff;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 Manrope, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.err { color: var(--bad); min-height: 1.2em; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface); border-radius: 24px; padding: 32px 24px; box-shadow: var(--shadow); text-align: center; display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 0; }
.logo-big { font-size: 44px; }
input { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; }
input:focus { outline: 2px solid var(--on); outline-offset: 1px; }

/* Layout */
main { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 92px); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 14px; gap: 12px; }
.brand { font-weight: 800; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.brand .where { font-weight: 500; font-size: 13px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--on); box-shadow: 0 0 0 4px color-mix(in srgb, var(--on) 25%, transparent); }
.dot.off { background: var(--off); }
.fresh { font-size: 12px; color: var(--muted); text-align: right; }
.fresh.stale { color: var(--bad); font-weight: 600; }

.card { background: var(--surface); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card-title { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 12px; }
.card-title.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-head { padding: 4px 2px 12px; }
.section-head h2 { margin: 0 0 4px; font-size: 22px; }

/* Hero */
.hero { border-radius: 24px; padding: 22px 20px 20px; margin-bottom: 12px; position: relative; overflow: hidden; transition: background .4s; }
.hero.on { background: linear-gradient(140deg, #ffd45a, #f2a900); color: #2a1f00; }
.hero.off { background: linear-gradient(140deg, #2b3245, #161a26); color: #f1f0ec; }
.hero.unknown { background: var(--surface-2); }
.hero::after { content: ''; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%; background: rgba(255,255,255,.14); }
.hero.off::after { background: rgba(255,255,255,.04); }
.hero-label { font-size: 32px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.hero-sub { font-size: 16px; margin-top: 6px; font-weight: 600; opacity: .85; }
.hero-extra { font-size: 14px; margin-top: 12px; opacity: .85; }
.hero-extra:empty { display: none; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 99px; background: rgba(255,255,255,.22); font-weight: 700; font-size: 13px; margin: 2px 4px 2px 0; }
.hero.off .pill { background: rgba(255,255,255,.1); }

/* Battery */
.battery { display: flex; gap: 18px; align-items: center; }
.ring { position: relative; width: 112px; height: 112px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--soc); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .8s, stroke .3s; }
.ring-val { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 30px; }
.ring-val small { font-size: 14px; margin-left: 1px; }
.ring-val > span { display: flex; align-items: baseline; }
.ring-val { grid-auto-flow: column; justify-content: center; align-items: center; }
.bat-state { font-weight: 700; font-size: 16px; }
.bat-runtime { font-size: 22px; font-weight: 800; margin: 4px 0 2px; }
.bat-note { font-size: 13px; }

/* Next outage */
.next { display: flex; gap: 14px; align-items: center; }
.next .ico { font-size: 26px; width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); flex: none; }
.next .t1 { font-weight: 700; }
.next .t2 { font-size: 13px; color: var(--muted); }
.next .countdown { margin-left: auto; text-align: right; font-weight: 800; font-size: 18px; white-space: nowrap; }

/* Metrics */
.grid-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.metric { background: var(--surface); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.metric .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.metric .v { font-size: 22px; font-weight: 800; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .v small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.metric .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.energy-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.energy-row .k { font-size: 12px; color: var(--muted); }
.energy-row .v { font-weight: 800; font-size: 18px; }

/* Plan */
.day { margin-bottom: 12px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 8px; }
.day-head b { font-size: 17px; }
.bar { position: relative; display: grid; grid-template-columns: repeat(48, 1fr); height: 40px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.bar .c { border-right: 1px solid color-mix(in srgb, var(--surface) 35%, transparent); }
.bar .c:nth-child(2n) { border-right-color: color-mix(in srgb, var(--surface) 80%, transparent); }
.c.on { background: var(--on-soft); }
.c.off { background: var(--off); }
.c.maybe { background: repeating-linear-gradient(45deg, var(--maybe) 0 4px, transparent 4px 8px); }
.c.unknown { background: var(--surface-2); }
.bar .fact { position: absolute; bottom: 0; height: 6px; background: var(--fact); border-radius: 3px; }
.bar .now { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); border-radius: 2px; }
.hours { display: grid; grid-template-columns: repeat(8, 1fr); font-size: 11px; color: var(--muted); margin-top: 4px; }
.intervals { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 10px; border-radius: 10px; background: var(--surface-2); font-weight: 700; font-size: 14px; }
.chip.off { background: var(--off); color: #fff; }
.chip.maybe { background: color-mix(in srgb, var(--maybe) 45%, var(--surface)); }
.empty { padding: 14px; border-radius: 12px; background: var(--surface-2); color: var(--muted); text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); padding: 4px 2px; }
.legend.small { font-size: 12px; margin-top: 8px; padding: 0; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 5px; }
.lg.on { background: var(--on-soft); border: 1px solid var(--on); }
.lg.off { background: var(--off); }
.lg.maybe { background: repeating-linear-gradient(45deg, var(--maybe) 0 3px, transparent 3px 6px); border: 1px solid var(--maybe); }
.lg.fact { background: var(--fact); height: 5px; vertical-align: 2px; }
.lg.soc { background: var(--soc); height: 4px; vertical-align: 3px; }
.lg.load { background: var(--load); height: 4px; vertical-align: 3px; }

/* History */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border-radius: var(--r); padding: 12px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 20px; font-weight: 800; }
.stat .s { font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; text-transform: none; letter-spacing: 0; }
.seg button { border: 0; background: none; padding: 5px 9px; border-radius: 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.chart { width: 100%; height: 200px; position: relative; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .axis { font-size: 10px; fill: var(--muted); font-family: Manrope, sans-serif; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 8px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); font-weight: 600; }
.out-day { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 6px; }
.out-day:first-child { margin-top: 0; }
.out { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.out:last-child { border-bottom: 0; }
.out .t { font-weight: 700; }
.out .d { font-weight: 800; white-space: nowrap; }
.out .m { font-size: 12px; color: var(--muted); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; margin-left: 6px; vertical-align: 1px; }
.tag.plan { background: var(--off-soft); color: var(--text); }
.tag.unplan { background: color-mix(in srgb, var(--fact) 18%, transparent); color: var(--fact); }
.tag.live { background: var(--fact); color: #fff; }

/* Settings */
.btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 11px 16px; font-weight: 700; }
.btn.primary { background: var(--on); border-color: var(--on); color: #2a1f00; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.toggle { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.toggle:last-of-type { border-bottom: 0; }
.toggle .tt { font-weight: 600; }
.toggle .ts { font-size: 12px; color: var(--muted); }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--good); border-color: var(--good); }
.switch input:checked + span::before { transform: translateX(18px); }
.hint { background: var(--on-soft); border-radius: 12px; padding: 12px; font-size: 13px; margin-bottom: 10px; }
.log-item { padding: 8px 0; border-bottom: 1px solid var(--line); }
.log-item:last-child { border-bottom: 0; }
.log-item .lt { font-weight: 700; }

/* Tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px); z-index: 10; }
.tabs button { border: 0; background: none; display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.tabs .ti { font-size: 20px; filter: grayscale(1); opacity: .6; }
.tabs button.active { color: var(--text); }
.tabs button.active .ti { filter: none; opacity: 1; }

@media (max-width: 380px) {
  .hero-label { font-size: 28px; }
  .ring { width: 96px; height: 96px; }
  .stats .v { font-size: 17px; }
}

/* Смуга світла по днях */
.stripe-row { display: grid; grid-template-columns: 58px 1fr 52px; align-items: center; gap: 8px; margin-bottom: 7px; }
.stripe-row .lbl { font-size: 12px; font-weight: 700; color: var(--muted); line-height: 1.15; }
.stripe-row .lbl b { color: var(--text); display: block; font-size: 13px; }
.stripe-row .tot { font-size: 12px; font-weight: 800; text-align: right; white-space: nowrap; }
.stripe-row .tot.zero { color: var(--muted); font-weight: 600; }
.stripe { position: relative; height: 26px; border-radius: 7px; background: var(--on-soft); overflow: hidden; }
.stripe .o { position: absolute; top: 0; bottom: 0; background: var(--off); min-width: 2px; }
.stripe .p { position: absolute; top: 0; height: 4px; background: var(--fact); opacity: .85; }
.stripe .nd { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, var(--surface-2) 0 4px, var(--line) 4px 8px); }
.stripe .nowline { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); }
.stripe-hours { display: grid; grid-template-columns: 58px 1fr 52px; gap: 8px; font-size: 10px; color: var(--muted); margin-top: 2px; }
.stripe-hours > div { display: flex; justify-content: space-between; }
.lg.plan { background: var(--fact); height: 4px; vertical-align: 3px; }
.lg.nodata { background: repeating-linear-gradient(45deg, var(--surface-2) 0 3px, var(--line) 3px 6px); }

/* Погода */
.weather .now-w { display: flex; align-items: center; gap: 14px; }
.weather .w-ico { font-size: 44px; line-height: 1; }
.weather .w-temp { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.weather .w-desc { font-weight: 700; }
.weather .w-sub { font-size: 12px; color: var(--muted); }
.weather .w-warn { margin-top: 10px; font-size: 13px; font-weight: 700; color: var(--warn); }
.hourly { display: flex; gap: 6px; overflow-x: auto; margin: 12px -16px 0; padding: 0 16px 4px; scrollbar-width: none; }
.hourly::-webkit-scrollbar { display: none; }
.hr { flex: none; width: 50px; text-align: center; padding: 8px 0; border-radius: 12px; background: var(--surface-2); font-size: 12px; }
.hr.offplan { box-shadow: inset 0 -3px 0 var(--fact); }
.hr .h { color: var(--muted); font-weight: 700; }
.hr .i { font-size: 20px; margin: 2px 0; }
.hr .t { font-weight: 800; }
.hr .p { color: var(--load); font-size: 11px; font-weight: 700; min-height: 14px; }
.daily { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.dy { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; font-size: 12px; }
.dy b { display: block; font-size: 13px; }
.dy .i { font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 4px; }
.chips button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px; padding: 5px 11px; font-size: 13px; font-weight: 700; color: var(--muted); }
.chips button.on { background: var(--on); border-color: var(--on); color: #2a1f00; }

/* Дні з відключеннями */
.dayblk { padding: 12px 0 14px; border-bottom: 1px solid var(--line); }
.dayblk:first-child { padding-top: 0; }
.dayblk-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.dayblk-h b { font-size: 15px; }
.dayblk-h span { font-size: 13px; font-weight: 800; }
.dayblk .stripe { height: 30px; }
.stripe .tick { position: absolute; top: 0; bottom: 0; width: 1px; background: color-mix(in srgb, var(--text) 12%, transparent); }
.stripe-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin: 3px 0 8px; }
.ev { display: grid; grid-template-columns: auto auto 1fr; gap: 10px; align-items: baseline; padding: 5px 0; }
.ev-t { font-size: 16px; font-weight: 700; }
.ev-d { font-weight: 800; font-size: 14px; }
.ev-m { font-size: 12px; color: var(--muted); text-align: right; }
.ev-m .unpl { color: var(--fact); font-weight: 700; }
.ev-plan { font-size: 12px; color: var(--muted); margin-top: 4px; }
.day-quiet { display: flex; justify-content: space-between; gap: 8px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.day-quiet span:first-child { color: var(--text); font-weight: 600; }
.warn-pill { background: #fff3 !important; outline: 2px solid currentColor; }

/* Вода */
.water-active { display: flex; gap: 12px; align-items: center; }
.wa-ico { font-size: 30px; width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: color-mix(in srgb, var(--load) 18%, var(--surface)); flex: none; }
.wa-txt { display: grid; }
.wa-txt b { font-size: 16px; }
.wa-txt span { font-size: 13px; color: var(--muted); }
.water-start { margin-top: 0; }
.water-start .btn { flex: 1 1 calc(50% - 8px); }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; }
.month-nav b { font-size: 17px; }
.month-nav .btn { padding: 8px 14px; }
.bill-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; }
.bill-row.big { font-size: 18px; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.bill-sub { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.bill-warn { font-size: 13px; color: var(--warn); font-weight: 700; margin-top: 8px; }
.wrow { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.wrow:last-of-type { border-bottom: 0; }
.wrow .t { font-weight: 700; }
.wrow .m { font-size: 12px; color: var(--muted); }
.wrow .r { text-align: right; }
.wrow .kwh { font-weight: 800; white-space: nowrap; }
.warn-t { color: var(--warn); }
.small-btn { padding: 6px 10px; font-size: 12px; text-transform: none; letter-spacing: 0; }
.wadd { display: grid; grid-template-columns: 1fr 1fr 70px; gap: 8px; margin-bottom: 12px; }
.wadd button { grid-column: 1 / -1; }
.wadd input { padding: 10px; }
.wset summary { cursor: pointer; margin-bottom: 0; list-style: none; }
.wset[open] summary { margin-bottom: 12px; }
.fgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
select { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 10px; width: 100%; }
.tabs button { font-size: 10px; }

.top-r { display: flex; align-items: center; gap: 8px; }
.refresh { border: 1px solid var(--line); background: var(--surface); width: 36px; height: 36px; border-radius: 12px; font-size: 18px; font-weight: 700; line-height: 1; display: grid; place-items: center; flex: none; }
.refresh.spin { animation: spin 0.9s linear infinite; pointer-events: none; opacity: .7; }
@keyframes spin { to { transform: rotate(360deg); } }
