:root {
  --bg: #f3f5f6; --card: #ffffff; --fg: #14201f; --muted: #5d6b6a; --line: #dfe5e5; --soft: #eaf0f0;
  --accent: #0f766e; --accent-fg: #ffffff; --home: #15803d; --homebg: #dcfce7; --away: #6b7280; --awaybg: #eceff1;
  --warn: #b45309; --warnbg: #fef3c7; --bad: #b91c1c; --badbg: #fee2e2; --shadow: 0 1px 2px rgba(0,0,0,.06);
  --nav-h: 62px; --top-h: 46px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1213; --card: #162022; --fg: #e8f0ef; --muted: #98a8a6; --line: #263234; --soft: #1d292b;
          --accent: #2dd4bf; --accent-fg: #06201c; --home: #4ade80; --homebg: #123a22; --away: #9ca3af; --awaybg: #222b2d;
          --warn: #fbbf24; --warnbg: #3b2f0b; --bad: #f87171; --badbg: #3f1717; --shadow: none; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 24px; line-height: 1.15; margin: 4px 0 2px; letter-spacing: -.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 2px 8px; font-weight: 700; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---- layout: top bar, content, bottom tabs on phones, left rail on wide screens ---- */
#topbar { position: sticky; top: 0; z-index: 20; height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 16px 0; display: flex; align-items: center; justify-content: space-between; background: var(--accent); color: var(--accent-fg); }
.brand { font-weight: 700; letter-spacing: .01em; }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; opacity: .95; }
.status i { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; display: inline-block; }
.status.ok i { background: #4ade80; } .status.err i { background: #f87171; } .status.demo i { background: #fbbf24; }
#demo-banner { background: var(--warnbg); color: var(--warn); font-size: 13px; font-weight: 600; text-align: center; padding: 6px 12px; }
#view { padding: 14px 14px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; outline: none; }
#nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#nav button { flex: 1; min-height: var(--nav-h); border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; font-weight: 600; color: var(--muted); position: relative; }
#nav button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#nav button[aria-current="page"] { color: var(--accent); }
#nav button[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 24%; right: 24%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
#nav .badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--warn); color: #fff; font-size: 11px; line-height: 17px; text-align: center; }
body.nonav #nav { display: none; }
body.nonav #view { padding-bottom: 28px; }
@media (min-width: 900px) {
  #nav { top: calc(var(--top-h) + env(safe-area-inset-top)); bottom: 0; right: auto; width: 188px; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--line); padding: 12px 10px; gap: 4px; }
  #nav button { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 46px; padding: 0 12px; border-radius: 10px; font-size: 15px; }
  #nav button[aria-current="page"] { background: var(--soft); }
  #nav button[aria-current="page"]::before { display: none; }
  #nav .badge { position: static; margin-left: auto; }
  #view { margin-left: 188px; max-width: none; padding: 20px 28px 40px; }
  #view > .wrap { max-width: 860px; }
  body.nonav #view { margin-left: 0; }
  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
}

/* ---- cards and rows ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin: 10px 0; box-shadow: var(--shadow); }
.card.hero { padding: 18px 18px; }
.hero .big { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.person { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 14px; margin: 10px 0; box-shadow: var(--shadow); }
.person.away { background: var(--bg); }
.person.away .avatar { filter: grayscale(.9); opacity: .75; }
.avatar { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #fff; }
.avatar.sm { width: 30px; height: 30px; font-size: 14px; }
.pbody { flex: 1; min-width: 0; }
.pname { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.pline { font-size: 14px; color: var(--muted); }
.pline.where { color: var(--fg); font-weight: 500; }
.pill { font-size: 11.5px; font-weight: 800; letter-spacing: .05em; padding: 3px 9px; border-radius: 999px; text-transform: uppercase; white-space: nowrap; }
.pill.home { background: var(--homebg); color: var(--home); } .pill.away { background: var(--awaybg); color: var(--away); }
.pill.new { background: var(--warnbg); color: var(--warn); }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin: 2px 4px 0 0; white-space: nowrap; }
.tag.always { border-style: dashed; } .tag.person { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--card); border: 0; border-bottom: 1px solid var(--line); padding: 12px 14px; min-height: 60px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.list > .row:last-child { border-bottom: 0; }
.row .ico { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 11px; background: var(--soft); display: grid; place-items: center; color: var(--accent); }
.row .ico svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.row .ico.mine { background: var(--accent); color: var(--accent-fg); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .title.dim { font-weight: 500; color: var(--muted); }
.row .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .tech { font-size: 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .side { text-align: right; font-size: 13px; color: var(--muted); flex: 0 0 auto; }
.row .side b { display: block; color: var(--fg); font-size: 14px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-right: 5px; }
.dot.on { background: var(--home); }

/* ---- controls ---- */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; min-height: 46px; padding: 0 16px; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.link { border: 0; background: none; color: var(--accent); min-height: 44px; padding: 0 4px; }
.btn:disabled { opacity: .5; }
.actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }
input[type=text], input[type=search], input[type=password], input[type=url], input[type=number], select { width: 100%; min-height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: 16px; }
input:focus-visible, button:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
label.f { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 14px 2px 5px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 0 14px; min-height: 44px; font-size: 14px; font-weight: 600; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip small { opacity: .75; margin-left: 4px; font-weight: 500; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; min-height: 44px; border: 0; background: var(--card); font-size: 14px; font-weight: 600; color: var(--muted); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--muted); background: none; border: 0; min-height: 44px; }
.switch i { width: 42px; height: 24px; border-radius: 12px; background: var(--line); position: relative; transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch[aria-pressed="true"] i { background: var(--accent); } .switch[aria-pressed="true"] i::after { transform: translateX(18px); }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.notice { border-radius: 12px; padding: 10px 14px; font-size: 14px; margin: 10px 0; background: var(--soft); }
.notice.warn { background: var(--warnbg); color: var(--warn); } .notice.err { background: var(--badbg); color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 28px 14px; }

/* ---- rooms, activity ---- */
.room h3 { margin: 0; font-size: 18px; }
.roomhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.pchips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.pchip { display: inline-flex; align-items: center; gap: 8px; background: var(--soft); border-radius: 999px; padding: 4px 12px 4px 4px; font-weight: 600; font-size: 14px; }
.pchip small { color: var(--muted); font-weight: 500; }
.counts { font-size: 13px; color: var(--muted); margin-top: 8px; }
.techlist { margin-top: 8px; border-top: 1px solid var(--line); font-size: 12.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.techlist div { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.day { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top)); background: var(--bg); padding: 10px 2px 6px; margin: 0; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; z-index: 5; }
.ev { display: flex; gap: 12px; padding: 10px 2px; align-items: flex-start; }
.ev .time { flex: 0 0 66px; font-size: 13px; color: var(--muted); padding-top: 2px; font-variant-numeric: tabular-nums; }
.ev .mark { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; font-weight: 800; }
.ev .mark.arrive { background: var(--homebg); color: var(--home); } .ev .mark.depart { background: var(--awaybg); color: var(--away); } .ev .mark.new { background: var(--warnbg); color: var(--warn); }
.ev .t { font-weight: 600; } .ev .n { font-size: 13px; color: var(--muted); }

/* ---- sheet (bottom sheet on phones, centered on desktop) ---- */
dialog#sheet { border: 0; padding: 0; background: var(--card); color: var(--fg); width: 100%; max-width: 520px; max-height: 92dvh; margin: auto auto 0; border-radius: 22px 22px 0 0; overflow: auto; box-shadow: 0 -8px 40px rgba(0,0,0,.25); }
dialog#sheet::backdrop { background: rgba(0,0,0,.45); }
@media (min-width: 700px) { dialog#sheet { margin: auto; border-radius: 22px; } }
.sheetin { padding: 8px 18px calc(22px + env(safe-area-inset-bottom)); }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 10px; }
.sheetin h3 { margin: 4px 0 2px; font-size: 20px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; margin-top: 8px; }
.kv span:nth-child(odd) { color: var(--muted); } .kv span:nth-child(even) { word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
details.tech summary { cursor: pointer; font-size: 14px; font-weight: 650; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
svg.spark { width: 100%; height: 70px; margin-top: 8px; background: var(--soft); border-radius: 10px; }
svg.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.8; vector-effect: non-scaling-stroke; }
#toast { position: fixed; left: 50%; transform: translate(-50%, 20px); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); background: #111; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.nonav #toast { bottom: 24px; }
@media (min-width: 900px) { #toast { bottom: 24px; } }

/* ---- first-run ---- */
.welcome { max-width: 460px; margin: 6vh auto 0; text-align: center; }
.welcome .logo { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto 14px; display: block; }
.welcome .card { text-align: left; }

/* ---- device categories, bulk select, smart home ---- */
.pagehead .btn { margin-left: auto; min-height: 44px; padding: 0 18px; }
.pagehead .btn + .switch { margin-left: 8px; }
.check { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 8px; border: 2px solid var(--line); display: grid; place-items: center; font-size: 15px; font-weight: 800; color: var(--accent-fg); }
.check.on { background: var(--accent); border-color: var(--accent); }
.row[aria-pressed="true"] { background: var(--soft); }
.selbar { position: fixed; z-index: 25; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0,0,0,.12); padding: 10px 14px; }
.selbar[hidden] { display: none; }
.selhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.selinfo { font-weight: 650; }
.selhead .btn.link { padding: 0 2px; }
.selbtns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.selbtns .btn { min-height: 48px; padding: 0 6px; }
body.selecting #view { padding-bottom: calc(var(--nav-h) + 140px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .selbar { left: 188px; } }
details.smart { padding: 0; }
details.smart > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; min-height: 48px; }
details.smart > summary::-webkit-details-marker { display: none; }
details.smart .stitle { font-weight: 700; }
details.smart > summary .pill { margin-left: auto; }
.smartbody { padding: 0 16px 14px; }
.smartbody .list { margin: 6px 0 10px; }
.btn.link { background: none; border: 0; color: var(--accent); padding: 0 4px; min-height: 44px; font-weight: 600; text-align: left; }

/* ---- rooms: house map ---- */
.wrapchips { flex-wrap: wrap; overflow: visible; margin: 0; padding: 4px 0 6px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btnrow .btn { min-height: 44px; padding: 0 12px; }
.pagehead.sub { margin-top: 18px; }
.pagehead.sub h2 { margin: 0; }
.floor { margin: 18px 0 6px; }
.floorhead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 0 2px 8px; }
.floorhead h2 { margin: 0; }
.plan { display: grid; grid-template-columns: repeat(6, 1fr); grid-auto-rows: minmax(84px, auto); gap: 6px; padding: 8px; background: var(--soft); border: 2px solid var(--line); border-radius: 18px; }
.plan.wide { grid-template-columns: repeat(2, 1fr); grid-auto-rows: minmax(64px, auto); }
.tile { position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 6px; text-align: left; padding: 10px 11px 9px; min-height: 84px; min-width: 0; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 12px; color: var(--fg); }
.tile:active { transform: scale(.98); }
.tile .tname { font-weight: 700; font-size: 14.5px; line-height: 1.2; overflow-wrap: anywhere; }
.tile .tmeta { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; flex-wrap: wrap; }
.tile .tdot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--away); }
.tile .tdot.on { background: var(--home); }
.tile .tdot.off { background: var(--warn); margin-left: 6px; }
.tile .tnone { opacity: .6; }
.tile .tprobe { margin-left: auto; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 0 6px; }
.tile .tppl { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.tile .tppl small { font-size: 12px; color: var(--fg); font-weight: 600; }
.tile.st-ok { border-left-color: var(--home); }
.tile.st-partial { border-left-color: var(--warn); }
.tile.st-off { border-left-color: var(--bad); }
.tile.st-empty { background: transparent; border-style: dashed; border-left-style: dashed; }
.tile.st-empty .tname { color: var(--muted); font-weight: 600; }
.tile.st-need { border-left-color: var(--warn); background: var(--warnbg); color: var(--warn); grid-column: 1 / -1; }
.tile.st-need .tname, .tile.st-need .tmeta { color: var(--warn); }
@media (min-width: 900px) { .plan { max-width: 640px; } }
.tile .tnear { font-size: 12px; color: var(--muted); font-weight: 500; }

/* --- Tightening pass --- */
.chips.wrapchips { flex-wrap: wrap; overflow: visible; margin: 10px 0; padding: 0; gap: 8px; }
.actions.tight { margin-top: 10px; }
.actions.tight .btn { flex: 1 1 0; }
.anonline { margin-top: 8px; }
.sheetin .actions { position: sticky; bottom: calc(-22px - env(safe-area-inset-bottom)); margin: 14px -18px calc(-22px - env(safe-area-inset-bottom)); padding: 10px 18px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); z-index: 2; }
.sheetin h3 { margin-bottom: 6px; }
.view-pad { padding-bottom: 8px; }
.btn.link { min-width: 44px; }

