:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #15181d;
  --muted: #646b76;
  --line: #dde0e5;
  --accent: #d9822b;
  --accent-text: #ffffff;
  --on: #e8a33d;
  --on-bg: #fdf1dc;
  --off-bg: #eceef1;
  --danger: #c0392b;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1d2128;
    --text: #e9ebee;
    --muted: #98a0ab;
    --line: #2c323b;
    --accent: #e8a33d;
    --accent-text: #1a1206;
    --on: #f0b44f;
    --on-bg: #3a2c14;
    --off-bg: #262b33;
    --danger: #ef6b5b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.6rem 0 .6rem; }

.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: calc(.8rem + env(safe-area-inset-top)) 16px .8rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.2rem; }
.sun { font-size: .9rem; text-align: right; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px 2rem; }
.view.center { text-align: center; padding-top: 18vh; }
.view.center .field { text-align: left; }

button {
  font: inherit; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: .6rem 1rem; border-radius: 10px;
  min-height: 44px;
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.big { width: 100%; max-width: 340px; padding: .9rem; font-size: 1.05rem; margin-top: 1rem; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); background: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.msg { min-height: 1.4em; color: var(--danger); }

.tabs {
  position: sticky; top: 3.2rem; z-index: 1;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: var(--off-bg); padding: 4px; border-radius: 12px; margin: 1rem 0;
}
.tabs button { border: 0; background: transparent; min-height: 40px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card, .list > li {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.list.compact > li { padding: 8px 12px; font-size: .9rem; }

.dev { display: flex; align-items: center; gap: 12px; }
.dev .info { flex: 1; min-width: 0; }
.dev .name { font-weight: 600; overflow-wrap: anywhere; }
.dev .sub { font-size: .85rem; color: var(--muted); }
.dev.is-on { border-color: var(--on); background: var(--on-bg); }
.dev .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--line); flex: none; }
.dev.is-on .dot { background: var(--on); box-shadow: 0 0 10px var(--on); }

.onoff { display: flex; flex: none; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.onoff button { border: 0; border-radius: 0; min-width: 52px; padding: .5rem .7rem; background: var(--surface); }
.onoff button + button { border-left: 1px solid var(--line); }
.onoff button.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.door .state { font-weight: 600; }
.door.open .state { color: var(--danger); }

.sched { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.sched .info { flex: 1; min-width: 0; }
.sched .name { font-weight: 600; }
.sched .sub { font-size: .9rem; color: var(--muted); }
.sched.disabled .info { opacity: .55; }
#btn-new-schedule { margin-top: 12px; width: 100%; }

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

.pk { display: flex; align-items: center; gap: 8px; }
.pk .info { flex: 1; min-width: 0; }
.pk .sub { font-size: .85rem; color: var(--muted); }
.invite { margin-top: 10px; display: grid; gap: 8px; }
.invite p { margin: 0; }
#btn-invite, #btn-logout { margin-top: 10px; }
#btn-logout { width: 100%; }

.field { display: grid; gap: 4px; margin: 10px 0; font-size: .9rem; color: var(--muted); }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; min-height: 44px; width: 100%;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 0; padding: 0; margin: 12px 0; min-width: 0; }
legend { font-size: .9rem; color: var(--muted); padding: 0; margin-bottom: 6px; }
.seg, .days { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label, .days label { position: relative; }
.seg input, .days input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span, .days span {
  display: inline-block; padding: .45rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.seg input:checked + span, .days input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.seg input:focus-visible + span, .days input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.checks { display: grid; gap: 4px; }
.check { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--accent); }

dialog {
  width: min(560px, calc(100vw - 16px)); max-height: calc(100dvh - 16px);
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--text); padding: 16px;
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { margin-top: 0; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.actions .spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; max-width: calc(100vw - 32px);
  z-index: 10;
}
