/*
 * Design tokens. Theme comes only from <html data-theme> (user setting in Profile; no automatic dark mode).
 * light = mockup «A» (light tiles), dark = mockup «B» (dark glass).
 * Later tasks use: --bg --surface --surface-2 --text --muted --line --accent --on --warn --heat --cool --radius --shadow.
 */
:root, [data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb; --backdrop: #f4f6fb;
  --surface: #ffffff; --surface-2: #eef1f6; --surface-solid: #ffffff;
  --text: #0f172a; --muted: #5b687c; --line: #e2e8f0;
  --accent: #2563eb; --accent-soft: rgba(37, 99, 235, .12);
  --on: #15803d; --warn: #dc2626; --heat: #c2410c; --cool: #0369a1;
  --ink-on-color: #ffffff; /* text on --accent/--on/--warn/--heat/--cool fills */
  /* tinted chips/pills/selected modes: text ≥ 4.5:1 on its own tint */
  --ok-bg: #dcfce7; --ok-ink: #166534; --bad-bg: #fee2e2; --bad-ink: #b91c1c;
  --heat-bg: #ffedd5; --heat-ink: #9a3412; --heat-line: #fdba74; --cool-bg: #e0f2fe; --cool-ink: #075985; --cool-line: #7dd3fc;
  --radius: 20px; --radius-sm: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --blur: none;
  --nav-bg: rgba(255, 255, 255, .94); --nav-ink: #5b687c; --nav-active: #2563eb;
  --seg-sel: #ffffff; --seg-sel-shadow: 0 1px 2px rgba(15, 23, 42, .12);
  --tabbar-h: 64px;
  /* legacy aliases for templates not yet restyled (Task 3–5) */
  --card: var(--surface); --chip: var(--surface-2); --off: var(--muted);
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120; --backdrop: radial-gradient(120% 60% at 0% 0%, #1e3a8a 0%, #0b1120 55%);
  --surface: rgba(255, 255, 255, .06); --surface-2: rgba(255, 255, 255, .09); --surface-solid: #111a2e;
  --text: #e2e8f0; --muted: #a7b4c8; --line: rgba(255, 255, 255, .12);
  --accent: #60a5fa; --accent-soft: rgba(96, 165, 250, .16);
  --on: #22c55e; --warn: #f87171; --heat: #fb923c; --cool: #38bdf8;
  --ink-on-color: #0b1120;
  --ok-bg: rgba(34, 197, 94, .16); --ok-ink: #86efac; --bad-bg: rgba(239, 68, 68, .18); --bad-ink: #fca5a5;
  --heat-bg: rgba(251, 146, 60, .18); --heat-ink: #fdba74; --heat-line: rgba(251, 146, 60, .6);
  --cool-bg: rgba(56, 189, 248, .16); --cool-ink: #7dd3fc; --cool-line: rgba(56, 189, 248, .55);
  --shadow: 0 8px 24px rgba(0, 0, 0, .22);
  --blur: blur(10px);
  --nav-bg: rgba(15, 23, 42, .85); --nav-ink: #a7b4c8; --nav-active: #60a5fa;
  --seg-sel: rgba(255, 255, 255, .16); --seg-sel-shadow: none;
  --tabbar-h: 86px; /* floating bar: 62 px + 12 px gap + spacing */
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--backdrop); background-color: var(--bg); background-attachment: fixed; color: var(--text);
  font: 16px/1.4 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
main { max-width: 560px; margin: 0 auto; padding: 16px 16px 40px; }
h1 { font-size: 22px; margin: 0; }
.upd { color: var(--muted); font-size: 13px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  box-shadow: var(--shadow); border: 1px solid var(--line); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.title { font-weight: 600; font-size: 17px; }
.sub { color: var(--muted); font-size: 14px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 2px 6px; }
/* segmented control (mockup .seg): a track with the selected segment raised */
.seg { display: flex; flex-wrap: wrap; gap: 3px; padding: 3px; border-radius: var(--radius-sm); background: var(--surface-2); margin: 0; }
.seg button { flex: 1 1 auto; min-width: 48px; min-height: 44px; padding: 9px 8px; border-radius: 9px; border: 0;
  background: transparent; color: var(--muted); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }
.seg button.sel, .seg button[aria-pressed="true"] { background: var(--seg-sel); color: var(--text); box-shadow: var(--seg-sel-shadow); font-weight: 600; }
/* six fan buttons share one row even at 375 px instead of wrapping the last one */
.seg.fan { flex-wrap: nowrap; }
.seg.fan button { flex: 1 1 0; min-width: 0; padding-left: 4px; padding-right: 4px; }
.seg button.sel.cool { background: var(--cool); color: var(--ink-on-color); }
.seg button.sel.heat { background: var(--heat); color: var(--ink-on-color); }
.bar { height: 10px; background: var(--chip); border-radius: 6px; overflow: hidden; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 50; transform: translateX(-50%); background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: .95; }
.busy { opacity: .6; pointer-events: none; }
header.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; margin: 4px 2px 14px; }
header.top .upd { flex: 1 1 auto; text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 28px 16px; }
.empty[hidden] { display: none; }
.err { color: var(--warn); font-size: 14px; margin-top: 8px; }
button:disabled { cursor: not-allowed; }
.seg button:disabled { opacity: .5; }
.card.off .title { color: var(--muted); }
main { overflow-x: hidden; }
/* admin */
main.admin h2 { font-size: 16px; margin: 0 0 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--accent); background: var(--accent); color: var(--ink-on-color); font: inherit; font-size: 15px; font-weight: 600;
  text-decoration: none; cursor: pointer; min-height: 44px; }
