:root {
  --bg: #0b0f19;
  --bg-card: #131a2a;
  --bg-elevated: #1c2539;
  --border: #28344e;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #f6821f; /* Laranja Cloudflare */
  --accent-hover: #fa983a;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --radius: 12px;
  --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

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

/* Regra crítica para que qualquer elemento com atributo hidden desapareça mesmo se tiver display:flex */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-block-size: 100dvh;
  display: flex;
  flex-direction: column;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(19, 26, 42, 0.85);
  backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--border);
}

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

.brand-logo {
  inline-size: 42px;
  block-size: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #f97316);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px rgba(246, 130, 31, 0.35);
}

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

.subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.status-dot {
  inline-size: 8px;
  block-size: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.connection-pill[data-state="live"] .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.connection-pill[data-state="connecting"] .status-dot {
  background: var(--accent);
}

.connection-pill[data-state="error"] .status-dot {
  background: var(--danger);
}

/* LAYOUT PRINCIPAL */
.container {
  inline-size: min(1320px, 100%);
  margin-inline: auto;
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* TABS */
.mode-tabs {
  display: inline-flex;
  align-self: flex-start;
  background: var(--bg-card);
  padding: 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  gap: 0.35rem;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.15rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.tab-btn:hover {
  color: var(--text);
}

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

.grid-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 960px) {
  .grid-layout {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.controls-card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.card-desc {
  margin: 0 0 1.1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-block-end: 0.9rem;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
}

select,
input[type="text"],
input[type="password"] {
  inline-size: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.9rem;
}

select:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* TOGGLES DE ÁUDIO */
.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-block: 1rem;
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
}

.toggle-text {
  display: flex;
  flex-direction: column;
}

.toggle-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.toggle-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.toggle-row input[type="checkbox"] {
  inline-size: 1.15rem;
  block-size: 1.15rem;
  accent-color: var(--primary);
  cursor: pointer;
}

/* BOTÕES */
.host-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.2rem;
  border-radius: 9px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
}

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

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  background: #27334d;
}

/* CONVITE E BOTÃO DE COPIAR (Seguindo guia copy-button) */
.invite-box {
  margin-block-start: 1.1rem;
  padding: 1rem;
  border-radius: 10px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.invite-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-block-end: 0.65rem;
}

.badge-live {
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.viewer-count {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.auto-connect-msg {
  margin: 0 0 0.8rem;
  font-size: 0.82rem;
  color: #e2e8f0;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
}

.share-field {
  margin-block-end: 0.75rem;
}

.input-copy-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-block-start: 0.25rem;
}

.input-copy-row input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

/* Positioning context para a bolha de status do copy-button */
.copy {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.copy-button {
  min-inline-size: 24px;
  min-block-size: 36px;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.copy-button:hover {
  background: #27334d;
}

.copy-button .icon {
  inline-size: 16px;
  block-size: 16px;
  display: inline-block;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E") no-repeat center / contain;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E") no-repeat center / contain;
}

.copy-button[data-copied] {
  border-color: var(--success);
  color: var(--success);
}

.copy-button[data-copied] .icon {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") no-repeat center / contain;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") no-repeat center / contain;
}

.copy-button[data-failed] {
  border-color: var(--danger);
  color: var(--danger);
}

.copy .tip {
  position: absolute;
  inset-block-end: calc(100% + 6px);
  inset-inline-end: 0;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid var(--border);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 10;
}

.copy-button[data-copied] + .tip,
.copy-button[data-failed] + .tip {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .copy .tip {
    transform: none;
    transition: opacity 0.15s ease;
  }
}

.audio-status-note {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: #cbd5e1;
}

.advanced-ice {
  margin-block-start: 1rem;
  padding-block-start: 0.75rem;
  border-block-start: 1px solid var(--border);
  font-size: 0.82rem;
}

.advanced-ice summary {
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  margin-block-end: 0.5rem;
}

.small-note {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: 0 0 0.75rem;
}

/* ÁREA DE VÍDEO */
.video-card {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.video-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.video-header h3 {
  margin: 0;
  font-size: 1rem;
}

.stream-metrics {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg-elevated);
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.video-stage {
  position: relative;
  inline-size: 100%;
  aspect-ratio: 16 / 9;
  background: #050811;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.video-stage video {
  inline-size: 100%;
  block-size: 100%;
  object-fit: contain;
  background: #000;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  background: radial-gradient(circle at center, #111827 0%, #050811 100%);
  z-index: 2;
}

.video-placeholder p {
  margin: 0.75rem 0 0.35rem;
  color: var(--text);
  max-inline-size: 46ch;
}

.video-placeholder small {
  max-inline-size: 52ch;
  color: var(--text-muted);
}

.spinner {
  inline-size: 40px;
  block-size: 40px;
  border: 3px solid rgba(59, 130, 246, 0.25);
  border-block-start-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* PAINEL DO ESPECTADOR */
.viewer-status-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

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

.volume-control {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-elevated);
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.btn-icon {
  min-inline-size: 28px;
  min-block-size: 28px;
  background: transparent;
  border: none;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

#sliderVolume {
  inline-size: 80px;
  accent-color: var(--primary);
  cursor: pointer;
}

.unmute-banner {
  position: absolute;
  inset-block-start: 1rem;
  inset-inline: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.15rem;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  z-index: 5;
}
