/* ── CSS Variables ───────────────────────────────────────────────────────── */
:root {
  --bg: #fffaf2;
  --surface: #ffffff;
  --surface-2: #fdf0dc;
  --text: #1a0f00;
  --muted: #4a2800;
  --line: #e8cfa0;
  --brand: #c45e00;
  --brand-2: #e08820;
  --accent: #f0b840;
  --danger: #b64242;
  --ok: #1a9f4a;
  --shadow: 0 12px 36px rgba(140,60,0,.10);
  --radius: 18px;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
body { margin: 0; font-family: Roboto, Arial, sans-serif; background: linear-gradient(180deg, #fffaf2 0%, #fdf0dc 100%); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
h1, h2 { margin: 0 0 10px; }
.container { max-width: 1440px; margin: 0 auto; padding: 0 22px; }

/* ── Header ──────────────────────────────────────────────────────────────── */
.site-header { background: rgba(255,255,255,.88); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.header-flex { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; gap: 18px; }
.eyebrow { color: var(--accent); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 12px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.page-main { padding: 28px 0 50px; }
.grid { display: grid; gap: 18px; }
.cards-3 { grid-template-columns: repeat(3, 1fr); margin-bottom: 18px; }
.two-col { grid-template-columns: 1fr 1.15fr; }
.stack-lg { display: grid; gap: 14px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card, .auth-card, .player-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.auth-card.narrow, .card.narrow { max-width: 560px; margin: 0 auto; }

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stat-label { color: var(--muted); font-size: 14px; }
.stat-value { font-size: 30px; font-weight: 700; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }
.btn-soft { background: #fff8ef; border-color: #f0dcc0; }
.btn-danger { background: #fff1f1; border-color: #f2c5c5; color: var(--danger); }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--brand); cursor: pointer; padding: 0; }
.btn-link.danger { color: var(--danger); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
input, select, textarea, button { font: inherit; }
input, select, textarea { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
textarea { resize: vertical; }
label { display: grid; gap: 6px; font-weight: 500; }
.check { grid-template-columns: auto 1fr; align-items: center; }
.check input { width: auto; }
.link-row { text-align: center; }

/* File input */
input[type="file"] {
  padding: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
}
input[type="file"]:hover {
  border-color: var(--brand-2);
  background: #eef6ff;
}

/* ── Password field with regen button ────────────────────────────────────── */
.password-field {
  display: flex;
  gap: 8px;
  align-items: center;
}
.password-field input {
  flex: 1;
  font-family: monospace;
  font-size: 13px;
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.toolbar-form, .actions-inline, .header-actions, .player-top, .player-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ── Status dots ─────────────────────────────────────────────────────────── */
.status-dot, .live-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 999px; margin-right: 6px;
  vertical-align: middle; background: #9ca3af;
  transition: background .3s, box-shadow .3s;
}
.status-dot.online, .live-dot.online {
  background: #22c55e;
  box-shadow: 0 0 0 5px rgba(34,197,94,.12), 0 0 12px rgba(34,197,94,.9);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 5px rgba(34,197,94,.12), 0 0 12px rgba(34,197,94,.9); }
  50%       { box-shadow: 0 0 0 8px rgba(34,197,94,.06), 0 0 20px rgba(34,197,94,.7); }
}

/* ── Toast notifications ─────────────────────────────────────────────────── */
.toast { position: fixed; top: 18px; left: 50%; transform: translate(-50%, -20px); opacity: 0; transition: .25s ease; z-index: 999; padding: 14px 18px; border-radius: 999px; color: #fff; box-shadow: var(--shadow); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast-success { background: #1a9f4a; }
.toast-error   { background: #b64242; }

/* ── Role badges ─────────────────────────────────────────────────────────── */
.role-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-superadmin { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.role-admin      { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.role-user       { background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}
.badge-ok        { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.badge-error     { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.badge-generated { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; font-size: 11px; padding: 2px 8px; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow: auto; }
.table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; white-space: nowrap; }
tr { border-bottom: 1px solid var(--line); }

/* ── Responsive users table ──────────────────────────────────────────────── */
#usersTable { table-layout: auto; }

#usersTable td,
#usersTable th {
  white-space: normal;
  vertical-align: middle;
}

/* Status, Role, Last Login, Actions — shrink-wrap */
#usersTable th:nth-child(1), #usersTable td:nth-child(1),
#usersTable th:nth-child(5), #usersTable td:nth-child(5),
#usersTable th:nth-child(6), #usersTable td:nth-child(6),
#usersTable th:nth-child(7), #usersTable td:nth-child(7) {
  white-space: nowrap;
  width: 1%;
}

/* Name */
#usersTable th:nth-child(2), #usersTable td:nth-child(2) {
  min-width: 130px;
  word-break: break-word;
}

/* Username */
#usersTable th:nth-child(3), #usersTable td:nth-child(3) {
  min-width: 90px;
  word-break: break-all;
}

/* Email */
#usersTable th:nth-child(4), #usersTable td:nth-child(4) {
  min-width: 140px;
  word-break: break-all;
}

#usersTable .actions-inline {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
}

/* ── Search bar ──────────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-wrap input {
  padding-left: 38px;
  padding-right: 36px;
}
.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state svg { margin-bottom: 10px; opacity: .4; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(31,42,68,.18);
  padding: 28px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h2 { margin: 0; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 8px;
}
.modal-close:hover { background: var(--surface-2); }
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.modal-actions {
  display: flex;
  gap: 10px;
}

/* ── Import styles ───────────────────────────────────────────────────────── */
.import-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}
.import-divider::before,
.import-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}
.import-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
tr.row-error td { background: #fff5f5; }
tr.row-ok td    { background: #f0fdf4; }
.import-ok    { color: var(--ok);     font-weight: 500; }
.import-error { color: var(--danger); font-size: 12px; }

/* ── Profile password section ────────────────────────────────────────────── */
.profile-pw-section {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.profile-pw-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.pw-fields { margin-top: 16px; display: grid; gap: 12px; }
.pw-policy {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.pw-rules {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--muted);
}
.pw-rules li { transition: color .2s; }
.rule-pass { color: var(--ok) !important; }
.rule-fail { color: var(--danger) !important; }
.pw-strength-wrap { display: flex; align-items: center; gap: 10px; }
.pw-strength-bar {
  flex: 1;
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.pw-strength-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  transition: width .3s, background .3s;
}

/* ── Player shell ────────────────────────────────────────────────────────── */
.player-shell {
  display: grid;
  place-items: center;
  align-items: stretch;
  margin: 0 auto;
}
.player-card {
  width: 70%;
  max-width: 70%;
  padding: 0;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(31, 42, 68, 0.35), 0 8px 24px rgba(31, 42, 68, 0.2);
}

/* Remove extra bottom padding on video page */
.page-main:has(.player-shell) {
  padding-bottom: 5 !important;
}

#playerStatus { display: none; }

/* ── Video wrap ──────────────────────────────────────────────────────────── */
.video-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #0f172a;
  aspect-ratio: 16/9;
  width: 100%;
}

#streamVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#webrtcVideo {
  width: 100%; height: 100%;
  display: block;
  background: transparent;
}

/* ── Video overlays ──────────────────────────────────────────────────────── */
.unmute-overlay,
.offline-overlay,
.connecting-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
}

.unmute-overlay {
  background: transparent;
  align-items: flex-end;
  padding-bottom: 18px;
  cursor: pointer;
}
.unmute-badge {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  animation: fadeUp .3s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.offline-overlay { background: rgba(15,23,42,.82); backdrop-filter: blur(6px); }
.offline-badge {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  color: rgba(255,255,255,.8); font-size: 15px; font-weight: 500;
}
.offline-badge svg { opacity: .6; }

.connecting-overlay { background: rgba(15,23,42,.55); }
.spinner {
  width: 44px; height: 44px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Play/pause overlay ──────────────────────────────────────────────────── */
.playpause-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 6;
  cursor: pointer;
}
.playpause-btn {
  width: 64px; height: 64px;
  background: rgba(220,38,38,.9);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, background .15s;
}
.playpause-btn:hover { transform: scale(1.08); background: rgba(220,38,38,1); }

/* ── FB-style viewer count ───────────────────────────────────────────────── */
.fb-viewer-count {
  position: absolute;
  top: 14px; left: 14px;
  z-index: 8;
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  color: #fff; font-size: 14px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px;
  transition: opacity .4s ease;
}

/* ── Live badge ──────────────────────────────────────────────────────────── */
.live-badge {
  position: absolute;
  top: 14px; right: 14px;
  z-index: 8;
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  color: rgba(255,255,255,.7); font-size: 12px; font-weight: 700;
  letter-spacing: .08em; padding: 6px 12px; border-radius: 999px;
  text-transform: uppercase;
  transition: opacity .4s ease;
}
.live-badge.is-live { background: rgba(220,38,38,.85); color: #fff; }

/* ── Video controls overlay ──────────────────────────────────────────────── */
.video-controls {
  position: absolute;
  bottom: 14px; left: 14px;
  display: flex; align-items: center; gap: 6px;
  z-index: 8;
  opacity: 1;
  transition: opacity .4s ease;
}
.vid-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px; border: none;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  color: #fff; cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}
.vid-btn:hover { background: rgba(0,0,0,.8); }
.vid-btn svg   { stroke: #fff; }

/* ── Overlay auto-hide ───────────────────────────────────────────────────── */
.fb-viewer-count.overlay-hidden,
.live-badge.overlay-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}
.video-controls.overlay-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}
/* JS controls visibility — these ensure overlay-hidden always wins */
.video-wrap .video-controls.overlay-hidden,
.video-wrap:hover .video-controls.overlay-hidden,
.video-wrap.paused .video-controls.overlay-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ── Volume control ──────────────────────────────────────────────────────── */
.volume-wrap { position: relative; }
.volume-popup {
  position: absolute;
  right: auto;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
  display: flex; align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
  white-space: nowrap;
  z-index: 10;
}
.volume-wrap:hover .volume-popup,
.volume-wrap:focus-within .volume-popup {
  opacity: 1;
  pointer-events: auto;
}
.volume-slider {
  width: 80px; height: 4px;
  -webkit-appearance: none;
  background: rgba(255,255,255,.3);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
}

/* ── Quality selector ────────────────────────────────────────────────────── */
.quality-wrap { position: relative; }
#qualityBtn {
  font-size: 11px; font-weight: 700;
  letter-spacing: .04em;
  min-width: 52px; padding: 0 8px;
}
.quality-popup {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 12px;
  padding: 6px;
  min-width: 80px;
  z-index: 20;
  flex-direction: column;
  gap: 2px;
}
.quality-popup.open { display: flex; }
.quality-option {
  background: none; border: none;
  color: rgba(255,255,255,.8);
  font: inherit; font-size: 13px;
  padding: 8px 12px; border-radius: 8px;
  cursor: pointer; text-align: center;
  transition: background .1s;
}
.quality-option:hover  { background: rgba(255,255,255,.1); color: #fff; }
.quality-option.active { background: rgba(255,255,255,.15); color: #fff; font-weight: 600; }

/* Hide old viewer pill */
.viewer-pill { display: none; }
.player-top  { margin-bottom: 0; }

/* Fullscreen */
.video-wrap:fullscreen       { aspect-ratio: unset; border-radius: 0; }
.video-wrap:fullscreen video { width: 100vw; height: 100vh; object-fit: contain; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .cards-3, .two-col { grid-template-columns: 1fr; }
  .header-flex { align-items: flex-start; }
  .player-actions { flex-wrap: wrap; gap: 8px; }
  .modal-grid { grid-template-columns: 1fr; }
  .player-card { width: 100%; max-width: 100%; }
}

@media (max-width: 1024px) {
  #usersTable th, #usersTable td { padding: 10px 7px; font-size: 13px; }
}

@media (max-width: 768px) {
  #usersTable th, #usersTable td { padding: 8px 5px; font-size: 12px; }
  .role-badge { font-size: 10px; padding: 2px 7px; }
}

.status-dot.disabled {
  background: #1a0f00;
}
