.events-layout {
  grid-template-columns: 420px minmax(0, 1fr);
}

.events-list {
  max-height: calc(100vh - 240px);
  overflow: auto;
}

.event-row {
  cursor: pointer;
}

.event-row.is-active {
  background: var(--accent-soft);
}

.event-detail-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.media-card--tracking {
  min-width: 0;
}

.tracking-media {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: var(--surface);
}

.tracking-media img {
  display: block;
  width: 100%;
}

.event-video {
  display: block;
  width: 100%;
  max-height: 320px;
  border-radius: 10px;
  background: #000;
}

.tracking-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tracking-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
}

.tracking-points circle {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.tracking-points circle.is-last {
  fill: var(--green);
  stroke: #ffffff;
}

.tracking-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.tracking-panel__head {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(320px, 1.4fr);
  gap: 14px;
  align-items: start;
}

.tracking-panel h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.tracking-panel p {
  margin: 0;
}

.track-timeline {
  display: grid;
  gap: 0;
  padding: 8px 0;
}

.track-timeline__item {
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
}

.track-timeline__item::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.track-timeline__item:first-child::before {
  top: 14px;
}

.track-timeline__item:last-child::before {
  bottom: calc(100% - 14px);
}

.track-timeline__dot {
  position: relative;
  z-index: 1;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
}

.track-timeline__item strong {
  display: block;
  margin-bottom: 2px;
}

.tracking-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.tracking-summary .field-value {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.candidate-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.candidate-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

.candidate-table th,
.candidate-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.candidate-table th {
  color: var(--muted);
  font-size: 12px;
}

.candidate-table tr:last-child td {
  border-bottom: 0;
}

.candidate-table tr.is-best {
  background: var(--accent-soft);
}

.candidate-best {
  display: inline-flex;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.decision-card {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.decision-card .field-value {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

@media (max-width: 1100px) {
  .events-layout,
  .event-detail-grid,
  .decision-card,
  .tracking-panel__head,
  .tracking-summary {
    grid-template-columns: 1fr;
  }

  .events-list {
    max-height: none;
  }
}

/* P1.0 Frigate-like event viewer */
.event-viewer {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr);
  gap: 12px;
  grid-column: 1 / -1;
}

.viewer-media {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #050b16;
}

.viewer-media video {
  display: block;
  width: 100%;
}

.viewer-media svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* The overlay layer itself must NOT swallow clicks: the native video
     controls stay usable. Only the track points are clickable. */
  pointer-events: none;
}

.viewer-media .viewer-point {
  pointer-events: all;
}

.viewer-status {
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
}

.viewer-status.is-error {
  color: #ef4444;
}

.viewer-path {
  fill: none;
  stroke: #22c55e;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
  opacity: 0.8;
}

.viewer-point {
  fill: #f59e0b;
  stroke: #111827;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  opacity: 0.75;
}

.viewer-point.is-active {
  fill: #ef4444;
  opacity: 1;
}

.viewer-bbox {
  fill: none;
  stroke: #38bdf8;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  opacity: 0;
}

.viewer-bbox.is-visible {
  opacity: 1;
}

.event-viewer__panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  overflow-y: auto;
  max-height: 420px;
}

.viewer-timeline {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.viewer-timeline__item {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.viewer-timeline__item.is-active {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.08);
}

.viewer-timeline__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.viewer-fallback-note {
  grid-column: 1 / -1;
}

@media (max-width: 900px) {
  .event-viewer {
    grid-template-columns: 1fr;
  }
}

/* P1.0.2: compact Frigate-like playback controls + overlay polish + mobile */
.viewer-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 12px 12px;
  background: rgba(5, 11, 22, 0.85);
}

.vc-btn {
  min-width: 40px;
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
}

.vc-btn:active {
  background: rgba(59, 130, 246, 0.18);
}

.vc-scrub {
  flex: 1;
  min-width: 80px;
  accent-color: #22c55e;
}

.vc-time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.vc-rate {
  font-weight: 600;
}

/* Delicate track overlay (Frigate-like): thinner, calmer, readable */
.viewer-path {
  stroke-width: 1.5;
  opacity: 0.55;
}

.viewer-point {
  stroke-width: 1.5;
  opacity: 0.6;
}

.viewer-point--key {
  fill: #38bdf8;
  opacity: 0.85;
}

.viewer-point.is-active {
  fill: #ef4444;
  stroke: #ffffff;
  stroke-width: 2;
  opacity: 1;
}

.viewer-bbox {
  stroke-width: 1.5;
}

/* Mobile: video first, touch-friendly controls, calm timeline */
[data-event-detail] {
  scroll-margin-top: 64px; /* keep the card below the sticky header */
}

[data-event-detail].is-just-selected {
  animation: event-detail-flash 1.6s ease-out;
}

@keyframes event-detail-flash {
  0% { box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.9); }
  100% { box-shadow: 0 0 0 2px rgba(34, 197, 94, 0); }
}

@media (max-width: 768px) {
  .event-viewer {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .event-viewer__panel {
    max-height: 240px;
  }

  .viewer-timeline__item {
    padding: 10px 12px; /* touch-friendly */
  }

  .viewer-controls {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  .vc-scrub {
    order: -1;
    flex-basis: 100%;
  }

  .vc-btn {
    min-height: 40px;
  }
}

/* P1.2 canonical vehicle class badges */
.vclass {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 18px;
  border: 1px solid transparent;
  white-space: nowrap;
  vertical-align: middle;
}

.vclass--car { background: rgba(59, 130, 246, 0.16); color: #93c5fd; border-color: rgba(59, 130, 246, 0.4); }
.vclass--van { background: rgba(168, 85, 247, 0.16); color: #d8b4fe; border-color: rgba(168, 85, 247, 0.4); }
.vclass--truck { background: rgba(249, 115, 22, 0.16); color: #fdba74; border-color: rgba(249, 115, 22, 0.4); }
.vclass--motorcycle { background: rgba(34, 197, 94, 0.16); color: #86efac; border-color: rgba(34, 197, 94, 0.4); }
.vclass--bus { background: rgba(234, 179, 8, 0.16); color: #fde047; border-color: rgba(234, 179, 8, 0.4); }
.vclass--special { background: rgba(190, 24, 60, 0.18); color: #fda4af; border-color: rgba(190, 24, 60, 0.45); }
.vclass--unknown { background: rgba(148, 163, 184, 0.14); color: #cbd5e1; border-color: rgba(148, 163, 184, 0.35); }

.vclass--uncertain {
  border-style: dashed;
}

.events-vclass-filter {
  padding: 8px 12px 0;
}

@media (max-width: 768px) {
  .events-vclass-filter select {
    width: 100%;
    min-height: 40px; /* touch-friendly compact dropdown */
  }
}


/* P1.2.1: vehicle type semantics block */
.vehicle-type-block {
  display: grid;
  gap: 6px;
}

.vehicle-type-conflict {
  font-size: 12px;
  color: #fbbf24;
}

.vclass-note {
  font-size: 11px;
  margin-top: 2px;
}

/* A8n.5: suppressed plate candidate */
.vpass-suppressed-candidate {
  background: rgba(255, 170, 0, 0.08);
  border-left: 3px solid #fa0;
  padding: 6px 8px;
  margin: 4px 0;
}
.vpass-suppressed-note {
  display: block;
  color: #a80;
  font-size: 11px;
  margin-top: 2px;
}
