:root {
  --accent: #2f6fed;
  --accent-ink: #fff;
  --ink: #1d2433;
  --muted: #6b7280;
  --bg: #f6f7fb;
  --card: #fff;
  --line: #e4e7ee;
  --ok: #1a7f37;
  --warn: #b7791f;
  --bad: #c0392b;
  --grey: #9aa3b2;
  --radius: 14px;
  --nav-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root { --ink: #eef1f6; --muted: #a0a8b8; --bg: #0f1218; --card: #181c25; --line: #2a3040; --grey: #6c7686; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
  min-height: 100vh; padding-bottom: env(safe-area-inset-bottom);
}
body.has-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); }
main { max-width: 480px; margin: 0 auto; padding: 8px 16px 24px; }
h1 { font-size: 1.5rem; margin: 12px 0; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
p { margin: 8px 0; }
a { color: var(--accent); }
code { font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.top { max-width: 480px; margin: 0 auto; padding: 14px 16px 0; display: flex; align-items: center; min-height: 44px; }
.brand { font-weight: 800; font-size: 1.15rem; color: inherit; text-decoration: none; }
.back { text-decoration: none; font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; }
.env { position: fixed; top: 0; right: 0; background: #d97706; color: #fff; font-size: .7rem; padding: 2px 8px; border-radius: 0 0 0 8px; z-index: 20; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.card.empty { text-align: center; padding: 24px 16px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.phone { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-height: 72px; }
.phone .name { font-size: 1.1rem; display: block; }
.phone .sub { display: block; font-size: .9rem; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-size: 1.5rem; flex: none; }
.chev { color: var(--grey); font-size: 1.6rem; }

input, select, button, textarea { font: inherit; }
input:not([type=radio]):not([type=checkbox]):not([type=hidden]), select {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
input:disabled { color: var(--muted); }
input.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.4rem; letter-spacing: .25em; text-transform: uppercase; text-align: center; }
label { display: block; font-size: .9rem; font-weight: 600; }
label > input, label > select { margin-top: 4px; font-weight: 400; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 18px;
  border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); }
button.x { background: none; border: 0; font-size: 1.6rem; line-height: 1; color: var(--muted); min-width: 44px; min-height: 44px; }

.flash { padding: 10px 14px; border-radius: 10px; margin: 10px 0; font-size: .95rem; }
.flash.error { background: #fdecea; color: #8a1c10; }
.flash.ok { background: #e6f4ea; color: #14532d; }
.banner { background: color-mix(in srgb, var(--accent) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; font-weight: 600; }
.pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--grey); flex: none; }
.pill.connected { color: var(--ok); } .pill.connected .dot { background: var(--ok); }
.pill.fetched { color: var(--warn); } .pill.fetched .dot { background: var(--warn); }
.pill.offline { color: var(--muted); } .pill.offline .dot { background: var(--grey); }
.pill.waiting { color: var(--muted); } .pill.waiting .dot { background: var(--grey); animation: pulse 1.6s infinite; }
.pill.big { font-size: 1.15rem; padding: 14px; border-radius: 12px; background: var(--bg); width: 100%; justify-content: center; margin: 12px 0; }
.pill.big .dot { width: 14px; height: 14px; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pill .dot { animation: none !important; } }

.hero { text-align: center; padding: 24px 0 8px; }
.logo { font-size: 3rem; line-height: 1; }
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 8px 0 16px; counter-reset: s; }
.steps li { flex: 1; text-align: center; font-size: .8rem; color: var(--muted); padding-top: 8px; border-top: 4px solid var(--line); }
.steps li[aria-current] { color: var(--accent); border-color: var(--accent); font-weight: 700; }
.steps li.done { border-color: var(--ok); color: var(--ok); }

.ports { margin: 12px 0; }
.ports .box { background: #eef1f7; border: 2px solid #c9d0dd; border-radius: 10px; height: 84px; display: flex; justify-content: space-around; align-items: center; padding: 0 8px; color: #1d2433; }
.port { font-size: .75rem; font-weight: 700; padding: 6px 10px; border-radius: 6px; border: 2px solid #1d2433; background: #fff; }
.port.lan { border-color: var(--accent); color: var(--accent); }
.port.phone { border-color: var(--ok); color: var(--ok); }
.port.pwr { border-color: #111; }
.ports ol { padding-left: 20px; margin: 10px 0 0; }
.trouble { margin: 8px 0; } .trouble summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }

.phone-head h1 { display: inline; margin: 0; }
.rename summary { list-style: none; cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.rename summary::-webkit-details-marker { display: none; }
.rename .edit { font-size: 1rem; margin-left: 6px; }
.rename form { margin: 8px 0; align-items: flex-end; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.key {
  min-height: 92px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px 6px; position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.key:active { transform: translateY(1px); }
.key.empty { border: 2px dashed var(--line); background: transparent; box-shadow: none; }
.key .digit { font-size: 2rem; font-weight: 800; line-height: 1; }
.key .label { font-size: .9rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key .plus { font-size: 1.4rem; color: var(--grey); }
.key .ico { position: absolute; top: 6px; right: 8px; font-size: .8rem; opacity: .7; }
.key.filled { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

.sheet { border: 0; border-radius: 18px 18px 0 0; padding: 0; width: 100%; max-width: 480px; margin: auto auto 0; background: var(--card); color: var(--ink); }
.sheet::backdrop { background: rgba(0,0,0,.45); }
.sheet-body { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-body h2 { margin: 6px 0; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { flex: 1; text-align: center; padding: 10px 6px; border-radius: 8px; font-weight: 600; font-size: .9rem; cursor: pointer; min-height: 40px; }
.seg input:checked + label { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.12); color: var(--accent); }
.seg input:focus-visible + label { outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); }
.panel { display: none; }
.slot-form:has(#k-device:checked) .panel-device, .slot-form:has(#k-device:checked) .panel-label,
.slot-form:has(#k-mobile:checked) .panel-mobile, .slot-form:has(#k-mobile:checked) .panel-label,
.slot-form:has(#k-clear:checked) .panel-clear { display: block; }
.group { margin: 10px 0 4px; }
.opt { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; }
.opt input { width: 20px; height: 20px; }

.danger { margin-top: 24px; }
.danger summary { color: var(--muted); cursor: pointer; min-height: 44px; display: flex; align-items: center; }

.t { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 8px; }
.t th, .t td { text-align: left; padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.t th { color: var(--muted); font-weight: 600; border-top: 0; }

.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: space-around; z-index: 10;
}
.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; color: var(--muted); text-decoration: none; font-weight: 600; }
.bottom a .ico { font-size: 1.3rem; line-height: 1; }
.bottom a[aria-current] { color: var(--accent); }
