:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1b1c1f;
  --muted: #62646b;
  --border: #dcd9d2;
  --accent: #1f4fd1;
  --accent-text: #ffffff;
  --accent-soft: #e4ebfc;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #1d6b3a;
  --ok-soft: #e3f3e8;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #121316;
  --surface: #1b1d21;
  --surface-2: #25282d;
  --text: #ecedef;
  --muted: #a0a3ab;
  --border: #33363c;
  --accent: #7c9dff;
  --accent-text: #0d1220;
  --accent-soft: #1f2a47;
  --danger: #ff8a80;
  --danger-soft: #3a1f1d;
  --ok: #7fd49b;
  --ok-soft: #1a3324;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color .2s, color .2s;
}
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; word-break: break-all; }
img, video { max-width: 100%; display: block; }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand-mark { width: 14px; height: 14px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: .95rem; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; margin-left: 6px; }
.icon-btn:hover { background: var(--surface-2); }
[data-theme="light"] .icon-sun, [data-theme="dark"] .icon-moon { display: none; }

/* Layout */
main.wrap { padding-top: 28px; padding-bottom: 40px; }
.hero h1 { font-size: clamp(1.6rem, 3.5vw, 2.3rem); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.02em; }
.lede { color: var(--muted); max-width: 62ch; margin: 0 0 24px; font-size: 1.05rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.muted { color: var(--muted); }
.site-footer { color: var(--muted); font-size: .85rem; padding-bottom: 32px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--muted); }
input[type=text], input[type=search], input[type=date], input[type=time], input[type=number], textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; width: 100%;
}
input:focus-visible, textarea:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
textarea { resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; margin: 6px 0 18px; }
.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .95rem;
  padding: 10px 16px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0 0 0 8px; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; border: 1px solid; }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: currentColor; }
.alert.success { background: var(--ok-soft); color: var(--ok); border-color: currentColor; }

/* Search */
.filters { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters .field { margin: 0; }
.filters .grow { flex: 1 1 260px; }
.filters .field:not(.grow) { flex: 0 1 170px; }
.filter-actions { display: flex; gap: 8px; }
.result-count { color: var(--muted); font-size: .9rem; margin: 0 0 14px; }

.grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.incident-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; color: inherit; text-decoration: none; height: 100%; transition: transform .12s, border-color .12s; }
.incident-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 16/9; background: #000; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.badge { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.75); color: #fff; font-size: .78rem; padding: 2px 7px; border-radius: 5px; font-variant-numeric: tabular-nums; }
.incident-body { padding: 14px 16px 16px; }
.incident-body h2 { font-size: 1.02rem; margin: 0 0 2px; }
.meta { color: var(--muted); font-size: .88rem; margin: 0; }
.desc { margin: 8px 0 0; font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.empty { text-align: center; padding: 40px 20px; }

/* Upload */
.upload-layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; }
.section-title { font-size: 1.05rem; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; }
.step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: .85rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

