:root {
  --bg: #0f172a;
  --card: #1e293b;
  --online: #22c55e;
  --offline: #ef4444;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --card-border: #334155;
  --error-bg: #450a0a;
  --error-border: #7f1d1d;
  --placeholder-bg: #0f172a;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────── */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background-color: var(--card);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.125rem;
}

.status-summary {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.last-update {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Error banner ────────────────────────────────────── */

.error-banner {
  background-color: var(--error-bg);
  border: 1px solid var(--error-border);
  color: #fca5a5;
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
  text-align: center;
}

.error-banner.hidden {
  display: none;
}

/* ── Main / Grid ─────────────────────────────────────── */

.main-content {
  padding: 1.5rem;
}

.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.loading-msg {
  color: var(--text-muted);
  font-size: 0.9rem;
  grid-column: 1 / -1;
}

/* ── Card ────────────────────────────────────────────── */

.camera-card {
  background-color: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.camera-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.5rem;
}

.card-title-block {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-online {
  background-color: var(--online);
  color: #052e16;
}

.badge-offline {
  background-color: var(--offline);
  color: #fff;
}

.badge-bitrate {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Player area ─────────────────────────────────────── */

.player-area {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: var(--placeholder-bg);
  margin: 0.75rem 0 0;
  overflow: hidden;
}

.player-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-placeholder svg {
  opacity: 0.15;
  width: 48px;
  height: 48px;
}

.camera-card video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background-color: #000;
  display: block;
}

/* ── Card footer ─────────────────────────────────────── */

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.stream-key {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  background-color: var(--placeholder-bg);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

/* ── Buttons ─────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.4rem 0.9rem;
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-primary {
  background-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-stop {
  background-color: #334155;
  color: var(--text);
}

.btn-stop:hover {
  background-color: #475569;
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 480px) {
  .site-header {
    padding: 0.875rem 1rem;
  }

  .main-content {
    padding: 1rem;
  }

  .camera-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .stream-key {
    max-width: 120px;
  }
}
