:root {
  --paper: #ece9e3;
  --surface: #ffffff;
  --surface-2: #f7f5f1;
  --surface-3: #f1eee8;
  --ink: #1c1b18;
  --ink-2: #625c53;
  --ink-3: #918a7e;
  --line: #e4dfd6;
  --line-strong: #d5cec2;
  --green: #146b5a;
  --green-soft: #e7f1ed;
  --amber: #a96a10;
  --amber-soft: #fdf1de;
  --blue: #2f6fed;
  --blue-soft: #eaf0fe;
  --red: #b42318;
  --red-soft: #fdecea;
  --gray-soft: #efebe4;
  --shadow: 0 1px 2px rgba(28, 27, 24, .04);
  --shadow-lg: 0 24px 60px rgba(28, 27, 24, .18);
  --radius: 16px;
}

[data-theme="dark"] {
  --paper: #131311;
  --surface: #1c1b19;
  --surface-2: #232220;
  --surface-3: #2a2926;
  --ink: #f2efe9;
  --ink-2: #b3aca1;
  --ink-3: #857f74;
  --line: #33302b;
  --line-strong: #423e37;
  --green: #56c3a8;
  --green-soft: #123a32;
  --amber: #e2a34c;
  --amber-soft: #38280f;
  --blue: #7fa5ff;
  --blue-soft: #1a2642;
  --red: #f0776b;
  --red-soft: #3a1b17;
  --gray-soft: #2b2a27;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 28px 70px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html {
  color-scheme: light dark;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI Variable", "Segoe UI", -apple-system, BlinkMacSystemFont,
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

input { border: 0; background: none; }

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 10px;
}

a { color: inherit; text-decoration: none; }

.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: 0 0 auto; }
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber); }
.dot.gray { background: var(--line-strong); }

.muted { color: var(--ink-3); }

/* ---------- shell ---------- */

.shell { min-height: 100dvh; }

.main {
  padding: 18px 16px calc(92px + env(safe-area-inset-bottom));
  max-width: 1160px;
  margin: 0 auto;
}

.sidebar { display: none; }

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  gap: 2px;
  padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-2);
  font-weight: 600;
  font-size: 13px;
  border-radius: 12px;
  padding: 10px 12px;
  position: relative;
}

.nav-item .icon { width: 21px; height: 21px; }

.nav-item.active { color: var(--ink); }

.nav-item.tab {
  flex-direction: column;
  gap: 3px;
  padding: 6px 2px;
  font-size: 10px;
  font-weight: 650;
  color: var(--ink-3);
  text-align: center;
}

.nav-item.tab.active { color: var(--green); }
.nav-item.tab.active .icon { stroke-width: 2; }
.nav-item.tab .icon { width: 22px; height: 22px; }

.nav-badge {
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 9.5px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}

.nav-item.tab .nav-badge {
  position: absolute;
  top: 3px;
  right: calc(50% - 20px);
}

.nav-item.active { background: var(--surface); box-shadow: var(--shadow); }
.nav-item.tab.active { background: none; box-shadow: none; }

/* ---------- brand / sidebar ---------- */

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 5px 14px rgba(20, 107, 90, .22);
  flex: 0 0 auto;
}

[data-theme="dark"] .brand-mark { color: #0d1a16; }

.brand h1 { font-size: 20px; margin: 0; line-height: 1.1; letter-spacing: -.02em; }
.bld { font-size: 10px; color: var(--ink-3); margin-top: 3px; }

.mobile-only { display: flex; }
.desktop-only { display: none; }

/* ---------- view heads ---------- */

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 16px;
}

.home-head { align-items: center; padding-bottom: 20px; }

.view-title h1 { font-size: 28px; margin: 0; letter-spacing: -.03em; line-height: 1.1; }
.home-head .view-title h1 { font-size: 20px; }
.view-title .sub { margin: 5px 0 0; font-size: 11.5px; color: var(--ink-3); }
.head-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.sub-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 14px;
}

.sub-head .view-title { flex: 1; min-width: 0; }
.sub-head h1 { font-size: 24px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  white-space: nowrap;
}

