*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #6c63ff;
  --accent2: #00d4aa;
  --danger: #ff4d6d;
  --text: #e8eaf6;
  --text-muted: #7b82a8;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  padding: 24px 16px;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

header { text-align: center; }
header h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.5px; }
header .subtitle { color: var(--text-muted); margin-top: 6px; font-size: 0.95rem; }

/* Status */
.model-status {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.9rem;
}

/* Model selector */
.model-selector {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.9rem;
  flex-wrap: wrap;
}
.model-selector label {
  font-weight: 600;
  white-space: nowrap;
}
.model-selector select {
  flex: 1;
  min-width: 180px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 0.9rem;
  cursor: pointer;
}
.model-selector select:disabled { opacity: 0.5; cursor: not-allowed; }
.model-desc {
  color: var(--text-muted);
  font-size: 0.8rem;
  flex-basis: 100%;
}

/* Labels panel */
.labels-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.labels-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  user-select: none;
  list-style: none;
}
.labels-panel summary::-webkit-details-marker { display: none; }
.labels-panel summary::before {
  content: '▸';
  margin-right: 8px;
  transition: transform 0.2s;
}
.labels-panel[open] summary::before { transform: rotate(90deg); }
.labels-count {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.labels-search {
  padding: 0 12px 8px;
}
.labels-search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 12px;
  font-size: 0.85rem;
  outline: none;
}
.labels-search input:focus { border-color: var(--accent); }
.labels-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 12px;
  max-height: 220px;
  overflow-y: auto;
}
.label-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.label-chip.highlight {
  background: rgba(108,99,255,0.15);
  border-color: var(--accent);
  color: #fff;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.loading { background: #f59e0b; animation: pulse 1s infinite; }
.dot.ready   { background: var(--accent2); }
.dot.error   { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
}
.tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}
.tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.tab:hover:not(.active) { background: var(--surface2); color: var(--text); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Video area */
.video-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.video-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16/9;
}
.video-wrapper video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.video-wrapper canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.overlay-label {
  position: absolute;
  bottom: 12px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
  display: none;
  backdrop-filter: blur(4px);
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108,99,255,0.05);
}
.upload-icon { font-size: 3rem; margin-bottom: 12px; }
.upload-zone p { color: var(--text-muted); margin-bottom: 6px; }
.upload-zone .hint { font-size: 0.8rem; }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Controls */
.controls { display: flex; gap: 10px; flex-wrap: wrap; }
.params {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
}
.params label { display: flex; align-items: center; gap: 8px; }
.params input {
  width: 70px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 0.85rem;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary   { background: var(--accent); color: #fff; }
.btn.danger    { background: var(--danger); color: #fff; }
.btn.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn.small     { padding: 6px 14px; font-size: 0.8rem; }

/* Results */
.results-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.results-header h2 { font-size: 1.1rem; font-weight: 600; }

.sentence-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-height: 60px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  align-content: flex-start;
}
.sentence-box .placeholder { color: var(--text-muted); font-size: 0.95rem; }

.predictions-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}
.prediction-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.9rem;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn { from{opacity:0;transform:translateY(-6px)} to{opacity:1;transform:none} }
.prediction-item .label-chip { flex-shrink: 0; }
.pred-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}
.pred-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
}
.prediction-item .conf {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 48px;
  text-align: right;
}
.conf-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  min-width: 4px;
  max-width: 80px;
  transition: width 0.3s;
}
.time-range {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: 4px;
}

/* Progress bar for video analysis */
.progress-wrap {
  background: var(--surface2);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
  display: none;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 4px;
  transition: width 0.2s;
  width: 0%;
}

@media (max-width: 600px) {
  header h1 { font-size: 1.5rem; }
  .params { flex-direction: column; }
}

/* All Predictions panel */
.all-predictions-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.all-predictions-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  user-select: none;
  list-style: none;
}
.all-predictions-panel summary::-webkit-details-marker { display: none; }
.all-predictions-panel summary::before {
  content: '▸';
  margin-right: 8px;
  transition: transform 0.2s;
}
.all-predictions-panel[open] summary::before { transform: rotate(90deg); }
.all-pred-count {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.all-pred-filters {
  display: flex;
  gap: 8px;
  padding: 0 12px 8px;
  flex-wrap: wrap;
  align-items: center;
}
.all-pred-filters input,
.all-pred-filters select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 10px;
  font-size: 0.8rem;
}
.all-pred-filters input { flex: 1; min-width: 120px; }
.all-pred-filters input:focus { border-color: var(--accent); outline: none; }
.all-pred-sort { display: flex; align-items: center; gap: 4px; font-size: 0.8rem; color: var(--text-muted); }
.all-pred-table-wrap {
  max-height: 360px;
  overflow-y: auto;
  padding: 0 12px 12px;
}
.all-pred-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.all-pred-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
}
.all-pred-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.all-pred-table tr:hover td { background: var(--surface2); }
.all-pred-table .conf-cell {
  font-variant-numeric: tabular-nums;
}
