/* Dark theme, ChatGPT-style neutral greys. Depth here comes from stepped
   surface tints rather than shadows — drop shadows are near-invisible on a
   dark ground, so borders do the separating instead. */
:root {
  color-scheme: dark;

  --bg: #212121;
  --surface: #2f2f2f;
  --surface-alt: #383838;
  --border: #454545;
  --text: #ececec;
  --text-muted: #b4b4b4;
  --text-faint: #8f8f8f;

  /* Sidebar sits a step darker than the page, as in ChatGPT. */
  --sidebar-bg: #181818;
  /* Paper — the one deliberately light surface (the printed receipt). */
  --paper: #f5f5f2;
  --paper-text: #1a1a1a;

  --brand: #6366f1;         /* indigo, matches the Start button family */
  --brand-pale: #a5a0f7;    /* pale indigo — text/icons on dark tints */
  --brand-dark: #4338ca;    /* darkened indigo — solid fills, gradients */
  --brand-bg: #2b2668;

  --blue: #6ea8fe;
  --blue-bg: #1e2f47;
  --orange: #f0a45c;
  --orange-bg: #40301c;
  --green: #4ade80;         /* kept: categorical, used by the motorcycle badge */
  --green-bg: #1b3d2a;
  --success: #a5a0f7;       /* 'done' signalling, themed indigo */
  --purple: #b794f6;
  --purple-bg: #322447;
  --danger: #f87171;

  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.24);

  /* Both playground columns are pinned to this, so nothing on the page can
     change size as clips are added or a ticket lands. */
  --playground-h: 620px;

  /* Soft panels used by the playground tiles. */
  --tile-bg: #262626;
  --tile-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 1px 2px rgba(0, 0, 0, 0.3),
    0 12px 26px -16px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- App shell / sidebar ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 22px;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #ffffff;
  flex-shrink: 0;
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: none;
  background: transparent;
  border-left: 3px solid transparent;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.nav-item.active {
  background: var(--brand-bg);
  border-left-color: var(--brand-pale);
  color: var(--brand-pale);
  font-weight: 600;
}

.nav-logout {
  margin: 12px 0 0;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

/* ---------- Main area / content header ---------- */

.main-area {
  flex: 1;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.pill-btn:hover {
  filter: brightness(1.08);
}

.pill-btn svg {
  width: 15px;
  height: 15px;
}

.user-pill .user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
}

.user-avatar svg {
  width: 13px;
  height: 13px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #ffffff;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.icon-btn:hover {
  filter: brightness(1.08);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

/* Quieter variant, for use alongside a primary action. */
.ghost-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  box-shadow: var(--shadow);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.ghost-btn:hover {
  filter: none;
  color: var(--brand-pale);
  border-color: var(--brand-pale);
}

.ghost-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.ghost-btn:disabled:hover {
  color: var(--text-muted);
  border-color: var(--border);
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 52px;
  border-bottom: 1px solid var(--border);
  /* Flat band, matching the sidebar — the car photo that used to sit behind
     this was already 86% veiled and only added noise on the dark theme. */
  background: var(--sidebar-bg);
}

.content-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.content-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--brand-bg);
  color: var(--brand-pale);
}

.content-icon svg {
  width: 23px;
  height: 23px;
}

.content-title h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.refresh-btn.spinning svg,
.icon-btn.spinning svg {
  animation: refresh-spin 0.6s linear;
}

@keyframes refresh-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Page layout ---------- */

.page {
  padding: 26px 52px 64px;
}

/* Ease the gutters back on narrower screens before the mobile rules kick in. */
@media (max-width: 1180px) {
  .page {
    padding: 24px 32px 56px;
  }
  .content-header {
    padding: 14px 32px;
  }
}

.placeholder-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.placeholder-page[hidden] {
  display: none;
}

.placeholder-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
}

.placeholder-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-faint);
}

.placeholder-icon svg {
  width: 26px;
  height: 26px;
}

.placeholder-card p {
  font-size: 14px;
  margin: 0;
}

