/* ========================================================
   PolyU TAS Lab — IoT Cam Stylesheet
   ======================================================== */

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* TAS Lab brand colors */
  --primary: #0795d9;
  --primary-light: #7dd3fc;
  --primary-dark: #075985;
  --accent: #0795d9;
  --accent-hover: #38bdf8;

  /* Surfaces — softer, warmer dark palette (easier on the eyes) */
  --bg: #1a1d2e;
  --bg-gradient-start: #1a1d2e;
  --bg-gradient-end: #1f2236;
  --surface: #22263a;
  --surface-2: #292e45;
  --surface-3: #333952;
  --border: #3a4160;

  /* Text — softer contrast */
  --text: #dce1ed;
  --text-dim: #8e9ab8;

  /* Semantic */
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #22c55e;
  --warning: #f59e0b;

  /* PolyU red for accents */
  --polyu-red: #a0273e;

  /* AI Detection colors */
  --ai-face: #00e5ff;
  --ai-face-bg: rgba(0, 229, 255, .12);
  --ai-object: #ff9100;
  --ai-object-bg: rgba(255, 145, 0, .12);
  --ai-purple: #b388ff;
  --ai-green: #69f0ae;

  /* Effects */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .25);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, .35);
  --transition: .25s ease;
  --transition-fast: .15s ease;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Barlow', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(145deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 50%, #1e2035 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }

/* ---------- Top Bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1.25rem;
  background: rgba(34, 38, 58, .85);
  border-bottom: 1px solid rgba(58, 65, 96, .5);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(16px) saturate(1.2);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.logo-link {
  display: flex;
  align-items: center;
  transition: transform var(--transition-fast);
}
.logo-link:hover { transform: scale(1.08); }

/* ★ Logo images — transparent background (white removed at runtime) */
.logo-img {
  height: 42px;
  width: 42px;
  border-radius: 8px;
  object-fit: contain;
  background: transparent;
}

.topbar-titles h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.2;
}

.topbar-sep {
  color: var(--primary);
  margin: 0 .15rem;
}

.topbar-subtitle {
  font-size: .7rem;
  color: var(--text-dim);
  letter-spacing: .02em;
  font-weight: 500;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.polyu-link {
  display: flex;
  align-items: center;
  transition: opacity var(--transition);
}
.polyu-link:hover { opacity: .8; }

.polyu-logo {
  height: 28px;
  background: transparent;
  border-radius: 4px;
}

.clock {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: .82rem;
  font-weight: 500;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .72rem;
  font-weight: 700;
  padding: .25rem .65rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .05em;
  transition: all var(--transition);
}

.badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge--off {
  background: rgba(239, 68, 68, .12);
  color: var(--danger);
}
.badge--off::before { background: var(--danger); }

.badge--on {
  background: rgba(34, 197, 94, .12);
  color: var(--success);
}
.badge--on::before {
  background: var(--success);
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .3; transform: scale(.8); }
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
  padding: 1.25rem;
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Video Section ---------- */
.video-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.video-container {
  position: relative;
  background: #111320;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .3);
  border: 1px solid var(--border);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.video-container:hover {
  border-color: var(--primary-dark);
}

.video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ---------- Detection Canvas Overlay ---------- */
.detection-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  color: var(--text-dim);
  background: linear-gradient(135deg, #1c2030 0%, #232842 100%);
  transition: opacity .4s ease;
}

.video-placeholder.hidden { opacity: 0; pointer-events: none; }

.placeholder-logo {
  width: 80px;
  height: 80px;
  border-radius: 16px;
  background: transparent;
  opacity: .7;
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.placeholder-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.video-placeholder p {
  font-size: .9rem;
}

/* Recording indicator */
.rec-indicator {
  position: absolute;
  top: 1rem;
  left: 1rem;
  display: flex;
  align-items: center;
  gap: .4rem;
  background: rgba(239, 68, 68, .88);
  color: #fff;
  font-weight: 700;
  font-size: .72rem;
  padding: .3rem .7rem;
  border-radius: 6px;
  letter-spacing: .05em;
  z-index: 5;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  animation: pulse-dot 1s infinite;
}

.rec-indicator.hidden { display: none; }

/* AI indicator */
.ai-indicator {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  align-items: center;
  gap: .4rem;
  background: rgba(0, 229, 255, .82);
  color: #000;
  font-weight: 700;
  font-size: .72rem;
  padding: .3rem .7rem;
  border-radius: 6px;
  letter-spacing: .05em;
  z-index: 5;
  animation: ai-glow 2s ease-in-out infinite;
}

.ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #000;
  animation: pulse-dot 1.2s infinite;
}

.ai-indicator.hidden { display: none; }

@keyframes ai-glow {
  0%, 100% { box-shadow: 0 0 6px rgba(0, 229, 255, .4); }
  50% { box-shadow: 0 0 16px rgba(0, 229, 255, .7); }
}

/* FPS label */
.fps-label {
  position: absolute;
  bottom: .75rem;
  left: .75rem;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
  padding: .2rem .5rem;
  border-radius: 4px;
  z-index: 5;
  font-variant-numeric: tabular-nums;
}

/* Resolution label */
.res-label {
  position: absolute;
  bottom: .75rem;
  right: .75rem;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
  padding: .2rem .5rem;
  border-radius: 4px;
  z-index: 5;
  font-variant-numeric: tabular-nums;
}

/* ---------- Transport Controls ---------- */
.transport {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .55rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  position: relative;
  overflow: hidden;
}

/* Ripple effect on click */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(255,255,255,.2) 0%, transparent 60%);
  opacity: 0;
  transition: opacity .4s;
}

