:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687386;
  --border: #dfe4ec;
  --blue: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--blue);
  text-decoration: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  font-weight: 700;
}

nav {
  display: flex;
  gap: 18px;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 56px;
}

.hero,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 18px;
}

.hero h1,
.panel h1,
.panel h2 {
  margin: 0 0 10px;
}

.hero p,
.muted {
  color: var(--muted);
}

.upload-form {
  display: grid;
  gap: 18px;
}

.query-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(120px, 0.5fr) minmax(130px, 0.6fr) minmax(120px, 0.5fr) auto;
  gap: 14px;
  align-items: end;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

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

button,
.button-link {
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
  width: max-content;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head > div {
  flex: 1 1 auto;
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.filename-cell {
  max-width: 360px;
}

.filename-ellipsis {
  display: block;
  max-width: min(42vw, 360px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-title.filename-ellipsis {
  max-width: min(100%, 760px);
  width: 100%;
}

.status,
.severity {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.status-pending,
.status-processing {
  background: #fef3c7;
  color: #92400e;
}

.status-done,
.severity-low {
  background: #dcfce7;
  color: #166534;
}

.status-failed,
.severity-high {
  background: #fee2e2;
  color: #991b1b;
}

.severity-medium {
  background: #ffedd5;
  color: #9a3412;
}

.media-box video,
.media-box audio {
  width: 100%;
  max-height: 62vh;
  background: #0f172a;
  border-radius: 8px;
}

.timeline {
  position: relative;
  height: 26px;
  margin: 16px 0 8px;
  border-radius: 999px;
  background: #e5e7eb;
}

.timeline-marker {
  position: absolute;
  top: 2px;
  width: 12px;
  height: 22px;
  transform: translateX(-50%);
  border: 2px solid #fff;
  border-radius: 999px;
  padding: 0;
}

.timeline-marker.severity-low {
  background: var(--green);
}

.timeline-marker.severity-medium {
  background: var(--amber);
}

.timeline-marker.severity-high {
  background: var(--red);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.stats div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #fafafa;
}

.stats strong {
  display: block;
  font-size: 24px;
}

.stats span {
  color: var(--muted);
  font-size: 13px;
}

.event-stats div {
  background: #f8fafc;
}

.notice-box {
  border-radius: 8px;
  padding: 12px 14px;
  margin-top: 16px;
  background: #e0f2fe;
  color: #075985;
}

.group-list {
  display: grid;
  gap: 12px;
}

.group-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.group-card summary {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(5, minmax(82px, 0.5fr));
  gap: 12px;
  align-items: center;
  padding: 14px;
  cursor: pointer;
}

.group-range {
  font-weight: 700;
}

.group-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.group-stat strong {
  font-size: 18px;
}

.group-details {
  border-top: 1px solid var(--border);
  background: #fff;
}

.group-chart {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.chart-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 42px;
  gap: 12px;
  align-items: center;
}

.chart-label {
  color: var(--muted);
  font-size: 13px;
}

.chart-track {
  height: 18px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.chart-bar {
  display: block;
  height: 100%;
  min-width: 6px;
  border-radius: 999px;
  background: var(--blue);
}

.time-button {
  background: transparent;
  color: var(--blue);
  padding: 0;
}

.analysis-image {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.frame-preview {
  margin: 14px 0;
}

.frame-preview summary,
.ocr-debug summary {
  color: var(--blue);
  cursor: pointer;
  margin-bottom: 10px;
}

.ocr-debug {
  margin: 14px 0;
}

.ocr-debug pre {
  max-height: 260px;
  overflow: auto;
  background: #0f172a;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
}

.actions,
.table-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.table-actions form,
.actions form {
  margin: 0;
}

.link-danger {
  background: transparent;
  color: var(--red);
  padding: 0;
}

.danger-button {
  background: var(--red);
}

.flash,
.error-box,
.ocr-box {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.flash {
  background: #fef3c7;
  color: #92400e;
}

.error-box {
  background: #fee2e2;
  color: #991b1b;
}

.ocr-box {
  background: #e0f2fe;
  color: #075985;
}

@media (max-width: 760px) {
  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .grid,
  .query-form,
  .stats {
    grid-template-columns: 1fr;
  }

  .group-card summary,
  .chart-row {
    grid-template-columns: 1fr;
  }

  .filename-cell {
    max-width: 220px;
  }

  .filename-ellipsis {
    max-width: 58vw;
  }

  .detail-title.filename-ellipsis {
    max-width: 100%;
  }
}
