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

:root {
  --bg:       #0d0f14;
  --surface:  #161a24;
  --surface2: #1e2332;
  --border:   #2a3045;
  --accent:   #2c14db;
  --accent2:  #a61c1c;
  --text:     #e8eaf0;
  --muted:    #7a84a0;
  --live:     #ff3f60;
  --radius:   12px;
  --nav-h:    60px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { display: block; max-width: 100%; }

/* ── Nav ── */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(13,15,20,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
}

.nav-brand {
  font-size: 1.25rem; font-weight: 800; letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.nav-links { display: flex; gap: 8px; align-items: center; }

.nav-links a {
  padding: 6px 14px; border-radius: 8px; font-size: 0.9rem;
  color: var(--muted); transition: all .15s;
}
.nav-links a:hover, .nav-links a.active {
  background: var(--surface2); color: var(--text); text-decoration: none;
}

.nav-user { display: flex; align-items: center; gap: 10px; }
.nav-avatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--border); }

/* ── Layout ── */
.page { padding-top: calc(var(--nav-h) + 24px); min-height: 100vh; }

.container { max-width: 700px; margin: 0 auto; padding: 0 16px; }
.container-wide { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ── Auth ── */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 60% 40%, rgba(44,20,219,.15) 0%, transparent 60%),
              radial-gradient(ellipse at 20% 80%, rgba(166,28,28,.1) 0%, transparent 50%),
              var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%; max-width: 420px;
}

.auth-logo {
  font-size: 2rem; font-weight: 900; text-align: center; margin-bottom: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-tagline { text-align: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 28px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }

input[type=text], input[type=password], input[type=email], textarea, select {
  width: 100%; padding: 10px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.95rem;
  outline: none; transition: border-color .15s;
  font-family: inherit;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; border: none; transition: all .15s; font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1f0db8; }
.btn-danger  { background: var(--live);   color: #fff; }
.btn-danger:hover  { background: #e0002e; }
.btn-ghost  { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }

/* ── Cards ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}

/* ── Feed ── */
.feed-composer { margin-bottom: 20px; }
.composer-row { display: flex; gap: 12px; align-items: flex-start; }
.composer-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; border: 2px solid var(--border); }
.composer-inner { flex: 1; }
.composer-inner textarea { margin-bottom: 10px; }
.composer-footer { display: flex; justify-content: space-between; align-items: center; }
.char-count { font-size: 0.8rem; color: var(--muted); }
.char-count.warn { color: #f5a623; }
.char-count.over { color: var(--live); }

.post {
  display: flex; gap: 12px; padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.post:hover { background: rgba(255,255,255,.02); }
.post:last-child { border-bottom: none; }
.post-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; border: 2px solid var(--border); }
.post-body { flex: 1; min-width: 0; }
.post-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.post-name { font-weight: 700; font-size: 0.95rem; }
.post-handle { color: var(--muted); font-size: 0.85rem; }
.post-time { color: var(--muted); font-size: 0.8rem; margin-left: auto; }
.post-content { font-size: 0.95rem; line-height: 1.55; word-break: break-word; }
.post-actions { display: flex; gap: 16px; margin-top: 10px; }
.post-action {
  display: flex; align-items: center; gap: 4px;
  color: var(--muted); font-size: 0.82rem; cursor: pointer;
  background: none; border: none; font-family: inherit; transition: color .1s; padding: 2px 0;
}
.post-action:hover { color: var(--accent2); }
.post-action.liked { color: var(--accent2); }

.feed-tabs { display: flex; gap: 0; margin-bottom: 0; border-bottom: 1px solid var(--border); }
.feed-tab {
  flex: 1; padding: 14px; text-align: center; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 0.9rem;
  border-bottom: 2px solid transparent; transition: all .15s;
  background: none; border-top: none; border-left: none; border-right: none;
  font-family: inherit;
}
.feed-tab:hover { color: var(--text); }
.feed-tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ── Profile ── */
.profile-header {
  position: relative; border-radius: var(--radius);
  overflow: hidden; margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.profile-banner {
  height: 140px;
  background: linear-gradient(135deg, #1a0e6e 0%, #0d0730 50%, #4a0f0f 100%);
}
.profile-info { padding: 0 20px 20px; }
.profile-avatar-wrap { margin-top: -36px; margin-bottom: 12px; }
.profile-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  border: 4px solid var(--surface); background: var(--surface2);
}
.profile-top { display: flex; justify-content: space-between; align-items: flex-start; }
.profile-name { font-size: 1.2rem; font-weight: 800; }
.profile-handle { color: var(--muted); font-size: 0.9rem; }
.profile-bio { margin-top: 8px; font-size: 0.9rem; color: var(--muted); }
.profile-stats { display: flex; gap: 24px; margin-top: 12px; }
.stat-val { font-weight: 700; font-size: 1rem; }
.stat-label { color: var(--muted); font-size: 0.8rem; }

/* ── Live ── */
.live-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; min-height: calc(100vh - var(--nav-h) - 48px); }

.live-main { display: flex; flex-direction: column; gap: 16px; }

.video-stage {
  background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16/9; position: relative;
}
.video-stage video { width: 100%; height: 100%; object-fit: cover; }
.video-local {
  position: absolute; bottom: 12px; right: 12px;
  width: 140px; border-radius: 8px; overflow: hidden;
  border: 2px solid var(--accent); aspect-ratio: 16/9;
  background: #000;
}
.video-local video { width: 100%; height: 100%; object-fit: cover; }
.video-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--muted); font-size: 0.95rem;
}
.live-badge {
  position: absolute; top: 12px; left: 12px;
  background: var(--live); color: #fff;
  font-size: 0.72rem; font-weight: 800; letter-spacing: 1px;
  padding: 3px 8px; border-radius: 4px;
}
.viewer-count {
  position: absolute; top: 12px; right: 12px;
  background: rgba(0,0,0,.6); color: #fff;
  font-size: 0.8rem; font-weight: 600;
  padding: 4px 10px; border-radius: 20px; display: flex; align-items: center; gap: 4px;
}

.live-controls { display: flex; gap: 10px; flex-wrap: wrap; }

.rooms-panel { display: flex; flex-direction: column; gap: 12px; }
.rooms-header { display: flex; justify-content: space-between; align-items: center; }
.rooms-header h3 { font-size: 1rem; font-weight: 700; }

.room-card {
  padding: 14px 16px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; transition: all .15s;
}
.room-card:hover { border-color: var(--accent); background: var(--surface2); }
.room-card.active { border-color: var(--accent); }
.room-title { font-weight: 700; font-size: 0.9rem; margin-bottom: 4px; }
.room-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.8rem; }
.room-live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live); animation: pulse 1.5s infinite; }
.room-lock-badge { font-size: .8em; opacity: .8; }

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