.btn:active::after {
  opacity: 1;
  transition: none;
}

.btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

.btn:active:not(:disabled) {
  transform: translateY(0) scale(.97);
  box-shadow: none;
}

.btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.btn svg { flex-shrink: 0; }

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn--danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn--small {
  font-size: .78rem;
  padding: .35rem .7rem;
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn--recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: pulse-btn 1.2s infinite;
}

@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.4); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  overflow-y: auto;
  max-height: calc(100vh - 80px);
  padding-right: 4px;
  padding-bottom: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
  flex-shrink: 0;
}

.card:hover {
  border-color: var(--primary-dark);
}

/* AI Detection card special styling */
.card--ai {
  border-color: rgba(0, 229, 255, .25);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(0, 229, 255, .03) 100%);
}

.card--ai:hover {
  border-color: rgba(0, 229, 255, .45);
}

.card-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.card-title:hover {
  background: var(--surface-2);
  color: var(--text);
}

.card-title--ai {
  color: var(--ai-face);
}

.card-title--ai:hover {
  background: rgba(0, 229, 255, .06);
}

.card-title .chevron {
  margin-left: auto;
  transition: transform var(--transition);
  flex-shrink: 0;
}

.card.collapsed .card-title .chevron {
  transform: rotate(-90deg);
}

.card-body {
  padding: 0 1rem 1rem;
  transition: all var(--transition);
  max-height: 1000px;
  overflow: visible;
}

.card.collapsed .card-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}

/* ---------- AI Badge ---------- */
.ai-badge {
  font-size: .6rem;
  font-weight: 700;
  padding: .15rem .45rem;
  border-radius: 4px;
  background: rgba(239, 68, 68, .15);
  color: var(--danger);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-left: .25rem;
}

.ai-badge.active {
  background: rgba(0, 229, 255, .15);
  color: var(--ai-face);
  animation: ai-badge-pulse 2s ease-in-out infinite;
}

@keyframes ai-badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .6; }
}

/* ---------- AI Sections ---------- */
.ai-section {
  margin-bottom: .25rem;
}

.ai-feature-icon {
  font-size: 1rem;
  margin-right: .15rem;
}

.ai-suboptions {
  margin-left: 1.5rem;
  padding-left: .75rem;
  border-left: 2px solid var(--border);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all .3s ease;
}

.ai-suboptions.visible {
  max-height: 200px;
  opacity: 1;
  margin-top: .25rem;
  margin-bottom: .25rem;
}

.toggle-row--sub {
  padding: .2rem 0;
}

.toggle-label--sub {
  font-size: .78rem;
}

.toggle--small {
  width: 32px;
  height: 18px;
}

.toggle--small::after {
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
}

.toggle--small:checked::after {
  transform: translateX(14px);
}

.ai-divider {
  height: 1px;
  background: var(--border);
  margin: .5rem 0;
  opacity: .5;
}

/* Model status */
.model-status {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .72rem;
  color: var(--text-dim);
  padding: .25rem 0;
  margin-top: .15rem;
}