/* Wi-Fi sniffer + CSI motion */
.card.motion .mrow { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.card.motion .mrow strong { flex: 1; }
.mdot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.mdot.still { background: #2f9e61; }
.mdot.motion { background: #e5484d; box-shadow: 0 0 0 4px rgba(229, 72, 77, .25); animation: mpulse 1.2s infinite; }
.mdot.cal { background: #d9a400; }
@keyframes mpulse { 50% { box-shadow: 0 0 0 8px rgba(229, 72, 77, 0); } }
.pill.m-still { background: rgba(47, 158, 97, .15); color: #2f9e61; }
.pill.m-motion { background: rgba(229, 72, 77, .15); color: #e5484d; }
.pill.m-cal { background: rgba(217, 164, 0, .18); color: #a67c00; }
.pill.m-off { background: var(--soft); color: var(--muted); }
svg.mchart line.thr { stroke: #e5484d; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; opacity: .7; }
.mfoot { margin-top: 8px; }
.walksteps { padding-left: 20px; margin: 12px 0; line-height: 1.45; }
.walkclock { font-size: 44px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0; }
.card.verdict.detected { border-color: #2f9e61; }
.card.verdict.none { border-color: #e5484d; }
.heardbox { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--soft); border-left: 4px solid var(--muted); }
.heardbox.near { border-left-color: var(--accent); }
.heardnone { margin-top: 8px; }
.heardtag { font-size: 12px; color: var(--accent); font-weight: 600; padding: 0 12px 8px; }
.tile .tmotion { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; border-radius: 999px; padding: 0 6px; border: 1px solid #2f9e61; color: #2f9e61; }
.tile .tmotion.motion { border-color: #e5484d; color: #e5484d; font-weight: 700; }