/* ---------- Stat tiles ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-tile {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  cursor: default;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s ease;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid transparent;
}

.tile-total { border-left-color: #059669; box-shadow: 0 8px 18px -8px rgba(5, 150, 105, 0.35); }
.tile-parked { border-left-color: #ea580c; box-shadow: 0 8px 18px -8px rgba(234, 88, 12, 0.35); }
.tile-completed { border-left-color: #4f46e5; box-shadow: 0 8px 18px -8px rgba(79, 70, 229, 0.35); }
.tile-tariff { border-left-color: #9f1239; box-shadow: 0 8px 18px -8px rgba(159, 18, 57, 0.35); }

.stat-tile:hover {
  transform: translateY(-5px);
}

.tile-total:hover { box-shadow: 0 16px 28px -8px rgba(5, 150, 105, 0.4); }
.tile-parked:hover { box-shadow: 0 16px 28px -8px rgba(234, 88, 12, 0.4); }
.tile-completed:hover { box-shadow: 0 16px 28px -8px rgba(79, 70, 229, 0.4); }
.tile-tariff:hover { box-shadow: 0 16px 28px -8px rgba(159, 18, 57, 0.4); }

.tile-icon {
  position: absolute;
  right: -6px;
  bottom: -10px;
  opacity: 0.14;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s ease;
}

.tile-total .tile-icon { color: #059669; right: 12px; bottom: 2px; }
.tile-parked .tile-icon { color: #ea580c; right: 16px; }
.tile-completed .tile-icon { color: #4f46e5; }
.tile-tariff .tile-icon { color: #9f1239; }

.tile-parked .tile-icon svg {
  width: 112px;
  height: 112px;
}

.stat-tile:hover .tile-icon {
  transform: scale(1.15) rotate(-6deg);
  opacity: 0.22;
}

.tile-icon svg {
  width: 84px;
  height: 84px;
}

.tile-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 1;
}

.tile-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.01em;
  z-index: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.tile-caption {
  font-size: 12px;
  color: var(--text-faint);
  z-index: 1;
}

/* ---------- Filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-wide {
  flex: 1 1 320px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--text-faint);
  pointer-events: none;
}

input[type="text"],
input[type="date"],
select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px 9px 32px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}

input[type="text"] {
  min-width: 200px;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

select {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  cursor: pointer;
}

.date-range {
  display: flex;
  align-items: center;
  gap: 10px;
}

.date-range .input-group {
  flex: 1;
}

.date-sep {
  color: var(--text-faint);
  font-size: 13px;
}

/* ---------- Table card ---------- */

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  position: sticky;
  top: 0;
  text-align: left;
  padding: 11px 16px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

th.col-right,
td.col-right {
  text-align: right;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  color: var(--text);
}

tbody tr:nth-child(even) {
  background: var(--surface-alt);
}

tbody tr:hover {
  background: #3a3a3a;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr.row-open {
  box-shadow: inset 3px 0 0 var(--orange);
}

td.plate-cell {
  font-weight: 600;
  letter-spacing: 0.02em;
}

td.tariff-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

td.duration-cell {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-car { background: var(--blue-bg); color: var(--blue); }
.badge-truck { background: var(--orange-bg); color: var(--orange); }
.badge-bus { background: var(--purple-bg); color: var(--purple); }
.badge-motorcycle { background: var(--green-bg); color: var(--green); }
.badge-default { background: var(--surface-alt); color: var(--text-muted); }

.status-open {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--orange);
}

.status-open::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
}

td.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 14px;
  white-space: normal;
}

.plate-thumb {
  height: 34px;
  border-radius: 5px;
  border: 1px solid var(--border);
  display: block;
  transition: transform 0.15s ease;
}

.plate-thumb:hover {
  transform: scale(2.4);
  transform-origin: left center;
  position: relative;
  z-index: 5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
}

.vehicle-thumb {
  height: 40px;
  width: 60px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border);
  display: block;
  transition: transform 0.15s ease;
}

