:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #5f6b67;
  --line: #e2e7e5;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --danger: #c2410c;
  --locked: #b91c1c;
  --unlocked: #15803d;
  --warn-bg: #fff7e6;
  --warn-line: #f5c26b;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --card: #17201d;
    --text: #e8eeec;
    --muted: #97a39f;
    --line: #26322e;
    --brand: #2dd4bf;
    --brand-ink: #062b27;
    --danger: #fb923c;
    --locked: #f87171;
    --unlocked: #4ade80;
    --warn-bg: #2b2412;
    --warn-line: #7a5a17;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom, 0px));
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
code { font-size: .9em; word-break: break-all; }
a { color: var(--brand); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; }
.topbar-actions { display: flex; gap: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { border-color: var(--line); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
}
label { display: block; margin: 12px 0; font-weight: 600; font-size: .9rem; }
label input, label select { margin-top: 6px; font-weight: 400; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.error { color: var(--danger); }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }

.login { display: grid; place-items: center; min-height: 60vh; }
.login-card { width: 100%; max-width: 380px; }

.empty { text-align: center; padding: 32px 18px; }
.empty p { color: var(--muted); }

.device-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; margin-top: 4px; flex-wrap: wrap; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status-dot.on { background: var(--unlocked); }
.battery:not(:empty)::before { content: "· "; }
.mode-badge {
  font-size: .75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.mode-badge.strong { color: var(--unlocked); border-color: currentColor; }

.pairing { text-align: center; padding-top: 8px; }
.pair-code {
  font: 700 2.4rem/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: .25em;
  margin: 12px 0 4px;
}

.lock-btn {
  width: 100%;
  margin-top: 16px;
  border: 0;
  border-radius: var(--radius);
  padding: 18px;
  font: 700 1.15rem/1 system-ui, sans-serif;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 64px;
}
.lock-btn.is-unlocked { background: var(--locked); }
.lock-btn.is-locked { background: var(--unlocked); }
@media (prefers-color-scheme: dark) { .lock-btn { color: #0e1412; } }
.lock-icon { font-size: 1.3rem; }
.lock-sync { text-align: center; margin: 8px 0 0; min-height: 1.2em; }

.section { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
details.section summary { cursor: pointer; font-weight: 700; list-style-position: inside; padding: 4px 0; }
details.section textarea { margin: 10px 0; }

.map {
  height: 240px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  z-index: 0;
}
.loc-text { margin: 8px 0 0; }

.contacts { list-style: none; padding: 0; margin: 10px 0; }
.contacts li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.contacts li:last-child { border-bottom: 0; }
.contacts .num { color: var(--muted); font-size: .9rem; }
.contacts .empty-row { color: var(--muted); font-style: italic; }
.contact-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
@media (max-width: 480px) {
  .contact-form { grid-template-columns: 1fr 1fr; }
  .contact-form .btn { grid-column: 1 / -1; }
}

.warnings:empty { display: none; }
.warnings {
  margin-top: 14px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .9rem;
}
.warnings ul { margin: 6px 0 0; padding-left: 20px; }

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  z-index: 2000;
  max-width: calc(100vw - 32px);
}
