/* Тёмная/светлая тема без переключателя: телефон сам знает, что показать. */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --fg: #16181d;
  --muted: #6b7280;
  --line: #e3e5e9;
  --on: #16a34a;
  --off: #9ca3af;
  --warn: #d97706;
  --bad: #dc2626;
  --accent: #2563eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a20;
    --fg: #e8eaed;
    --muted: #9aa1ab;
    --line: #262a32;
    --on: #22c55e;
    --off: #6b7280;
    --warn: #f59e0b;
    --bad: #ef4444;
    --accent: #60a5fa;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 16px;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* iPhone: не даём Safari увеличивать шрифт в альбомной ориентации */
  -webkit-text-size-adjust: 100%;
  max-width: 720px;
  margin-inline: auto;
}

h1 { font-size: 20px; margin: 0 0 4px; }

.stale {
  color: var(--warn);
  font-size: 13px;
  margin-bottom: 12px;
}

.offline { color: var(--bad); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

.card h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}

/* Плитка энергии */
.energy { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.energy div { text-align: center; }
.energy .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.energy .k { font-size: 12px; color: var(--muted); }

/* Устройства */
.dev {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.dev:last-child { border-bottom: 0; }
.dev .name { font-weight: 550; }
.dev .sub { font-size: 12px; color: var(--muted); }

button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  padding: 9px 18px;
  min-width: 74px;
  color: #fff;
  background: var(--off);
  cursor: pointer;
  /* Палец, а не мышь: 44px — минимальная зона нажатия на iOS */
  min-height: 44px;
}
button.on { background: var(--on); }
button:disabled { opacity: .5; cursor: default; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bad);
  color: #fff;
  margin-left: 6px;
}

/* Датчики */
.sensors { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.sensors .t { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sensors .na { color: var(--muted); }

/* График: чистый SVG, без библиотек */
.chart { width: 100%; height: 150px; display: block; touch-action: manipulation; }
.chart .bar { fill: var(--accent); }
.chart .bar:active { fill: var(--warn); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 9px; }
.chart .empty { fill: var(--muted); font-size: 11px; }

.note { color: var(--warn); font-weight: 500; text-transform: none; letter-spacing: 0; }

.hint {
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
  margin-top: 4px;
}

/* Переключатель периода */
.ranges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ranges button {
  flex: 1 1 28%;
  min-width: 0;
  padding: 7px 4px;
  min-height: 36px;
  font-size: 13px;
  font-weight: 550;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.ranges button.sel {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Форма входа */
.login { max-width: 340px; margin: 12vh auto; }
.login input {
  width: 100%;
  font: inherit;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
}
.login button { width: 100%; background: var(--accent); }
.err { color: var(--bad); font-size: 14px; margin-bottom: 10px; }

form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
form.inline input { width: 110px; font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); }

/* График отопления: полный столбик — весь расход, тёмный — доля отопления */
.chart .bar-other { fill: var(--accent); }
.chart .bar-heat { fill: var(--warn); }

.legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
  margin: -4px 0 8px;
}
.legend .swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.legend .swatch.heat { background: var(--warn); }
.legend .swatch.other { background: var(--accent); }

/* Наработка устройств */
.runtime { margin: 10px 0 12px; }
.runtime div {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}
.runtime div:last-child { border-bottom: 0; }
.rt-name { font-size: 14px; }
.rt-val { font-weight: 600; font-variant-numeric: tabular-nums; }