.pill .dot { width: 6px; height: 6px; }
.pill.live { background: var(--green-soft); border-color: transparent; color: var(--green); }
.pill.live .dot { background: var(--green); }
.pill.demo { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.pill.demo .dot { background: var(--amber); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.btn .icon { width: 15px; height: 15px; }
.btn.small { padding: 7px 11px; font-size: 11px; border-radius: 9px; }
.btn.primary { background: var(--green); border-color: transparent; color: #fff; }
[data-theme="dark"] .btn.primary { color: #0d1a16; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-2); }
.btn.danger { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn:disabled { opacity: .45; cursor: default; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  flex: 0 0 auto;
}

.icon-btn.ghost { background: transparent; border-color: transparent; }
.icon-btn .icon { width: 19px; height: 19px; }

/* ---------- search / chips ---------- */

.search {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0 12px;
  margin-bottom: 12px;
  color: var(--ink-3);
}

.search .icon { width: 17px; height: 17px; }

.search input {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  font-size: 13px;
  color: var(--ink);
}

.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { display: none; }

.search .clear {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--gray-soft);
  color: var(--ink-2);
}

.search .clear .icon { width: 12px; height: 12px; }

.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.active-chips { margin: 0 0 12px; flex-wrap: wrap; overflow: visible; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
}

.chip .icon { width: 13px; height: 13px; }
.chip.active { background: var(--green); border-color: var(--green); color: #fff; }
[data-theme="dark"] .chip.active { color: #0d1a16; }
.chip.ghost { background: transparent; border-color: transparent; color: var(--ink-3); }
.chip-count { opacity: .65; font-size: 10px; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-bottom: 4px;
  margin: 2px 0 14px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  padding: 9px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 650;
}

.tab-chip span { font-size: 10px; opacity: .6; font-weight: 700; }
.tab-chip.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
[data-theme="dark"] .tab-chip.active { background: var(--ink); color: #14140f; }

/* ---------- sections ---------- */

.section { margin-bottom: 22px; }
.floor-section { scroll-margin-top: 14px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 9px;
}

.section-head h2 { font-size: 14.5px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.section-head .count { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel.note {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px;
  font-size: 12.5px;
  color: var(--ink-2);
}

.panel.note .icon { color: var(--green); width: 17px; height: 17px; }

.stack { display: flex; flex-direction: column; gap: 10px; }

.list { display: flex; flex-direction: column; gap: 8px; }

.more-note { padding: 10px 4px 2px; font-size: 11px; color: var(--ink-3); }

/* ---------- home empty ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 54px 22px;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: 20px;
}

.empty-ico {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--green-soft);
  color: var(--green);
  margin-bottom: 4px;
}

.empty-ico .icon { width: 26px; height: 26px; }
.empty h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.empty p { margin: 0; max-width: 340px; font-size: 12.5px; line-height: 1.55; color: var(--ink-2); }
.empty-actions { display: flex; gap: 9px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.empty.small { padding: 34px 20px; border-style: solid; background: var(--surface); }
.empty.small h2 { font-size: 15px; }
.empty.small p { font-size: 12px; }

/* ---------- home shortcuts ---------- */

.device-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  min-height: 118px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.tile-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  margin-bottom: 2px;
}

.tile-ico .icon { width: 18px; height: 18px; }
.tile-ico.on { background: var(--amber-soft); color: var(--amber); }

.tile-name { font-size: 13px; font-weight: 650; line-height: 1.25; }
.tile-meta { font-size: 10.5px; color: var(--ink-3); }

.tile .switch { margin-top: 8px; }
.tile .tile-open {
  position: absolute;
  right: 8px;
  bottom: 10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-3);
  background: var(--surface-2);
}

.tile .tile-open .icon { width: 13px; height: 13px; }

.tile-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--red-soft);
  color: var(--red);
  display: grid;
  place-items: center;
  z-index: 2;
}

.tile-remove .icon { width: 12px; height: 12px; }

.missing-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--ink-2);
  font-size: 12px;
}

.missing-row .icon { color: var(--amber); width: 16px; height: 16px; }
.missing-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---------- scenes ---------- */

.scene-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.run {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.run .icon { width: 13px; height: 13px; margin-left: 1px; }

.scene-main { flex: 1; min-width: 0; }
.scene-title { display: flex; align-items: center; gap: 7px; min-width: 0; }
.scene-title h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scene-meta {
  font-size: 10.5px;
  color: var(--ink-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--gray-soft);
  color: var(--ink-2);
}

.tag.warn { background: var(--amber-soft); color: var(--amber); }
.tag.kind-time { background: var(--blue-soft); color: var(--blue); }
.tag.kind-sensor { background: var(--amber-soft); color: var(--amber); }
.tag.kind-switch { background: var(--green-soft); color: var(--green); }
.tag.kind-other { background: var(--gray-soft); color: var(--ink-2); }

.star {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-3);
  flex: 0 0 auto;
}

.star .icon { width: 16px; height: 16px; }
.star.on { color: var(--green); background: var(--green-soft); }
.star.remove { color: var(--red); background: var(--red-soft); }

/* ---------- rooms ---------- */

.room-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.room-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 13px;
  min-height: 104px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}

.room-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }

.room-ico {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  margin-bottom: 3px;
}

.room-ico.on { background: var(--amber-soft); color: var(--amber); }
.room-ico .icon { width: 17px; height: 17px; }
.room-name { font-size: 13.5px; font-weight: 650; }
.room-meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.room-meta .icon { width: 12px; height: 12px; color: var(--amber); }
.room-meta .muted { font-size: 10.5px; }

/* ---------- room detail ---------- */

.device-row, .sensor-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.device-row:first-child, .sensor-row:first-child { border-top: 0; }

.device-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.device-ico.on { background: var(--amber-soft); color: var(--amber); }
.device-ico.blue { background: var(--blue-soft); color: var(--blue); }
.device-ico .icon { width: 18px; height: 18px; }

.device-main { flex: 1; min-width: 0; }
.device-main strong { display: block; font-size: 12.5px; font-weight: 600; }
.device-main small { display: block; font-size: 10.5px; color: var(--ink-3); margin-top: 1px; }
.sensor-value { font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }

.switch {
  width: 46px;
  height: 27px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  flex: 0 0 auto;
  transition: background .18s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .18s;
}

.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(19px); }

