:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --border: #dce3ec;
  --green: #16804b;
  --blue: #2563eb;
  --red: #dc2626;
  --orange: #ea580c;
  --shadow: 0 16px 40px rgba(22, 32, 51, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 20px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #dbeafe 0, transparent 32%), var(--bg);
}

button { font: inherit; }

.app { width: 100%; max-width: 1100px; margin: 0 auto; }

.header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(26px, 4vw, 40px); }
h2 { margin-bottom: 0; }
.header p { color: var(--muted); margin-bottom: 0; }

.status {
  flex-shrink: 0;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}
.status.loading { background: #fef3c7; color: #92400e; }
.status.ready { background: #dcfce7; color: #166534; }
.status.error { background: #fee2e2; color: #991b1b; }

.viewer-card,
.people-panel,
.history-panel,
.notice {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.viewer-card { padding: 16px; }

.viewer {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  background: #07111f;
}

video, canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
video { visibility: hidden; }
canvas { z-index: 2; }

.camera-badge {
  position: absolute;
  z-index: 4;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(7,17,31,.78);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.dot { width: 10px; height: 10px; border-radius: 50%; background: #9ca3af; }
.dot.active { background: #22c55e; box-shadow: 0 0 0 5px rgba(34,197,94,.2); }

.summary {
  position: absolute;
  z-index: 4;
  right: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  padding: 11px 14px;
  border-radius: 12px;
  background: rgba(7,17,31,.82);
  color: white;
  font-size: 18px;
  font-weight: 900;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.controls button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  color: white;
  font-weight: 850;
  cursor: pointer;
}
.controls button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--green); }
.secondary { background: var(--blue); }
.danger { background: var(--red); }

.error-box {
  margin-top: 12px;
  padding: 13px;
  border: 1px solid #fca5a5;
  border-radius: 12px;
  background: #fee2e2;
  color: #991b1b;
  white-space: pre-line;
}
.hidden { display: none; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.metrics article {
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(255,255,255,.92);
}
.metrics span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 5px; }
.metrics strong { font-size: 18px; }

.people-panel, .history-panel { padding: 17px; margin-top: 14px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 13px; }
.clear-btn {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  font-weight: 750;
  cursor: pointer;
}

.people-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.person-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px;
}
.person-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.person-name { font-weight: 900; }
.person-id {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: white;
  font-weight: 900;
}
.person-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  font-size: 14px;
}
.ok { color: #15803d; font-weight: 850; }
.bad { color: #dc2626; font-weight: 900; text-decoration: underline; text-decoration-thickness: 3px; }
.unknown { color: #6b7280; font-weight: 800; }

.history-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 13px; }
.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: 0; }
.history-icon { font-size: 20px; }
.history-name { font-weight: 800; }
.history-time { color: var(--muted); font-size: 13px; }
.empty { padding: 24px; color: var(--muted); text-align: center; }

.notice {
  margin-top: 14px;
  padding: 15px;
  color: #7c2d12;
  background: #fff7ed;
  border-color: #fed7aa;
  line-height: 1.55;
}

@media (max-width: 760px) {
  body { padding: 10px; }
  .header { display: block; }
  .status { display: inline-block; margin-top: 12px; }
  .viewer { aspect-ratio: 3 / 4; }
  .controls { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .people-list { grid-template-columns: 1fr; }
}
