:root {
  --bg: #0B0F14;
  --card: #11161D;
  --border: #1F2937;
  --accent: #2DD4A7;
  --danger: #F87171;
  --text: #E6EDF3;
  --dim: #8B98A5;
  --radius: 16px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body { padding-top: 4.25rem; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 4.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.25rem;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 650;
  margin: 0;
  letter-spacing: 0.02em;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(45, 212, 167, 0.7);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.interval-label {
  color: var(--dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
}

/* ---------- pill / badges / chips ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
}

.pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
}

.pill .dot.live {
  background: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}

.pill.online .dot { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.pill.online { border-color: rgba(45, 212, 167, 0.4); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(45, 212, 167, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(45, 212, 167, 0); }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--dim);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s, border-color 0.15s;
}

.chip.active {
  color: var(--accent);
  border-color: rgba(45, 212, 167, 0.5);
  background: rgba(45, 212, 167, 0.08);
}

/* ---------- layout ---------- */
.grid {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.card-wide { grid-column: 1 / -1; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.card-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--dim);
}

.hint { color: var(--dim); font-size: 0.8rem; }
.meta-row { display: flex; justify-content: space-between; gap: 1rem; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #161C24;
  color: var(--text);
  border-radius: 12px;
  padding: 0.55rem 1.1rem;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover:not(:disabled) { background: #1B222C; border-color: #2A3646; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: rgba(45, 212, 167, 0.14);
  border-color: rgba(45, 212, 167, 0.5);
  color: var(--accent);
}

.btn.primary:hover:not(:disabled) { background: rgba(45, 212, 167, 0.22); }
.btn.danger { border-color: rgba(248, 113, 113, 0.5); color: var(--danger); background: rgba(248, 113, 113, 0.08); }
.btn.danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.16); }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.78rem; border-radius: 9px; }

.btn.recording { background: rgba(248, 113, 113, 0.22); border-color: var(--danger); }

/* ---------- audio card ---------- */
#level-meter {
  width: 100%;
  height: 56px;
  border-radius: 10px;
  background: #0D1218;
  border: 1px solid var(--border);
}

/* ---------- camera card ---------- */
.cam-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #080B0F;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

#cam-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cam-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: #3D4A57;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.cam-placeholder-icon { font-size: 2.2rem; opacity: 0.6; }

.cam-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#cam-fps { font-variant-numeric: tabular-nums; }

/* ---------- clips ---------- */
.tabs {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
  align-self: flex-start;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--dim);
  padding: 0.45rem 1.1rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
}

.tab.active { background: rgba(45, 212, 167, 0.12); color: var(--accent); }
.tab:not(.active):hover { color: var(--text); }

.clip-list { display: flex; flex-direction: column; gap: 0.55rem; }

.clip-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(220px, 2fr) auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0E131A;
}

.clip-row:hover { border-color: #2A3646; }
.clip-info { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.clip-name { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-player { min-width: 0; }
.clip-player audio, .clip-player video {
  width: 100%;
  max-width: 420px;
  height: auto;
  border-radius: 8px;
  background: #080B0F;
}

.clip-player video { max-height: 120px; }

.clip-dl {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  border: 1px solid rgba(45, 212, 167, 0.4);
  border-radius: 9px;
  padding: 0.3rem 0.7rem;
  white-space: nowrap;
}

.clip-dl:hover { background: rgba(45, 212, 167, 0.12); }

.empty {
  color: var(--dim);
  font-size: 0.82rem;
  padding: 0.8rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 12px;
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  bottom: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 30;
  width: min(92vw, 420px);
}

.toast {
  background: #161C24;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  font-size: 0.85rem;
  animation: toast-in 0.2s ease-out;
}

.toast.error { border-left-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- reconnect banner ---------- */
.reconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  text-align: center;
  font-size: 0.8rem;
  padding: 0.35rem;
  background: rgba(248, 113, 113, 0.18);
  border-bottom: 1px solid rgba(248, 113, 113, 0.5);
  color: var(--danger);
}

/* ---------- login overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 15, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.login-card {
  width: min(92vw, 340px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.login-card h2 { margin: 0; font-size: 1.05rem; }
.login-card .hint { font-size: 0.8rem; }

.login-card input {
  background: #0D1218;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  font-family: inherit;
}

.login-card input:focus { outline: 1px solid var(--accent); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .clip-row { grid-template-columns: 1fr; }
  .topbar { height: auto; flex-direction: column; align-items: flex-start; padding: 0.6rem 1rem 0.7rem; }
  body { padding-top: 5.6rem; }
}