.vehicle-thumb:hover {
  transform: scale(2.2);
  transform-origin: left center;
  position: relative;
  z-index: 5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
}

.no-image {
  color: var(--text-faint);
  font-size: 13px;
}

/* ---------- Loading skeleton ---------- */

.skeleton-row td {
  padding: 14px 16px;
}

.skeleton-bar {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, #2f2f2f 25%, #3f3f3f 37%, #2f2f2f 63%);
  background-size: 400% 100%;
  animation: skeleton-pulse 1.4s ease infinite;
}

@keyframes skeleton-pulse {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .filters {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 10px 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-brand {
    padding: 0 14px;
    flex-shrink: 0;
  }
  .sidebar-nav {
    flex-direction: row;
  }
  .nav-item {
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
  }
  .nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--brand);
  }
  .nav-item span:last-child {
    display: none;
  }
  .nav-logout {
    margin: 0;
    border-top: none;
    padding: 11px 14px;
    flex-shrink: 0;
  }
}

@media (max-width: 520px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .content-header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 18px;
  }
  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }
  .page {
    padding: 18px 16px 48px;
  }
}

/* ---------- Playground ---------- */

/* Even split: video stage on the left, gallery + ticket fill the right half.
   Both columns stretch to the same height so the video bottom lines up with
   the bottom of the ticket tile. */
.playground-grid {
  display: grid;
  /* Left track = 720 card + 24 gap + 88 start control, so the card keeps its
     full width. Left-aligned so the card sits directly under the page title. */
  grid-template-columns: minmax(0, 832px) minmax(0, 560px);
  justify-content: start;
  gap: 28px;
  align-items: stretch;
  margin-top: 18px;
  margin-left: 48px;
}

.playground-left,
.playground-right {
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: var(--playground-h);
  min-height: 0;
}

/* Fixed-height header band, identical on both columns, so the panels below
   start on the same line. */
.playground-head {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 42px;
  flex-shrink: 0;
}

.select-group.compact {
  width: 196px;
}

.select-group.compact select {
  font-weight: 600;
  font-size: 13px;
}

/* Video stage + standalone circular Start control, side by side. */
.video-row {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

/* Vertically centred against the full height of the video stage. */
.start-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
  width: 88px;
}

.start-circle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  /* Glossy play button in the indigo of the Completed Sessions tile
     (#4f46e5): dark rim, lit body, highlight across the top. */
  border: 4px solid #302a94;
  background:
    radial-gradient(ellipse 68% 42% at 50% 10%, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0.26) 46%, rgba(255, 255, 255, 0) 72%),
    linear-gradient(180deg, #6d66ee 0%, #4f46e5 46%, #4038c9 72%, #7a73f2 100%);
  color: #efedfe;
  cursor: pointer;
  box-shadow: 0 12px 26px -10px rgba(79, 70, 229, 0.7);
  transition: filter 0.15s ease, transform 0.15s ease;
}

/* Soft halo so the primary action reads as the thing to click. */
.start-circle::after {
  content: "";
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  border: 2px solid rgba(79, 70, 229, 0.45);
  animation: start-pulse 2.6s ease-out infinite;
  pointer-events: none;
}

