:root {
  --bg: #FAF8F6;
  --card: #FFFFFF;
  --ink: #111111;
  --muted: #6F6B66;
  --line: #E9E6E2;
  --blue: #1A73E8;
  --blue-bg: #E8F0FE;
  --amber: #B26A00;
  --amber-bg: #FFF1D6;
  --green: #1E8E3E;
  --red: #D93025;
  --radius: 18px;
  --tab-h: 64px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
body.lock { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
svg.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

.page {
  padding: calc(var(--sat) + 22px) calc(var(--sar) + 16px) calc(var(--tab-h) + var(--sab) + 28px) calc(var(--sal) + 16px);
  min-height: 100vh;
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- tipografia ---------- */
.eyebrow { font-size: 15px; font-weight: 600; color: var(--muted); }
.h1 { font-size: 34px; line-height: 1.04; font-weight: 800; letter-spacing: -0.035em; margin-top: 4px; }
.h1.warn { color: var(--amber); }
.sub { color: var(--muted); font-size: 15px; margin-top: 6px; }
.h2 { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.link { color: var(--blue); font-weight: 600; font-size: 14px; }

/* ---------- topo ---------- */
.back { display: inline-flex; align-items: center; gap: 2px; margin-left: -6px; padding: 6px 10px 6px 4px; color: var(--blue); font-weight: 600; font-size: 15px; }
.statusrow { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 14px; color: var(--ink); font-size: 14px; font-weight: 500; }
.statusrow > span { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.statusrow .ok { color: var(--green); }
.statusrow .ok b { color: var(--ink); font-weight: 500; }
.statusrow .warn { color: var(--amber); }
.statusrow .warn b { font-weight: 600; }
.statusrow .ink svg { color: var(--muted); }

.hero { margin: 6px -8px 0; }
.hero img { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 7%, #000 97%, transparent 100%); mask-image: linear-gradient(to right, transparent 0, #000 7%, #000 97%, transparent 100%); }
.hero img, .roomimg img { display: block; width: 100%; height: auto; mix-blend-mode: multiply; filter: brightness(1.045); user-select: none; -webkit-user-drag: none; }
.roomimg { margin: 8px 0 0; padding: 0 10px; }
.roomimg img { max-height: 330px; object-fit: contain; }

/* ---------- chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 6px calc(var(--sar) * -1 - 16px) 0 calc(var(--sal) * -1 - 16px); padding: 4px calc(var(--sar) + 16px) 4px calc(var(--sal) + 16px); scrollbar-width: none; overscroll-behavior-x: contain; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 9px 16px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--blue-bg); border-color: var(--blue-bg); color: var(--blue); }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.quick { position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 18px; min-height: 134px; padding: 14px 14px 15px; text-align: left; width: 100%; }
.quick .qtop { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--blue-bg); color: var(--blue); flex: none; }
.ico.amber { background: var(--amber-bg); color: var(--amber); }
.ico.grey { background: #F1EFEC; color: var(--muted); }
.qtitle { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.qsub { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qsub b { color: var(--ink); font-weight: 600; }
.qchev { color: #B5B0AA; margin-top: 10px; }

/* ---------- switch ---------- */
.sw { position: relative; flex: none; width: 50px; height: 30px; border-radius: 999px; background: #D8D4CF; transition: background .18s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .18s; }
.sw[aria-checked="true"] { background: var(--blue); }
.sw[aria-checked="true"]::after { transform: translateX(20px); }
.sw:disabled { opacity: .5; }

/* ---------- rotinas ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.rot { display: flex; align-items: center; gap: 14px; padding: 12px 14px; }
.rot .rname { flex: 1; min-width: 0; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.rot .rhint { font-size: 12.5px; color: var(--muted); font-weight: 500; margin-top: 1px; }
.play { width: 44px; height: 44px; border-radius: 50%; background: var(--blue-bg); color: var(--blue); display: grid; place-items: center; flex: none; }
.play svg { fill: currentColor; stroke-width: 1.5; width: 18px; height: 18px; margin-left: 2px; }
.play.busy svg { display: none; }
.play.busy::after { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(26, 115, 232, .25); border-top-color: var(--blue); animation: spin .7s linear infinite; }

/* ---------- cômodos ---------- */
.counts { margin-top: 12px; color: var(--ink); font-weight: 600; font-size: 14px; }
.counts i { font-style: normal; color: #C3BEB8; margin: 0 6px; }
.rooms { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.room { display: block; padding: 8px 8px 14px; text-align: left; }
.room img { display: block; width: 100%; aspect-ratio: 1 / 0.88; object-fit: contain; mix-blend-mode: multiply; filter: brightness(1.045); }
.room .rn { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; margin: 4px 8px 0; }
.room .rc { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 3px 8px 0; font-weight: 500; }
.room .rc::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--blue); flex: none; }

/* ---------- cômodo ---------- */
.sensor { display: flex; margin-top: 14px; padding: 16px 0; }
.sensor > div { flex: 1; padding: 0 18px; min-width: 0; }
.sensor > div + div { border-left: 1px solid var(--line); }
.sensor .big { font-size: 42px; line-height: 1; font-weight: 800; letter-spacing: -0.04em; }
.sensor .big small { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-left: 1px; }
.sensor .lbl { display: flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.sensor .lbl svg { width: 15px; height: 15px; }
.sensor.offline { opacity: .6; }

.devs { margin-top: 16px; padding: 0 14px; }
.dev { padding: 14px 0; }
.dev + .dev { border-top: 1px solid var(--line); }
.dhead { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.dtxt { flex: 1; min-width: 0; }
.dname { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dstate { font-size: 13px; color: var(--muted); margin-top: 1px; }
.tag { font-size: 11px; font-weight: 700; letter-spacing: .02em; text-transform: lowercase; padding: 2px 8px; border-radius: 999px; background: #ECE9E5; color: var(--muted); }
.dev.off .dname { color: var(--muted); }
.dev.off .ico { background: #F1EFEC; color: #A8A39D; }

.slider-row { display: flex; align-items: center; gap: 14px; margin-top: 8px; padding-left: 52px; }
.slider-row .pct { width: 42px; text-align: right; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; flex: none; }
input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; min-width: 0; height: 32px; margin: 0; background: transparent; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 99px; background: linear-gradient(to right, var(--blue) var(--v, 0%), #E5E1DC var(--v, 0%)); }
input[type=range]::-moz-range-track { height: 8px; border-radius: 99px; background: #E5E1DC; }
input[type=range]::-moz-range-progress { height: 8px; border-radius: 99px; background: var(--blue); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%; background: #fff; border: 1px solid var(--line); box-shadow: 0 1px 4px rgba(0, 0, 0, .22); }
input[type=range]::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 1px solid var(--line); box-shadow: 0 1px 4px rgba(0, 0, 0, .22); }

.arbox { margin-top: 10px; padding-left: 52px; }
.stepper { display: flex; align-items: center; justify-content: space-between; background: #F6F4F1; border-radius: 16px; padding: 6px; }
.stepper .val { font-size: 34px; font-weight: 800; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.stepper .val small { font-size: 18px; font-weight: 700; }
.stepper button { width: 46px; height: 46px; border-radius: 13px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; color: var(--blue); }
.stepper button:disabled { color: #C3BEB8; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.seg button { padding: 10px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 13.5px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button.on { background: var(--blue-bg); border-color: var(--blue-bg); color: var(--blue); }
.seg button svg { width: 16px; height: 16px; }
.note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.arbox.dim .stepper, .arbox.dim .seg { opacity: .55; }

.lockbtn { display: block; width: 100%; margin-top: 12px; height: 52px; border-radius: 14px; font-weight: 700; font-size: 16px; background: var(--blue); color: #fff; }
.lockbtn.alt { background: var(--blue-bg); color: var(--blue); }
.lockbtn.amber { background: var(--amber-bg); color: var(--amber); }
.dbody { padding-left: 52px; }

/* ---------- ajustes ---------- */
.kv { padding: 4px 16px; margin-top: 12px; }
.kv .row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; }
.kv .row + .row { border-top: 1px solid var(--line); }
.kv .k { color: var(--muted); font-size: 14px; }
.kv .v { font-weight: 600; font-size: 14px; text-align: right; min-width: 0; overflow-wrap: anywhere; display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #BDB8B2; flex: none; }
.dot.g { background: var(--green); }
.dot.r { background: var(--red); }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 50px; margin-top: 12px; border-radius: 14px; font-weight: 700; font-size: 15px; background: var(--card); border: 1px solid var(--line); }
.btn.primary { background: var(--blue-bg); border-color: var(--blue-bg); color: var(--blue); }
.version { text-align: center; color: #A8A39D; font-size: 12px; margin-top: 32px; }
.log { margin-top: 12px; padding: 4px 16px; }
.log .ev { padding: 11px 0; }
.log .ev + .ev { border-top: 1px solid var(--line); }
.log .eh { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.log .et { font-weight: 600; font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.log .et.err { color: var(--red); }
.log .eh time { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; flex: none; }
.log .ed { color: var(--muted); font-size: 12px; margin-top: 3px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { color: var(--muted); font-size: 14px; padding: 14px 0; text-align: center; }

/* ---------- estados ---------- */
.state { text-align: center; padding: 90px 20px 0; }
.state .ico { width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 18px; }
.state .ico svg { width: 30px; height: 30px; }
.state h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.03em; }
.state p { color: var(--muted); margin-top: 8px; }
.state .btn { width: auto; display: inline-flex; padding: 0 24px; margin-top: 20px; }

.sk { background: linear-gradient(100deg, #EFECE8 30%, #F7F5F2 50%, #EFECE8 70%); background-size: 300% 100%; animation: shimmer 1.4s ease-in-out infinite; border-radius: 12px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- barra inferior ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); padding: 0 var(--sar) var(--sab) var(--sal); background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.tabbar a { height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: #77726C; font-size: 11.5px; font-weight: 600; }
.tabbar a svg { width: 23px; height: 23px; }
.tabbar a.on { color: var(--blue); }

/* ---------- toast e modal ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--sab) + 14px); z-index: 40; max-width: min(92vw, 420px); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; background: #1D1B19; color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 500; text-align: center; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #B3261E; }

.modal-root { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(17, 17, 17, .42); animation: fade .18s ease-out; }
.modal-root[hidden] { display: none; }
.sheet { width: 100%; max-width: 560px; background: var(--card); border-radius: 24px 24px 0 0; padding: 24px 20px calc(20px + var(--sab)); animation: up .22s ease-out; }
.sheet h3 { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.sheet p { color: var(--muted); margin-top: 8px; font-size: 15px; }
.sheet .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.sheet .acts button { height: 50px; border-radius: 14px; font-weight: 700; font-size: 15px; background: #F1EFEC; }
.sheet .acts button.go { background: var(--blue); color: #fff; }
.sheet.busy { text-align: center; padding: 34px 20px calc(34px + var(--sab)); }
.spin { width: 38px; height: 38px; margin: 0 auto 16px; border-radius: 50%; border: 4px solid var(--blue-bg); border-top-color: var(--blue); animation: spin .8s linear infinite; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (max-width: 360px) {
  .h1 { font-size: 30px; }
  .grid2, .rooms { gap: 10px; }
}