.btn.sec { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--warn); border-color: var(--warn); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions form { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.mv { display: flex; gap: 6px; }
.mv form { margin: 0; }
.field { margin-bottom: 14px; }
.flash { margin: 0 0 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; background: var(--surface); border: 1px solid var(--line); }
.flash-ok { border-left: 4px solid var(--on); }
.flash-warn { border-left: 4px solid var(--heat); margin-top: 8px; }
.flash-err { border-left: 4px solid var(--warn); }
.warns:empty { display: none; }
.userrow { display: block; color: inherit; text-decoration: none; }
.arow { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.arow label { flex: 1 1 auto; margin: 0; font-size: 16px; color: var(--text); }
/* device page */
main.devpage { max-width: 960px; }
.seg a { flex: 1 1 auto; min-width: 48px; padding: 10px 8px; border-radius: 9px; border: 0; background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 500; text-align: center; text-decoration: none; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.seg a.sel, .seg a[aria-current] { background: var(--seg-sel); color: var(--text); box-shadow: var(--seg-sel-shadow); font-weight: 600; }
.btn.sel { background: var(--accent); border-color: var(--accent); color: var(--ink-on-color); }
.periods .custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-top: 10px; }
.periods .custom label { flex: 1 1 130px; font-size: 12px; color: var(--muted); display: block; }
.periods .custom .btn { flex: 1 1 100%; }
.chart { width: 100%; height: 300px; }
.unlogged .sub { margin-top: 4px; }
@media (min-width: 700px) { .periods .custom .btn { flex: 0 0 auto; } .chart { height: 340px; } }

table.metrics { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
table.metrics th, table.metrics td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); }
table.metrics th:last-child, table.metrics td:last-child { text-align: center; }
table.metrics input[type=checkbox] { width: 22px; height: 22px; }

/* power / grid pages */
.status.ok { border-left: 5px solid var(--on); }
.status.bad { border-left: 5px solid var(--warn); }
.sums { display: flex; flex-wrap: wrap; gap: 12px 24px; margin-top: 8px; }
.sum { flex: 1 1 200px; }
.sum .big { font-size: 28px; font-weight: 300; }
.strip { margin-top: 8px; }
.strip .day { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.strip .lbl { flex: 0 0 38px; font-variant-numeric: tabular-nums; }
.strip .bar { position: relative; flex: 1 1 auto; height: 12px; background: var(--chip); border-radius: 3px; overflow: hidden; }
.strip .bar i { position: absolute; top: 0; bottom: 0; background: var(--warn); }
.strip .dur { flex: 0 0 64px; text-align: right; }
.axis { display: flex; justify-content: space-between; margin: 2px 72px 0 46px; font-size: 11px; color: var(--muted); }
/* edge fades/shadows appear only where the table can still be scrolled */
table.events { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
table.events th, table.events td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.events th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.events tfoot th, table.events tfoot td { font-weight: 600; border-bottom: 0; text-align: left; padding: 8px 6px; }
.push-device .btn[hidden] { display: none; }
.push-device .btn { margin-top: 8px; }
/* login */
main.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  max-width: 400px; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.auth-card { width: 100%; padding: 28px 22px 24px; margin: 0; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-logo { display: block; width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 16px; box-shadow: 0 4px 14px rgba(37,99,235,.3); }
.auth-head h1 { font-size: 24px; }
.auth-head .sub { margin: 4px 0 0; }
.auth .field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.auth .field input { width: 100%; padding: 11px 12px; font: inherit; font-size: 16px; min-height: 46px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); transition: border-color .15s, box-shadow .15s; }
.auth .field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.2); }
.auth-remember { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 2px 0 18px; cursor: pointer; }
.auth-remember input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.auth-submit, .auth-google { width: 100%; text-align: center; font-weight: 600; }
.auth-google { display: flex; align-items: center; justify-content: center; gap: 10px; }
.auth-or { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: 13px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth .error { margin-bottom: 16px; }
/* charts menu */
.tabs { margin-bottom: 12px; flex-wrap: nowrap; gap: 4px; }
.tabs a { min-width: 0; padding-left: 2px; padding-right: 2px; font-size: 13px; }
.chartsum { margin-top: 6px; min-height: 1.2em; }

/* ---------- icons (sprite: templates/_icons.html.twig) ---------- */
svg.i { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  flex: none; vertical-align: middle; }
svg.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- app shell: bottom tab bar on phones, sidebar from 900 px ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.shell-main { min-width: 0; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
.appnav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; align-items: stretch;
  height: calc(64px + env(safe-area-inset-bottom)); padding: 0 4px env(safe-area-inset-bottom);
  background: var(--nav-bg); border-top: 1px solid var(--line); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
[data-theme="dark"] .appnav { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); height: 62px; padding: 0 4px;
  border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
.appnav-brand { display: none; }
.appnav-item { flex: 1 1 0; min-width: 0; min-height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--nav-ink); text-decoration: none; font-size: 11px; font-weight: 500; border-radius: 14px; }
.appnav-item svg.i { width: 22px; height: 22px; }
.appnav-item[aria-current="page"] { color: var(--nav-active); font-weight: 600; }
.appnav-item:focus-visible { outline-offset: -4px; }
@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); align-items: start; }
  .shell-main { padding-bottom: 24px; }
  .appnav, [data-theme="dark"] .appnav { position: sticky; top: 0; left: auto; right: auto; bottom: auto; flex-direction: column; justify-content: flex-start;
    gap: 4px; height: 100vh; height: 100dvh; padding: 20px 12px; border-radius: 0; border: 0; border-right: 1px solid var(--line); box-shadow: none; }
  [data-theme="dark"] .appnav { top: 12px; height: calc(100vh - 24px); height: calc(100dvh - 24px); margin: 12px 0 12px 12px;
    border: 1px solid var(--line); border-radius: 22px; }
  .appnav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 18px; font-weight: 700; font-size: 18px; }
  .appnav-brand img { border-radius: 9px; }
  .appnav-item { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; font-size: 15px; }
  .appnav-item:hover { color: var(--text); background: var(--surface-2); }
  .appnav-item[aria-current="page"] { background: var(--accent-soft); color: var(--nav-active); }
  .shell-main main { max-width: 760px; padding: 28px 24px 40px; }
  .shell-main main.devpage { max-width: 1040px; }
  .toast { bottom: 24px; }
}