@keyframes start-pulse {
  0% { transform: scale(0.92); opacity: 0.75; }
  70% { transform: scale(1.28); opacity: 0; }
  100% { transform: scale(1.28); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .start-circle::after { animation: none; opacity: 0.4; }
}

.start-circle:hover {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.start-circle:disabled {
  cursor: not-allowed;
  filter: grayscale(0.3);
  transform: none;
}

.start-circle:disabled::after {
  display: none;
}

.start-circle svg {
  width: 23px;
  height: 23px;
  margin-left: 3px;
  fill: currentColor;
  stroke: #2a2465;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

.start-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.run-status {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-align: center;
}

.run-status-active { color: var(--orange); }
.run-status-done { color: var(--success); }
.run-status-error { color: var(--danger); }

/* Card wrapper: holds the stage plus the info strip, and fills the left column
   so its bottom edge matches the bottom of the ticket tile. */
.video-card {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 720px;
  min-height: 0;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.video-frame {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 180px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: radial-gradient(120% 130% at 50% 0%, #1a2530 0%, #0b0f14 62%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition: box-shadow 0.2s ease;
}

.video-frame.drag-over {
  box-shadow: inset 0 0 0 2px var(--brand);
}

/* Info strip: clip name on the left, resolution + duration on the right. */
.video-status {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 6px 2px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.vs-item {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.vs-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-faint);
}

.vs-clip {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
}

.vs-clip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vs-right {
  margin-left: auto;
  flex-shrink: 0;
}

.vs-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.video-card.has-clip .vs-dot {
  background: var(--brand-pale);
  box-shadow: 0 0 0 3px rgba(165, 160, 247, 0.22);
}

.video-frame video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: none;
}

.video-frame.has-video video {
  display: block;
}

/* Live annotated MJPEG stream — replaces the raw <video> during a run so the
   detection overlay is what's on screen, in step with the pipeline. */
#live-view {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.video-frame.is-live #live-view {
  display: block;
}

.video-frame.is-live video,
.video-frame.is-live .video-frame-empty {
  display: none;
}

/* Shown between "Start" and the first published frame — the models take a
   while to load, and a bare <img> with no data renders as a broken image. */
.video-starting {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
  padding: 24px;
}

.video-frame.is-starting .video-starting {
  display: flex;
}

.video-frame.is-starting video,
.video-frame.is-starting .video-frame-empty {
  display: none;
}

.video-starting p {
  margin: 0;
  font-size: 12.5px;
  max-width: 260px;
}

.vst-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #ffffff;
  animation: dt-spin 0.8s linear infinite;
}

.live-badge {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  background: rgba(8, 12, 16, 0.72);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.video-frame.is-live .live-badge {
  display: flex;
}

.live-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f04438;
  animation: live-blink 1.4s ease-in-out infinite;
}

@keyframes live-blink {
  50% { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
  .live-badge::before { animation: none; }
}

.video-frame-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.62);
  text-align: center;
  padding: 30px 38px;
  border: 1.5px dashed rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.video-frame.drag-over .video-frame-empty {
  border-color: rgba(255, 255, 255, 0.55);
  color: #ffffff;
}

.video-frame.has-video .video-frame-empty {
  display: none;
}

.video-frame-empty svg {
  width: 30px;
  height: 30px;
}

.video-frame-empty p {
  margin: 0;
  font-size: 12px;
  max-width: 200px;
}

/* Section title sits above the tile, not inside it. */
.playground-heading {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.gallery-card {
  background: var(--tile-bg);
  border: none;
  border-radius: 16px;
  box-shadow: var(--tile-shadow);
  padding: 16px;
  height: 164px;
  flex-shrink: 0;
}

/* Scrollable strip of clips, with the upload tile pinned outside the scroll. */
.gallery-body {
  display: flex;
  align-items: center;
  gap: 16px;
}

.video-gallery {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 12px;
  overflow-x: auto;
  /* Left inset nudges the thumbnails off the tile's edge; the Upload tile is
     a sibling, so it stays put. */
  padding: 3px 0 6px 12px;
  scrollbar-width: thin;
  /* Reserve the scrollbar's space whether it's showing or not — otherwise it
     appears with the Nth clip and silently makes this box taller. */
  scrollbar-gutter: stable;
}

.gallery-empty {
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  padding: 22px 0;
  margin: 0;
  width: 100%;
}

.video-tile {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 0 0 auto;
  width: 124px;
  cursor: grab;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: var(--surface);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.video-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.55);
}

/* Which clip is currently loaded in the stage. */
.video-tile.is-selected {
  border-color: transparent;
  box-shadow: 0 0 0 2px var(--brand-pale), 0 6px 14px -6px rgba(99, 102, 241, 0.5);
}

.video-tile.is-selected .video-tile-name {
  color: var(--brand-pale);
  font-weight: 600;
}

.video-tile:active {
  cursor: grabbing;
}

.video-tile video {
  width: 100%;
  height: 100px;
  object-fit: cover;
  background: #000;
  pointer-events: none;
}

.video-tile-name {
  font-size: 10.5px;
  color: var(--text-muted);
  padding: 5px 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-tile {
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 84px;
  height: 122px;
  border: 1.5px dashed rgba(255, 255, 255, 0.20);
  background: transparent;
  color: var(--text-faint);
}

.upload-tile:hover {
  border-color: var(--brand-pale);
  color: var(--brand-pale);
}

.upload-tile svg {
  width: 22px;
  height: 22px;
}

.upload-tile .video-tile-name {
  padding: 0;
  font-size: 11.5px;
  font-weight: 600;
}

/* ---------- Recognition-zone editor ---------- */

.zone-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.zone-btn svg { width: 15px; height: 15px; }

.zone-btn:hover:not(:disabled),
.zone-btn.is-active {
  color: var(--brand-pale);
  border-color: var(--brand-pale);
}

.zone-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  color: var(--text-muted);
  border-color: var(--border);
}

/* Sits over the whole stage; the box inside is positioned against the
   letterboxed video area, not this element. */
.zone-editor {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.zone-editor[hidden] { display: none; }

.zone-box {
  position: absolute;
  border: 2px solid #ffd60a;
  background: rgba(255, 214, 10, 0.1);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  cursor: move;
}

.zone-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #ffd60a;
  border: 1px solid rgba(0, 0, 0, 0.45);
}

.zone-handle[data-corner="nw"] { left: -8px; top: -8px; cursor: nwse-resize; }
.zone-handle[data-corner="ne"] { right: -8px; top: -8px; cursor: nesw-resize; }
.zone-handle[data-corner="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.zone-handle[data-corner="sw"] { left: -8px; bottom: -8px; cursor: nesw-resize; }

.zone-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 6px 0;
  flex-shrink: 0;
}

.zone-bar[hidden] { display: none; }

.zone-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-right: auto;
}

.zone-hint.is-error { color: var(--danger); }

.zone-action {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.zone-action:hover { color: var(--text); border-color: var(--text-faint); }

.zone-primary {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  border-color: transparent;
  color: #ffffff;
}

.zone-primary:hover { filter: brightness(1.08); color: #ffffff; }

/* ---------- Live detection tiles ---------- */

.detect-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  width: 720px;
  max-width: 100%;
  flex-shrink: 0;
}

.detect-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 12px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  text-align: center;
}

.dt-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  margin-bottom: 2px;
}

