/* Woodleaf Hammock Cameras — dark-mode-first, iPhone-first */

:root {
  color-scheme: dark light;
  /* dark theme (default) */
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-chip: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #4493f8;

  --c-vehicle: #4493f8;
  --c-vehicle-bg: rgba(68, 147, 248, 0.14);
  --c-person: #f0883e;
  --c-person-bg: rgba(240, 136, 62, 0.15);
  --c-animal: #3fb950;
  --c-animal-bg: rgba(63, 185, 80, 0.15);
  --c-other: #8b949e;
  --c-other-bg: rgba(139, 148, 158, 0.15);

  --radius: 12px;
  --topbar-blur: rgba(13, 17, 23, 0.88);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-elev: #ffffff;
    --bg-chip: #eceef1;
    --border: #d6d9de;
    --text: #1c2128;
    --text-dim: #59636e;
    --accent: #0969da;

    --c-vehicle: #0969da;
    --c-vehicle-bg: rgba(9, 105, 218, 0.10);
    --c-person: #bc4c00;
    --c-person-bg: rgba(188, 76, 0, 0.10);
    --c-animal: #1a7f37;
    --c-animal-bg: rgba(26, 127, 55, 0.10);
    --c-other: #59636e;
    --c-other-bg: rgba(89, 99, 110, 0.10);

    --topbar-blur: rgba(246, 247, 249, 0.9);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
button { cursor: pointer; border: none; background: none; }

.hscroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.hscroll::-webkit-scrollbar { display: none; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--topbar-blur);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 12px 10px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.topbar h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.date-row button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 18px;
  background: var(--bg-chip);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.date-row button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.filter-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.seg {
  display: flex;
  flex: 0 0 auto;
  background: var(--bg-chip);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.seg button {
  min-height: 44px;
  padding: 0 14px;
  font-size: 14px;
  color: var(--text-dim);
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.search-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
}
.search-wrap input {
  width: 100%;
  min-height: 44px;
  padding: 0 64px 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  font-size: 16px; /* prevents iOS zoom-on-focus */
  -webkit-appearance: none;
  appearance: none;
}
.search-wrap input::placeholder { color: var(--text-dim); }
.search-wrap .hits {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
  pointer-events: none;
}

/* ---------- channel chips (visible only for a specific camera) ---------- */
.channel-wrap {
  max-height: 0;
  overflow: hidden;
  margin-top: -8px; /* cancel the flex gap while collapsed */
  opacity: 0;
  transition: max-height 0.25s ease, margin-top 0.25s ease, opacity 0.25s ease;
}
.channel-wrap.open {
  max-height: 52px;
  margin-top: 0;
  opacity: 1;
}
.channel-row button {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  color: var(--text-dim);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.channel-row .cnt {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}
.channel-row button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.channel-row button.on .cnt { color: #fff; }

/* ---------- type / stat chips ---------- */
.type-row button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 19px;
  border: 1px solid var(--border);
  background: var(--bg-chip);
  color: var(--text-dim);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.type-row .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--tc, var(--c-other));
}
.type-row .cnt {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}
.type-row button.on {
  border-color: var(--tc, var(--accent));
  background: var(--tcbg, var(--bg-chip));
  color: var(--text);
  font-weight: 600;
}

/* ---------- list ---------- */
#main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.status {
  color: var(--text-dim);
  text-align: center;
  padding: 32px 0;
  font-size: 14px;
}
.status:empty { display: none; }

.list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 640px) {
  .list { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 980px) {
  .list { grid-template-columns: repeat(3, 1fr); }
}

.card {
  display: flex;
  gap: 10px;
  align-items: stretch;
  width: 100%;
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--tc, var(--c-other));
  border-radius: var(--radius);
  padding: 8px;
  min-height: 44px;
}
.card:active { filter: brightness(1.12); }

.thumb {
  flex: 0 0 128px;
  width: 128px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-chip);
  position: relative;
  align-self: center;
}
.thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.thumb .noimg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
}

.card-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.card-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.card .time {
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.card .conf {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.card .cam {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-badges {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  color: var(--tc, var(--c-other));
  background: var(--tcbg, var(--c-other-bg));
}
.plate {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1.5px solid var(--text);
  background: var(--bg);
}

.sentinel { height: 1px; }

/* ---------- player overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay[hidden] { display: none; }
.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.sheet {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 92dvh;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}
@media (min-width: 720px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 16px; }
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--border);
}
.sheet-meta {
  min-width: 0;
  flex: 1;
  font-size: 14px;
}
.sheet-meta .m-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.sheet-meta .m-cam { color: var(--text-dim); font-size: 12.5px; }
.close-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-chip);
  border: 1px solid var(--border);
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.video-wrap {
  background: #000;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-wrap video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}
.no-clip {
  color: #8b949e;
  font-size: 14px;
  text-align: center;
  padding: 24px;
}
.sheet-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}
.sheet-controls:has(> [hidden]:only-child),
.sheet-controls:empty { display: none; }
.lpr-btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  font-weight: 600;
  font-size: 14px;
}
.lpr-btn.on { background: var(--accent); color: #fff; }
.plate-big {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 4px 14px;
  border: 2px solid var(--text);
  border-radius: 8px;
}
.sheet-details {
  padding: 4px 16px 18px;
  color: var(--text-dim);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