/* ---------- components ---------- */
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-height: 132px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); color: var(--text); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line); color: var(--text); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad-ink); border-color: transparent; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.bad { background: var(--bad-bg); color: var(--bad-ink); }
.pill.warn { background: var(--heat-bg); color: var(--heat-ink); }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; flex: none; text-decoration: none; }
.icon-btn:disabled { opacity: .5; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 11px 12px; font: inherit; font-size: 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); }
/* switch: <button class="switch" role="switch" aria-checked="true|false"> (44 px tall hit area) */
.switch { position: relative; flex: none; width: 52px; height: 44px; padding: 0; border: 0; background: none; cursor: pointer; }
.switch::before { content: ""; position: absolute; left: 4px; right: 4px; top: 10px; height: 24px; border-radius: 999px; background: var(--line); transition: background .15s; }
.switch::after { content: ""; position: absolute; left: 7px; top: 13px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch[aria-checked="true"]::before, .switch.on::before { background: var(--on); }
.switch[aria-checked="true"]::after, .switch.on::after { transform: translateX(20px); }
.switch:disabled { opacity: .5; cursor: not-allowed; }
/* bottom sheet (dialog on wide screens) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .45); }
.sheet { position: fixed; z-index: 41; left: 0; right: 0; bottom: 0; max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface-solid); color: var(--text); border-radius: 28px 28px 0 0; border-top: 1px solid var(--line);
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0, 0, 0, .2); }
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet[hidden], .sheet-backdrop[hidden] { display: none; }
@media (min-width: 900px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: min(460px, calc(100vw - 48px)); transform: translate(-50%, -50%);
    border-radius: 28px; border: 1px solid var(--line); padding-bottom: 22px; }
  .sheet::before { display: none; }
}
/* list rows inside a card (Profile → «Керування») */
.card.list { padding: 4px 6px; }
.listrow { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 4px 10px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 500; }
.listrow:hover { background: var(--surface-2); }
.listrow .chev-r { margin-left: auto; color: var(--muted); }
main h2 { font-size: 16px; margin: 0 0 10px; }
.logout { margin: 18px 0 8px; }
.logout .btn { width: 100%; }

/* ---------- home (dashboard): header, energy card, room pills, tiles ---------- */
.home-head { margin: 4px 2px 14px; }
.home-date { font-size: 13px; color: var(--muted); }
.home-title { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; margin: 2px 0 12px; }
.home-title h1 { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:empty { display: none; }
.chip svg.i { width: 16px; height: 16px; }
.tile.wide { min-height: 0; margin-bottom: 12px; }
a.tile { text-decoration: none; }
.energy { flex-direction: row; align-items: center; gap: 14px; }
.energy .flows { flex: 1 1 auto; min-width: 0; display: grid; gap: 6px; font-size: 13.5px; }
.energy .fl { display: flex; justify-content: space-between; gap: 8px; }
.energy .fl > span { color: var(--muted); }
.energy .fl b { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.energy .flows { max-width: 460px; }
.energy-go { color: var(--muted); display: grid; margin-left: auto; }
.ring { --p: 0; --ring: var(--on); width: 64px; height: 64px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--ring) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring.low { --ring: var(--warn); }
.ring > span { width: 50px; height: 50px; border-radius: 50%; background: var(--surface-solid); display: grid; place-items: center;
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.rooms { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: 0 -2px 12px; }
.rooms::-webkit-scrollbar { display: none; }
.room-pill { flex: none; min-height: 44px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.room-pill[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.room-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.room-actions .btn { flex: 1 1 0; min-width: 0; }
.room-actions .btn:disabled { opacity: .5; }
.rooms[hidden], .room-actions[hidden] { display: none; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile.dev { position: relative; padding: 14px; }
.tile.ac { padding: 0; }
.tile-open { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; width: 100%; min-height: 130px; padding: 14px;
  border: 0; border-radius: inherit; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.tile .switch { position: absolute; top: 10px; right: 6px; }
.tile-ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--text); }
.tile-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tn { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.ts { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.tile .big { font-size: 28px; font-weight: 700; letter-spacing: -.5px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile.muted { background: var(--surface-2); box-shadow: none; }
.tile.muted .tn, .tile.muted .tile-ic { color: var(--muted); }
.tile.muted .tile-ic { background: var(--surface); }
/* AC on: warm gradient for heating, cool for every other mode (text sits on the darker half: white ≥ 4.5:1) */
.tile.on { border-color: transparent; color: #fff; }
.tile.on.heat { background: linear-gradient(200deg, #fb923c 0%, #ea580c 18%, #c2410c 42%, #9a3412 100%); }
.tile.on.cool { background: linear-gradient(200deg, #38bdf8 0%, #0284c7 18%, #0369a1 42%, #075985 100%); }
.tile.on .ts { color: #fff; }
.tile.on .tile-ic { background: rgba(255, 255, 255, .22); color: #fff; }
.tile.on .switch[aria-checked="true"]::before { background: rgba(255, 255, 255, .45); }
[data-theme="dark"] .tile.on { color: var(--text); }
[data-theme="dark"] .tile.on .ts { color: var(--text); }
[data-theme="dark"] .tile.on .tile-ic { background: rgba(255, 255, 255, .1); color: var(--text); }
[data-theme="dark"] .tile.on.heat { background: linear-gradient(160deg, rgba(249, 115, 22, .38), rgba(249, 115, 22, .12)); border-color: rgba(249, 115, 22, .5); }
[data-theme="dark"] .tile.on.cool { background: linear-gradient(160deg, rgba(56, 189, 248, .32), rgba(56, 189, 248, .1)); border-color: rgba(56, 189, 248, .45); }
[data-theme="dark"] .tile.on.heat .switch[aria-checked="true"]::before { background: rgba(249, 115, 22, .85); }
[data-theme="dark"] .tile.on.cool .switch[aria-checked="true"]::before { background: rgba(14, 165, 233, .85); }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) {
  .shell-main main.home { max-width: 1100px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
}

/* ---------- AC bottom sheet ---------- */
body.sheet-open { overflow: hidden; }
.ac-sheet::before { display: none; }
.ac-sheet:focus { outline: none; }
.ac-sheet.dragging { transition: none; }
.sh-top { touch-action: none; padding-top: 2px; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sh-head { display: flex; align-items: center; gap: 10px; }
.sh-name { flex: 1 1 auto; min-width: 0; }
.sh-name h2 { display: inline; font-size: 18px; font-weight: 700; margin: 0 8px 0 0; overflow-wrap: anywhere; }
.sh-name .pill { vertical-align: 2px; }
.sh-name .sub { font-size: 13px; margin-top: 2px; }
.sh-pwr { flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: var(--surface-2); color: var(--muted); }
.sh-pwr svg.i { width: 24px; height: 24px; }
.sh-pwr.on.heat { background: var(--heat); color: var(--ink-on-color); box-shadow: 0 6px 16px rgba(234, 88, 12, .35); }
.sh-pwr.on.cool { background: var(--cool); color: var(--ink-on-color); box-shadow: 0 6px 16px rgba(2, 132, 199, .35); }
.sh-pwr:disabled { opacity: .5; }
.sh-x { border-radius: 50%; }
.dial { --p: 0; --dial: var(--muted); width: 190px; height: 190px; border-radius: 50%; margin: 14px auto 6px; display: grid; place-items: center;
  background: conic-gradient(from 225deg, var(--dial) 0 calc(var(--p) * 75%), var(--surface-2) 0 75%, transparent 0); }
.dial.heat { --dial: var(--heat); }
.dial.cool { --dial: var(--cool); }
.dial > div { width: 156px; height: 156px; border-radius: 50%; background: var(--surface-solid); display: flex; flex-direction: column;
  align-items: center; justify-content: center; }
.dial b { font-size: 46px; font-weight: 700; letter-spacing: -1.5px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.dial span { font-size: 13px; color: var(--muted); }
.pm { position: relative; display: flex; justify-content: center; gap: 70px; margin: -40px 0 16px; }
.pm button { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  display: grid; place-items: center; cursor: pointer; }
.pm button:disabled { opacity: .5; }
.modes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.mode { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 58px; padding: 8px 0; border-radius: 14px;
  border: 0; background: var(--surface-2); color: var(--muted); font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
.mode[aria-pressed="true"] { font-weight: 600; }
.mode.heat[aria-pressed="true"] { background: var(--heat-bg); color: var(--heat-ink); box-shadow: inset 0 0 0 2px var(--heat-line); }
.mode.cool[aria-pressed="true"] { background: var(--cool-bg); color: var(--cool-ink); box-shadow: inset 0 0 0 2px var(--cool-line); }
.mode:disabled { opacity: .5; }
.ac-sheet .label { font-weight: 600; margin-top: 14px; }
.ac-sheet .err { margin-top: 12px; }
.sh-body.busy { opacity: .6; pointer-events: none; }
.sh-off { color: var(--muted); margin: 18px 2px 6px; overflow-wrap: anywhere; }
.sh-link { display: flex; align-items: center; justify-content: center; min-height: 44px; margin-top: 12px; font-weight: 600; text-decoration: none; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
.sheet-backdrop:not([hidden]) { animation: fade-in .2s ease-out; }
@media (max-width: 899px) {
  .ac-sheet { transition: transform .2s ease-out; }
  .ac-sheet:not([hidden]) { animation: sheet-up .25s ease-out; }
}
@media (min-width: 900px) { .grab { display: none; } .sh-top { touch-action: auto; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- energy flow screen («Енергія», templates/analytics/energy_flow.html.twig) ---------- */
.ef-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 4px 0 12px; }
.ef-back { border-radius: var(--radius-sm); }
.ef-title { flex: 1 1 170px; min-width: 0; }
.ef-title h1 { font-size: 20px; font-weight: 700; }
.ef-title .sub { font-size: 13px; }
.ef-badge { flex: none; margin-left: auto; }
.ef-badge:empty { display: none; }
.ef-badge svg.i { width: 16px; height: 16px; }
.ef-cols { display: grid; gap: 0 14px; }
.ef-col { min-width: 0; }
.ef-flowcard { padding: 12px; }
.ef-flow { width: 100%; max-width: 420px; height: auto; display: block; margin: 0 auto; }
.ef-flow [hidden] { display: none; }
.ef-flow .ln { fill: none; stroke: var(--line); stroke-width: 4; stroke-linecap: round; }
.ef-flow .fl { fill: none; stroke-width: 4; stroke-linecap: round; stroke-dasharray: 1 12; animation: ef-run 1s linear infinite; }
.ef-flow .fl.rev { animation-direction: reverse; }
.ef-flow .fl.off { display: none; }
@keyframes ef-run { to { stroke-dashoffset: -13; } }
.ef-flow .node { fill: var(--surface-solid); stroke: var(--line); stroke-width: 1.5; }
.ef-flow .hub { fill: #2563eb; }
.ef-flow .ic { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.ef-flow .ef-gridic { color: #6366f1; }
.ef-flow .ef-gridic.bad { color: #ef4444; }
.ef-flow text { font-family: inherit; text-anchor: middle; }
.ef-flow .nm { font-size: 11px; fill: var(--muted); }
.ef-flow .pw { font-size: 14px; font-weight: 700; fill: var(--text); font-variant-numeric: tabular-nums; }
.ef-bat { display: flex; align-items: center; gap: 14px; }
@media (min-width: 400px) {
  .ef-bat .ring { width: 74px; height: 74px; }
  .ef-bat .ring > span { width: 60px; height: 60px; font-size: 16px; }
}
.ef-kv { flex: 1 1 auto; min-width: 0; display: grid; gap: 6px; font-size: 13px; }
.ef-kv > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ef-kv > div[hidden] { display: none; }
.ef-kv span { color: var(--muted); }
.ef-kv b { font-weight: 600; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ef-lbl { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0 2px 8px; }
.ef-lbl h2 { margin: 0; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ef-lbl a { display: inline-flex; align-items: center; min-height: 44px; margin: -12px 0; font-size: 14px; font-weight: 600; text-decoration: none; }
.ef-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.ef-t { background: var(--surface-2); border-radius: 14px; padding: 9px 10px; min-width: 0; }
.ef-t .k { font-size: 11.5px; color: var(--muted); }
.ef-t .v { font-weight: 700; font-size: 15px; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: break-word; }
.ef-t .v small { font-size: 11px; font-weight: 500; color: var(--muted); }
.ef-spark { width: 100%; height: 64px; display: block; }
.ef-spark[hidden], .ef-nodata[hidden] { display: none; }
.ef-spark-line { fill: none; stroke: #0ea5e9; stroke-width: 2; vector-effect: non-scaling-stroke; }
.ef-spark-limit { stroke: #ef4444; stroke-width: 1.2; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.ef-nodata { margin: 8px 2px; }
@media (min-width: 900px) {
  .shell-main main.energy-flow { max-width: 1040px; }
  .ef-cols { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
}
@media (prefers-reduced-motion: reduce) {
  /* no motion: active lines stay as solid coloured strokes */
  .ef-flow .fl { animation: none !important; stroke-dasharray: none; }
}
/* ---------- end energy flow screen ---------- */

/* === Task 5: pages restyle === */
/* chart series colours (read by chart_controller.js / energy_chart_controller.js); ≥ 3:1 on the card surface */
:root, [data-theme="light"] {
  --c1: #2563eb; --c2: #c2410c; --c3: #15803d; --c4: #7e22ce; --c5: #dc2626; --c6: #0369a1; --c7: #a16207; --c8: #be185d;
  --band: rgba(22, 163, 74, .14);
}
[data-theme="dark"] {
  --c1: #60a5fa; --c2: #fb923c; --c3: #4ade80; --c4: #c084fc; --c5: #f87171; --c6: #38bdf8; --c7: #facc15; --c8: #f472b6;
  --band: rgba(74, 222, 128, .16);
}
/* page header with a back button (admin) */
header.top.head-back { flex-wrap: nowrap; align-items: center; justify-content: flex-start; gap: 12px; }
header.top.head-back h1 { min-width: 0; overflow-wrap: anywhere; }
/* sub-section tabs: one row, scrolls sideways inside the track when the labels do not fit (the active one is scrolled into view) */
.seg.tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
.seg.tabs::-webkit-scrollbar { display: none; }
.seg.tabs a { flex: 1 0 auto; padding-left: 14px; padding-right: 14px; white-space: nowrap; font-size: 14px; }
/* chart cards */
.chartcard .title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.unit { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; }
.chart { min-width: 0; }
/* events table scrolls inside its card; edge fades appear only where it can still scroll */
.tablewrap { overflow-x: auto; max-width: 100%; margin-top: 4px;
  background:
    linear-gradient(to right, var(--surface-solid) 30%, transparent) left center / 40px 100% no-repeat local,
    linear-gradient(to left, var(--surface-solid) 30%, transparent) right center / 40px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .2), transparent) left center / 12px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .2), transparent) right center / 12px 100% no-repeat scroll; }
table.events th, table.events td { padding: 10px 8px; }
.card .sub + .sub { margin-top: 6px; }
.sums .big { font-weight: 700; letter-spacing: -.5px; }
/* forms: every row is a full-width `.field` (templates/form/theme.html.twig) */
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field ul { list-style: none; margin: 4px 0 0; padding: 0; color: var(--warn); font-size: 14px; }
.field .sub { margin: 6px 0 0; }
.field.check { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 12px; min-height: 44px; }
.field.check input[type=checkbox] { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); }
.field.check label { margin: 0; font-size: 15px; color: var(--text); }
.field.check > :not(input):not(label) { grid-column: 1 / -1; }
.field.actions-row { margin-bottom: 0; }
.field.arow select { width: 150px; flex: none; }
.periods .custom input { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; font-size: 16px; min-height: 44px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.periods .custom label { margin: 0; min-width: 0; }
.periods .custom input { min-width: 0; }
form .btn[type=submit] { max-width: 100%; }
.card form .btn { width: 100%; }
@media (min-width: 600px) { .card form .btn { width: auto; } }
.err { margin: 8px 0 0; }
/* admin lists */
.mv .icon-btn svg { transition: transform .1s; }
.mv-up svg { transform: rotate(-90deg); }
.mv-down svg { transform: rotate(90deg); }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; text-decoration: none; font-weight: 600; }
.back svg.i { width: 18px; height: 18px; }
.room-card form.rename { margin-top: 12px; }
.room-card .note { margin-top: 8px; }
.userrow { padding: 14px 16px; }
.userrow .pill { margin-left: 8px; vertical-align: 1px; }
.card .chips { margin-bottom: 6px; }
.unlogged .sub a { display: inline-flex; align-items: center; min-height: 44px; }
.card.off { background: var(--surface-2); box-shadow: none; }
table.metrics th, table.metrics td { padding: 11px 6px; }
table.metrics th { color: var(--muted); font-weight: 500; font-size: 12px; }
/* profile */
.who { display: flex; align-items: center; gap: 14px; }
.who-txt { min-width: 0; }
.who-txt .title, .who-txt .sub { overflow-wrap: anywhere; }
.avatar { flex: none; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--ink-on-color);
  font-size: 24px; font-weight: 700; }
.subhead { font-size: 14px; font-weight: 600; margin: 18px 0 8px; }
.card.list .listrow { min-height: 56px; }
@media (min-width: 900px) { .shell-main main.profile, .shell-main main.admin { max-width: 640px; } }
/* === end Task 5 === */