.dt-icon svg {
  width: 19px;
  height: 19px;
}

.dt-icon-green { background: var(--brand-bg); color: var(--brand-pale); }
.dt-icon-blue { background: var(--blue-bg); color: var(--blue); }
.dt-icon-amber { background: var(--orange-bg); color: var(--orange); }

.dt-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.dt-value {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.dt-caption {
  font-size: 11px;
  color: var(--text-faint);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* States: the tile's own accent tints the value once it has landed. */
.detect-tile.is-done .dt-value { color: var(--success); }
.detect-tile.is-failed .dt-value { color: var(--danger); }
.detect-tile.is-failed .dt-caption { color: var(--danger); }

/* Small round spinner shown while the backend is still extracting. */
.dt-spinner {
  display: block;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--brand);
  animation: dt-spin 0.75s linear infinite;
}

@keyframes dt-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .dt-spinner { animation-duration: 2s; }
}

/* ---------- Parking ticket ---------- */

.ticket-card {
  background: var(--tile-bg);
  border: none;
  border-radius: 16px;
  box-shadow: var(--tile-shadow);
  padding: 20px 18px;
  min-height: 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ticket-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-faint);
  text-align: center;
}

.ticket-empty svg {
  width: 28px;
  height: 28px;
}

.ticket-empty p {
  margin: 0;
  font-size: 12px;
  max-width: 190px;
}

