:root {
  --bg: #0b0f14;
  --panel: #131a23;
  --panel-2: #1b2531;
  --border: #24313f;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #38bdf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Fira Code", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body { overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: #0e141b;
  border-bottom: 1px solid var(--border);
  height: 54px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 16px; margin: 0; letter-spacing: 0.5px; }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.live { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot.alert { background: var(--danger); box-shadow: 0 0 10px var(--danger); }

.topbar-status { display: flex; gap: 8px; }

.pill {
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
}
.pill.cam { color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 54px);
}

.viewport-panel { display: flex; flex-direction: column; gap: 10px; }

.viewport {
  position: relative;
  flex: 1;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  min-height: 320px;
}

#video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; }

.viewport-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
  z-index: 5;
  background: rgba(0,0,0,0.4);
}

.viewport-msg.hidden { display: none; }

.alarm {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(248,113,113,0.35), rgba(0,0,0,0.7));
  animation: alarmPulse 1s ease-in-out infinite;
  pointer-events: none;
}
.alarm[hidden] { display: none; }

.alarm-inner {
  text-align: center;
  border: 2px solid var(--danger);
  border-radius: 14px;
  padding: 22px 40px;
  background: rgba(0,0,0,0.6);
}
.alarm-inner h2 { font-size: 42px; margin: 0; color: var(--danger); letter-spacing: 2px; }
.alarm-inner p { color: var(--text); margin: 8px 0 0; font-family: var(--mono); font-size: 13px; }

@keyframes alarmPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

/* 3-stage alert status bar: BODY TRACKER -> GEMINI AI -> ALERT */
.alert-status {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.astage {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--muted);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.astage .alab { text-transform: uppercase; }
.alamp {
  width: 10px; height: 10px; border-radius: 50%;
  background: #2a3542;
  border: 1px solid var(--border);
  flex: none;
  transition: background 0.2s, box-shadow 0.2s;
}
.astage .astate { margin-left: auto; font-family: var(--mono); font-size: 10px; }

/* stage 1: internal body tracker detected the transition */
.astage.detect { color: var(--text); border-color: var(--danger); }
.astage.detect .alamp { background: var(--danger); box-shadow: 0 0 10px var(--danger); animation: alarmPulse 1s infinite; }

/* stage 2: Gemini is processing */
.astage.processing { color: var(--text); border-color: var(--warn); }
.astage.processing .alamp { background: var(--warn); box-shadow: 0 0 10px var(--warn); animation: lampBlink 0.8s infinite; }

/* stage 3: Gemini confirmed the fall — full alert */
.astage.confirmed { color: var(--text); border-color: var(--danger); background: rgba(248,113,113,0.12); }
.astage.confirmed .alamp { background: var(--danger); box-shadow: 0 0 14px var(--danger); animation: alarmPulse 0.7s infinite; }

@keyframes lampBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: center;
}
.stat-val { display: block; font-size: 20px; font-family: var(--mono); font-weight: 600; color: var(--accent); }
.stat-lab { display: block; font-size: 10px; color: var(--muted); margin-top: 2px; letter-spacing: 0.5px; }

.sidebar { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; padding-right: 2px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin: 0 0 12px;
}

.row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.row:last-child { margin-bottom: 0; }

.btn {
  background: var(--accent);
  border: none;
  color: #06121b;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(0.98); }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.mode.active { background: var(--warn); color: #06121b; border-color: var(--warn); }
.btn.mode.active::before { content: "\25C9  "; }
.btn.small { padding: 6px 9px; font-size: 12px; }

.hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin-bottom: 10px; }
.hint b { color: var(--text); }

.slider-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.slider-row label { flex: 1; font-size: 12px; display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.slider-row input[type=range] { width: 100%; accent-color: var(--accent); }
.slider-val { font-family: var(--mono); font-size: 12px; color: var(--accent); min-width: 26px; text-align: right; }

.state-detail {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 10px;
  line-height: 1.6;
  min-height: 62px;
}

.log {
  font-family: var(--mono);
  font-size: 11px;
  height: 130px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
}
.log-item { color: var(--muted); display: flex; gap: 6px; }
.log-item .t { color: var(--accent); }
.log-item.fall .m { color: var(--danger); font-weight: 600; }
.log-item.warn .m { color: var(--warn); }
.log-item.info .m { color: var(--muted); }
.log-item.ok .m { color: var(--ok); }

/* Gemini panel */
.gemini-opt { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.gemini-opt .switch-lab { font-size: 12px; color: var(--muted); }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 22px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); transition: background 0.2s;
}
.switch span::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px;
  border-radius: 50%; background: var(--muted); transition: transform 0.2s, background 0.2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); background: #06121b; }

.gemini-result {
  margin-top: 10px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px;
}
.gemini-result[hidden] { display: none; }
.gemini-verdict { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.gemini-verdict.yes { color: var(--danger); }
.gemini-verdict.no { color: var(--ok); }
.gemini-verdict.neutral { color: var(--warn); }
.gemini-reason { font-size: 12px; color: var(--muted); line-height: 1.5; }
