:root, [data-theme="dark"] {
  --bg: #0f1115;
  --card: #181b22;
  --card-2: #20242d;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --good: #2ec27e;
  --warn: #f5c211;
  --bad: #ff5d5d;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f5f7;
  --card: #ffffff;
  --card-2: #eef0f4;
  --line: #dde1e8;
  --text: #14171c;
  --muted: #5f6878;
  --accent: #2f6fe4;
  --good: #1a9a5c;
  --warn: #b98a00;
  --bad: #d63a3a;
  --shadow: 0 1px 2px rgba(20, 23, 28, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 1000;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { margin: 0; font-size: 1.05rem; font-weight: 650; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-btn { width: 44px; height: 44px; border: 0; background: none; border-radius: 12px;
  display: grid; place-items: center; cursor: pointer; }
.bar-btn:active { background: var(--card-2); }
.bar-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--text); stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
#menu { grid-column: 3; }

main { max-width: 640px; margin: 0 auto; padding: 14px 16px calc(env(safe-area-inset-bottom) + 28px); }

/* ---------- generic ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); }
.list { display: grid; gap: 10px; }
.tap { cursor: pointer; transition: transform .08s ease; text-decoration: none; color: inherit; display: block; }
.tap:active { transform: scale(.985); }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.empty { color: var(--muted); text-align: center; padding: 40px 12px; }
.section { margin: 22px 4px 8px; font-size: .78rem; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); }
.section:first-child { margin-top: 4px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card-2); font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.error { color: var(--bad); margin: 12px 4px; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px;
  border-radius: 12px; font-weight: 600; z-index: 2000; max-width: 90vw; }

/* ---------- people ---------- */
.person { padding: 14px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 1.25rem; color: #fff; background: var(--c, var(--accent)); position: relative; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.5rem; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--good); border: 3px solid var(--card); }
.avatar .dot.moving { background: var(--warn); }
.avatar .dot.stale { background: var(--muted); }
.name { font-weight: 650; font-size: 1.08rem; }
.status { margin-top: 2px; }
.status b { font-weight: 600; }
.meta { display: flex; gap: 10px; align-items: center; font-size: .82rem; color: var(--muted); margin-top: 4px; }
.battery { display: inline-flex; align-items: center; gap: 4px; }
.battery i { width: 20px; height: 10px; border: 1.5px solid currentColor; border-radius: 3px; position: relative;
  display: inline-block; }
.battery i::after { content: ""; position: absolute; left: 1px; top: 1px; bottom: 1px;
  width: calc((100% - 2px) * var(--lvl, 1)); background: currentColor; border-radius: 1px; }
.battery.low { color: var(--bad); }
.chev { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; }

.pill.unc { color: var(--warn); }
.note { padding: 12px 14px; margin: 10px 0 4px; color: var(--muted); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }

/* ---------- weather ---------- */
.wx { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; }
.wx img { width: 18px; height: 18px; }
.wxcard { padding: 14px; margin: 10px 0 4px; }
.wxcard img.big { width: 48px; height: 48px; flex: none; }
.wx-temp { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.wx-bits { text-align: right; line-height: 1.45; }
.hours { display: flex; gap: 4px; overflow-x: auto; margin: 12px -14px -4px; padding: 2px 14px 4px;
  scroll-snap-type: x proximity; scrollbar-width: none; }
.hours::-webkit-scrollbar { display: none; }
.hour { flex: none; width: 54px; text-align: center; scroll-snap-align: start; }
.hour img { width: 28px; height: 28px; margin: 4px 0 2px; }
.hour .t { font-weight: 600; font-variant-numeric: tabular-nums; }
.hour .rain { color: var(--accent); }

/* ---------- person page ---------- */
.hero { padding: 16px; margin-bottom: 4px; }
.hero .status { font-size: 1.05rem; }
.trip { padding: 14px 14px 12px; }
.trip .times { font-weight: 650; font-variant-numeric: tabular-nums; }
.trip .route { margin-top: 3px; }
.trip .stats { display: flex; gap: 14px; margin-top: 8px; font-size: .86rem; color: var(--muted);
  font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.trip .stats b { color: var(--text); font-weight: 600; }
.live { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .05em; color: #111;
  background: var(--warn); border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: 2px; }

/* ---------- trip page ---------- */
.map { height: 58vh; min-height: 280px; border-radius: 16px; overflow: hidden; border: 1px solid var(--line);
  background: var(--card-2); }
[data-theme="dark"] .map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
.map .leaflet-control-attribution { font-size: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.stat { padding: 12px 14px; }
.stat .k { font-size: .78rem; color: var(--muted); }
.stat .v { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .s { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.legend { display: flex; gap: 12px; justify-content: center; font-size: .78rem; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 16px; height: 4px; border-radius: 2px; display: inline-block; background: var(--c); }
.pin { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.pin.start { background: var(--good); }
.pin.end { background: var(--bad); }
.gm-html { position: absolute; }
.gm-html.centered { transform: translate(-50%, -50%); }
.gm-html.above { transform: translate(-50%, calc(-100% - 8px)); }
.speed-tag { background: #111; color: #fff; font-weight: 700; font-size: 12px; padding: 2px 6px; border-radius: 8px;
  white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.4); }

/* ---------- bottom tabs ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; display: flex;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 6px); }
.tabs a { flex: 1; display: grid; justify-items: center; gap: 2px; color: var(--muted); text-decoration: none;
  font-size: .72rem; font-weight: 600; padding: 4px 0; }
.tabs a.on { color: var(--accent); }
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body.has-tabs main { padding-bottom: calc(env(safe-area-inset-bottom) + 90px); }

/* ---------- cameras ---------- */
.seg.wide { display: flex; margin-bottom: 12px; }
.seg.wide button { flex: 1; padding: 8px 10px; font-size: .92rem; }
.cams { gap: 12px; }
.cam { position: relative; border-radius: 16px; overflow: hidden; background: #000; min-height: 120px;
  border: 1px solid var(--line); }
.cam img { display: block; width: 100%; height: auto; }
.cam-label { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between;
  align-items: flex-end; gap: 8px; padding: 22px 12px 10px; color: #fff; font-weight: 650;
  background: linear-gradient(transparent, rgba(0, 0, 0, .72)); }
.cam-label .small { font-weight: 500; opacity: .85; }
.cam-off { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 700;
  background: rgba(0, 0, 0, .55); }
.player { position: relative; background: #000; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.player video { display: block; width: 100%; max-height: 62vh; background: #000; }
.player-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 600;
  background: rgba(0, 0, 0, .45); text-align: center; padding: 16px; cursor: pointer; }
.controls { margin: 10px 0; gap: 8px; flex-wrap: wrap; }
.controls .btn { min-height: 40px; padding: 0 14px; }
.center { text-align: center; }
.alert { padding: 10px; gap: 12px; align-items: flex-start; }
.alert .thumb { width: 104px; height: 58px; object-fit: cover; border-radius: 10px; background: #000; flex: none; }
.alert .desc, p.desc { color: var(--muted); margin: 4px 0 0; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; }
p.desc { -webkit-line-clamp: unset; color: var(--text); }
.new-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  margin-left: 6px; vertical-align: 1px; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 10px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 12px; font-size: .86rem; cursor: pointer; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.timeline { position: relative; height: 54px; margin: 6px 0 4px; background: var(--card-2); border-radius: 10px;
  border: 1px solid var(--line); cursor: pointer; overflow: hidden; touch-action: manipulation; }
.timeline .span { position: absolute; top: 8px; height: 22px; background: color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 3px; min-width: 2px; }
.timeline .mark { position: absolute; top: 4px; width: 2px; height: 30px; background: var(--warn); }
.timeline .mark.alert { background: var(--bad); }
.timeline .head { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); }
.timeline .hr { position: absolute; bottom: 3px; font-size: .68rem; color: var(--muted); transform: translateX(2px); }
.timeline .sel { position: absolute; top: 2px; bottom: 2px; background: color-mix(in srgb, var(--good) 35%, transparent);
  border: 1px solid var(--good); border-radius: 4px; }
a.btn { text-decoration: none; color: inherit; }
.clip { width: 100%; background: none; border: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.cam-ico { background: var(--card-2); color: var(--text); }
.cam-ico svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; }

/* ---------- sign in ---------- */
.hello { text-align: center; padding: 12vh 12px 0; }
.hello img { width: 88px; height: 88px; border-radius: 22px; }
.hello h2 { margin: 18px 0 6px; font-size: 1.6rem; }
.hello p { color: var(--muted); margin: 0 0 28px; }
.hello .btn { max-width: 340px; margin: 0 auto; }

/* ---------- admin ---------- */
.setting { padding: 12px 14px; display: flex; align-items: center; gap: 12px; }
.setting + .setting { border-top: 1px solid var(--line); }
.stack > .setting { border-radius: 0; }
select, input[type="text"] { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; }
input[type="text"] { width: 100%; }
.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: none; padding: 6px 10px; border-radius: 8px; font-size: .84rem; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.seg button.on.allow { color: var(--good); }
.seg button.on.deny { color: var(--bad); }
.pill { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--card-2);
  color: var(--muted); }
.pill.yes { color: var(--good); }
.pill.no { color: var(--bad); }
.linkbox { word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem;
  background: var(--card-2); border-radius: 10px; padding: 10px; margin: 10px 0; user-select: all; }
.audit { font-size: .86rem; padding: 10px 14px; }
.audit + .audit { border-top: 1px solid var(--line); }
form.stackform { display: grid; gap: 10px; padding: 14px; }

/* Jelly (Jellyfin/Moonfin) button at the top of the family list */
.card.jelly { margin-bottom: 14px; }
.jelly-ic { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent); flex: none; }
.jelly-ic svg { width: 26px; height: 26px; fill: none; stroke: #fff; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