.climate-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  box-shadow: var(--shadow);
}

.climate-top { display: flex; align-items: center; gap: 10px; }
.climate-top .device-main strong { font-size: 13px; }

.temp-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}

.temp-value {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.temp-value span { font-size: 11px; color: var(--ink-3); margin-left: 3px; font-weight: 600; }

.stepper { margin-left: auto; display: flex; gap: 6px; }

.stepper button {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--ink-2);
}

.stepper .icon { width: 15px; height: 15px; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 11px;
  margin-top: 10px;
}

.segmented.two { grid-template-columns: repeat(2, 1fr); }
.segmented.inline { margin: 0; width: 190px; background: var(--surface-2); }

.segmented button {
  padding: 7px 0;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
  text-align: center;
}

.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .1);
}

/* ---------- rules ---------- */

.rule-grid { display: grid; gap: 9px; }

.rule {
  display: flex;
  gap: 11px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kind-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--gray-soft);
  color: var(--ink-2);
}

.kind-ico .icon { width: 17px; height: 17px; }
.kind-ico.kind-time { background: var(--blue-soft); color: var(--blue); }
.kind-ico.kind-sensor { background: var(--amber-soft); color: var(--amber); }
.kind-ico.kind-switch { background: var(--green-soft); color: var(--green); }

.rule-main { flex: 1; min-width: 0; }
.rule-title { display: flex; align-items: flex-start; gap: 10px; }
.rule-title h3 {
  flex: 1;
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.rule-title .switch { width: 42px; height: 25px; }
.rule-title .switch::after { width: 19px; height: 19px; }
.rule-title .switch.on::after { transform: translateX(17px); }

.rule-trigger {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  min-width: 0;
}

.trigger-text {
  font-size: 11.5px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rule-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 7px;
  font-size: 10px;
  color: var(--ink-3);
  white-space: nowrap;
}

/* ---------- more ---------- */

.attention-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: var(--shadow);
}

.attention-ico {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.attention-ico .icon { width: 16px; height: 16px; }
.attention-ico.red { background: var(--red-soft); color: var(--red); }
.attention-ico.amber { background: var(--amber-soft); color: var(--amber); }

.attention-copy { flex: 1; min-width: 0; }
.attention-copy strong { display: block; font-size: 12.5px; font-weight: 650; }
.attention-copy small { display: block; font-size: 10.5px; color: var(--ink-3); margin-top: 1px; }

.conn-row, .setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.conn-row:first-child, .setting-row:first-child { border-top: 0; }
.conn-row .dot { margin: 0 2px; }

.ha-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 11px;
  font-weight: 650;
}

.ha-btn .icon { width: 15px; height: 15px; color: var(--green); }
.ha-btn.wide { padding: 14px; border-radius: var(--radius); font-size: 12px; }
.ha-btn.wide .icon { width: 18px; height: 18px; }
.ha-btn.wide div { display: flex; flex-direction: column; gap: 2px; }
.ha-btn.wide small { font-size: 10.5px; font-weight: 500; color: var(--ink-3); }

.about {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--ink-3);
}

/* ---------- banner / boot / toast ---------- */

.banner {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px;
  border-radius: 13px;
  margin-bottom: 14px;
  background: var(--red-soft);
  color: var(--red);
}

.banner-ico .icon { width: 18px; height: 18px; }
.banner-copy { flex: 1; min-width: 0; }
.banner-copy strong { display: block; font-size: 12.5px; }
.banner-copy small { display: block; font-size: 10.5px; opacity: .8; margin-top: 1px; }

