/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #222222;
  --border: #2a2a2a;
  --accent: #6c63ff;
  --accent-hover: #7b73ff;
  --danger: #e05555;
  --text: #e8e8e8;
  --text-muted: #888;
  --text-dim: #555;
  --tile-bg: #0a0a0a;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

button { cursor: pointer; font-family: inherit; font-size: 14px; border: none; outline: none; }
input { font-family: inherit; font-size: 14px; outline: none; border: none; }

/* ── JOIN PAGE ── */

#join-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 0%, rgba(108,99,255,0.12) 0%, transparent 60%), var(--bg);
  overflow: auto;
}

.join-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  position: relative;
  box-shadow: 0 0 0 1px rgba(108,99,255,0.15), 0 24px 60px rgba(0,0,0,0.5);
}

.join-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 21px;
  background: linear-gradient(135deg, rgba(108,99,255,0.4), transparent 50%);
  z-index: -1;
  pointer-events: none;
}

.join-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.join-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.room-hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.input-group {
  margin-bottom: 16px;
}

.input-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.input-group input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text);
  transition: border-color 0.2s;
}

.input-group input:focus {
  border-color: var(--accent);
}

.input-group input::placeholder { color: var(--text-dim); }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  transition: background 0.2s, transform 0.1s;
  margin-top: 4px;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.99); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
  color: var(--text-dim);
  font-size: 12px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-secondary {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background 0.2s;
}

.btn-secondary:hover { background: rgba(108,99,255,0.1); }

/* ── Admin login specific ── */

