/* Цвета берутся из темы Telegram, чтобы приложение выглядело родным
   и в светлой, и в тёмной теме; значения после запятой — для браузера. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111114);
  --hint: var(--tg-theme-hint-color, #8a8a93);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --heat: #ff7a2f;
  --heat-soft: color-mix(in srgb, var(--heat) 16%, transparent);
  --cold: #3d8bfd;
  --cold-soft: color-mix(in srgb, var(--cold) 15%, transparent);
  --out: #14a39a;
  --ok: #34c759;
  --danger: #ff3b30;
  --radius: 20px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #0f0f12; --card: #1c1c21; --text: #f2f2f5; --hint: #8d8d96;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

.app { max-width: 560px; margin: 0 auto; padding: 18px 16px 32px; }
@media (max-width: 360px) { .app { padding: 14px 12px 28px; } .card { padding: 14px; } .step { width: 46px; height: 46px; } }

.top { display: flex; align-items: flex-start; justify-content: space-between; }
.top-left { position: relative; min-width: 0; }
.headline {
  display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; margin: 2px 0 0;
  font-size: 30px; font-weight: 700; letter-spacing: -.02em; cursor: pointer; color: var(--text); max-width: 100%;
}
.headline #home-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.headline .caret { font-size: 16px; color: var(--accent); transform: translateY(2px); }
.home-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 230px; padding: 6px;
  display: grid; gap: 2px; box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.home-item { border: 0; background: none; text-align: left; padding: 11px 12px; border-radius: 10px; font-size: 16px; cursor: pointer; }
.home-item.active { background: var(--bg); font-weight: 600; }
.home-item.active::after { content: " ✓"; color: var(--accent); }
.home-item.manage { color: var(--accent); font-size: 14px; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--heat); }
h1 { margin: 2px 0 0; font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.status-line { margin: 4px 0 18px; color: var(--hint); font-size: 14px; display: flex; align-items: center; gap: 6px; }
.status-line .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.status-line .dot.warn { background: var(--heat); }
.status-line .dot.bad { background: var(--danger); }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--card);
  display: grid; place-items: center; cursor: pointer; color: var(--accent);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.icon-btn.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.04);
}
.hint { color: var(--hint); font-size: 14px; }
.device-name { font-weight: 600; }

/* Главная карточка термостата */
.hero { margin-bottom: 22px; position: relative; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; inset: -40% -30% auto auto; width: 260px; height: 260px;
  border-radius: 50%; background: radial-gradient(closest-side, var(--cold-soft), transparent);
  transition: background .6s; pointer-events: none;
}
.hero.heating::before { background: radial-gradient(closest-side, var(--heat-soft), transparent); }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; position: relative; }
.temp { display: flex; align-items: flex-start; margin-top: 6px; line-height: 1; }
.temp-value { font-size: clamp(56px, 19vw, 76px); font-weight: 300; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.temp-unit { font-size: 40px; font-weight: 300; color: var(--hint); margin-top: 6px; }

.pill {
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  background: var(--cold-soft); color: var(--cold); white-space: nowrap;
}
.pill.heating { background: var(--heat-soft); color: var(--heat); }
.pill.heating::before { content: "🔥 "; }
.pill.off, .pill.offline { background: var(--line); color: var(--hint); }
.pill.idle { background: var(--line); color: var(--text); }

.target {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 12px; padding: 10px; border-radius: 18px; background: var(--bg); position: relative;
}
.step {
  width: 52px; height: 52px; border-radius: 16px; border: 0; background: var(--card);
  font-size: 28px; font-weight: 400; line-height: 1; cursor: pointer; color: var(--accent);
  box-shadow: 0 1px 2px rgba(0,0,0,.06); transition: transform .08s;
}
.step:active { transform: scale(.94); }
.step:disabled { opacity: .35; }
.target-center { text-align: center; }
.target-value { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.target-hint.saving { color: var(--accent); }

/* Режимы — три плитки: крупно температура, мелко название. minmax(0, 1fr)
   позволяет колонкам сжиматься в узком окне (Telegram на компьютере),
   иначе ширина текста распирает карточку и появляется прокрутка вбок. */
.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.preset {
  border: 1px solid var(--line); background: transparent; border-radius: 14px;
  padding: 8px 4px; cursor: pointer; display: grid; gap: 1px; min-width: 0;
}
.preset b { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.preset span { font-size: 12px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.preset.active span { color: inherit; opacity: .85; }
.preset:disabled { opacity: .4; }

.chart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--hint); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chart { height: 150px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--hint); font-size: 14px; }

.row { display: flex; align-items: center; justify-content: space-between; }
.toggle-row { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); cursor: pointer; }

/* Переключатель в стиле iOS */
.switch {
  appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 999px;
  background: var(--line); position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s;
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .45; }

.section-title { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--hint); margin: 0 4px 10px; }
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.plug { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.plug-icon {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; flex: none;
  background: var(--line); color: var(--hint); transition: background .2s, color .2s;
}
.plug.on .plug-icon { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.plug.drawing .plug-icon { background: var(--heat-soft); color: var(--heat); }
.plug-body { flex: 1; min-width: 0; }
.plug-body .device-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offline { opacity: .6; }

.alerts { display: grid; gap: 8px; margin-bottom: 16px; }
.alert {
  border-radius: 16px; padding: 12px 14px; font-size: 15px;
  background: color-mix(in srgb, var(--danger) 12%, var(--card)); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}

/* Вкладки */
.tabs { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, .5fr) minmax(0, .5fr); background: var(--card); border-radius: 14px; padding: 3px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.tabs button { border: 0; background: transparent; padding: 9px 2px; border-radius: 11px; font-size: 15px; font-weight: 500; color: var(--hint); cursor: pointer; display: grid; place-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 360px) { .tabs button { font-size: 13.5px; } }
.tabs button.active { background: var(--accent); color: var(--accent-text); }

/* Расход */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { padding: 14px 16px; }
.stat-main { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--hint); margin: 4px 0 8px; }
.lg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 6px; }
.lg:first-child { margin-left: 0; }
.lg.day { background: var(--heat); } .lg.night { background: #6c63ff; }
.bars { height: 170px; display: flex; align-items: flex-end; gap: 4px; padding-top: 18px; }
.bar { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; cursor: pointer; position: relative; border: 0; background: none; padding: 0; }
.bar .stack { width: 100%; max-width: 30px; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 6px 6px 3px 3px; overflow: hidden; min-height: 2px; background: var(--line); }
.bar .d { background: var(--heat); } .bar .n { background: #6c63ff; }
.bar.nodata .stack { background: repeating-linear-gradient(45deg, var(--line) 0 3px, transparent 3px 6px); height: 30%; }
.bar .lbl { font-size: 10px; color: var(--hint); margin-top: 4px; height: 13px; }
.bar.sel .stack { outline: 2px solid var(--accent); outline-offset: 1px; }
.bar .val { position: absolute; top: -16px; font-size: 10px; color: var(--hint); white-space: nowrap; }
.e-detail { margin-top: 12px; min-height: 40px; }
.e-detail b { color: var(--text); font-weight: 600; }

/* Настройки */
.form { display: grid; gap: 12px; margin-bottom: 22px; }
.field { display: grid; gap: 5px; font-size: 14px; color: var(--hint); }
.field input, .field select {
  font: inherit; font-size: 17px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; width: 100%; min-width: 0;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-part { display: grid; gap: 12px; }
.price-preview { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.price-preview .p { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; }
.price-preview .p b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.price-preview .p span { font-size: 12px; color: var(--hint); }
.link-btn { border: 0; background: none; color: var(--accent); font-size: 14px; padding: 2px 0; text-align: left; cursor: pointer; }
.warn { color: var(--heat); }

/* Расписание */
.ghost { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px; font-size: 15px; font-weight: 500; color: var(--accent); cursor: pointer; }
.add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0 0; }
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.days button { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 9px 0; font-size: 14px; cursor: pointer; color: var(--text); }
.days button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.rule { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; column-gap: 12px; padding: 12px 14px; }
.rule-time { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rule-body { min-width: 0; }
.rule-body .device-name { line-height: 1.25; }
.rule-body .hint { font-size: 13px; line-height: 1.3; }
.rule.off { opacity: .5; }
.del { border: 0; background: none; color: var(--hint); font-size: 22px; line-height: 1; padding: 4px 2px; cursor: pointer; }
.trip-head { font-size: 18px; font-weight: 600; }
.trip-state { display: flex; gap: 10px; align-items: flex-start; }
.trip-icon { font-size: 26px; line-height: 1; }
.estimate { background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 14px; color: var(--hint); }
.estimate b { color: var(--text); font-weight: 600; }
.empty-note { color: var(--hint); font-size: 14px; padding: 4px 4px 0; }
.seg.wide { display: grid; grid-template-columns: 1fr 1fr; }
.seg.wide button { padding: 8px 4px; font-size: 14px; }
.primary { border: 0; border-radius: 12px; padding: 12px; font-size: 16px; font-weight: 600; background: var(--accent); color: var(--accent-text); cursor: pointer; }
.primary:disabled { opacity: .5; }
.device-setting { margin-bottom: 0; }
.vendor { font-size: 13px; }

.footnote { color: var(--hint); font-size: 13px; text-align: center; margin-top: 24px; }
.small { font-size: 12.5px; line-height: 1.35; }
.mt { margin-top: 14px; }
.block { display: block; width: 100%; }
.link-btn.center { display: block; margin: 8px auto 0; text-align: center; }

/* Погода над термостатом */
.weather {
  width: 100%; display: flex; align-items: center; gap: 10px; border: 0; cursor: default;
  background: linear-gradient(135deg, color-mix(in srgb, var(--out) 16%, var(--card)), var(--card));
  border-radius: 16px; padding: 11px 14px; margin-bottom: 12px; text-align: left;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.weather .w-icon { font-size: 22px; line-height: 1; }
.weather .w-main { font-weight: 600; white-space: nowrap; }
.weather .w-sub { color: var(--hint); font-size: 13.5px; margin-left: auto; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.weather.empty { cursor: pointer; font-size: 14px; color: var(--hint); }
.weather.empty span:nth-child(2) { flex: 1; }
.weather .chev { font-size: 22px; color: var(--accent); }

/* Легенда графика температуры */
.chart-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; color: var(--hint); margin-top: 6px; }
.lgl { display: inline-block; flex: none; align-self: center; width: 14px; height: 3px; max-height: 3px; border-radius: 2px; margin-left: 6px; }
.lgl:first-child { margin-left: 0; }
.lgl.in { background: var(--cold); }
.lgl.out { background: var(--out); }
.lgl.setpoint { background: linear-gradient(90deg, var(--hint) 55%, transparent 0) 0 0 / 6px 100%; }
.lgl.heat { background: var(--heat); }
.lg.out { background: var(--out); border-radius: 50%; }

/* Карточка «Защита» */
.protect { display: grid; gap: 0; padding: 6px 16px; margin-bottom: 22px; }
.prow { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; column-gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.prow:first-child { border-top: 0; }
.p-icon { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 17px; background: color-mix(in srgb, var(--ok) 14%, transparent); }
.prow.warn .p-icon { background: var(--heat-soft); }
.prow.bad .p-icon { background: color-mix(in srgb, var(--danger) 16%, transparent); }
.prow.muted .p-icon { background: var(--line); filter: grayscale(1); }
.p-title { font-weight: 600; font-size: 15px; }
.p-sub { color: var(--hint); font-size: 12.5px; line-height: 1.35; }
.p-value { font-weight: 600; font-size: 14px; text-align: right; color: var(--ok); white-space: nowrap; }
.prow.warn .p-value { color: var(--heat); }
.prow.bad .p-value { color: var(--danger); }
.prow.muted .p-value { color: var(--hint); }
.spark { grid-column: 2 / 4; margin-top: 6px; }
.spark svg { display: block; width: 100%; height: 44px; }
.spark-legend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--hint); margin-top: 4px; }
.spark-legend > span { display: inline-flex; align-items: center; gap: 5px; }
.spark-legend i { width: 12px; height: 3px; border-radius: 2px; flex: none; }

/* Журнал */
.events { padding: 4px 16px; }
.ev { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; column-gap: 10px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line); }
.ev:first-child { border-top: 0; }
.ev-icon { font-size: 17px; line-height: 1.3; text-align: center; }
.ev-text { font-weight: 500; font-size: 15px; }
.ev.warn .ev-text { color: var(--heat); }
.ev.error .ev-text { color: var(--danger); }
.ev-detail { color: var(--hint); font-size: 12.5px; line-height: 1.35; overflow-wrap: anywhere; }
.ev-time { color: var(--hint); font-size: 12px; white-space: nowrap; padding-top: 2px; }

/* Расход: прогноз, обогрев и погода, паспорт дома */
.stat.span2 { grid-column: 1 / -1; }
.forecast { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.saving { text-align: right; border-radius: 12px; padding: 6px 10px; }
.saving b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.saving span { font-size: 11.5px; color: var(--hint); }
.saving.good { background: color-mix(in srgb, var(--ok) 13%, transparent); }
.saving.good b { color: var(--ok); }
.saving.bad { background: var(--heat-soft); }
.saving.bad b { color: var(--heat); }
.chart.tall { height: 180px; }
#climate-note { margin-top: 8px; }
.house { padding: 4px 16px 12px; }
.hrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.hrow:first-child { border-top: 0; }
.h-label { font-weight: 500; }
.h-value { font-weight: 700; font-size: 17px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.house-note { margin: 6px 0 0; }

/* Здания и помещения на главном экране */
.building { margin-bottom: 8px; }
.building-title { font-size: 20px; font-weight: 700; margin: 6px 4px 10px; letter-spacing: -.01em; }
.room { margin-bottom: 18px; }
.room > .list { margin-top: 0; }
.room-title { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--hint); margin: 0 4px 10px; }
.room .hero { margin-bottom: 10px; }
.building > .empty-note { margin: -4px 4px 18px; }

/* Здания и помещения в настройках */
.building-edit { display: grid; gap: 10px; margin-bottom: 10px; padding: 12px; }
.building-edit .home-row { border-top: 0; padding: 0; }
.building-edit .home-row input { font-weight: 600; }
.b-threshold { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--hint); flex-wrap: wrap; }
.b-threshold input {
  width: 64px; font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; text-align: center;
}
.b-threshold .mini { margin-left: auto; }
.rooms { display: flex; flex-wrap: wrap; gap: 6px; }
.rooms:empty { display: none; }
.room-chip { display: inline-flex; align-items: center; gap: 2px; background: var(--bg); border-radius: 999px; padding: 4px 4px 4px 12px; font-size: 14px; }
.room-chip > span { cursor: pointer; }
.room-chip button { border: 0; background: none; color: var(--hint); font-size: 17px; line-height: 1; padding: 2px 6px; cursor: pointer; }
.add-room { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.add-room input {
  font: inherit; font-size: 15px; color: var(--text); background: var(--bg); border: 1px dashed var(--line);
  border-radius: 10px; padding: 8px 10px; min-width: 0;
}
.house-building { font-weight: 700; padding: 10px 0 2px; }
.house-building.next { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 14px; }

/* Объекты в настройках */
.homes { padding: 6px 12px; margin-bottom: 10px; }
.home-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.home-row:first-child { border-top: 0; }
.home-row input, .add-home input {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; min-width: 0; width: 100%;
}
.home-row.current input { border-color: var(--accent); }
.mini { border: 0; border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 600; background: var(--bg); color: var(--accent); cursor: pointer; }
.add-home { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-bottom: 22px; }
.add-home .primary { padding: 9px 14px; font-size: 15px; }
.home-settings-title { font-size: 20px; font-weight: 700; margin: 4px 4px 14px; }
.home-settings-title:empty { display: none; }

/* Место дома */
.place-current { display: flex; gap: 8px; align-items: center; font-size: 15px; }
.place-results { display: grid; gap: 6px; }
.place { display: grid; text-align: left; gap: 1px; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 9px 12px; cursor: pointer; }
.place b { font-weight: 600; }
.place span { font-size: 12.5px; color: var(--hint); }
.place:active { background: var(--line); }

.gate { min-height: 100vh; display: grid; place-content: center; text-align: center; padding: 24px; }
.gate-icon { width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 8px; display: block; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.gate p { color: var(--hint); max-width: 280px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.chip-input { font: inherit; font-size: 14px; border: 0; background: var(--card); border-radius: 8px; padding: 2px 6px; width: 120px; color: var(--text); }

/* Колокольчик событий: красная точка, пока есть открытые тревоги */
.tabs .bell { position: relative; }
.alert-dot { position: absolute; top: 6px; right: calc(50% - 13px); width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--card); }

/* Сворачиваемые здания и помещения на обзоре */
.fold { width: 100%; display: flex; align-items: baseline; gap: 8px; border: 0; background: none; padding: 0; cursor: pointer; text-align: left; color: var(--text); }
.fold .chev { color: var(--accent); font-size: 14px; transition: transform .15s; flex: none; }
.fold.folded .chev { transform: rotate(-90deg); }
.fold-title { flex: none; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold-sum { color: var(--hint); font-size: 13px; margin-left: auto; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.building-head { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 6px 4px 12px; width: calc(100% - 8px); }
.building-head.folded { background: var(--card); border-radius: 16px; padding: 14px 16px; margin: 0 0 12px; width: 100%; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.room-head { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--hint); margin: 4px 4px 10px; width: calc(100% - 8px); }
.room-head .fold-title { color: var(--hint); }
.room-head .fold-sum { text-transform: none; letter-spacing: 0; font-weight: 400; }
.room-head.folded { margin-bottom: 14px; }
.fold-body > .list { margin-bottom: 14px; }
.empty-rooms { color: var(--hint); font-size: 13px; margin: 0 4px 18px; }

/* Структура в настройках: помещения с устройствами */
.rooms-edit { display: grid; gap: 8px; }
.room-edit { background: var(--bg); border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; }
.room-edit.loose { background: none; border: 1px dashed var(--line); }
.re-head { display: flex; align-items: center; gap: 6px; }
.re-name { font-weight: 600; flex: 1; }
.re-tools { display: flex; gap: 2px; }
.icon-mini { border: 0; background: none; color: var(--hint); font-size: 16px; padding: 2px 6px; cursor: pointer; }
.re-devices { display: flex; flex-wrap: wrap; gap: 6px; }
.dev-chip { display: inline-flex; align-items: center; gap: 2px; background: var(--card); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 13.5px; }
.dev-chip button { border: 0; background: none; color: var(--hint); font-size: 16px; line-height: 1; padding: 0 4px; cursor: pointer; }
.re-add { font: inherit; font-size: 14px; color: var(--accent); background: var(--card); border: 1px dashed var(--line); border-radius: 10px; padding: 7px 10px; width: 100%; }

/* Кто сколько потратил */
/* minmax(0, 1fr): иначе строка с длинным названием распирает колонку шире карточки. */
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.split-row { padding: 6px 0; min-width: 0; }
.s-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; min-width: 0; }
.s-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-val { flex: none; white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 14px; }
.s-bar { height: 5px; border-radius: 3px; background: var(--bg); margin-top: 5px; overflow: hidden; }
.s-bar i { display: block; height: 100%; border-radius: 3px; background: var(--heat); }
.s-building { padding-top: 10px; }
.s-building .s-name { font-weight: 700; }
.s-building .s-val { font-weight: 600; }
.s-room { padding-left: 14px; }
.s-room .s-name { font-weight: 600; font-size: 14px; }
.s-room .s-bar i { opacity: .7; }
.s-device { padding-left: 28px; }
.s-device .s-name, .s-device .s-val { color: var(--hint); font-size: 13.5px; }
.s-device .s-bar { height: 3px; }
.s-device .s-bar i { opacity: .45; }

/* Группы правил расписания по месту */
.rule-group { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--hint); margin: 8px 4px 0; }
.rule-group:first-child { margin-top: 0; }

/* Неактивная «Сохранить»: изменений нет */
button[type=submit]:disabled { opacity: .45; cursor: default; }

/* Уведомления */
.notify { padding: 4px 16px; }
.notify-row { padding: 12px 0; border-top: 1px solid var(--line); gap: 12px; cursor: pointer; }
.notify-row:first-child { border-top: 0; }
.notify { margin-bottom: 8px; }
.notify-note { margin: 0 4px 22px; }

/* Вход через сайт */
.login-form { width: min(360px, 100%); margin: 8px auto 12px; text-align: left; }
.login-error { color: var(--danger); font-size: 14px; }
.login-error:empty { display: none; }
.site-link { font-weight: 600; color: var(--accent); word-break: break-all; }
#logout { margin: -10px 0 22px; color: var(--danger); }

/* Куда присылать */
.channels { display: grid; gap: 12px; margin-bottom: 22px; }
.ch-row { display: flex; align-items: center; gap: 12px; }
.ch-icon { font-size: 20px; width: 28px; text-align: center; flex: none; }
.ch-body { flex: 1; min-width: 0; }
.ch-title { font-weight: 600; }
.ch-email { display: grid; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
#notify-test-result:empty { display: none; }

/* Плашка «установить на телефон» */
.install-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; max-width: 536px; margin: 0 auto;
  background: var(--card); border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.install-bar img { border-radius: 10px; flex: none; }
.ib-text { flex: 1; min-width: 0; display: grid; font-size: 13px; color: var(--hint); }
.ib-text b { color: var(--text); font-size: 15px; }
.install-bar .primary { padding: 9px 12px; font-size: 14px; flex: none; }
.ib-close { border: 0; background: none; color: var(--hint); font-size: 22px; padding: 0 4px; cursor: pointer; }

/* Поле пароля с кнопкой «показать» */
.pw { position: relative; display: block; }
.pw input { padding-right: 44px; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; font-size: 18px; cursor: pointer; opacity: .6; }

/* Настройки: меню и подстраницы */
.menu-group-title { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--hint); margin: 4px 4px 8px; }
.menu { padding: 0 0 0 14px; margin-bottom: 20px; overflow: hidden; }
.menu-row {
  width: 100%; display: flex; align-items: center; gap: 12px; border: 0; background: none; cursor: pointer;
  padding: 13px 14px 13px 0; border-top: 1px solid var(--line); text-align: left; color: var(--text); font-size: 16px;
}
.menu-row:first-child { border-top: 0; }
.menu-row:active { background: var(--bg); }
.mi { font-size: 19px; width: 26px; text-align: center; flex: none; }
.mt { flex: none; }
.ms { margin-left: auto; color: var(--hint); font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.menu-row .chev { color: var(--hint); font-size: 22px; line-height: 1; flex: none; }
.subpage-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.sub-back { border: 0; background: none; color: var(--accent); font-size: 16px; padding: 4px 0; cursor: pointer; }
.sub-title { font-size: 22px; font-weight: 700; margin: 0; width: 100%; }
.subpage .notify-note { margin-top: -12px; }
.menu-row > span { line-height: 1.3; align-self: center; }

/* Руководство */
.guide-h { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--hint); margin: 4px 4px 8px; }
.checklist { padding: 0 0 0 14px; margin-bottom: 8px; }
.check-row { width: 100%; display: flex; align-items: center; gap: 12px; border: 0; background: none; text-align: left; cursor: pointer;
  padding: 12px 14px 12px 0; border-top: 1px solid var(--line); color: var(--text); font-size: 15px; }
.check-row:first-child { border-top: 0; }
.check-mark { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center;
  font-size: 14px; font-weight: 700; color: #fff; }
.check-row.done .check-mark { background: var(--ok); border-color: var(--ok); }
.check-row.done .check-text { color: var(--hint); }
.check-text { flex: 1; min-width: 0; line-height: 1.35; }
.check-row .chev { color: var(--hint); font-size: 22px; }
.guide-note { margin: 0 4px 20px; }
.guide { padding: 2px 16px; margin-bottom: 22px; }
.guide details { border-top: 1px solid var(--line); }
.guide details:first-child { border-top: 0; }
.guide summary { padding: 13px 0; font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 10px; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "›"; color: var(--hint); font-size: 22px; line-height: 1; transition: transform .15s; }
.guide details[open] summary::after { transform: rotate(90deg); }
.guide details p { margin: 0 0 10px; font-size: 14.5px; line-height: 1.45; color: var(--text); }
.guide details p:last-child { margin-bottom: 14px; }

/* Питание и работа: тумблер — питание, рядом — что происходит */
.power-label { display: grid; gap: 1px; min-width: 0; padding-right: 10px; }
.pl-title { font-size: 16px; }
.plug-status { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.plug-chip { font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.plug-chip.working { background: var(--heat-soft); color: var(--heat); }
.plug-chip.idle { background: color-mix(in srgb, var(--ok) 13%, transparent); color: var(--ok); }
.plug-chip.off { background: var(--line); color: var(--hint); }
.plug-status .plug-meta { font-size: 13px; }

/* Тип устройства крупно, название владельца мелко */
.device-sub { color: var(--hint); font-size: 13px; line-height: 1.25; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Переименование устройства на месте */
.name-line { display: flex; align-items: center; gap: 4px; min-width: 0; }
.name-line .device-sub { min-width: 0; }
.rename-btn { border: 0; background: none; color: var(--hint); font-size: 13px; padding: 0 4px; cursor: pointer; opacity: .7; flex: none; }
.rename-input { font: inherit; font-size: 15px; color: var(--text); background: var(--bg); border: 1px solid var(--accent);
  border-radius: 8px; padding: 4px 8px; width: 100%; min-width: 0; }
.chip-name { cursor: pointer; border-bottom: 1px dashed var(--line); }

/* «Греть с запасом» в карточке термостата */
.band { margin: -4px 0 16px; padding: 12px; border-radius: 14px; background: var(--bg); }
.band-toggle { cursor: pointer; gap: 10px; }
.band-edit { margin-top: 10px; }
.band-line { display: flex; align-items: center; gap: 8px; }
.band-line > span { flex: 1; font-size: 15px; white-space: nowrap; }
.band-line .step { width: 40px; height: 40px; font-size: 22px; border-radius: 12px; }
.band-upper { min-width: 44px; text-align: center; font-size: 20px; font-variant-numeric: tabular-nums; }
.band-save { padding: 9px 12px; font-size: 14px; margin-left: 4px; }
.band-note { margin-top: 8px; }

/* Прогноз на неделю */
.week-fc { margin-bottom: 14px; }
.forecast-head { font-size: 17px; font-weight: 700; margin: 2px 4px 10px; width: calc(100% - 8px); }
.forecast-head.folded { background: var(--card); border-radius: 16px; padding: 14px 16px; margin: 0; width: 100%; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.forecast-body { display: grid; gap: 10px; }
.fc-days { display: grid; gap: 2px; }
.fc-day {
  display: grid; grid-template-columns: minmax(0, 1.2fr) 26px minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center; gap: 6px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 14.5px;
}
.fc-day:last-child { border-bottom: 0; }
.fc-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fc-icon { font-size: 18px; text-align: center; }
.fc-temp { font-variant-numeric: tabular-nums; white-space: nowrap; }
.fc-rain { color: var(--hint); font-size: 12.5px; white-space: nowrap; }
.fc-in { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.fc-in.warn { color: var(--heat); font-weight: 600; }
.fc-chart { height: 140px; }
.lgl.cold { background: linear-gradient(90deg, var(--heat) 55%, transparent 0) 0 0 / 6px 100%; }
.fc-notes { display: grid; gap: 6px; }
.fc-warn { color: var(--heat); font-size: 14px; font-weight: 600; line-height: 1.35; }