.dropzone { position: relative; display: grid; place-items: center; text-align: center; border: 2px dashed var(--border); border-radius: 10px; padding: 30px 16px; cursor: pointer; color: var(--muted); transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone strong { color: var(--accent); }
.dropzone.has-file { padding: 12px; }

.editor { margin-top: 16px; }
.editor video { width: 100%; max-height: 55vh; background: #000; border-radius: 8px; }
.hint { color: var(--muted); font-size: .9rem; }

.trim { margin-top: 16px; }
/* Filmstrip timeline */
.timeline { padding: 6px 16px; user-select: none; -webkit-user-select: none; touch-action: none; }
.track { position: relative; height: 56px; border-radius: 6px; background: var(--surface-2); cursor: pointer; }
.filmstrip { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 6px; }
.track.loading::after { content: ""; position: absolute; inset: 0; border-radius: 6px; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.18), transparent); background-size: 40% 100%;
  background-repeat: no-repeat; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.shade { position: absolute; top: 0; bottom: 0; background: rgba(0,0,0,.6); pointer-events: none; }
.shade-left { left: 0; border-radius: 6px 0 0 6px; }
.shade-right { right: 0; border-radius: 0 6px 6px 0; }
.selection { position: absolute; top: -3px; bottom: -3px; border-top: 3px solid var(--accent); border-bottom: 3px solid var(--accent); pointer-events: none; }
.handle { position: absolute; top: -3px; bottom: -3px; width: 16px; background: var(--accent); cursor: ew-resize; display: grid; place-items: center; touch-action: none; z-index: 2; }
.handle.start { border-radius: 6px 0 0 6px; }
.handle.end { border-radius: 0 6px 6px 0; }
.handle::before { content: ""; width: 3px; height: 20px; border-radius: 2px; background: rgba(0,0,0,.45); }
.handle::after { content: ""; position: absolute; inset: -8px -6px; }  /* bigger touch target */
.handle:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.playhead { position: absolute; top: -7px; bottom: -7px; width: 2px; margin-left: -1px; background: #fff; border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.55); pointer-events: none; z-index: 3; }
.hover-time { position: absolute; bottom: calc(100% + 10px); transform: translateX(-50%); background: var(--text); color: var(--bg);
  font-size: .75rem; padding: 2px 6px; border-radius: 4px; pointer-events: none; white-space: nowrap; font-variant-numeric: tabular-nums; z-index: 4; }
.ruler { position: relative; height: 16px; margin: 4px 16px 0; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ruler span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.ruler span:first-child { transform: none; }
.ruler span:last-child { transform: translateX(-100%); }
.timeline-hint { font-size: .8rem; margin: 6px 0 14px; }

.trim-row { display: grid; grid-template-columns: 1fr auto auto 1fr; gap: 10px; align-items: end; }
.trim-row .field { margin: 0; }
.clip-summary { margin: 12px 0 0; font-size: .95rem; font-variant-numeric: tabular-nums; }

.submit-row { display: flex; flex-direction: column; gap: 12px; }
.submit-row .btn { width: 100%; padding: 13px; }
.progress { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; color: var(--muted); }
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress.indeterminate .progress-fill { width: 35% !important; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

/* Incident */
.back { display: inline-block; margin-bottom: 14px; text-decoration: none; font-size: .92rem; }
.incident-layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); align-items: start; margin-bottom: 20px; }
.player { padding: 0; overflow: hidden; background: #000; }
.player video { width: 100%; max-height: 70vh; }
.details h1 { font-size: 1.35rem; margin: 0 0 12px; line-height: 1.25; }
.facts, .hashes { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 14px; font-size: .92rem; }
.facts dt, .hashes dt { color: var(--muted); }
.facts dd, .hashes dd { margin: 0; min-width: 0; }
.desc-full { white-space: pre-wrap; margin: 0 0 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card.tech-details { padding: 0; }
.tech-details summary { padding: 14px 20px; cursor: pointer; font-weight: 600; font-size: .95rem; color: var(--muted); list-style: none; display: flex; align-items: center; gap: 8px; border-radius: var(--radius); }
.tech-details summary::-webkit-details-marker { display: none; }
.tech-details summary::before { content: "▸"; width: 1em; }
.tech-details[open] summary::before { content: "▾"; }
.tech-details summary:hover { color: var(--text); }
.tech-details summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tech-details .hashes { padding: 0 20px; }
.tech-note { font-size: .85rem; margin: 0; padding: 0 20px 18px; }

.prose { max-width: 760px; }
.prose h2 { font-size: 1.1rem; margin: 1.2em 0 .4em; }
.prose h2:first-child { margin-top: 0; }


/* Location: suggestions + map picker */
.place-row { display: flex; gap: 8px; align-items: stretch; }
.combo { position: relative; flex: 1; min-width: 0; }
.map-btn { flex: none; }
.suggestions { position: absolute; z-index: 2000; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18);
  max-height: 300px; overflow-y: auto; }
.suggestion { display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; border-radius: 7px; cursor: pointer; line-height: 1.3; }
.suggestion[aria-selected="true"] { background: var(--accent-soft); }
.s-primary { font-weight: 600; font-size: .95rem; }
.s-secondary { color: var(--muted); font-size: .83rem; }
.suggestion-msg { padding: 10px; color: var(--muted); font-size: .9rem; }
.place-status { margin: 6px 0 0; font-size: .85rem; color: var(--muted); }
.place-status.ok { color: var(--ok); }
.place-status.warn { color: var(--muted); }
.place-status .link-btn { font-size: inherit; }

.map-dialog { width: min(960px, calc(100vw - 32px)); height: min(720px, calc(100dvh - 32px)); max-width: none; max-height: none;
  padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); overflow: hidden; }
.map-dialog[open] { display: flex; flex-direction: column; }
.map-dialog::backdrop { background: rgba(0,0,0,.6); }
.map-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.map-head h2 { font-size: 1.05rem; margin: 0; white-space: nowrap; }
.map-search { max-width: 420px; margin-left: auto; }
.map-head .icon-btn { margin-left: 0; flex: none; }
.map-canvas { flex: 1; min-height: 240px; background: var(--surface-2); }
.map-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-top: 1px solid var(--border); }
.map-address { margin: 0; flex: 1 1 280px; font-size: .92rem; min-width: 0; overflow-wrap: anywhere; }
.map-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.incident-map { height: 220px; border-radius: 10px; border: 1px solid var(--border); margin: 0 0 6px; z-index: 0; }
.map-link { display: inline-block; font-size: .88rem; margin-bottom: 16px; }

/* Leaflet in dark mode: darken tiles, theme controls */
[data-theme="dark"] .leaflet-tile-pane { filter: brightness(.75) invert(1) contrast(.85) hue-rotate(180deg) saturate(.7); }
[data-theme="dark"] .leaflet-container { background: #1d2024; }
[data-theme="dark"] .leaflet-bar a { background: var(--surface-2); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .leaflet-control-attribution { background: rgba(27,29,33,.8); color: var(--muted); }
[data-theme="dark"] .leaflet-control-attribution a { color: var(--accent); }
.leaflet-container { font: inherit; }

@media (max-width: 560px) {
  .place-row { flex-direction: column; }
  .map-dialog { width: 100vw; height: 100dvh; border-radius: 0; border: 0; margin: 0; }
  .map-head { flex-wrap: wrap; }
  .map-head h2 { flex: 1; }
  .map-search { order: 3; flex: 1 1 100%; max-width: none; margin: 0; }
  .map-actions { width: 100%; }
  .map-actions .btn { flex: 1; }
  .map-actions #map-confirm { flex-basis: 100%; order: -1; }
}


/* Search: list / map switch, pagination, map search */
.view-switch { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; margin-bottom: 14px; }
.view-switch .seg { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .93rem; }
.view-switch .seg:hover { color: var(--text); }
.view-switch .seg.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 22px; }

.card.map-search-card { padding: 0; overflow: visible; margin-bottom: 14px; }
.map-search-bar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; padding: 16px 16px 14px; }
.map-search-bar .field { margin: 0; }
.map-search-bar .grow { flex: 1 1 240px; }
.map-search-bar .field:not(.grow) { flex: 0 1 165px; }
.map-search-bar .time-field, .filters .time-field { flex: 0 1 125px; }
.filter-note { margin: -6px 0 14px; font-size: .85rem; color: var(--muted); }
.search-map { height: min(58vh, 520px); min-height: 300px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); z-index: 0; }
.map-hint { margin: 0; padding: 10px 16px 12px; font-size: .85rem; color: var(--muted); }
.map-popup { display: flex; flex-direction: column; gap: 4px; font: inherit; }
.map-popup img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: #000; margin-bottom: 4px; display: block; }
.map-popup strong { font-size: .92rem; line-height: 1.3; }
.map-popup .muted { font-size: .82rem; }
.map-popup .popup-link { font-weight: 600; font-size: .88rem; margin-top: 2px; }
.leaflet-popup-content { margin: 12px; }
[data-theme="dark"] .leaflet-popup-content-wrapper, [data-theme="dark"] .leaflet-popup-tip { background: var(--surface); color: var(--text); }

