/* ==========================================================
   Design tokens — claro (padrão) e escuro
   ========================================================== */
:root {
  --bg: #eef3f7;
  --surface: #ffffff;
  --surface-2: #f4f8fb;
  --border: #e1e8ef;
  --text: #101828;
  --text-secondary: #66788f;
  --text-tertiary: #94a3b8;

  --accent: #06b6d4;
  --accent-2: #0891b2;
  --accent-gradient: linear-gradient(135deg, #22d3ee 0%, #0891b2 100%);
  --accent-soft: #e0f7fb;
  --accent-contrast: #ffffff;

  --live: #10b981;
  --live-soft: #d8f6ea;
  --danger: #ef4444;
  --danger-soft: #fde3e3;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
  --shadow-accent: 0 12px 28px rgba(8, 145, 178, 0.28);

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1220;
    --surface: #111d2e;
    --surface-2: #162336;
    --border: #223349;
    --text: #eaf1f8;
    --text-secondary: #93a6bd;
    --text-tertiary: #5b6f88;

    --accent: #22d3ee;
    --accent-2: #0891b2;
    --accent-gradient: linear-gradient(135deg, #22d3ee 0%, #0e7490 100%);
    --accent-soft: #0c2b34;
    --accent-contrast: #04121a;

    --live: #34d399;
    --live-soft: #0c2b22;
    --danger: #f87171;
    --danger-soft: #3a1616;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.4);
    --shadow-accent: 0 14px 32px rgba(34, 211, 238, 0.18);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0a1220;
  --surface: #111d2e;
  --surface-2: #162336;
  --border: #223349;
  --text: #eaf1f8;
  --text-secondary: #93a6bd;
  --text-tertiary: #5b6f88;

  --accent: #22d3ee;
  --accent-2: #0891b2;
  --accent-gradient: linear-gradient(135deg, #22d3ee 0%, #0e7490 100%);
  --accent-soft: #0c2b34;
  --accent-contrast: #04121a;

  --live: #34d399;
  --live-soft: #0c2b22;
  --danger: #f87171;
  --danger-soft: #3a1616;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.4);
  --shadow-accent: 0 14px 32px rgba(34, 211, 238, 0.18);

  color-scheme: dark;
}

/* ========================================================== */

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a { color: inherit; }

button { font-family: inherit; }

/* --- Theme toggle --- */
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--accent-2); border-color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

/* ==========================================================
   App shell (dashboard)
   ========================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-accent);
  flex-shrink: 0;
}
.brand-mark svg { width: 22px; height: 22px; color: white; }

.brand-text h1 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.brand-text .role-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

/* --- Tabs --- */
.tabs {
  display: inline-flex;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-bottom: 18px;
}
.tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.tab.active {
  background: var(--accent-gradient);
  color: white;
  box-shadow: var(--shadow-accent);
}

/* --- Stats row --- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-pill .value {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.stat-pill .label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* --- Hero card --- */
.hero {
  position: relative;
  background: var(--accent-gradient);
  border-radius: var(--radius-lg);
  padding: 22px 22px 24px;
  color: white;
  box-shadow: var(--shadow-accent);
  overflow: hidden;
  margin-bottom: 24px;
}
.hero::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}
.hero-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
}
.hero-value {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 6px 0 2px;
  position: relative;
}
.hero-sub {
  font-size: 13px;
  opacity: 0.9;
  position: relative;
}
.hero-icon {
  position: absolute;
  right: 20px;
  top: 20px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
}
.hero-icon svg { width: 24px; height: 24px; }

/* --- Section heading --- */
.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 2px 12px;
}
.section-heading h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}
.section-heading .hint {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* --- Device list --- */
.device-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.device-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 14px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  text-align: left;
  width: 100%;
}
.device-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

.device-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.device-icon svg { width: 22px; height: 22px; }

.device-info { flex: 1; min-width: 0; }
.device-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 3px var(--live-soft);
  flex-shrink: 0;
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.watch-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-gradient);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-accent);
}
.watch-btn svg { width: 12px; height: 12px; }

/* --- Highlights feed --- */
.highlights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.highlight-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  text-align: left;
  padding: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.highlight-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

.highlight-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--surface-2) center/cover no-repeat;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 8px;
}
.highlight-thumb .play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,0.55) 100%);
}
.highlight-thumb .play-overlay svg {
  width: 34px;
  height: 34px;
  color: white;
  opacity: 0.9;
}
.score-badge {
  position: relative;
  z-index: 1;
  background: var(--accent-gradient);
  color: white;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
}
.duration-badge {
  position: relative;
  z-index: 1;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}

.highlight-info { padding: 10px 12px 12px; }
.highlight-device {
  font-size: 13px;
  font-weight: 700;
}
.highlight-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}
.highlight-reason {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Empty / status states --- */
.status {
  color: var(--text-secondary);
  font-size: 13px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}
.empty-state .icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
}
.empty-state .icon svg { width: 26px; height: 26px; }
.empty-state p { margin: 0; font-size: 13px; }

.hidden { display: none; }

/* ==========================================================
   Player
   ========================================================== */

.player-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.back-btn:hover { border-color: var(--accent); color: var(--accent-2); }
.back-btn svg { width: 14px; height: 14px; }

.player-heading {
  flex: 1;
  min-width: 0;
}
.player-heading .name {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--live-soft);
  color: var(--live);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  margin-top: 3px;
}

.player-frame {
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  position: relative;
}
video#player {
  width: 100%;
  max-height: 70vh;
  display: block;
  background: #000;
}

.player-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 0 2px;
}
.viewer-count {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.viewer-count svg { width: 14px; height: 14px; }

@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .hero-value { font-size: 28px; }
}