.boot {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(8px);
}

.boot-card {
  width: min(320px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 22px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.boot-ico {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  margin-bottom: 6px;
}

[data-theme="dark"] .boot-ico { color: #0d1a16; }
.boot-ico .icon { width: 23px; height: 23px; }
.boot-card strong { font-size: 13px; }
.boot-card small { font-size: 11px; color: var(--ink-3); }

.progress {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 12px;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width .3s ease;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 90;
  padding: 10px 15px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}

[data-theme="dark"] .toast { background: var(--ink); color: #14140f; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- sheets ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(12, 12, 10, .42);
  z-index: 60;
  animation: fade .15s ease;
}

.sheet {
  position: fixed;
  z-index: 70;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  inset: auto 0 0 0;
  max-height: 86dvh;
  border-radius: 22px 22px 0 0;
  padding: 6px 0 calc(12px + env(safe-area-inset-bottom));
  animation: rise .22s cubic-bezier(.2, .8, .2, 1);
}

.sheet-grab {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-strong);
  margin: 4px auto 4px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px 6px;
}

.sheet-head h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.sheet-body { padding: 4px 16px 12px; overflow-y: auto; }
.sheet-body h3 {
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 16px 0 8px;
  font-weight: 700;
}

.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px 4px;
  border-top: 1px solid var(--line);
}

.rule.tappable, .scene-row.tappable { cursor: pointer; }
.rule.tappable:hover, .scene-row.tappable:hover { border-color: var(--line-strong); }

.sheet-sub {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--ink-3);
}

.detail-block { margin-top: 14px; }
.detail-block h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.detail-block .count {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--ink-3);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 7px;
}
.detail-line {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
}
.detail-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-2);
}
.detail-list li::marker { color: var(--ink-3); font-variant-numeric: tabular-nums; }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.field > span { font-size: 11.5px; font-weight: 650; color: var(--ink-2); }

.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
}

.field small { font-size: 10.5px; color: var(--ink-3); line-height: 1.5; }
.hint { font-size: 10.5px; color: var(--ink-3); margin: 12px 0 0; }
.hint.warn { color: var(--amber); background: var(--amber-soft); border-radius: 10px; padding: 8px 10px; line-height: 1.5; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }

/* ---------- responsive ---------- */

@media (min-width: 620px) {
  .room-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .device-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .main { padding-left: 22px; padding-right: 22px; }
}

@media (min-width: 960px) {
  .shell {
    display: grid;
    grid-template-columns: 252px minmax(0, 1fr);
    min-height: 100dvh;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: 20px 14px;
    background: var(--surface-2);
    border-right: 1px solid var(--line);
    min-width: 0;
  }

  .sidebar .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .sidebar .brand h1 { font-size: 17px; }
  .sidebar .bld { font-size: 9.5px; }

  .side-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 22px; }
  .side-nav .nav-item { padding: 9px 11px; }
  .side-nav .nav-item.active { background: var(--surface); box-shadow: var(--shadow); }
  .side-nav .nav-item.active .icon { color: var(--green); }
  .side-nav .nav-badge { margin-left: auto; }

  .side-label {
    font-size: 9.5px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--ink-3);
    font-weight: 700;
    margin: 22px 11px 6px;
  }

  .side-floors { display: flex; flex-direction: column; gap: 1px; }

  .floor-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 11px;
    border-radius: 8px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ink-2);
  }

  .floor-link .icon { width: 13px; height: 13px; color: var(--ink-3); }
  .floor-link:hover { background: var(--surface-3); }

  .side-bottom { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }

  .side-status {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 10px;
    padding: 0 4px;
    font-size: 9.5px;
    color: var(--ink-3);
  }

  .tabbar { display: none; }
  .mobile-only { display: none; }
  .desktop-only { display: block; }

  .main {
    padding: 30px 34px 48px;
    width: 100%;
    max-width: none;
  }

  .view-head { padding-bottom: 20px; }
  .view-title h1 { font-size: 30px; }
  .home-head { justify-content: space-between; padding-bottom: 22px; }
  .home-head .head-actions { margin-left: auto; }

  .toast { bottom: 26px; }
  .sheet {
    inset: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(560px, calc(100vw - 60px));
    max-height: min(80dvh, 720px);
    border-radius: 20px;
    padding-bottom: 4px;
    animation: pop .18s ease;
  }
  .sheet-grab { display: none; }
  .sheet-head { padding-top: 16px; }

  .device-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
  .room-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
  .rule-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .empty { padding: 70px 30px; }
}

@media (min-width: 1360px) {
  .rule-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .device-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@keyframes pop { from { transform: translate(-50%, -48%); opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
