:root {
  --bg: #FEFCF8;
  --card: #FFFFFF;
  --ink: #2F3A33;
  --ink-2: #5E6B62;
  --ink-3: #8C968F;
  --line: #E8E1D4;
  --soft: #F1EBDF;
  --accent: #B8704B;
  --accent-soft: #F4E3D8;
  --ok: #3E7A55;
  --ok-soft: #E1EEE5;
  --warn: #A2572F;
  --radius: 18px;
  --tabs-h: 64px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  min-height: 100dvh;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--line) 60%, transparent);
}
.logo { height: 46px; width: auto; display: block; }
.lang {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; font-weight: 600; color: var(--ink-2);
}

main { max-width: 640px; margin: 0 auto; padding: 4px 16px 16px; }
h1 { font-size: 26px; margin: 8px 0 14px; letter-spacing: -0.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin: 24px 4px 8px; font-weight: 600; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 1px 0 var(--line), 0 6px 20px rgba(47, 58, 51, 0.05);
  margin-bottom: 12px;
}
.card.flush { padding: 4px 0; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 60px;
}
.row + .row { border-top: 1px solid var(--soft); }
.row .name { flex: 1; min-width: 0; }
.row .name b { display: block; font-weight: 600; }
.row .name span { font-size: 13px; color: var(--ink-3); }
.icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--soft); color: var(--ink-2); flex: none; }
.icon svg { width: 20px; height: 20px; }
.icon.on { background: var(--accent-soft); color: var(--accent); }

.banner { border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; background: var(--accent-soft); color: var(--warn); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }

.btn {
  appearance: none; border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600;
  background: var(--soft); color: var(--ink); cursor: pointer; min-height: 46px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn svg { width: 18px; height: 18px; }
.btns { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.seg { display: flex; gap: 6px; }
.seg .btn { min-height: 40px; padding: 8px 12px; border-radius: 12px; }

/* switch */
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }

input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; }
.slider { padding: 0 16px 14px 66px; margin-top: -6px; }

/* climate stepper */
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .btn { width: 40px; min-height: 40px; padding: 0; border-radius: 12px; font-size: 20px; }
.stepper output { min-width: 58px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* door */
.door { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.door .icon { width: 56px; height: 56px; border-radius: 18px; }
.door .icon svg { width: 28px; height: 28px; }
.door b { font-size: 20px; display: block; }
.door.unlocked .icon { background: var(--accent-soft); color: var(--accent); }
.door.locked .icon { background: var(--ok-soft); color: var(--ok); }

.cam { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 12px; background: var(--soft); display: block; }
.cam.big { position: fixed; inset: 0; z-index: 30; width: 100vw; height: 100dvh; object-fit: contain; background: #000; border-radius: 0; aspect-ratio: auto; }

.scenes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.scenes .btn { flex-direction: column; font-size: 13px; padding: 12px 4px; min-height: 76px; gap: 6px; background: var(--card); box-shadow: 0 1px 0 var(--line), 0 4px 14px rgba(47,58,51,.05); }
.scenes .btn svg { width: 22px; height: 22px; color: var(--accent); }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--ink-3); text-decoration: none; padding: 4px 0;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a[aria-current=page] { color: var(--accent); }

/* info */
details.card { padding: 0; }
details.card summary { list-style: none; padding: 16px; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "+"; color: var(--ink-3); font-weight: 400; font-size: 20px; line-height: 1; }
details.card[open] summary::after { content: "–"; }
details.card .md { padding: 0 16px 16px; color: var(--ink-2); }
.md p { margin: 0 0 10px; }
.md ul { margin: 0 0 10px; padding-left: 20px; }
.md li { margin-bottom: 4px; }
.md b { color: var(--ink); }

/* login */
.hero { text-align: center; padding: 28px 8px 8px; }
.hero img { width: 120px; height: 120px; }
.hero h1 { margin-top: 20px; }
.field { display: block; margin: 12px 0; text-align: left; }
.field span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.check { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* admin */
.user .devices { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
.user .devices div { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.linkbox { word-break: break-all; font-size: 13px; background: var(--soft); padding: 10px; border-radius: 10px; margin: 8px 0; user-select: all; }
.log { font-size: 13px; }
.log div { padding: 6px 0; border-top: 1px solid var(--soft); }
.log time { color: var(--ink-3); margin-right: 6px; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--ink-2); margin-left: 6px; vertical-align: 2px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--accent-soft); color: var(--warn); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
[hidden] { display: none !important; }

/* wifi */
.gap { height: 12px; }
.wifi .kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--soft); }
.wifi .kv span { color: var(--ink-3); }
.wifi .kv b { text-align: right; word-break: break-all; }
.wifi .pw { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.wifi > .btn { margin-top: 12px; }
.wifi .qr { width: 220px; max-width: 70%; margin: 16px auto 8px; }
.wifi .qr svg { width: 100%; height: auto; display: block; }
.mt { margin-top: 10px; }
.row.bare { padding: 0; }
a.btn { text-decoration: none; }
.logo-link { display: flex; }

/* v2: compact buttons, floors, live camera, admin edit */
.btns { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.btns.three { grid-template-columns: repeat(3, 1fr); }
.btns.three .btn { font-size: 14px; padding: 10px 6px; line-height: 1.2; text-align: center; }
.btn { white-space: nowrap; }
.btns.three .btn, .scenes .btn { white-space: normal; }
.row .name b { overflow: hidden; text-overflow: ellipsis; }
.row .name span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper { flex: none; }
.stepper .btn { width: 36px; min-height: 36px; font-size: 18px; }
.stepper output { min-width: 52px; font-size: 15px; }
.seg { flex: none; gap: 4px; }
.seg .btn { width: 40px; padding: 0; }
.floor .head { cursor: default; }
.floor .head .name { cursor: pointer; }
.chev { appearance: none; border: 0; background: var(--soft); width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--ink-2); flex: none; cursor: pointer; }
.chev svg { width: 20px; height: 20px; transition: transform .15s; }
.floor.open .chev svg { transform: rotate(180deg); }
.floor .rooms { border-top: 1px solid var(--soft); background: color-mix(in srgb, var(--soft) 35%, var(--card)); border-radius: 0 0 var(--radius) var(--radius); }
.floor .rooms .row .icon { width: 32px; height: 32px; border-radius: 10px; }
.camcard { position: relative; }
.camcard .live { position: absolute; right: 26px; bottom: 26px; min-height: 36px; padding: 6px 12px; background: rgba(47,58,51,.8); color: #fff; font-size: 14px; }
.camcard .live.on { background: var(--accent); }
.camcard .live svg { width: 14px; height: 14px; fill: currentColor; }
video.cam { background: #000; }
.editform { margin-top: 12px; padding-top: 4px; border-top: 1px solid var(--soft); }
.user .btns { grid-template-columns: 1fr 1fr; }
.btns.three .btn svg { width: 16px; height: 16px; }
.wifi h3 { font-size: 15px; margin: 18px 0 8px; padding-top: 14px; border-top: 1px solid var(--soft); }
.wifi #ios, .wifi #saveQr { margin-top: 4px; }