.chat-panel {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  height: 400px;
}
.chat-panel h4 { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { font-size: 0.85rem; }
.chat-msg-user { font-weight: 700; color: var(--accent); margin-right: 4px; }
.chat-msg-text { color: var(--text); }
.chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-input-row input { flex: 1; }

/* ── Stage Grid ── */
.stage-tile {
  position: relative; border-radius: 8px; overflow: hidden;
  background: #000; border: 2px solid var(--border);
  width: 160px; aspect-ratio: 16/9; flex-shrink: 0;
}
.stage-tile video { width: 100%; height: 100%; object-fit: cover; }
.stage-tile-label {
  position: absolute; bottom: 4px; left: 6px;
  font-size: 0.7rem; font-weight: 700; color: #fff;
  background: rgba(0,0,0,.55); padding: 2px 6px; border-radius: 4px;
}

/* ── Toasts ── */
#toasts { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: 10px; font-size: 0.9rem; font-weight: 600;
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  animation: slideIn .2s ease;
}
.toast.error { border-color: var(--live); color: var(--live); }
.toast.success { border-color: #4caf7d; color: #4caf7d; }

@keyframes slideIn { from { transform: translateX(60px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Spinner ── */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.2); border-top-color: #fff;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty states ── */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty svg { margin: 0 auto 12px; opacity: .3; }

/* ── Replies ── */
.reply-section { border-top: 1px solid var(--border); padding: 12px 20px 4px 72px; }
.reply-item { display: flex; gap: 8px; margin-bottom: 10px; }
.reply-avatar { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; border: 1px solid var(--border); }
.reply-body { flex: 1; }
.reply-meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.reply-name { font-weight: 700; font-size: .82rem; }
.reply-time { color: var(--muted); font-size: .75rem; }
.reply-content { font-size: .88rem; line-height: 1.45; }
.reply-composer { display: flex; gap: 8px; margin-top: 8px; align-items: flex-start; }
.reply-composer textarea { flex: 1; min-height: 36px; font-size: .88rem; resize: none; }

/* ── Video grid ── */
.video-grid-container {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16/9;
}
.video-grid {
  display: grid;
  gap: 2px;
  width: 100%;
  height: 100%;
}
.video-grid[data-cols="1"] { grid-template-columns: 1fr; }
.video-grid[data-cols="2"] { grid-template-columns: repeat(2, 1fr); }
.video-grid[data-cols="3"] { grid-template-columns: repeat(3, 1fr); }
.video-grid[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }

.video-grid-tile { position: relative; background: #111; overflow: hidden; }
.video-grid-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid-tile-label {
  position: absolute; bottom: 6px; left: 8px;
  font-size: .7rem; font-weight: 700; color: #fff;
  background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 4px;
  pointer-events: none;
}
.grid-tile-kick {
  position: absolute; top: 4px; right: 4px;
  background: rgba(220,30,50,.8); color: #fff;
  border: none; border-radius: 4px; padding: 2px 7px;
  cursor: pointer; font-size: .7rem; font-weight: 700;
}

/* ── Admin broadcast banner ── */
#broadcast-banners {
  position: fixed; top: var(--nav-h); left: 0; right: 0; z-index: 300;
  display: flex; flex-direction: column;
}
.broadcast-banner {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #2c14db 0%, #a61c1c 100%);
  border-bottom: 1px solid rgba(255,255,255,.12);
  color: #fff; font-size: .9rem;
  animation: slideDown .25s ease;
}
@keyframes slideDown { from { transform: translateY(-100%); opacity:0; } to { transform: translateY(0); opacity:1; } }
.broadcast-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.broadcast-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.broadcast-from { font-size: .78rem; opacity: .75; }
.broadcast-msg  { word-break: break-word; line-height: 1.4; }
.broadcast-dismiss {
  background: none; border: none; color: rgba(255,255,255,.6);
  cursor: pointer; font-size: 1rem; padding: 2px 4px; flex-shrink: 0;
  transition: color .15s; margin-top: -1px;
}
.broadcast-dismiss:hover { color: #fff; }

/* Tile status overlays */
.tile-muted-badge {
  position: absolute; bottom: 6px; right: 8px;
  background: rgba(220,30,50,.85); color: #fff;
  font-size: .7rem; border-radius: 4px; padding: 2px 6px;
  pointer-events: none;
}
.tile-cam-off {
  position: absolute; inset: 0;
  background: #111; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 6px; color: var(--muted);
  font-size: .85rem; pointer-events: none;
}
.tile-cam-off svg { opacity: .4; }

/* Active control button states */
.btn-ctrl-active {
  background: rgba(220,30,50,.2) !important;
  border-color: var(--live) !important;
  color: var(--live) !important;
}

.stage-overflow-area { margin-top: 8px; }
.stage-overflow-label { font-size: .75rem; color: var(--muted); margin-bottom: 6px; }
.stage-overflow-tiles { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Mobile chat toggle button ── */
.chat-mobile-toggle {
  display: none;
  align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; font-size: .85rem; font-weight: 600;
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; font-family: inherit;
}

.chat-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chat-header h4 { margin: 0; font-size: .9rem; }
.chat-close-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 0 4px; display: none; }

/* ── Admin table ── */
.admin-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.admin-table th { text-align: left; padding: 10px 12px; color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); }
.admin-table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: rgba(255,255,255,.02); }

.role-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .72rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.role-superadmin { background: rgba(44,20,219,.2); color: var(--accent); }
.role-admin      { background: rgba(166,28,28,.2); color: var(--accent2); }
.role-user       { background: rgba(255,255,255,.06); color: var(--muted); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .live-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 28px 20px; }
  .nav { padding: 0 16px; }

  /* Hide sidebar chat panel, show toggle button instead */
  .rooms-panel .chat-panel { display: none !important; }
  .chat-mobile-toggle { display: inline-flex !important; }
  .chat-close-btn { display: block !important; }

  /* Chat overlays video on mobile */
  .chat-panel {
    position: fixed !important;
    bottom: 0; left: 0; right: 0;
    height: 60vh;
    z-index: 200;
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(100%);
    transition: transform .25s ease;
    display: flex !important;
  }
  .chat-panel.chat-open { transform: translateY(0); }

  /* Stage tiles smaller on mobile */
  .stage-tile { width: 110px; }

  /* Tighter controls */
  .live-controls { gap: 6px; }
  .live-controls .btn { padding: 8px 12px; font-size: .82rem; }
}
