/* Inerka Design System, палітра «Нічне небо» (полотно «Дизайн сторінки sanya.inerka.app»).
   Шрифти — системні: на Android Roboto / One UI / MiSans, на iPhone SF (цифри — SF Pro Rounded).
   Кольори джерел (дім, сонце, мережа, батарея) перевірено валідатором dataviz для обох тем, з урахуванням дальтонізму.
   Без color-mix() та інших свіжих функцій: вбудовані браузери Xiaomi бувають старими. */
:root {
  color-scheme: light;
  --ground: #eef3fa;
  --ground-glow: #dde9fb;
  --sheet: #ffffff;
  --field: #e9eff8;
  --line: #d3dde9;
  --ink: #0a1020;
  --ink-2: #4f5d73;
  --accent: #1f6fd6;
  --on-accent: #ffffff;
  --accent-ink: #1a4c94;
  --good: #147a3a;
  --good-soft: #e1f5e6;
  --bad: #c62828;
  --bad-soft: #fde7e5;
  --c-home: #1f6fd6;
  --c-sun: #b97800;
  --c-grid: #14968a;
  --c-batt: #7b55d3;
  --c-home-soft: #e2edfb;
  --c-sun-soft: #f6ecd6;
  --c-grid-soft: #dcf1ee;
  --c-batt-soft: #ece6f9;
  --seg-shadow: 0 1px 2px #0a10201f;
  --tip-shadow: 0 6px 18px #17468f24;
  --f-ui: -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --f-display: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Segoe UI", sans-serif;
  --f-mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ground: #0a1020;
    --ground-glow: #182a4f;
    --sheet: #111a2b;
    --field: #1c2741;
    --line: #28344d;
    --ink: #eaf0fa;
    --ink-2: #a3b1c8;
    --accent: #7cc4ff;
    --on-accent: #0a1020;
    --accent-ink: #bfddff;
    --good: #3dd68c;
    --good-soft: #10291f;
    --bad: #ff6b5e;
    --bad-soft: #2e1620;
    --c-home: #3d8fe0;
    --c-sun: #c48210;
    --c-grid: #20a88a;
    --c-batt: #9a7ee8;
    --c-home-soft: #17294a;
    --c-sun-soft: #2c2412;
    --c-grid-soft: #11302c;
    --c-batt-soft: #231f42;
    --seg-shadow: 0 1px 2px #02050c99;
    --tip-shadow: 0 2px 12px #02050cb3;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--ground); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(120% 420px at 50% 0, var(--ground-glow), var(--ground) 72%) var(--ground);
  font: 500 15px/22px var(--f-ui);
}
h1, h2, p, dl, dd, ol, ul { margin: 0; }
button { font: inherit; color: inherit; }