.model-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.model-dot--idle { background: var(--text-dim); opacity: .4; }
.model-dot--loading { background: var(--warning); animation: pulse-dot 1s infinite; }
.model-dot--ready { background: var(--success); }
.model-dot--error { background: var(--danger); }

/* ---------- Face Registration ---------- */
.face-reg-header {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .85rem;
  color: var(--text);
  margin-bottom: .35rem;
}

.face-reg-hint {
  font-size: .72rem;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: .55rem;
}

.face-reg-input-row {
  display: flex;
  gap: .4rem;
  align-items: stretch;
  margin-bottom: .5rem;
}

.face-reg-input {
  flex: 1;
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: .82rem;
  outline: none;
  transition: all var(--transition-fast);
}

.face-reg-input::placeholder {
  color: var(--text-dim);
  opacity: .6;
}

.face-reg-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(7, 149, 217, .18);
}

.face-reg-btn {
  white-space: nowrap;
  flex-shrink: 0;
  font-size: .75rem !important;
  padding: .35rem .6rem !important;
}

.registered-faces-list {
  max-height: 140px;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.reg-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: .75rem;
  padding: .75rem .5rem;
  opacity: .6;
}

.reg-person {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .35rem .6rem;
  border-bottom: 1px solid rgba(58, 65, 96, .3);
  transition: background var(--transition-fast);
}

.reg-person:last-child {
  border-bottom: none;
}

.reg-person:hover {
  background: var(--surface-3);
}

.reg-person-name {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--success);
}

.reg-person-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.reg-person-count {
  font-size: .65rem;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface);
  padding: .05rem .3rem;
  border-radius: 4px;
}

.reg-person-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: .8rem;
  cursor: pointer;
  padding: .15rem .35rem;
  border-radius: 4px;
  transition: all var(--transition-fast);
  line-height: 1;
}

.reg-person-remove:hover {
  background: rgba(239, 68, 68, .15);
  color: var(--danger);
}

/* Face Registration Actions (Export / Import) */
.face-reg-actions {
  display: flex;
  gap: .5rem;
  margin-top: .5rem;
}

.face-action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  font-size: .72rem;
  padding: .4rem .5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.face-action-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--primary);
}

.face-action-btn svg {
  flex-shrink: 0;
}

.face-reg-privacy {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .65rem;
  color: var(--text-dim);
  opacity: .7;
  margin-top: .5rem;
  line-height: 1.4;
}

.face-reg-privacy svg {
  flex-shrink: 0;
  color: var(--success);
}

/* Detection stats */
.detection-stats {
  margin-top: .6rem;
  padding: .6rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .2rem 0;
}

.stat-label {
  font-size: .75rem;
  color: var(--text-dim);
  font-weight: 500;
}

.stat-value {
  font-size: .75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.stat-value[data-type="faces"] { color: var(--ai-face); }
.stat-value[data-type="objects"] { color: var(--ai-object); }
.stat-value[data-type="inference"] { color: var(--ai-purple); }

/* ---------- Select ---------- */
.select {
  width: 100%;
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: .85rem;
  appearance: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238899b8'%3E%3Cpath d='M6 8.5 1 3.5h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
}

.select:hover {
  border-color: var(--primary-dark);
}

.select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(7, 149, 217, .2);
}

/* ---------- Presets ---------- */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .45rem;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .2rem;
  padding: .45rem .2rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: inherit;
  font-size: .62rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  min-height: 54px;
  text-align: center;
  line-height: 1.2;
  overflow: hidden;
}

.preset-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.preset-name {
  display: block;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-btn:hover {
  border-color: var(--primary-dark);
  background: var(--surface-3);
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}

.preset-btn.active {
  border-color: var(--primary);
  background: rgba(7, 149, 217, .12);
  color: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary);
}

/* ---------- Slider ---------- */
.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--text-dim);
  margin-top: .6rem;
  margin-bottom: .25rem;
}

