:root {
  --bg: #0f0f0f;
  --panel: #181818;
  --panel-2: #212121;
  --border: #303030;
  --text: #f1f1f1;
  --muted: #aaaaaa;
  --accent: #ff3b3b;
  --accent-2: #3ea6ff;
  --danger: #ff4d4d;
  --ok: #3ea63e;
}

:root[data-theme="light"] {
  --bg: #f5f5f5;
  --panel: #ffffff;
  --panel-2: #ececec;
  --border: #dcdcdc;
  --text: #0f0f0f;
  --muted: #5c5c5c;
}

* { box-sizing: border-box; }

body { transition: background-color 0.2s ease, color 0.2s ease; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app {
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

header.topbar {
  position: relative;
  flex: none;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
}

header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header.topbar .brand .dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

header.topbar .brand .dot.live {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  animation: pulse 1.4s infinite;
}

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

.badge {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--muted);
}

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

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
}

.menu-toggle:hover { background: var(--panel-2); }

.topbar-extra {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--muted);
  text-decoration: none;
  font-size: 16px;
  border-radius: 4px;
}

.icon-btn:hover { color: var(--text); background: var(--panel-2); }

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.player-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.player-wrap {
  background: #000;
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

video {
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
}

.mute-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mute-btn:hover { background: rgba(0, 0, 0, 0.75); }

.fullscreen-btn {
  position: absolute;
  bottom: 12px;
  right: 56px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fullscreen-btn:hover { background: rgba(0, 0, 0, 0.75); }

.player-wrap:fullscreen {
  background: #000;
}

.ended-overlay {
  position: absolute;
  inset: 0;
  background: #000;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 2;
}

.ended-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.player-info {
  flex: none;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.player-info h1 {
  font-size: 16px;
  margin: 0 0 4px;
}

.player-info p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.rtmp-config {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 2px;
}

.rtmp-preview {
  flex: none;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.rtmp-preview code {
  color: var(--text);
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 3px;
}

.rtmp-form {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  flex: none;
}

.rtmp-form label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.rtmp-form input {
  flex: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 13px;
}

.rtmp-form input[type="number"] { width: 90px; }
.rtmp-form input[type="text"] { width: 120px; }
.rtmp-form #rtmpHostInput { width: 150px; }
.rtmp-form #rtmpSaveBtn { flex: none; }
.rtmp-form #rtmpConfigMsg { flex: none; white-space: nowrap; }

.rtmp-msg {
  font-size: 12px;
  color: var(--muted);
}

.rtmp-msg.ok { color: var(--ok); }
.rtmp-msg.error { color: var(--danger); }

.stats-panel {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.stats-row {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 10px;
}

.stats-metric {
  display: flex;
  flex-direction: column;
}

.stats-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-2);
}

.stats-label {
  font-size: 12px;
  color: var(--muted);
}

#viewerChart {
  display: block;
  width: 100%;
  height: 60px;
}

.chat-col {
  width: 340px;
  min-width: 280px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, min-width 0.25s ease;
}

.chat-col.collapsed {
  width: 0;
  min-width: 0;
  border-left: none;
  overflow: hidden;
}

.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  font-size: 13px;
  line-height: 1.4;
  padding: 4px 6px;
  border-radius: 4px;
  word-wrap: break-word;
}

.chat-msg:hover { background: var(--panel-2); }

.chat-msg .name {
  color: var(--accent-2);
  font-weight: 600;
  margin-right: 6px;
}

.chat-msg .name.admin { color: var(--accent); }

.chat-msg .del-btn {
  float: right;
  color: var(--danger);
  cursor: pointer;
  font-size: 11px;
  display: none;
  border: none;
  background: none;
}

.chat-msg:hover .del-btn { display: inline; }

.chat-input-row {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  gap: 6px;
}

.chat-input-row input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
}

.chat-input-row input:focus { outline: 1px solid var(--accent-2); }

.chat-input-row button {
  background: var(--accent-2);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 600;
}

.chat-input-row button:disabled {
  background: var(--panel-2);
  color: var(--muted);
  cursor: not-allowed;
}

.chat-blocked-notice {
  padding: 8px 12px;
  background: #3a1f1f;
  color: #ffb3b3;
  font-size: 12px;
  text-align: center;
  display: none;
}

.chat-blocked-notice.show { display: block; }

.name-setup {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
}

.name-setup input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 12px;
}

/* Admin */
.admin-toolbar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}

.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn:hover { filter: brightness(1.1); }

.token-gate {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.token-gate input {
  padding: 10px;
  width: 260px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
}

/* Responsivo */
@media (max-width: 860px) {
  .menu-toggle { display: block; }

  .topbar-extra {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    max-height: 0;
    overflow: hidden;
    padding: 0 16px;
    transition: max-height 0.25s ease, padding 0.25s ease;
    z-index: 10;
  }

  .topbar-extra.open {
    max-height: 200px;
    padding: 12px 16px;
  }
}

/* Celular deitado (mobile landscape): mantem o layout em linha (video + chat lado
   a lado, como no desktop) em vez de empilhar - empilhar aqui forcaria o video
   (aspect-ratio 16:9 em 100% da largura) a ficar mais alto que a propria tela. */
@media (max-width: 860px) and (orientation: landscape) {
  .chat-col { width: 260px; min-width: 220px; }
}

/* Celular em pe (mobile portrait): empilha video em cima, chat embaixo. */
@media (max-width: 860px) and (orientation: portrait) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .layout {
    flex-direction: column;
    height: auto;
  }

  .player-col { flex: none; }

  .player-wrap {
    flex: none;
    width: 100%;
    aspect-ratio: 16 / 9;
  }

  .chat-col {
    width: 100%;
    min-width: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    flex: 1;
    min-height: 320px;
  }

  .chat-col.collapsed {
    flex: none;
    min-height: 0;
    height: 0;
    border-top: none;
  }
}
