:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --ink: #0b1d2e;
  --muted: #5b6b7b;
  --line: #e2e7ec;
  --brand: #0b1d2e;
  --live: #0d9488;
  --live-soft: #ccfbf1;
  --sos: #d62828;
  --sos-soft: #fde2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --chip: #eef2f5;
  --shadow: 0 1px 2px rgb(11 29 46 / .06), 0 4px 16px rgb(11 29 46 / .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07131f; --card: #0f2133; --ink: #e8eef4; --muted: #93a4b5; --line: #1f3447;
    --brand: #e8eef4; --live: #2dd4bf; --live-soft: #0f3b3a; --sos: #f05252; --sos-soft: #3d1416;
    --warn: #fbbf24; --warn-soft: #3a2a08; --chip: #172c40; --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #07131f; --card: #0f2133; --ink: #e8eef4; --muted: #93a4b5; --line: #1f3447;
  --brand: #e8eef4; --live: #2dd4bf; --live-soft: #0f3b3a; --sos: #f05252; --sos-soft: #3d1416;
  --warn: #fbbf24; --warn-soft: #3a2a08; --chip: #172c40; --shadow: 0 1px 2px rgb(0 0 0 / .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
a { color: var(--live); }
.boot { height: 100vh; display: grid; place-items: center; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 500; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
}
.top h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -.01em; flex: 1; }
.top .back { border: 0; background: var(--chip); width: 38px; height: 38px; border-radius: 50%; font-size: 20px; cursor: pointer; }
.wrap { padding: 0 16px; max-width: 640px; width: 100%; margin: 0 auto; }

.logo { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0; cursor: pointer; user-select: none; -webkit-user-select: none; }
.logo-mark { width: 30px; height: 30px; border-radius: 50%; background: radial-gradient(circle, var(--bg) 0 22%, #2dd4bf 23% 46%, transparent 47% 58%, rgb(45 212 191 / .45) 59% 66%, transparent 67%); background-color: #0b1d2e; }
.logo-mark.big { width: 72px; height: 72px; background: radial-gradient(circle, #0b1d2e 0 20%, #2dd4bf 21% 42%, transparent 43% 56%, rgb(45 212 191 / .5) 57% 63%, transparent 64% 78%, rgb(45 212 191 / .25) 79% 84%, transparent 85%); background-color: #0b1d2e; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 600; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.nav a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: 12px; padding: 6px 0; border-radius: 12px; position: relative; }
.nav a svg { display: block; margin: 0 auto 2px; width: 24px; height: 24px; }
.nav a.on { color: var(--ink); font-weight: 600; }
.nav .dot { position: absolute; top: 4px; left: calc(50% + 8px); width: 9px; height: 9px; border-radius: 50%; background: var(--sos); }

/* ---------- pieces ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--chip); font-size: 13px; white-space: nowrap; }
.chip.live { background: var(--live-soft); color: var(--live); font-weight: 600; }
.chip.sos { background: var(--sos-soft); color: var(--sos); font-weight: 700; }
.chip.warn { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 currentColor; } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 600; cursor: pointer; background: var(--brand); color: var(--bg); text-decoration: none; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: var(--sos); color: #fff; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
label.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }
input.in { width: 100%; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 13px 14px; outline: none; }
input.in:focus { border-color: var(--live); }
input.code { letter-spacing: .6em; font-size: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.err { color: var(--sos); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: 16px; }

/* ---------- map ---------- */
.map { height: 42vh; min-height: 260px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 12px; background: #dfe7ee; position: relative; z-index: 1; }
.map.tall { height: 52vh; }
:root[data-theme="dark"] .map, :root:not([data-theme="light"]) .map { background: #0c1a28; }
.leaflet-container { font: inherit; background: transparent; }
.pin { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 8px rgb(0 0 0 / .35); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; }
.pin.stale { filter: grayscale(.7); opacity: .8; }
.pin.sos { border-color: var(--sos); animation: ring 1.2s infinite; }
.pin.warn { border-color: #f59e0b; animation: ring-w 1.2s infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgb(214 40 40 / .7); } 100% { box-shadow: 0 0 0 18px rgb(214 40 40 / 0); } }
@keyframes ring-w { 0% { box-shadow: 0 0 0 0 rgb(245 158 11 / .7); } 100% { box-shadow: 0 0 0 18px rgb(245 158 11 / 0); } }
.map-badge { position: absolute; z-index: 800; left: 10px; top: 10px; }

/* ---------- people ---------- */
.person { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.person:first-child { border-top: 0; }
.person .name { font-weight: 600; }
.person .place { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; padding: 28px 12px; }
.empty .logo-mark { margin: 0 auto 12px; }

.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.banner.sos { background: var(--sos); color: #fff; }
.banner.warn { background: var(--warn-soft); color: var(--ink); border: 2px solid #f59e0b; }
.banner > b:first-child { display: block; font-size: 17px; margin-bottom: 2px; }
.banner .btn { margin-top: 10px; }
.banner.sos .btn { background: #fff; color: var(--sos); }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fact { background: var(--chip); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.fact .k { font-size: 12px; color: var(--muted); }
.fact .v { font-weight: 600; overflow-wrap: anywhere; }
.fact.wide { grid-column: 1 / -1; }

/* ---------- SOS button ---------- */
.sos-wrap { position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 700; display: flex; flex-direction: column; align-items: center; }
.sos-wrap .hint { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--card); padding: 2px 8px; border-radius: 999px; margin-top: 6px; box-shadow: var(--shadow); }
.home-pad { height: 120px; }
.sos-btn {
  width: 84px; height: 84px; border-radius: 50%; border: 0; cursor: pointer; position: relative;
  background: var(--sos); color: #fff; font-weight: 800; font-size: 22px; letter-spacing: .04em;
  box-shadow: 0 8px 24px rgb(214 40 40 / .35); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.sos-btn svg { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); transform: rotate(-90deg); pointer-events: none; }
.sos-btn circle { fill: none; stroke: var(--sos); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 440; stroke-dashoffset: 440; }
.sos-btn.holding circle { transition: stroke-dashoffset 2s linear; stroke-dashoffset: 0; }
.sos-btn.holding { transform: scale(.96); }

/* ---------- toggles ---------- */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 30px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgb(0 0 0 / .3); }
.switch input:checked + span { background: var(--live); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--live); outline-offset: 2px; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list-row:first-of-type { border-top: 0; }
.list-row button.link { background: none; border: 0; color: var(--live); font-weight: 600; cursor: pointer; padding: 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; font-weight: 600; }
.seg { display: inline-flex; background: var(--chip); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); font-weight: 600; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: calc(24px + env(safe-area-inset-top)) 20px 32px; max-width: 440px; margin: 0 auto; }
.auth h2 { font-size: 28px; margin: 16px 0 4px; letter-spacing: -.02em; }
.tabs { display: flex; background: var(--chip); border-radius: 12px; padding: 4px; margin: 20px 0; }
.tabs button { flex: 1; border: 0; background: none; padding: 10px; border-radius: 9px; font-weight: 600; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.note { background: var(--chip); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.note.warn { background: var(--warn-soft); }

/* ---------- modal + toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 2000; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 480px; border-radius: 20px 20px 0 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0 0 6px; font-size: 20px; }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }
#toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 3000; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

.offline-bar { background: var(--warn-soft); color: var(--ink); font-size: 13px; padding: 8px 16px; text-align: center; }