.slider-value {
  font-variant-numeric: tabular-nums;
  color: var(--primary-light);
  font-weight: 700;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.slider:hover {
  background: var(--surface-3);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: 0 0 0 0 rgba(7,149,217,0);
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
  box-shadow: 0 0 0 4px rgba(7,149,217,.25);
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
  cursor: pointer;
}

/* ---------- Toggle ---------- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .35rem 0;
}

.toggle-label {
  font-size: .85rem;
  color: var(--text-dim);
}

.toggle {
  -webkit-appearance: none;
  appearance: none;
  width: 38px;
  height: 22px;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}

.toggle:checked {
  background: var(--primary);
}

.toggle:checked::after {
  transform: translateX(16px);
}

/* ---------- Gallery ---------- */
.gallery-count {
  background: var(--surface-2);
  font-size: .65rem;
  padding: .1rem .45rem;
  border-radius: 999px;
  font-weight: 700;
  color: var(--primary-light);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .4rem;
  max-height: 220px;
  overflow-y: auto;
}

.gallery:empty::before {
  content: 'No snapshots yet';
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-dim);
  font-size: .8rem;
  padding: 1.5rem 0;
  opacity: .6;
}

.gallery-thumb {
  aspect-ratio: 16/9;
  border-radius: 6px;
  object-fit: cover;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition-fast);
  width: 100%;
}

.gallery-thumb:hover {
  border-color: var(--primary);
  transform: scale(1.06);
  box-shadow: 0 4px 16px rgba(7,149,217,.3);
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 999;
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  box-shadow: var(--shadow);
  animation: toast-in .35s cubic-bezier(.175,.885,.32,1.275) forwards;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.toast--success { border-left: 3px solid var(--success); }
.toast--error { border-left: 3px solid var(--danger); }
.toast--info { border-left: 3px solid var(--primary); }
.toast--ai { border-left: 3px solid var(--ai-face); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px) scale(.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(16px) scale(.95); }
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  gap: 1rem;
  backdrop-filter: blur(8px);
  animation: fade-in .25s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lightbox.hidden { display: none; }

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  font-size: 2rem;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  line-height: 1;
  transition: transform var(--transition-fast);
}
.lightbox-close:hover { transform: scale(1.2) rotate(90deg); }

.lightbox-img {
  max-width: 90vw;
  max-height: 72vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: zoom-in .3s cubic-bezier(.175,.885,.32,1.275);
}

@keyframes zoom-in {
  from { opacity: 0; transform: scale(.85); }
  to { opacity: 1; transform: scale(1); }
}

.lightbox-download {
  text-decoration: none;
}

/* ---------- Footer ---------- */
.app-footer {
  background: rgba(34, 38, 58, .7);
  border-top: 1px solid rgba(58, 65, 96, .5);
  padding: 1.25rem 1.5rem;
  margin-top: auto;
  backdrop-filter: blur(12px);
}

.footer-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .6rem;
  text-align: center;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .85rem;
  color: var(--text-dim);
}

.footer-brand strong {
  color: var(--primary-light);
}

.footer-logo {
  height: 30px;
  width: 30px;
  border-radius: 6px;
  background: transparent;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
}

.footer-links a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: .82rem;
  font-weight: 500;
  transition: color var(--transition-fast);
}

.footer-links a:hover {
  color: var(--primary);
}

.footer-copy {
  font-size: .72rem;
  color: var(--text-dim);
  opacity: .6;
}

/* ---------- Detection Output Window ---------- */
.output-window {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}

.output-window:hover {
  border-color: var(--primary-dark);
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .55rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: default;
}

.output-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
}

.output-title svg {
  color: var(--primary);
  flex-shrink: 0;
}

.output-count {
  background: var(--primary-dark);
  color: var(--primary-light);
  font-size: .6rem;
  font-weight: 700;
  padding: .1rem .4rem;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.output-actions {
  display: flex;
  gap: .25rem;
}

.output-body {
  transition: max-height .35s ease, opacity .25s ease;
  max-height: 500px;
  opacity: 1;
  overflow: hidden;
}

.output-window.collapsed .output-body {
  max-height: 0;
  opacity: 0;
}

.output-window.collapsed .output-header svg.chevron-icon {
  transform: rotate(-90deg);
}

.output-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 200px;
  max-height: 340px;
}

/* ── Summary side ── */
.output-summary {
  padding: .75rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.summary-section {
  margin-bottom: .75rem;
}

.summary-section:last-child {
  margin-bottom: 0;
}

.summary-heading {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  margin-bottom: .5rem;
  display: flex;
  align-items: center;
  gap: .3rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem;
}

.summary-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .6rem;
  text-align: center;
  transition: border-color var(--transition-fast);
}

.summary-card:hover {
  border-color: var(--primary-dark);
}

