/* ─────────────────────────────────────────────────────────────────────────
   MeetFree — Whereby-inspired Video Conferencing UI
   Clean dark theme, responsive grid, Whereby-like control bar
   ───────────────────────────────────────────────────────────────────────── */

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

:root {
  --bg:        #1a1a2e;
  --bg2:       #16213e;
  --surface:   #0f3460;
  --surface2:  #1a2744;
  --accent:    #e94560;
  --accent2:   #533483;
  --text:      #f0f0f0;
  --text-muted:#a0a8b8;
  --border:    rgba(255,255,255,0.1);
  --bar-h:     72px;
  --radius:    12px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
body { background: var(--bg); color: var(--text); }


/* ── Shared ─────────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 1.8rem; }
.logo-text { font-size: 1.5rem; font-weight: 700; color: var(--text); letter-spacing: -0.5px; }
.logo.small .logo-icon { font-size: 1.4rem; }
.logo.small .logo-text { font-size: 1.2rem; }


/* ── Landing Page ───────────────────────────────────────────────────────── */

.landing-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1a2744 0%, #1a1a2e 60%);
}

.landing-container {
  text-align: center;
  padding: 2rem;
  max-width: 520px;
  width: 100%;
}

.landing-container .logo { justify-content: center; margin-bottom: 2rem; }

h1 {
  font-size: 2.2rem; font-weight: 800; line-height: 1.2;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, #fff 30%, #a78bfa);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.subtitle { color: var(--text-muted); font-size: 1.05rem; margin-bottom: 2rem; line-height: 1.6; }

.room-form {
  display: flex; gap: 10px; margin-bottom: 1rem;
}

.room-form input {
  flex: 1; padding: 14px 18px; border-radius: 10px;
  border: 2px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 1rem; outline: none;
  transition: border-color 0.2s;
}
.room-form input:focus { border-color: var(--accent2); }
.room-form input.error { border-color: var(--accent); animation: shake 0.3s; }

.room-form button {
  padding: 14px 22px; border-radius: 10px; border: none;
  background: var(--accent2); color: #fff; font-size: 1rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: background 0.2s, transform 0.1s;
}
.room-form button:hover { background: #6a45a0; transform: translateY(-1px); }
.room-form button:active { transform: translateY(0); }

.hint { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 2.5rem; }
.hint code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; }

.features {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px;
}

.feature {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  padding: 8px 16px; border-radius: 100px;
  font-size: 0.875rem; color: var(--text-muted);
}


/* ── Pre-Call Modal ─────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10,10,20,0.85); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem;
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal h2 { font-size: 1.5rem; font-weight: 700; }
.room-label { color: var(--text-muted); font-size: 0.9rem; }
.room-label strong { color: var(--text); }

.preview-wrapper {
  position: relative; width: 100%; aspect-ratio: 16/9;
  border-radius: 10px; overflow: hidden; background: #000;
}

.preview-wrapper video {
  width: 100%; height: 100%; object-fit: cover;
  transform: scaleX(-1); /* mirror local preview */
  display: none;
}

.modal input[type="text"] {
  width: 100%; padding: 12px 16px; border-radius: 8px;
  border: 2px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.95rem; outline: none;
  transition: border-color 0.2s;
}
.modal input:focus { border-color: var(--accent2); }

.pre-controls { display: flex; gap: 12px; }