.admin-logo span { color: #f59e0b; }

.btn-admin { background: #d97706; }
.btn-admin:hover { background: #b45309; }
.btn-admin:disabled { opacity: 0.6; cursor: not-allowed; }

.admin-error {
  background: rgba(220, 40, 40, 0.12);
  border: 1px solid rgba(220, 40, 40, 0.35);
  color: #ff7777;
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 13px;
  margin-bottom: 14px;
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  flex: 1;
  padding-right: 42px;
}

.toggle-pass {
  position: absolute;
  right: 10px;
  background: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 0;
  line-height: 1;
  cursor: pointer;
  border: none;
  transition: color 0.15s;
}

.toggle-pass:hover { color: var(--text); }

.admin-back {
  margin-top: 18px;
  text-align: center;
}

.admin-back a {
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.15s;
}

.admin-back a:hover { color: var(--text-muted); }

/* ── Admin login specific ── */

.admin-logo span { color: #f59e0b; }
.btn-admin { background: #d97706; }
.btn-admin:hover { background: #b45309; }
.btn-admin:disabled { opacity: 0.6; cursor: not-allowed; }

.admin-error {
  background: rgba(220,40,40,0.12);
  border: 1px solid rgba(220,40,40,0.35);
  color: #ff7777;
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 13px;
  margin-bottom: 14px;
}

.password-wrap { position: relative; display: flex; align-items: center; }
.password-wrap input { flex: 1; padding-right: 42px; }

.toggle-pass {
  position: absolute; right: 10px; background: none;
  color: var(--text-dim); font-size: 16px; padding: 0; cursor: pointer; border: none;
}
.toggle-pass:hover { color: var(--text); }

.admin-back { margin-top: 18px; text-align: center; }
.admin-back a { color: var(--text-dim); font-size: 13px; text-decoration: none; }
.admin-back a:hover { color: var(--text-muted); }

/* ── ROOM LAYOUT ── */

#room-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top bar ── */

.room-topbar {
  height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  gap: 12px;
}

.room-topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.room-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.live-badge {
  background: rgba(220,40,40,0.18);
  color: #ff5555;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid rgba(220,40,40,0.3);
  animation: livePulse 2s infinite;
  white-space: nowrap;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.room-id-label {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-id-label strong { color: var(--text); }

.viewer-badge {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}

.btn-participants {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s, border-color 0.2s;
  position: relative;
}

.btn-participants:hover {
  background: rgba(108,99,255,0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.pending-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #e05555;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  animation: badgePulse 1.5s ease-in-out infinite;
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.btn-leave {
  background: var(--danger);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  font-weight: 600;
  font-size: 13px;
  transition: opacity 0.2s;
}

.btn-leave:hover { opacity: 0.85; }

/* ── Main content ── */

.room-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Video area ── */

.room-video-area {
  flex: 3;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  padding: 14px;
  gap: 10px;
}

/* ── Video grid 2×2 ── */

.video-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  overflow: hidden;
}

.video-tile {
  background: var(--tile-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-element-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-element-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}

.placeholder-text {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 12px;
}

.video-tile.empty {
  border-style: dashed;
  border-color: var(--border);
}

.tile-label {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  border-radius: 6px;
  padding: 5px 9px;
  pointer-events: none;
}

.tile-name {
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-location {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.tile-mute-icon {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(220,40,40,0.85);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 14px;
  align-items: center;
  justify-content: center;
}

.you-badge {
  font-size: 10px;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  vertical-align: middle;
}

/* ── Broadcaster controls ── */

.broadcaster-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-shrink: 0;
  padding-bottom: 4px;
}

.ctrl-btn {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s, border-color 0.2s;
}

.ctrl-btn:hover {
  background: rgba(108,99,255,0.15);
  border-color: var(--accent);
}

.ctrl-btn.active {
  background: rgba(220,40,40,0.18);
  border-color: var(--danger);
  color: #ff7777;
}

/* ── Chat panel ── */

.room-chat {
  flex: 1;
  max-width: 300px;
  min-width: 240px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 14px 16px 12px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.chat-msg {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  border-left: 2px solid var(--accent);
}

.chat-msg-header {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.chat-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
}

.chat-loc {
  font-size: 11px;
  color: var(--text-dim);
}

.chat-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: auto;
}

.chat-text {
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
  line-height: 1.45;
}

.chat-system {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 3px 0;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.2s;
}

.chat-input-area input:focus { border-color: var(--accent); }
.chat-input-area input::placeholder { color: var(--text-dim); }

.btn-chat-send {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn-chat-send:hover { background: var(--accent-hover); }

/* ── Participants drawer ── */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.drawer-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.participants-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}

.participants-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.btn-icon-sm {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon-sm:hover { background: var(--border); color: var(--text); }

.drawer-subtitle {
  padding: 8px 18px;
  font-size: 12px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.participants-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.participants-list::-webkit-scrollbar { width: 4px; }
.participants-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.participant-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  gap: 8px;
}

.participant-item:hover { background: var(--surface2); }

.participant-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.participant-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.participant-dot.broadcasting {
  background: #3ddc84;
  box-shadow: 0 0 6px #3ddc84;
}

.participant-name {
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.participant-location {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.participant-actions {
  flex-shrink: 0;
}

.action-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.promote-btn {
  background: rgba(108,99,255,0.15);
  color: var(--accent);
  border: 1px solid rgba(108,99,255,0.3);
}

.promote-btn:hover { background: rgba(108,99,255,0.3); }
.promote-btn.disabled { opacity: 0.3; cursor: not-allowed; }

.remove-btn {
  background: rgba(220,40,40,0.15);
  color: var(--danger);
  border: 1px solid rgba(220,40,40,0.3);
}

.remove-btn:hover { background: rgba(220,40,40,0.3); }

.me-label {
  font-size: 10px;
  color: var(--text-dim);
  padding: 2px 7px;
}

/* ── Go Live button ── */

.golive-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 6px 0 4px;
  flex-shrink: 0;
}

.golive-btn {
  background: linear-gradient(135deg, #6c63ff, #a855f7);
  color: #fff;
  border: none;
  border-radius: 30px;
  padding: 11px 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s, background 0.2s;
  box-shadow: 0 4px 18px rgba(108,99,255,0.35);
}

.golive-btn:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }
.golive-btn:active:not(:disabled) { transform: scale(0.98); }
.golive-btn:disabled { cursor: not-allowed; }
.golive-btn.pending { background: linear-gradient(135deg, #374151, #4b5563); box-shadow: none; }
.golive-btn.rejected { background: linear-gradient(135deg, #991b1b, #b45309); }

.golive-status {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.golive-status.rejected { color: #ff7777; }

/* ── Audio unlock ── */

.audio-unlock {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  pointer-events: none;
}

.audio-unlock button {
  background: rgba(0,0,0,0.85);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  backdrop-filter: blur(6px);
  transition: background 0.2s;
  pointer-events: all;
}

.audio-unlock button:hover { background: rgba(108,99,255,0.3); border-color: var(--accent); }

/* ── Admin panel sections ── */

.drawer-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  padding: 12px 8px 6px;
  margin-top: 4px;
}

.drawer-section-title.live { color: #3ddc84; }

/* ── Pending broadcast preview ── */

.pending-item {
  background: var(--surface2);
  border: 1px solid rgba(108,99,255,0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}

.pending-preview-wrap {
  position: relative;
  width: 100%;
  height: 130px;
  background: #000;
  overflow: hidden;
}

.pending-preview-label {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
  padding: 2px 7px;
}

.pending-info {
  padding: 8px 10px 4px;
}

.pending-actions {
  display: flex;
  gap: 8px;
  padding: 6px 10px 10px;
}

.approve-btn {
  flex: 1;
  background: rgba(61,220,132,0.15);
  color: #3ddc84;
  border: 1px solid rgba(61,220,132,0.35);
  border-radius: var(--radius-sm);
  padding: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.approve-btn:hover { background: rgba(61,220,132,0.3); }

.reject-btn {
  flex: 1;
  background: rgba(220,40,40,0.12);
  color: var(--danger);
  border: 1px solid rgba(220,40,40,0.3);
  border-radius: var(--radius-sm);
  padding: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.reject-btn:hover { background: rgba(220,40,40,0.25); }

/* ── Responsive ── */

@media (max-width: 768px) {
  html, body { overflow: auto; }

  #room-container { height: auto; min-height: 100vh; }

  .room-topbar { height: auto; padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .room-id-label { font-size: 12px; }

  .room-main { flex-direction: column; overflow: visible; }

  .room-video-area { padding: 10px 10px 6px; height: 55vw; min-height: 200px; }

  .room-chat {
    max-width: 100%;
    min-width: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    height: 300px;
  }

  .participants-drawer { width: 100%; max-width: 360px; }

  .video-grid { gap: 6px; }
}

@media (max-width: 480px) {
  .join-card { padding: 28px 20px; }
  .broadcaster-controls { flex-wrap: wrap; }
}