.summary-card-value {
  display: block;
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: var(--text);
}

.summary-card-label {
  display: block;
  font-size: .6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-dim);
  margin-top: .15rem;
}

.summary-card--faces .summary-card-value { color: var(--ai-face); }
.summary-card--objects .summary-card-value { color: var(--ai-object); }
.summary-card--fps .summary-card-value { color: var(--ai-purple); }
.summary-card--frames .summary-card-value { color: var(--ai-green); }

.summary-breakdown {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 120px;
  overflow-y: auto;
}

.breakdown-empty {
  display: block;
  text-align: center;
  padding: .6rem;
  font-size: .72rem;
  color: var(--text-dim);
  opacity: .5;
}

.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .3rem .6rem;
  border-bottom: 1px solid rgba(58, 65, 96, .25);
  font-size: .75rem;
  transition: background var(--transition-fast);
}

.breakdown-row:last-child {
  border-bottom: none;
}

.breakdown-row:hover {
  background: var(--surface-3);
}

.breakdown-name {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-weight: 600;
  color: var(--text);
}

.breakdown-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.breakdown-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary-light);
  background: var(--surface);
  padding: .05rem .35rem;
  border-radius: 4px;
  font-size: .68rem;
}

/* ── Log side ── */
.output-log-container {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.output-log {
  flex: 1;
  overflow-y: auto;
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-family: 'Barlow', 'Consolas', 'Courier New', monospace;
  font-size: .72rem;
  max-height: 340px;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: .4rem;
  padding: .25rem .4rem;
  border-radius: 4px;
  line-height: 1.4;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.log-entry:hover {
  background: var(--surface-2);
}

.log-time {
  color: var(--text-dim);
  font-size: .65rem;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 62px;
  opacity: .7;
}

.log-badge {
  font-size: .55rem;
  font-weight: 700;
  padding: .1rem .3rem;
  border-radius: 3px;
  letter-spacing: .03em;
  text-transform: uppercase;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
}

.log-badge--face {
  background: rgba(0, 229, 255, .15);
  color: var(--ai-face);
}

.log-badge--object {
  background: rgba(255, 145, 0, .15);
  color: var(--ai-object);
}

.log-badge--warn {
  background: rgba(239, 68, 68, .15);
  color: var(--danger);
}

.log-badge--system {
  background: rgba(7, 149, 217, .12);
  color: var(--primary);
}

.log-badge--ok {
  background: rgba(34, 197, 94, .12);
  color: var(--success);
}

.log-msg {
  color: var(--text);
  word-break: break-word;
}

.log-entry--system .log-msg { color: var(--text-dim); }
.log-entry--face .log-msg { color: var(--ai-face); }
.log-entry--object .log-msg { color: var(--ai-object); }
.log-entry--warn .log-msg { color: var(--danger-hover); }

/* Fade-in for new entries */
@keyframes log-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.log-entry--new {
  animation: log-fade-in .25s ease forwards;
}

/* ── Responsive output window ── */
@media (max-width: 700px) {
  .output-cols {
    grid-template-columns: 1fr;
  }

  .output-summary {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
  }

  .output-log {
    max-height: 200px;
  }
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }

/* Flash effect for snapshot */
@keyframes snap-flash {
  0% { box-shadow: inset 0 0 0 0 rgba(255,255,255,.6); }
  50% { box-shadow: inset 0 0 80px 40px rgba(255,255,255,.15); }
  100% { box-shadow: inset 0 0 0 0 rgba(255,255,255,0); }
}

.video-container.snap-flash {
  animation: snap-flash .4s ease;
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: none;
  }

  .video-container {
    aspect-ratio: 4 / 3;
  }

  .presets-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: .5rem .75rem;
    gap: .5rem;
  }

  .topbar-subtitle { display: none; }

  .polyu-logo { display: none; }

  .layout { padding: .75rem; gap: .75rem; }

  .transport { gap: .35rem; }

  .btn span { display: none; }
  .btn { padding: .55rem .65rem; }

  .presets-grid { grid-template-columns: repeat(3, 1fr); }

  .footer-brand { flex-direction: column; }
}

@media (max-width: 400px) {
  .topbar-titles h1 { font-size: .95rem; }
  .logo-img { height: 34px; width: 34px; }
  .presets-grid { grid-template-columns: repeat(2, 1fr); }
}
