:root {
  --bg: #0f0f12;
  --surface: #1a1a20;
  --surface-hover: #24242c;
  --text: #ececf1;
  --muted: #9a9aa8;
  --accent: #e5484d;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: rgba(15, 15, 18, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #26262e;
}

.brand {
  color: var(--text);
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  white-space: nowrap;
}
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand .logo { width: 30px; height: 30px; border-radius: 7px; }

#search {
  flex: 1;
  max-width: 480px;
  margin-left: auto;
  padding: 9px 14px;
  border: 1px solid #33333d;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

main { max-width: 1400px; margin: 0 auto; padding: 24px; }

.meta { color: var(--muted); font-size: 0.9rem; }

/* ---------- layout with sidebar ---------- */

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}
.layout:has(.sidebar[hidden]) { grid-template-columns: minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.sidebar h2 {
  margin: 4px 10px 10px;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px calc(10px + var(--depth, 0) * 16px);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}
.sidebar a:hover { background: var(--surface-hover); }
.sidebar a[aria-current="page"] { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar .name-short { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .name-full { display: none; }
.sidebar .count { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.library-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 18px; }
.library-head h1 { margin: 0; font-size: 1.5rem; }
.library-head .meta { margin: 0; }

.sidebar a.empty { color: var(--muted); }

/* ---------- date filter ---------- */

.date-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  margin: -6px 0 22px;
}
.date-filter .presets { display: flex; flex-wrap: wrap; gap: 6px; }
.date-filter button {
  padding: 5px 12px;
  border: 1px solid #33333d;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.date-filter button:hover { border-color: #55555f; }
.date-filter button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.custom-range { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 0.85rem; }
.custom-range label { display: flex; align-items: center; gap: 6px; }
.custom-range input {
  padding: 4px 8px;
  border: 1px solid #33333d;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  color-scheme: dark;
}
.date-filter.custom-active .custom-range input { border-color: var(--accent); }

/* Narrow screens: folders become a horizontal row of chips. */
@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .sidebar { position: static; max-height: none; overflow: visible; }
  .sidebar h2 { display: none; }
  .sidebar ul {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 6px;
    scrollbar-width: none;
  }
  .sidebar a {
    padding: 6px 12px;
    border: 1px solid #33333d;
    border-radius: 999px;
    white-space: nowrap;
  }
  .sidebar a[aria-current="page"] { box-shadow: none; border-color: var(--accent); }
  .sidebar .name-short { display: none; }
  .sidebar .name-full { display: inline; }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.folder { margin-bottom: 28px; }
.folder > summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid #26262e;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.folder > summary::-webkit-details-marker { display: none; }
.folder > summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s;
}
.folder[open] > summary::before { transform: rotate(90deg); }
.folder > summary h2 { margin: 0; font-size: 1.2rem; font-weight: 650; }
.folder > summary:hover h2 { color: var(--accent); }

.card {
  display: block;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius);
  transition: background 0.15s;
  padding: 6px;
}
.card:hover, .card:focus-visible { background: var(--surface-hover); outline: none; }

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.thumb img,
.thumb video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.thumb img { opacity: 0; transition: opacity 0.25s; }
.thumb.loaded img { opacity: 1; }
/* Shimmer while the thumbnail is generated/loaded */
.thumb:not(.loaded)::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.05) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.thumb .hover-preview { opacity: 0; transition: opacity 0.2s; }
.thumb .hover-preview.playing { opacity: 1; }
.duration {
  position: absolute;
  z-index: 1;
  right: 8px;
  bottom: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.8);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.duration:empty { display: none; }

.card h3 { margin: 10px 4px 4px; font-size: 1rem; font-weight: 600; }
.card .meta { margin: 0 4px 4px; }

/* ---------- new videos ---------- */