/* --- текстові стилі Inerka --- */
.kicker { font: 500 12px/16px var(--f-mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2); }
.note { font-size: 13px; line-height: 18px; font-weight: 600; color: var(--ink-2); }
.body { font-size: 15px; line-height: 22px; font-weight: 500; color: var(--ink); }
.strong { font-size: 16px; line-height: 22px; font-weight: 700; color: var(--ink); }
.secondary { color: var(--ink-2); }
.fig-m { font: 600 20px/26px var(--f-display); letter-spacing: -0.01em; color: var(--ink); font-variant-numeric: tabular-nums; }
.data { font: 500 12px/16px var(--f-mono); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ic { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; display: block; }

/* --- сторінка --- */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.title { display: flex; flex-direction: column; gap: 2px; }
h1 { font: 600 22px/28px var(--f-display); letter-spacing: -0.02em; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px 0 12px;
  border-radius: 9999px; background: var(--sheet); border: 1px solid var(--line);
  font-size: 13px; line-height: 18px; font-weight: 600; color: var(--ink);
}
.dot { width: 8px; height: 8px; border-radius: 9999px; background: var(--ink-2); flex: none; }
.pill[data-level="good"] .dot { background: var(--good); }
.pill[data-level="bad"] .dot { background: var(--bad); }

/* Телефон: одна колонка, картки в порядку макета. Комп'ютер: сітка 3 / 2 / 2. */
.layout { display: flex; flex-direction: column; gap: 12px; }
.row, .col { display: contents; }
.state { order: 1; } .flow-card { order: 2; } .today { order: 3; } .light { order: 4; }
.bms { order: 5; } .history { order: 6; } .events-card { order: 7; } .rows { order: 8; }
@media (min-width: 700px) and (max-width: 999px) {
  .page { max-width: 640px; }
}
@media (min-width: 1000px) {
  .page { padding: 32px 40px 40px; gap: 16px; }
  .layout { gap: 16px; }
  .row { display: grid; gap: 16px; align-items: start; }
  .col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
  .row-top { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .row-mid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  .row-bottom { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layout .card { order: 0; }
}

.card {
  background: var(--sheet); border: 1px solid var(--line); border-radius: 22px; padding: 16px;
  display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-head.center { align-items: center; flex-wrap: wrap; }

/* --- стан --- */
.state { padding: 20px 20px 18px; background: linear-gradient(180deg, var(--field) 0%, var(--sheet) 100%); }
.state[data-tone="good"] { background: linear-gradient(180deg, var(--good-soft) 0%, var(--sheet) 100%); }
.state[data-tone="bad"] { background: linear-gradient(180deg, var(--bad-soft) 0%, var(--sheet) 100%); }
.state-head { display: flex; align-items: center; gap: 10px; }
.state-icon {
  width: 36px; height: 36px; flex: none; border-radius: 9999px; background: var(--ink-2); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center;
}
.state[data-tone="good"] .state-icon { background: var(--good); }
.state[data-tone="bad"] .state-icon { background: var(--bad); }
.state-sub { font-weight: 500; color: var(--ink-2); }
.state-figure { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hero { display: flex; align-items: baseline; gap: 6px; }
.hero > span:first-child { font: 600 56px/1 var(--f-display); letter-spacing: -0.03em; color: var(--ink); }
.hero-unit { font: 500 22px/1 var(--f-display); color: var(--ink-2); }
.state-figure .note { margin-bottom: 4px; text-align: right; font-variant-numeric: tabular-nums; }
.meter { height: 10px; border-radius: 9999px; background: var(--field); overflow: hidden; }
.meter-fill { height: 100%; width: 0; border-radius: 9999px; background: var(--accent); transition: width .4s ease; }
.meter-fill[data-level="bad"] { background: var(--bad); }
.est { display: flex; align-items: center; gap: 8px; }
.est .ic { color: var(--ink-2); }
.est b { font-weight: 700; }

/* --- сьогодні --- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.key-label { display: flex; align-items: center; gap: 6px; }
.key { width: 14px; height: 3px; border-radius: 2px; flex: none; display: inline-block; }
.stat-value { display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }

/* --- потоки --- */
.flow { position: relative; width: 100%; max-width: 380px; margin: 0 auto; aspect-ratio: 326 / 248; }
.flow svg.lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.flow .node {
  position: absolute; display: flex; align-items: center; gap: 8px; padding: 0 8px;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 16px; min-width: 0;
}
.flow .node-icon {
  width: 32px; height: 32px; flex: none; border-radius: 9999px; background: var(--field); color: var(--ink-2);
  display: flex; align-items: center; justify-content: center;
}
.flow .node-text { display: flex; flex-direction: column; min-width: 0; }
.flow .node-value { font: 600 16px/20px var(--f-display); letter-spacing: -0.01em; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.flow .node-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow .hub {
  position: absolute; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--field); border: 1px solid var(--line); border-radius: 9999px; color: var(--ink);
}
.flow .hub .ic { color: var(--ink-2); }

/* --- світло за добу --- */
.strip-wrap { display: flex; flex-direction: column; gap: 6px; }
.strip { display: flex; gap: 2px; }
.strip span { flex: 1 1 0; height: 28px; border-radius: 4px; background: var(--field); }
.strip span[data-s="on"] { background: var(--good); }
.strip span[data-s="off"] { background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
.ticks { display: flex; justify-content: space-between; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-on { background: var(--good); }
.sw-off { background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
.sw-unknown { background: var(--field); box-shadow: inset 0 0 0 1px var(--line); }

/* --- історія --- */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 14px; background: var(--field); }
.segmented button {
  min-height: 44px; padding: 0 14px; border: 0; border-radius: 11px; background: transparent; cursor: pointer;
  font-size: 14px; line-height: 20px; font-weight: 700; color: var(--ink-2);
}
.segmented button[aria-pressed="true"] { background: var(--sheet); color: var(--ink); box-shadow: var(--seg-shadow); }
.segmented button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.history { gap: 18px; }
.charts { display: flex; flex-direction: column; gap: 18px; transition: opacity .2s; }
.charts.loading, .table-wrap.loading { opacity: .5; }
.chart { margin: 0; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chart figcaption { font-size: 16px; line-height: 22px; font-weight: 700; }
.legend-line { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; padding: 0; }
.legend-line li { display: inline-flex; align-items: center; gap: 6px; }
.plot { width: 100%; touch-action: pan-y; }
.plot .u-select { background: transparent; }
.plot .u-cursor-x { border-right: 1px solid var(--ink-2); }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; min-width: 150px; padding: 8px 10px;
  background: var(--sheet); color: var(--ink); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--tip-shadow); font: 500 13px/18px var(--f-ui);
}
.tooltip .t { color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.tooltip .tip-row { display: grid; grid-template-columns: 14px auto 1fr; align-items: center; gap: 6px; }
.tooltip b { font: 600 13px/18px var(--f-display); font-variant-numeric: tabular-nums; }
.tooltip .tip-row span:last-child { color: var(--ink-2); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; line-height: 18px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 600; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.all td:last-child { font-family: var(--f-mono); font-size: 12px; color: var(--ink-2); }

/* --- батарея --- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px 0 8px;
  border-radius: 9999px; background: var(--field); font-size: 13px; line-height: 18px; font-weight: 600; color: var(--ink);
}
.chip .ic { color: var(--ink-2); }
.chip[data-level="good"] .ic { color: var(--good); }
.chip[data-level="bad"] .ic { color: var(--bad); }
.status-line { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.status-line .ic { color: var(--bad); }
.cells { display: flex; flex-direction: column; gap: 8px; }
.cells-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.cells-delta { display: flex; align-items: baseline; gap: 4px; }
#cells-chart svg { display: block; width: 100%; height: 84px; }
.cells-idx { display: flex; gap: 6px; font-size: 11px; line-height: 14px; }
.cells-idx span { flex: 1 1 0; text-align: center; }
.cells-minmax { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 16px; }
.facts > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.facts dt { font-size: 13px; line-height: 18px; font-weight: 600; color: var(--ink-2); }
.facts dd { font-size: 16px; line-height: 22px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* --- події --- */
.events { list-style: none; padding: 0; display: flex; flex-direction: column; }
.events li { display: grid; grid-template-columns: 76px 22px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 44px; padding: 6px 0; }
.events li + li { border-top: 1px solid var(--line); }
.events time { font: 500 13px/18px var(--f-mono); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.events .ic { color: var(--ink-2); }
.events .ic[data-level="good"] { color: var(--good); }
.events .ic[data-level="bad"] { color: var(--bad); }

/* --- технічні деталі --- */
.rows { padding: 0; gap: 0; overflow: hidden; }
.rows-title { padding: 16px 16px 4px; }
.row-item + .row-item { border-top: 1px solid var(--line); }
.row-item summary {
  list-style: none; cursor: pointer; min-height: 60px; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.row-item summary::-webkit-details-marker { display: none; }
.row-icon { width: 36px; height: 36px; flex: none; border-radius: 9999px; background: var(--field); color: var(--ink-2); display: flex; align-items: center; justify-content: center; }
.row-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.row-text .note { overflow-wrap: anywhere; }
.chevron { color: var(--ink-2); transition: transform .2s; }
.row-item[open] .chevron { transform: rotate(90deg); }
.row-body { padding: 4px 16px 16px; }

footer { text-align: center; padding: 4px 8px 0; }

/* Немає зв'язку з платою: останні дані лишаються, але приглушені. */
.stale .state .hero, .stale .flow, .stale .stats, .stale #cells-block { opacity: .55; }