/* Marker clusters, in the app's colours */
.marker-cluster { background: color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 50%; }
.marker-cluster div { width: 30px; height: 30px; margin: 5px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  font: 600 13px/30px system-ui, sans-serif; text-align: center; }
.marker-cluster span { line-height: 30px; }

@media (max-width: 560px) {
  .view-switch { display: flex; }
  .view-switch .seg { flex: 1; justify-content: center; padding: 8px 6px; font-size: .88rem; }
  .map-search-bar { padding: 14px 14px 12px; }
  .map-search-bar .field:not(.grow) { flex: 1 1 130px; }
  .map-search-bar .time-field, .filters .time-field { flex: 1 1 130px; }
  .map-search-bar .filter-actions { width: 100%; }
  .map-search-bar .filter-actions .btn { flex: 1; }
  .search-map { height: 55vh; }
}


/* Place/time suggested from the video's metadata or file name */
.meta-suggest { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 10px; padding: 14px 16px; margin: -4px 0 18px; }
.meta-title { margin: 0 0 8px; font-weight: 700; }
.meta-items { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.meta-items li { display: grid; grid-template-columns: 7.5em 1fr; gap: 2px 10px; font-size: .93rem; }
.meta-label { color: var(--muted); }
.meta-value { font-weight: 600; overflow-wrap: anywhere; }
.meta-source { grid-column: 2; font-size: .8rem; color: var(--muted); }
.meta-note { margin: 0 0 12px; font-size: .82rem; color: var(--muted); }
.meta-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 560px) {
  .meta-items li { grid-template-columns: 1fr; }
  .meta-source { grid-column: 1; }
  .meta-actions .btn { flex: 1; }
}

/* Responsive */
@media (max-width: 860px) {
  .upload-layout, .incident-layout { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .track { height: 48px; }
  .wrap { padding: 0 14px; }
  .header-row { padding-top: 8px; padding-bottom: 8px; }
  .nav a { padding: 6px 8px; font-size: .9rem; }
  .card { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
  .trim-row { grid-template-columns: 1fr 1fr; }
  .trim-row .btn { grid-row: 2; }
  .filters .field:not(.grow) { flex: 1 1 130px; }
  .filter-actions { width: 100%; }
  .filter-actions .btn { flex: 1; }
  .facts, .hashes { grid-template-columns: 1fr; gap: 2px; }
  .facts dd, .hashes dd { margin-bottom: 8px; }
}