.new-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.card.flash { animation: flash 2s ease-out; }
@keyframes flash {
  0%, 30% { background: rgba(229, 72, 77, 0.35); }
  100% { background: transparent; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 10px 10px 10px 16px;
  border: 1px solid #33333d;
  border-radius: 12px;
  background: #24242c;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button {
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.toast button.close { padding: 4px 8px; background: transparent; color: var(--muted); font-size: 1.1rem; }
.toast button.close:hover { color: var(--text); }

/* ---------- license plates ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 4px 4px; }
.chips:empty { display: none; }
.chip {
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.04em;
}
.chip.plate.likely { background: #ececf1; color: #111; }
.chip.plate.uncertain { border: 1px dashed #6b6b78; color: var(--muted); }
.chip.pending { font-family: inherit; font-weight: 500; color: var(--muted); background: var(--surface); }

.plates {
  margin-top: 24px;
  padding: 16px 18px;
  border: 1px solid #26262e;
  border-radius: var(--radius);
  background: var(--surface);
}
.plates-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; }
.plates-head h2 { margin: 0; font-size: 1.1rem; }
.plates-head button { margin-left: auto; }
.plates button {
  padding: 6px 12px;
  border: 1px solid #3a3a45;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.plates button:hover:not(:disabled) { border-color: var(--accent); }
.plates button:disabled { opacity: 0.5; cursor: default; }
.plates button.link { padding: 0; border: 0; color: var(--accent); text-align: left; }
.plates button.link:hover { text-decoration: underline; }

.plate-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 14px; }
.plate-item { display: flex; gap: 16px; align-items: flex-start; }
.plate-item img {
  width: 220px;
  max-width: 40%;
  border-radius: 6px;
  background: #000;
  image-rendering: auto;
}
.plate-item .meta { margin: 4px 0; }
.plate-item .small { font-size: 0.8rem; }
.plate-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.plate-text {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.plate-text .low { color: var(--muted); text-decoration: underline dotted; text-underline-offset: 4px; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.likely { background: #1f6f43; color: #fff; }
.badge.uncertain { background: #6b5513; color: #fff; }

@media (max-width: 600px) {
  .plate-item { flex-direction: column; }
  .plate-item img { width: 100%; max-width: none; }
}

.back {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--muted);
  text-decoration: none;
}
.back:hover { color: var(--text); }

#player {
  width: 100%;
  max-height: 75vh;
  background: #000;
  border-radius: var(--radius);
}
#player-title { margin: 16px 0 4px; font-size: 1.4rem; }

@media (max-width: 600px) {
  .topbar { padding: 10px 16px; }
  main { padding: 16px; }
}

/* "Weitere anzeigen" below a group of cards */
button.more {
  display: block;
  margin: 16px auto 8px;
  padding: 8px 20px;
  border: 1px solid #33333d;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
button.more:hover { border-color: var(--accent); }

/* Note below the player, e.g. while a video is converted for the browser */
.player-note { margin: 8px 0 0; }

/* ---------- events: several clips / lenses ---------- */

/* "3 Clips" on the card thumbnail */
.clips-badge {
  position: absolute;
  z-index: 1;
  left: 8px;
  bottom: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.8);
  font-size: 0.8rem;
}

/* Below the player: lens switch + clip list */
.clip-nav { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; margin: 12px 0 0; }
.clip-nav button {
  padding: 5px 12px;
  border: 1px solid #33333d;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.clip-nav button:hover { border-color: #55555f; }
.clip-nav button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.segmented { display: inline-flex; }
.segmented button { border-radius: 0; }
.segmented button + button { margin-left: -1px; }
.segmented button:first-child { border-radius: 999px 0 0 999px; }
.segmented button:last-child { border-radius: 0 999px 999px 0; }
.clip-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.clip-list button { border-radius: 999px; }
.clip-list .meta { margin-right: 4px; }

.download {
  display: inline-block; margin: 4px 0 0; padding: 6px 12px;
  border: 1px solid #33333d;
  color: var(--text); text-decoration: none; font-size: 0.85rem;
}
.download:hover { border-color: #55555f; }

/* ---------- account (top bar) ---------- */
.account { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.account.push { margin-left: auto; }
.account a { color: var(--muted); text-decoration: none; }
.account a:hover { color: var(--text); }
button.link {
  padding: 0; border: 0; background: none;
  color: var(--muted); font: inherit; font-size: 0.9rem; cursor: pointer;
}
button.link:hover { color: var(--text); text-decoration: underline; }
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .account { margin-left: auto; }
}

/* ---------- forms (login, settings) ---------- */
.form { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.form input:not([type=checkbox]) {
  padding: 9px 12px;
  border: 1px solid #33333d;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form button { align-self: flex-start; }
button.primary, button.danger {
  padding: 9px 18px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
button.primary:disabled { opacity: 0.6; cursor: default; }
button.danger { background: transparent; color: var(--accent); }
button.danger:hover { background: rgba(229, 72, 77, 0.12); }
.form-error { margin: 0; color: #ff8a8e; }
.form-ok { margin: 0; color: #7fd18b; }
.form .meta { margin: 0; }
fieldset.folders { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 12px 14px; border: 1px solid #33333d; border-radius: 6px; }
fieldset.folders legend { padding: 0 6px; color: var(--muted); font-size: 0.9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* login page */
.auth-page main.auth-box { max-width: 420px; margin: 12vh auto 0; padding: 24px; }
.auth-box .brand { display: block; margin: 0 0 24px; }
.auth-box h1 { margin: 0; font-size: 1.4rem; }

/* settings page */
.settings { max-width: 760px; }
.settings h1 { margin: 12px 0 24px; }
.panel { margin-bottom: 32px; padding: 20px 24px; border-radius: var(--radius); background: var(--surface); }
.panel h2 { margin: 0 0 12px; font-size: 1.15rem; }
.panel h3 { margin: 28px 0 12px; font-size: 1rem; }
.panel .form input:not([type=checkbox]) { background: var(--bg); }
.user-card { border-top: 1px solid #2c2c35; }
.user-card summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; padding: 12px 0; cursor: pointer; }
.user-card summary .meta { flex-basis: 100%; margin-left: 0; }
.user-card .form { padding: 0 0 18px; }
.user-card.disabled summary strong { color: var(--muted); text-decoration: line-through; }
.badge { padding: 1px 8px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 0.75rem; }
.badge.muted { background: #33333d; color: var(--text); }

/* ---------- warnings (silent cameras) ---------- */
.alerts {
  margin: 0 0 20px;
  padding: 12px 16px;
  border: 1px solid #8a5a12;
  border-radius: var(--radius);
  background: rgba(245, 166, 35, 0.12);
  color: #f5c46a;
}
.alerts p { margin: 0; }
.alerts p + p { margin-top: 6px; }
.alerts a { color: inherit; font-weight: 600; }

/* camera monitoring on the settings page */
.form.wide { max-width: none; }
table.cameras { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.cameras th { text-align: left; color: var(--muted); font-weight: 400; padding: 6px 8px 6px 0; }
table.cameras td { padding: 8px 8px 8px 0; border-top: 1px solid #2c2c35; vertical-align: middle; }
table.cameras tr.silent td:nth-child(2) { color: #f5c46a; }
table.cameras td:last-child { display: flex; flex-wrap: wrap; gap: 8px; }
.form select, .form input.hours {
  padding: 6px 10px;
  border: 1px solid #33333d;
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.form input.hours { width: 90px; }
.form.wide input[name=silentHours] { max-width: 140px; }

/* ---------- touch screens: larger tap targets (about 40 px) ---------- */
@media (pointer: coarse) {
  .date-filter button, .clip-nav button, .plates button, button.more { min-height: 40px; padding-left: 16px; padding-right: 16px; }
  .custom-range input { min-height: 40px; }
  .sidebar a { min-height: 40px; }
  .download { min-height: 40px; display: inline-flex; align-items: center; }
  .account a, .account button.link { padding: 10px 4px; }
  .folder > summary { padding-top: 10px; padding-bottom: 10px; }
  .toast button { min-height: 40px; }
}

/* system errors (admins) */
.alerts p.system { color: #ff8a8e; }
