/* ===== A9 Live Control — tema sala de controle ===== */

:root {
  --bg: #0a0d13;
  --surface: #11161f;
  --surface-2: #171e2a;
  --border: #232c3d;
  --text: #eef2f9;
  --muted: #8a94a8;
  --live: #ff3b4d;
  --accent: #3ee0c4;
  --gold: #ffc94d;
  --font-display: "Archivo", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  --radius: 12px;
  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 500px at 70% -10%, rgba(62, 224, 196, 0.06), transparent 60%),
    radial-gradient(900px 400px at 10% 110%, rgba(255, 59, 77, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 15px;
}

body { display: flex; flex-direction: column; overflow: hidden; }

a { color: var(--accent); }

/* ===== Barra superior ===== */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 13, 19, 0.85);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: baseline; gap: 8px; }

.brand-mark {
  font-weight: 900;
  font-stretch: 115%;
  font-size: 20px;
  color: var(--live);
  letter-spacing: -0.5px;
}

.brand-name {
  font-weight: 700;
  font-stretch: 110%;
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--muted);
}

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

.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  transition: background var(--duration-normal);
}
.status-dot.is-live {
  background: var(--live);
  box-shadow: 0 0 10px var(--live);
  animation: pulse 1.6s ease-in-out infinite;
}
.status-dot.is-demo { background: var(--gold); box-shadow: 0 0 10px var(--gold); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.status-text { font-size: 13px; color: var(--muted); }

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

.quota-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
}

/* ===== Botões ===== */

.btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 18px;
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out),
              background var(--duration-fast),
              border-color var(--duration-fast);
}
.btn:hover { background: #1e2736; border-color: #35415a; }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--live);
  border-color: var(--live);
  color: #fff;
}
.btn-primary:hover { background: #ff5262; border-color: #ff5262; }

.btn-ghost { background: transparent; }

.btn-danger {
  background: transparent;
  border-color: rgba(255, 59, 77, 0.5);
  color: var(--live);
}
.btn-danger:hover { background: rgba(255, 59, 77, 0.12); border-color: var(--live); }

.btn-small { font-size: 12px; padding: 6px 12px; }

/* ===== Tela de configuração ===== */

.setup {
  flex: 1;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 30px 20px;
}

.setup-card {
  width: min(560px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 34px 36px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.setup-title {
  margin: 0 0 8px;
  font-weight: 900;
  font-stretch: 115%;
  font-size: 28px;
  letter-spacing: -0.5px;
}

.setup-sub { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }

.mode-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px;
  margin-bottom: 18px;
}

.mode-tab {
  flex: 1;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  padding: 9px 10px;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.mode-tab:hover { color: var(--text); }
.mode-tab.is-active {
  background: var(--surface-2);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(62, 224, 196, 0.4);
}
.mode-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: block; margin-bottom: 16px; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  padding: 11px 14px;
  font-family: var(--font-mono);
  transition: border-color var(--duration-fast);
}
.field input:focus { outline: none; border-color: var(--accent); }

.field-details { margin-bottom: 20px; }
.field-details summary {
  cursor: pointer;
  font-weight: 700;
  padding: 8px 0;
  color: var(--text);
}
.field-details[open] summary { color: var(--accent); }

.key-status { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.key-status.ok { color: var(--accent); }

.help-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
}
.help-box ol { margin: 8px 0 4px; padding-left: 20px; }
.help-box strong, .help-box em { color: var(--text); font-style: normal; }

.setup-actions { display: flex; gap: 12px; margin-top: 8px; }

.setup-error {
  margin: 16px 0 0;
  color: var(--live);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== Painel principal ===== */

.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  padding: 16px 20px;
  min-height: 0;
}

.col-left {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

/* --- cartão do vídeo --- */

.video-card {
  display: flex;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  align-items: center;
}

.video-thumb {
  width: 150px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
}

.video-meta { min-width: 0; }

.live-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #fff;
  background: var(--live);
  border-radius: 4px;
  padding: 3px 8px;
  margin-bottom: 6px;
}
.live-badge.is-off { background: var(--muted); }

.video-title {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-channel { margin: 0; color: var(--muted); font-size: 13.5px; }

/* --- grade de métricas --- */

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-hero {
  grid-row: span 2;
  justify-content: center;
  background: linear-gradient(160deg, rgba(62, 224, 196, 0.10), transparent 55%), var(--surface);
  border-color: rgba(62, 224, 196, 0.35);
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-size: 26px;
  font-weight: 900;
  font-stretch: 110%;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.stat-hero .stat-value { font-size: 46px; color: var(--accent); }

.stat-mono { font-family: var(--font-mono); font-stretch: normal; font-weight: 700; }

.stat-delta { font-size: 13px; font-weight: 700; color: var(--muted); min-height: 1em; }
.stat-delta.up { color: var(--accent); }
.stat-delta.down { color: var(--live); }

/* --- gráfico --- */

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.chart-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.chart-hint { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#viewersChart { width: 100%; height: 130px; display: block; }

/* --- comentário no ar --- */

.onair-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.onair-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.onair-empty { color: var(--muted); font-size: 14px; padding: 10px 0 14px; }

.onair-comment {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid rgba(255, 201, 77, 0.4);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.onair-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--border); }

.onair-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }

.onair-author { font-weight: 800; font-size: 13.5px; color: var(--gold); }
.onair-text { font-size: 14.5px; line-height: 1.4; overflow-wrap: anywhere; }

.share-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding: 12px 0;
}

.share-label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.share-label code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
}

/* ===== Modo "só chat" (cliente): ?modo=chat ou chat.<dominio> ===== */

.chat-mode .main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-mode .col-left { flex: 0 0 auto; overflow: visible; }
.chat-mode .col-right { flex: 1; min-height: 0; }
.chat-mode .stats-grid,
.chat-mode .chart-card,
.chat-mode .quota-badge,
.chat-mode #btnOpenOverlay,
.chat-mode .share-row,
.chat-mode .onair-controls { display: none !important; }

.onair-controls {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.control { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.control select, .control input[type="range"] { accent-color: var(--accent); }
.control select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-family: var(--font-display);
}
.control-check { cursor: pointer; }

/* ===== Coluna do chat ===== */

.col-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.chat-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast);
  animation: msg-in var(--duration-normal) var(--ease-out);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.chat-msg:hover { background: var(--surface-2); border-color: var(--border); }
.chat-msg.is-selected { background: rgba(255, 201, 77, 0.08); border-color: rgba(255, 201, 77, 0.45); }

.chat-msg.is-superchat {
  background: linear-gradient(120deg, rgba(255, 201, 77, 0.14), transparent 70%);
  border-color: rgba(255, 201, 77, 0.35);
}

.chat-avatar { width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto; background: var(--border); }

.chat-body { min-width: 0; }

.chat-author {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--muted);
  margin-right: 6px;
}
.chat-author.is-owner { color: var(--gold); }
.chat-author.is-mod { color: var(--accent); }

.chat-platform {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 6px;
  vertical-align: 1px;
}

.chat-amount {
  font-weight: 900;
  font-size: 12.5px;
  color: var(--gold);
  margin-right: 6px;
}

.chat-text { font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }

.btn-float {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  background: var(--accent);
  border-color: var(--accent);
  color: #06231d;
}

/* ===== Responsivo ===== */

@media (max-width: 980px) {
  body { overflow: auto; }
  .main { grid-template-columns: 1fr; overflow: visible; }
  .col-left { overflow: visible; }
  .col-right { min-height: 480px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