.join-btn {
  width: 100%; padding: 14px; border-radius: 10px; border: none;
  background: var(--accent2); color: #fff;
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.join-btn:hover { background: #6a45a0; transform: translateY(-1px); }


/* ── Room Layout ────────────────────────────────────────────────────────── */

.room-page { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.room-container {
  display: flex; flex: 1; overflow: hidden;
  padding-bottom: var(--bar-h);
}

/* ── Video Grid ─────────────────────────────────────────────────────────── */

.video-grid {
  flex: 1; display: grid; gap: 6px; padding: 6px;
  background: #0d0d1a; overflow: auto;
  align-content: start;
}

.video-grid.grid-1 { grid-template-columns: 1fr; }
.video-grid.grid-2 { grid-template-columns: 1fr 1fr; }
.video-grid.grid-4 { grid-template-columns: 1fr 1fr; }
.video-grid.grid-many { grid-template-columns: repeat(3, 1fr); }

.video-tile {
  position: relative; border-radius: 10px; overflow: hidden;
  background: #111120; aspect-ratio: 16/9;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}

.video-tile:hover { border-color: var(--border); }

.video-tile video {
  width: 100%; height: 100%; object-fit: cover;
  display: block;
}

/* Mirror local video for natural selfie view */
#tile-local video { transform: scaleX(-1); }

.name-tag {
  position: absolute; bottom: 10px; left: 12px;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(4px);
  padding: 3px 10px; border-radius: 100px;
  font-size: 0.78rem; font-weight: 600; color: #fff;
  pointer-events: none;
}


/* ── Video Placeholder (camera off) ────────────────────────────────────── */

.video-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  background: var(--surface2);
  color: var(--text-muted); font-size: 0.9rem;
}
.video-placeholder span { font-size: 2.5rem; }


/* ── Chat Panel ─────────────────────────────────────────────────────────── */

.chat-panel {
  width: 300px; min-width: 260px;
  background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}

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

.close-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1rem; padding: 4px;
}

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

.chat-msg { display: flex; flex-direction: column; gap: 2px; max-width: 90%; }
.chat-msg.self { align-self: flex-end; align-items: flex-end; }
.chat-msg.other { align-self: flex-start; }

.chat-sender { font-size: 0.72rem; color: var(--text-muted); padding: 0 6px; }

.chat-text {
  padding: 8px 12px; border-radius: 10px;
  font-size: 0.88rem; line-height: 1.4;
  word-break: break-word;
}
.self .chat-text { background: var(--accent2); color: #fff; }
.other .chat-text { background: var(--surface2); color: var(--text); }

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

.chat-input-row input {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.875rem; outline: none;
}
.chat-input-row button {
  padding: 8px 14px; border-radius: 8px; border: none;
  background: var(--accent2); color: #fff;
  font-size: 0.875rem; cursor: pointer;
}


/* ── Control Bar ────────────────────────────────────────────────────────── */

.control-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bar-h);
  background: rgba(15,15,30,0.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; gap: 16px; z-index: 500;
}

.controls-left, .controls-right { display: flex; align-items: center; gap: 10px; flex: 1; }
.controls-right { justify-content: flex-end; }
.controls-center { display: flex; align-items: center; gap: 10px; }

.room-name-badge {
  font-size: 0.82rem; color: var(--text-muted);
  background: var(--surface2); padding: 5px 12px;
  border-radius: 100px; border: 1px solid var(--border);
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Control button */
.ctrl-btn {
  position: relative;
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: var(--surface2); color: var(--text);
  font-size: 1.1rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
  border: 1px solid var(--border);
}
.ctrl-btn:hover { background: var(--surface); transform: scale(1.08); }
.ctrl-btn:active { transform: scale(0.96); }
.ctrl-btn.active { background: var(--surface); }
.ctrl-btn.muted { background: rgba(233,69,96,0.25); border-color: var(--accent); }
.ctrl-btn.danger { background: var(--accent); border-color: var(--accent); }
.ctrl-btn.danger:hover { background: #c43050; }

/* Unread badge on chat button */
.badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--accent); color: #fff;
  font-size: 0.65rem; font-weight: 700;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}


/* ── Toast notification ─────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: calc(var(--bar-h) + 16px); left: 50%;
  transform: translateX(-50%);
  background: rgba(30,30,50,0.95); border: 1px solid var(--border);
  backdrop-filter: blur(8px);
  padding: 10px 20px; border-radius: 100px;
  font-size: 0.9rem; color: var(--text);
  z-index: 9999; pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}


/* ── Scrollbar Styling ──────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }


/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .room-form { flex-direction: column; }
  .chat-panel { width: 100%; position: fixed; inset: 0; bottom: var(--bar-h); z-index: 400; }
  .video-grid.grid-many { grid-template-columns: 1fr 1fr; }
  .room-name-badge { display: none; }
}

/* ── Production additions ──────────────────────────────────────────────── */

/* Error banner on landing page */
.error-banner {
  width: 100%; padding: 10px 16px; border-radius: 8px;
  background: rgba(233,69,96,0.2); border: 1px solid var(--accent);
  color: #ff8fa3; font-size: 0.9rem; text-align: center;
  animation: fadeInUp 0.3s ease;
}

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

/* Auth modal */
.auth-modal { gap: 1.5rem; text-align: center; }
.auth-modal p { color: var(--text-muted); }

/* Landing page: two-field form stacked */
.room-form { flex-direction: column; }
.room-form input { width: 100%; }
.room-form button { width: 100%; }

/* Name display in pre-call modal */
.name-display {
  font-size: 1rem; font-weight: 600; color: var(--text-muted);
  text-align: center;
}

/* Control group: button + label stacked */
.ctrl-group { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.ctrl-label { font-size: 0.65rem; color: var(--text-muted); user-select: none; }

/* Participant count badge in control bar */
.participant-count {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.82rem; color: var(--text-muted);
  background: var(--surface2); padding: 4px 10px;
  border-radius: 100px; border: 1px solid var(--border);
}

/* Connection quality indicator */
.conn-quality {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; cursor: default;
}
#qualityIcon { font-size: 1rem; }

/* Tile overlay icons (mute, cam-off, hand) */
.tile-overlay-icon {
  position: absolute; font-size: 1rem;
  background: rgba(0,0,0,0.6); border-radius: 50%;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.mute-icon  { top: 10px; right: 10px; }
.camoff-icon { top: 10px; right: 44px; }
.hand-icon  { top: 10px; left: 10px; animation: bounce 0.6s infinite alternate; }

@keyframes bounce {
  from { transform: translateY(0); }
  to   { transform: translateY(-4px); }
}

/* Chat timestamp */
.chat-ts {
  font-size: 0.68rem; color: var(--text-muted);
  align-self: flex-end; padding: 0 6px;
}

/* Screen share button active state */
#screenBtn.active { background: #1a6b3a; border-color: #2ecc71; }

/* Hand raise active */
#handBtn.active { background: #6b4a00; border-color: #f39c12; }