.ticket-card.has-session .ticket-empty {
  display: none;
}

.ticket-content {
  display: none;
  align-items: stretch;
  align-self: stretch;
  justify-content: center;
  gap: 24px;
  width: 100%;
}

.ticket-card.has-session .ticket-content {
  display: flex;
}

/* Solid front-view vehicle silhouette, left of the receipt. Cut-outs inside
   the icons are painted in --tile-bg, so they read as holes against the tile. */
.vehicle-icon-slot {
  flex-shrink: 0;
  width: 96px;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  opacity: 0;
}

.vehicle-icon-slot svg {
  width: 100%;
  height: auto;
}

.vehicle-icon-slot.vehicle-icon-enter {
  animation: vehicle-arrive 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes vehicle-arrive {
  0% { opacity: 0; transform: translateY(10px) scale(0.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .vehicle-icon-slot.vehicle-icon-enter { animation: none; opacity: 1; }
}

/* Portrait receipt: fixed narrow width, fills the tile's height. */
.ticket {
  position: relative;
  flex: 0 0 auto;
  width: 214px;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--paper-text);
  border: none;
  border-radius: 3px;
  padding: 16px 18px 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45), 0 10px 24px -16px rgba(0, 0, 0, 0.6);
  animation: ticket-print 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes ticket-print {
  0% { opacity: 0; transform: translateY(-14px); }
  100% { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .ticket { animation: none; }
}

.ticket::before,
.ticket::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 8px;
  background-image: radial-gradient(circle at 8px 0, transparent 7px, var(--tile-bg) 7.5px);
  background-size: 16px 16px;
  background-repeat: repeat-x;
}

.ticket::before { top: -5px; }
.ticket::after { bottom: -5px; transform: rotate(180deg); }

.ticket-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.ticket-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #ffffff;
  font-weight: 800;
  font-size: 15px;
}

.ticket-brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.ticket-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6f6f6f;
  margin: 12px 0 7px;
}

.ticket-plate {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--paper-text);
  margin-bottom: 12px;
  font-family: "Consolas", "SFMono-Regular", Menlo, monospace;
}

/* Takes the slack and scrolls if a completed session brings five rows —
   the receipt's height is fixed now, so it must absorb the overflow. */
.ticket-meta {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 16px;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Stacked label-over-value: a timestamp will not fit beside its label at
   this width. */
.ticket-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6f6f6f;
}

.ticket-row span:last-child {
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--paper-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Sits outside .ticket-meta so it can never be scrolled out of view — the
   amount payable is the one line that must always be on screen. */
.ticket-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  margin-bottom: 10px;
  padding-top: 9px;
  border-top: 1px dashed rgba(0, 0, 0, 0.22);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6f6f6f;
}

.ticket-total[hidden] {
  display: none;
}

.ticket-total span:last-child {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
  color: #4338ca;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ticket-barcode {
  /* Pushed to the bottom of the now-taller receipt. */
  margin-top: auto;
  height: 38px;
  background-image: repeating-linear-gradient(
    90deg,
    var(--paper-text) 0px, var(--paper-text) 2px,
    transparent 2px, transparent 4px,
    var(--paper-text) 4px, var(--paper-text) 5px,
    transparent 5px, transparent 9px,
    var(--paper-text) 9px, var(--paper-text) 12px,
    transparent 12px, transparent 14px
  );
  opacity: 0.7;
}

@media (max-width: 1000px) {
  .playground-grid {
    grid-template-columns: 1fr;
    margin-left: 0;
  }
  .video-row {
    align-items: center;
    flex: 0 0 auto;
  }
  .video-frame {
    aspect-ratio: 16 / 10;
    min-height: 0;
  }
}

@media (max-width: 520px) {
  .ticket-content {
    flex-direction: column;
    text-align: center;
  }
  .ticket-row {
    justify-content: space-between;
  }
  .video-row {
    flex-direction: column;
    align-items: flex-start;
  }
}
