/* Crow's Nest — calm, dark-first, cameras first.
   Night (dark) is the default; Day is a full palette of its own, not an inverted afterthought. */
:root,
:root[data-theme="dark"] {
  --bg: #000;
  --bg-blur: rgba(0, 0, 0, .72);
  --surface: #121214;
  --surface-2: #1c1c1e;
  --surface-3: #2c2c2e;
  --line: rgba(255, 255, 255, .09);
  --text: #f5f5f7;
  --text-2: #d1d1d6;
  --muted: #8e8e93;
  --faint: #48484a;
  --accent: #0a84ff;
  --accent-ink: #fff;
  --red: #ff453a;
  --amber: #ffd60a;
  --green: #30d158;
  --blue: #0a84ff;
  --tile: #0c0c0d;
  --shadow: none;
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .6);
  --scrim: rgba(0, 0, 0, .55);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2f2f7;
  --bg-blur: rgba(242, 242, 247, .78);
  --surface: #fff;
  --surface-2: #e9e9ee;
  --surface-3: #dcdce1;
  --line: rgba(60, 60, 67, .14);
  --text: #1c1c1e;
  --text-2: #3a3a3c;
  --muted: #6c6c70;
  --faint: #c7c7cc;
  --accent: #007aff;
  --accent-ink: #fff;
  --red: #ff3b30;
  --amber: #b26a00;
  --green: #248a3d;
  --blue: #007aff;
  --tile: #d8d8dd;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .05);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .18);
  --scrim: rgba(0, 0, 0, .32);
  color-scheme: light;
}
:root {
  --radius: 16px;
  --radius-sm: 12px;
  --gutter: 16px;
  --tabbar: 56px;
  --topbar: 52px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}
/* Gentle cross-fade when switching day/night */
:root.theme-anim, :root.theme-anim * {
  transition: background-color .35s ease, color .35s ease, border-color .35s ease, fill .35s ease !important;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  padding-top: calc(var(--topbar) + env(safe-area-inset-top));
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
body.locked { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, select, input { font: inherit; color: inherit; letter-spacing: inherit; }
button { -webkit-user-select: none; user-select: none; }
img, video { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
.ic { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.45; }
.center { text-align: center; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* Views fade in softly */
#main.enter { animation: enter .28s var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Splash */
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: url("/icons/icon.svg") center/cover no-repeat; }
.brand-mark.big { width: 72px; height: 72px; border-radius: 18px; }
#splash { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--bg); }
#splash .brand-mark { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .4; } }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--topbar) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  display: flex; align-items: center; gap: 2px;
  background: var(--bg-blur);
  -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8);
}
#topbar.has-back { padding-left: max(4px, env(safe-area-inset-left)); }
#topbar h1 {
  flex: 1; min-width: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#topbar.has-back h1 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
body.offline #topbar::after {
  content: "Reconnecting…"; position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + var(--topbar) + 6px); transform: translateX(-50%);
  background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 12px;
  box-shadow: var(--shadow);
}
.iconbtn {
  width: 42px; height: 42px; display: grid; place-items: center; flex: none;
  border: 0; background: transparent; border-radius: 21px; cursor: pointer; color: var(--text);
  transition: background .15s, transform .15s var(--ease);
}
.iconbtn:active { background: var(--surface-2); transform: scale(.94); }
.iconbtn.sm { width: 36px; height: 36px; }
.iconbtn:disabled { opacity: .28; }
#topbar [data-act="theme"] .ic { width: 21px; height: 21px; }

/* ---------- bottom tabs ---------- */
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex; justify-content: center;
  background: var(--bg-blur);
  -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8);
  border-top: .5px solid var(--line);
}
#tabs a {
  flex: 1; max-width: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 10.5px; font-weight: 600; letter-spacing: 0; position: relative;
  transition: color .2s;
}
#tabs a .ic { width: 23px; height: 23px; }
#tabs a.active { color: var(--text); }
.badge {
  position: absolute; top: 5px; left: calc(50% + 6px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 16px; text-align: center; font-style: normal;
}

/* ---------- generic blocks ---------- */
#main { min-height: calc(100vh - var(--topbar) - var(--tabbar)); }
.page { padding: 12px var(--gutter) 36px; max-width: 760px; margin: 0 auto; display: grid; gap: 28px; }
.block { display: grid; gap: 10px; min-width: 0; }
.block h2 { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; padding: 0 4px; }
.block h2.big { font-size: 24px; font-weight: 700; color: var(--text); letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; padding: 0; }
.block h2.big .lab { width: 24px; height: 24px; color: var(--muted); }
h3.sub { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 8px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 4px 16px; box-shadow: var(--shadow); }
.card > .row { min-height: 56px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.link { color: var(--accent); font-weight: 500; }
.hint { color: var(--muted); font-size: 12.5px; text-align: center; padding: 18px var(--gutter) 6px; }
.hint:empty { display: none; }
.note { display: flex; gap: 10px; align-items: flex-start; color: var(--text-2); font-size: 13.5px; padding: 12px 0; border-top: .5px solid var(--line); }
.note .ic { width: 18px; height: 18px; color: var(--amber); margin-top: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; cursor: pointer;
  background: var(--surface-2); border: 0; font-weight: 600; font-size: 15px;
  transition: transform .15s var(--ease), opacity .15s;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn .ic { width: 18px; height: 18px; }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.danger { color: var(--red); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.input {
  min-height: 48px; padding: 0 14px; border-radius: 12px; border: 0; background: var(--surface-2); width: 100%; min-width: 0;
  font-size: 16px;
}
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none; min-height: 36px; padding: 0 15px; border-radius: 18px; cursor: pointer;
  border: 0; background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .2s, color .2s, transform .15s var(--ease);
}
.chip:active { transform: scale(.96); }
.chip .ic { width: 15px; height: 15px; }
.chip.on { background: var(--text); color: var(--bg); }
.seg { display: flex; background: var(--surface-2); border-radius: 11px; padding: 2px; gap: 2px; }
.seg button {
  flex: 1; min-height: 34px; padding: 0 12px; white-space: nowrap; border: 0; border-radius: 9px; background: transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); transition: background .2s, color .2s;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }
:root[data-theme="dark"] .seg button.on { background: var(--surface-3); }
.seg.small button { min-height: 30px; font-size: 13px; }

/* ---------- switch rows ---------- */
.switches { display: grid; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; border-bottom: .5px solid var(--line); cursor: pointer;
}
.switch-row:last-child { border-bottom: 0; }
.switch-row > span { display: grid; gap: 1px; }
.switch-row small { color: var(--muted); font-size: 13px; }
.switch-row.big b { font-size: 16px; font-weight: 600; }
input[role="switch"] {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 51px; height: 31px; border-radius: 16px; background: var(--surface-3); position: relative; cursor: pointer; transition: background .25s;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .25); transition: transform .25s var(--ease);
}
input[role="switch"]:checked { background: var(--green); }
input[role="switch"]:checked::after { transform: translateX(20px); }
input[role="switch"]:disabled { opacity: .4; }

/* "Person now" pill */
.now {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px 0 8px; border-radius: 12px;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 12.5px; font-weight: 600;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.now i { width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: pulse 2s ease-in-out infinite; }
.now.off { padding-left: 10px; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------------- LIVE ---------------- */
.view-live { padding: 4px 12px 0; }
.favs, .cams { display: grid; gap: 8px; }
.favs { grid-template-columns: 1fr; margin-bottom: 8px; }
.cams { grid-template-columns: 1fr 1fr; }
.tile {
  position: relative; background: var(--tile); aspect-ratio: 16 / 9; overflow: hidden; cursor: pointer; border-radius: var(--radius);
  box-shadow: var(--shadow); isolation: isolate;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: transform .2s var(--ease);
}
.cams .tile { border-radius: var(--radius-sm); }
.tile img, .tile-video, .tile-video .live-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-video { opacity: 0; transition: opacity .5s; }
.tile.playing .tile-video { opacity: 1; }
.tile.stale img { opacity: .4; }
.tile:active { transform: scale(.985); }
.tile-over { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(transparent 62%, rgba(0, 0, 0, .45)); }
.tile-over .now { position: absolute; top: 10px; left: 10px; }
.tile-over .now.off { left: auto; right: 10px; }
.cam-label {
  position: absolute; left: 12px; bottom: 9px; color: #fff; font-size: 13px; font-weight: 600; letter-spacing: -.005em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}
.tile.big .cam-label { font-size: 15px; left: 14px; bottom: 11px; }
.live-foot { display: flex; justify-content: center; padding: 18px 0 0; }
.mode-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px 0 12px; border: 0; border-radius: 19px;
  background: var(--surface); color: var(--text-2); font-size: 14px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .15s var(--ease);
}
.mode-chip:active { transform: scale(.97); }
.mode-chip .ic { width: 17px; height: 17px; color: var(--muted); }
.mode-chip .ic.chev { width: 14px; height: 14px; }
.mode-chip b { color: var(--text); font-weight: 600; }
.view-live .hint { padding-top: 10px; }
@media (min-width: 700px) {
  .view-live { padding: 8px 20px 0; }
  .favs.n2, .favs.n3 { grid-template-columns: repeat(2, 1fr); }
  .cams { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1200px) {
  .favs.n3 { grid-template-columns: repeat(3, 1fr); }
  .cams { grid-template-columns: repeat(4, 1fr); }
}

/* ---------------- CAMERA ---------------- */
.player { position: relative; background: #000; width: 100%; aspect-ratio: 16 / 9; max-height: 75vh; overflow: hidden; }
.player .player-host, .player .live-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.player-status { position: absolute; inset: 0; display: grid; place-items: center; color: #aaa; font-size: 14px; pointer-events: none; }
.player-now { position: absolute; top: 12px; left: 12px; pointer-events: none; }
.player-bar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 2px;
  padding: 32px 6px 4px 14px; background: linear-gradient(transparent, rgba(0, 0, 0, .5)); color: #fff;
}
.player-bar .iconbtn { color: #fff; }
.player-bar .iconbtn:active { background: rgba(255, 255, 255, .15); }
.live-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .1em; }
.live-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: pulse 2s ease-in-out infinite; }
.stream-pick { background: rgba(0, 0, 0, .45); color: #fff; border: 0; border-radius: 8px; height: 30px; padding: 0 6px; }
.player:fullscreen { max-height: none; aspect-ratio: auto !important; }
.clip-player { display: grid; place-items: center; }
.clip-player video, .clip-player .snap { width: 100%; height: 100%; object-fit: contain; }
.play-over {
  position: absolute; width: 64px; height: 64px; border-radius: 32px; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .45); color: #fff; display: grid; place-items: center;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  transition: transform .15s var(--ease);
}
.play-over:active { transform: scale(.94); }
.play-over .ic { width: 26px; height: 26px; margin-left: 3px; fill: currentColor; }
.clip { width: 100%; border-radius: var(--radius-sm); background: #000; max-height: 60vh; }
.replay-pick { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.replay:empty { display: none; }
.replay { display: grid; gap: 8px; }
details.more { display: block; width: 100%; background: var(--surface); border-radius: var(--radius); padding: 0 16px; box-shadow: var(--shadow); }
details.more[open] { padding-bottom: 6px; }
.stat { font-size: 17px; font-weight: 600; }
details.more > summary {
  list-style: none; cursor: pointer; color: var(--text); font-weight: 500; font-size: 16px; min-height: 54px;
  display: flex; align-items: center; justify-content: space-between;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .25s var(--ease); margin-right: 4px; }
details.more[open] > summary::after { transform: rotate(45deg); }
details.more[open] > summary { border-bottom: .5px solid var(--line); }
.more-link { display: block; padding: 12px 0 0; font-size: 15px; }

/* PTZ */
.ptz { display: grid; gap: 12px; justify-items: center; }
.ptz-pad { display: grid; grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(3, 60px); grid-template-areas: ". up ." "left . right" ". down ."; gap: 6px; }
.ptz-b { border-radius: 30px; border: 0; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; touch-action: none; user-select: none; }
.ptz-b:active { background: var(--text); color: var(--bg); }
.ptz-b.up { grid-area: up; } .ptz-b.down { grid-area: down; } .ptz-b.left { grid-area: left; } .ptz-b.right { grid-area: right; }

/* ---------------- PLAYBACK ---------------- */
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.pb-cams { padding: 4px var(--gutter) 12px; margin: 0; }
.pb-player { aspect-ratio: 16 / 9; }
.pb-player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.pb-clock {
  position: absolute; left: 12px; top: 12px; pointer-events: none;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 11px;
  font-variant-numeric: tabular-nums; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.pb-controls { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 14px 12px 6px; }
.pb-controls .iconbtn { width: 46px; height: 46px; border-radius: 23px; }
.pb-controls .iconbtn b, .pb-speed { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pb-controls .iconbtn.big { width: 58px; height: 58px; border-radius: 29px; background: var(--text); color: var(--bg); margin: 0 6px; }
.pb-controls .iconbtn.big .ic { width: 24px; height: 24px; fill: currentColor; }
.live-dot { width: 7px; height: 7px; border-radius: 4px; background: var(--red); display: inline-block; }
.pb-day { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px var(--gutter) 4px 8px; }
.pb-daynav { display: flex; align-items: center; gap: 2px; }
.pb-day b { font-size: 17px; font-weight: 600; min-width: 112px; text-align: center; }
.live-chip { min-height: 32px; padding: 0 13px; font-size: 13px; }
.pb-wrap { position: relative; margin: 6px 0 0; }
.pb-strip {
  display: flex; overflow-x: auto; overflow-y: hidden; height: 96px; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
}
.pb-strip::-webkit-scrollbar { display: none; }
.pb-pad { flex: none; width: 50vw; }
.pb-day-track { flex: none; position: relative; height: 100%; background: var(--surface); }
.pb-tick { position: absolute; top: 0; height: 8px; width: 1px; background: var(--line); }
.pb-tick.hour { height: 16px; background: var(--faint); }
.pb-tick em { position: absolute; top: 18px; left: 5px; font-style: normal; font-size: 11px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.pb-layer { position: absolute; left: 0; right: 0; }
.pb-rec { top: 44px; height: 6px; }
.pb-rec i { position: absolute; top: 0; height: 100%; border-radius: 3px; background: color-mix(in srgb, var(--blue) 55%, transparent); }
.pb-motion { top: 54px; height: 10px; }
.pb-motion i { position: absolute; top: 0; width: 3px; height: 100%; border-radius: 1px; background: color-mix(in srgb, var(--amber) 65%, transparent); }
.pb-dots { top: 70px; height: 20px; }
.pb-dot { position: absolute; top: 2px; width: 14px; height: 14px; margin-left: -7px; border-radius: 7px; border: 2px solid var(--surface); background: var(--muted); padding: 0; cursor: pointer; }
.pb-dot.alert { background: var(--red); }
.pb-future { position: absolute; top: 0; bottom: 0; right: 0; background: repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--bg) 55%, transparent) 6px 12px); }
.pb-head { position: absolute; left: 50%; top: -4px; bottom: 0; width: 2px; margin-left: -1px; background: var(--text); border-radius: 1px; pointer-events: none; }
.pb-head span {
  position: absolute; top: 100%; margin-top: 6px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: var(--text); color: var(--bg); font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.view-playback .hint { padding-top: 10px; }
.pb-player .pb-main, .pb-player .pb-scrub, .pb-player .pb-scrub-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.pb-player .pb-scrub, .pb-player .pb-scrub-img { z-index: 1; }
.pb-player .pb-clock, .pb-player .player-status { z-index: 2; }
.pb-others { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 40px var(--gutter) 0; }
.pb-others::-webkit-scrollbar { display: none; }
.pb-mini {
  position: relative; flex: none; width: 108px; aspect-ratio: 4 / 3; padding: 0; border: 0; border-radius: 10px;
  overflow: hidden; background: var(--tile); cursor: pointer; box-shadow: var(--shadow);
  transition: transform .15s var(--ease);
}
.pb-mini video, .pb-mini img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.pb-mini span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 6px 4px; text-align: left;
  font-size: 10.5px; font-weight: 600; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .7));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pb-mini:active { transform: scale(.96); }

/* ---------------- DAY TIMELINE ---------------- */
.tl { display: grid; gap: 6px; user-select: none; -webkit-user-select: none; }
.tl-head { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.tl-head b { font-size: 17px; font-weight: 600; }
.tl-count { color: var(--muted); font-size: 13px; flex: 1; }
.tl-bar { position: relative; height: 34px; touch-action: none; cursor: ew-resize; }
.tl-track { position: absolute; left: 0; right: 0; top: 15px; height: 4px; border-radius: 2px; background: var(--surface-3); }
.tl-future { position: absolute; right: 0; top: 15px; height: 4px; background: repeating-linear-gradient(90deg, var(--surface-3) 0 3px, transparent 3px 6px); }
.tl-dot { position: absolute; top: 11px; width: 12px; height: 12px; margin-left: -6px; border-radius: 6px; background: var(--muted); border: 2px solid var(--bg); pointer-events: none; }
.tl-dot.alert { background: var(--text); }
.tl-dot.imp { background: var(--red); }
.tl-cursor { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--accent); pointer-events: none; }
.tl-cursor span {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 8px;
}
.tl-ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }

/* ---------------- EVENTS ---------------- */
.ev-top {
  position: sticky; top: calc(var(--topbar) + env(safe-area-inset-top)); z-index: 10;
  display: grid; gap: 12px; padding: 2px var(--gutter) 12px; background: var(--bg); max-width: 760px; margin: 0 auto;
}
.ev-top .seg { flex: 1; max-width: 300px; }
.ev-list { display: grid; max-width: 760px; margin: 0 auto; }
.ev-day { display: grid; }
.day-h {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  font-size: 20px; font-weight: 700; letter-spacing: -.02em; color: var(--text);
  padding: 22px var(--gutter) 8px;
}
.day-h span { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
/* the sticky day bar already names the first day */
.ev-day:first-child .day-h { display: none; }
.ev-day:first-child .day-empty { padding-top: 8px; }
.day-empty { padding: 4px var(--gutter) 10px; }
.hint.top { padding: 0 var(--gutter) 4px; max-width: 760px; margin: 0 auto; text-align: left; }
.ev-more { min-height: 40px; }
.ev-row { position: relative; overflow: hidden; touch-action: pan-y; }
.ev-swipe-bg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  color: #fff; font-weight: 600; font-size: 14px; opacity: 0; transition: opacity .15s;
  background: linear-gradient(90deg, var(--green) 50%, var(--blue) 50%);
}
.ev-row.swiping .ev-swipe-bg { opacity: 1; }
.ev-swipe-bg span { display: flex; align-items: center; gap: 6px; opacity: .55; transition: opacity .15s; }
.ev-swipe-bg.save-only { background: var(--blue); }
.ev-row.go-l .ev-swipe-bg span.l, .ev-row.go-r .ev-swipe-bg span.r { opacity: 1; }
.ev-front {
  position: relative; display: flex; gap: 14px; align-items: center; padding: 8px var(--gutter); background: var(--bg);
  transition: transform .3s var(--ease); -webkit-user-drag: none;
}
.ev-front:active { background: var(--surface); }
.ev-front::after { content: ""; position: absolute; left: calc(var(--gutter) + 126px); right: 0; bottom: 0; height: .5px; background: var(--line); }
.ev-day .ev-row:last-child .ev-front::after { display: none; }
.page .ev-front { padding-left: 0; padding-right: 0; background: transparent; }
.page .ev-front::after { left: 126px; }
.ev-thumbs { position: relative; width: 112px; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: var(--surface-2); flex: none; display: flex; gap: 1px; }
.ev-thumbs img { flex: 1; min-width: 0; height: 100%; object-fit: cover; }
.angles { position: absolute; right: 4px; bottom: 4px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.ev-text { min-width: 0; flex: 1; display: grid; gap: 2px; }
.ev-title { display: flex; align-items: center; gap: 7px; font-size: 16px; }
.ev-title b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-title .lab { width: 17px; height: 17px; color: var(--muted); }
.ev-sub { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-row.seen .ev-title b { font-weight: 400; color: var(--text-2); }
.ev-row.seen .ev-thumbs { opacity: .7; }
i.imp { width: 7px; height: 7px; border-radius: 4px; background: var(--red); flex: none; display: inline-block; }
.imp-note { display: flex; align-items: center; gap: 8px; color: var(--red); font-weight: 600; font-size: 14px; }
.summary { color: var(--text-2); font-size: 15px; line-height: 1.55; cursor: pointer; }
.summary.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.angles-pick { padding: 12px var(--gutter) 0; max-width: 760px; margin: 0 auto; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; }
.actions:has(> :nth-child(5)) { grid-template-columns: repeat(3, 1fr); }
.act {
  display: grid; justify-items: center; gap: 6px; padding: 14px 4px 12px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--surface); color: var(--text); font-size: 12.5px; font-weight: 500; box-shadow: var(--shadow);
  transition: transform .15s var(--ease);
}
.act:active { transform: scale(.96); }
.act .ic { width: 21px; height: 21px; }
.act.danger { color: var(--red); }

/* ---------------- SEARCH ---------------- */
.search-hero { display: grid; gap: 16px; padding: 4px var(--gutter) 18px; max-width: 760px; margin: 0 auto; }
.search { position: relative; }
.search .ic { position: absolute; left: 15px; top: 15px; color: var(--muted); }
.search input {
  width: 100%; min-height: 52px; padding: 0 16px 0 46px; border: 0; border-radius: 14px;
  background: var(--surface-2); font-size: 17px; -webkit-appearance: none;
}
.search input::placeholder { color: var(--muted); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.ex {
  border: 0; background: var(--surface); color: var(--text-2); font-size: 14px; font-weight: 500; padding: 7px 13px; border-radius: 16px;
  cursor: pointer; text-align: left; box-shadow: var(--shadow);
}
.ex:active { background: var(--surface-2); }
.labels { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
.labels::-webkit-scrollbar { display: none; }
.lab-btn {
  flex: none; display: grid; justify-items: center; gap: 6px; width: 72px; padding: 12px 0 10px; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow);
  transition: background .2s, color .2s;
}
.lab-btn .ic { width: 24px; height: 24px; color: var(--text); }
.lab-btn.on { background: var(--text); color: var(--bg); }
.lab-btn.on .ic { color: var(--bg); }
.results-head { color: var(--muted); font-size: 13px; font-weight: 600; padding: 0 var(--gutter) 10px; max-width: 760px; margin: 0 auto; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(30%, 150px), 1fr)); gap: 16px 10px; }
.results { padding: 0 var(--gutter); max-width: 760px; margin: 0 auto; }
.obj { display: grid; gap: 5px; min-width: 0; }
.obj-img { aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.obj-img img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s var(--ease); }
.obj:active .obj-img img { transform: scale(.97); }
.obj b { display: flex; align-items: center; gap: 5px; font-size: 13.5px; font-weight: 600; min-width: 0; }
.obj b span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.obj b .lab { width: 14px; height: 14px; color: var(--muted); }
.obj small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { padding: 16px; max-width: 760px; margin: 0 auto; }
details.more.block, .page > details.more { max-width: none; }

/* ---------------- SYSTEM / SETTINGS ---------------- */
.health { display: flex; gap: 16px; align-items: center; padding: 20px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.health .ic { width: 34px; height: 34px; }
.health.good .ic { color: var(--green); }
.health.bad .ic { color: var(--amber); }
.health b { font-size: 19px; font-weight: 600; }
.health p { color: var(--muted); font-size: 14px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--text); border-radius: 3px; opacity: .7; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 12px 0 6px; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
.kv { display: grid; }
.kv > div { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: .5px solid var(--line); font-size: 14px; }
.kv > div:last-child { border-bottom: 0; }
.kv > div span:last-child { color: var(--muted); text-align: right; }
.cam-list { display: grid; }
.cam-item { display: flex; align-items: center; gap: 8px; min-height: 54px; border-bottom: .5px solid var(--line); }
.cam-item:last-child { border-bottom: 0; }
.cam-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam-item .chip { min-height: 28px; padding: 0 11px; font-size: 12px; }
.cam-item .iconbtn { color: var(--muted); }
.cam-item .iconbtn.fav { color: var(--red); }
.cam-item .iconbtn.fav svg { fill: currentColor; }
.install { padding: 14px 16px; border-radius: var(--radius); background: var(--surface); display: block; font-size: 14px; box-shadow: var(--shadow); }
.mode-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 0; }
.mode-btn {
  display: grid; justify-items: center; gap: 4px; padding: 14px 4px 12px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--surface-2); color: var(--text); transition: background .2s, color .2s, transform .15s var(--ease);
}
.mode-btn:active { transform: scale(.97); }
.mode-btn .ic { width: 22px; height: 22px; }
.mode-btn b { font-size: 15px; font-weight: 600; }
.mode-btn small { font-size: 11.5px; color: var(--muted); text-align: center; line-height: 1.25; }
.mode-btn.on { background: var(--text); color: var(--bg); }
.mode-btn.on small { color: var(--bg); opacity: .7; }
.mode-tabs { margin: 4px 0 8px; }
.modes-card > .muted.small { padding: 2px 0 0; }

/* ---------------- sheets ---------------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0); transition: background .25s; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap.open { background: var(--scrim); }
.sheet {
  width: min(100%, 460px); margin: 0 8px calc(8px + env(safe-area-inset-bottom)); display: grid; gap: 0;
  transform: translateY(110%); transition: transform .32s var(--ease);
}
.sheet-wrap.open .sheet { transform: none; }
.sheet-title { background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 500; text-align: center; padding: 14px 18px; border-radius: 16px 16px 0 0; border-bottom: .5px solid var(--line); line-height: 1.4; }
.sheet-item {
  display: flex; align-items: center; gap: 14px; min-height: 58px; padding: 0 18px; border: 0; background: var(--surface);
  font-size: 17px; text-align: left; cursor: pointer; border-bottom: .5px solid var(--line); color: var(--text);
}
.sheet-item:active { background: var(--surface-2); }
.sheet-item .ic { color: var(--muted); }
.sheet-item > span { display: grid; gap: 1px; padding: 8px 0; }
.sheet-item small { color: var(--muted); font-size: 13px; }
.sheet-item:first-child, .sheet-title + .sheet-item { border-radius: 16px 16px 0 0; }
.sheet-title + .sheet-item { border-radius: 0; }
.sheet-item:nth-last-child(2) { border-radius: 0 0 16px 16px; border-bottom: 0; }
.sheet-item:first-child:nth-last-child(2) { border-radius: 16px; }
.sheet-item.cancel { margin-top: 8px; border-radius: 16px; justify-content: center; font-weight: 600; border-bottom: 0; }
.sheet-item.good .ic { color: var(--green); }
.sheet-item.warn .ic { color: var(--amber); }
.sheet-item.danger, .sheet-item.danger .ic { color: var(--red); }
.sheet-item.chosen .ic { color: var(--text); }
.sheet-item.chosen::after { content: ""; margin-left: auto; width: 6px; height: 12px; border-right: 2.5px solid var(--accent); border-bottom: 2.5px solid var(--accent); transform: rotate(45deg); flex: none; margin-right: 4px; }

/* ---------------- empty, loading, toast, dialog, login ---------------- */
.empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 64px 24px; color: var(--muted); }
.empty .ic { width: 40px; height: 40px; }
.skeleton-list, .skeleton-block, .skeleton-grid {
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 300% 100%; animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton-list { height: 260px; margin: 8px var(--gutter); }
.skeleton-block { height: 220px; }
.skeleton-grid { height: 300px; grid-column: 1 / -1; }
@keyframes shimmer { to { background-position: -100% 0; } }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 12px) scale(.98); opacity: 0; pointer-events: none; z-index: 80;
  background: var(--surface-3); color: var(--text); padding: 11px 18px; border-radius: 22px; font-weight: 600; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow-lg);
  transition: opacity .25s, transform .3s var(--ease);
}
:root[data-theme="light"] .toast { background: #1c1c1e; color: #fff; }
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.bad { background: var(--red); color: #fff; }
.dialog { border: 0; border-radius: 18px; padding: 22px; background: var(--surface); color: var(--text); width: min(92vw, 360px); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: var(--scrim); }
.dialog p { margin: 0 0 20px; font-size: 16px; }
#login { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: grid; place-items: center; padding: 24px 16px; overflow-y: auto; }
.login-theme { position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 12px; }
.login-card { width: min(100%, 360px); display: grid; gap: 14px; text-align: center; }
.login-card .brand-mark { justify-self: center; margin-bottom: 4px; }
.login-card .field { text-align: left; }
.login-card h1 { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.login-error { color: var(--red); min-height: 1.2em; font-weight: 600; }

@media (min-width: 760px) {
  :root { --gutter: 24px; }
  .ev-thumbs { width: 140px; }
  .ev-front::after { left: calc(var(--gutter) + 154px); }
}
