:root {
  --bg-dark: #111318;
  --bg-panel: #1a1d24;
  --bg-card: #222630;
  --bg-hover: #2c313e;
  --border: #313746;
  --text-main: #f1f3f9;
  --text-muted: #9ba3b5;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --screen-badge: #8b5cf6;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

/* ==================== LOBBY SCREEN ==================== */
.lobby-screen {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 20%, #1e2436 0%, #0f1116 100%);
  overflow-y: auto;
}

.lobby-card {
  width: 100%;
  max-width: 840px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
}

.brand-logo svg {
  color: var(--accent);
}

.brand-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.lobby-body {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 28px;
}

@media (max-width: 720px) {
  .lobby-body {
    grid-template-columns: 1fr;
  }
}

.preview-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0b0d11;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.lobby-avatar {
  position: absolute;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.preview-controls {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}

.ctrl-btn {
  background: rgba(20, 23, 30, 0.88);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s, border-color 0.15s;
}

.ctrl-btn.active {
  background: rgba(34, 197, 94, 0.18);
  border-color: rgba(34, 197, 94, 0.55);
}

.device-selectors {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.device-row select {
  width: 100%;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.82rem;
}

.join-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  justify-content: center;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field-group input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.98rem;
  outline: none;
  transition: border-color 0.15s;
}

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

.field-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.lobby-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.join-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

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

.join-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.feature-notes {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* ==================== ACTIVE ROOM LAYOUT ==================== */
.room-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
}

/* Top Stream Switchboard Bar */
.top-bar {
  min-height: 48px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  z-index: 20;
}

.room-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.room-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.participant-badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.top-chip-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.top-chip-btn:hover {
  background: var(--bg-hover);
  border-color: #4b5568;
}

.stream-switchboard {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 220px;
  overflow-x: auto;
  padding: 2px 0;
}

.switchboard-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.stream-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.stream-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  transition: all 0.15s;
  user-select: none;
}

.stream-pill.is-screen {
  border-color: rgba(139, 92, 246, 0.55);
  background: rgba(139, 92, 246, 0.16);
}

.stream-pill.is-cam {
  border-color: rgba(59, 130, 246, 0.45);
  background: rgba(59, 130, 246, 0.14);
}

.stream-pill.is-hidden {
  background: rgba(255, 255, 255, 0.03);
  border-color: #2e3340;
  color: var(--text-muted);
  opacity: 0.72;
  text-decoration: line-through;
}

.stream-pill:hover {
  transform: translateY(-1px);
  filter: brightness(1.12);
}

.quick-view-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ==================== WORKSPACE & VIDEO CANVAS ==================== */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.video-canvas {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  min-width: 0;
  min-height: 0;
  position: relative;
}

/* When stage is active + filmstrip is visible */
.video-canvas.has-stage {
  flex-direction: row;
}

@media (max-width: 900px) {
  .video-canvas.has-stage {
    flex-direction: column;
  }
}

.stage-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(var(--stage-cols, 1), 1fr);
  grid-auto-rows: 1fr;
}

.grid-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(var(--grid-cols, 1), 1fr);
  grid-auto-rows: 1fr;
}

/* When stage is active, grid-area acts as a Jitsi-style right-hand filmstrip */
.video-canvas.has-stage .grid-area {
  flex: 0 0 250px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  gap: 8px;
}

.video-canvas.has-stage .grid-area .video-tile {
  flex: 0 0 155px;
  min-height: 155px;
}

@media (max-width: 900px) {
  .video-canvas.has-stage .grid-area {
    flex: 0 0 140px;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .video-canvas.has-stage .grid-area .video-tile {
    flex: 0 0 210px;
    min-height: 100%;
  }
}

/* ==================== VIDEO TILE ==================== */
.video-tile {
  position: relative;
  background: #0a0c10;
  border: 1px solid #262b38;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  user-select: none;
}

.video-tile.is-speaking {
  border-color: var(--success);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.45);
}

.video-tile.is-screen-tile {
  border-color: rgba(139, 92, 246, 0.55);
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.08s ease-out;
  transform-origin: center center;
}

.video-tile.fit-cover video {
  object-fit: cover;
}

.video-tile.mirror-video video {
  transform: scaleX(-1);
}

/* Top-right hover actions on each tile */
.tile-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 5;
}

.video-tile:hover .tile-actions,
.video-tile.is-pinned .tile-actions {
  opacity: 1;
}

.tile-btn {
  background: rgba(15, 18, 25, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.tile-btn:hover {
  background: rgba(45, 52, 68, 0.95);
}

.tile-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tile-btn.hide-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
}

/* Bottom-left label on each tile */
.tile-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(15, 18, 25, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(6px);
  max-width: calc(100% - 16px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 4;
}

.tile-badge-screen {
  background: var(--screen-badge);
  color: #fff;
  font-size: 0.68rem;
  padding: 1px 5px;
  border-radius: 4px;
  text-transform: uppercase;
}

.zoom-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(15, 18, 25, 0.75);
  color: var(--text-muted);
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 0.7rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.video-tile.is-screen-tile:hover .zoom-hint {
  opacity: 1;
}

/* Empty state when no video streams are visible */
.empty-canvas-notice {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.empty-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  max-width: 680px;
  width: 100%;
  text-align: center;
}

.empty-card h3 {
  margin-bottom: 8px;
  font-size: 1.15rem;
}

.empty-card p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 20px;
}

.participant-roster-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.roster-avatar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.roster-avatar-card.is-speaking {
  border-color: var(--success);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35);
}

.roster-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #2f3646;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

/* ==================== SIDE DRAWER ==================== */
.side-drawer {
  width: 340px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

@media (max-width: 720px) {
  .side-drawer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: 340px;
    z-index: 30;
  }
}

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

.drawer-tabs {
  display: flex;
  gap: 6px;
}

.drawer-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.drawer-tab.active {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text-main);
}

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

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-help {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 8px 10px;
  border-radius: 8px;
  line-height: 1.4;
}

.people-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.person-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.person-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.88rem;
}

.person-tracks {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.track-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 4px 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
}

/* Chat Panel */
.chat-body {
  padding: 0;
}

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

.chat-msg {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.84rem;
}

.chat-msg-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.chat-msg-text {
  word-break: break-word;
  line-height: 1.38;
}

.chat-msg-text a {
  color: #60a5fa;
}

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

.chat-form input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 0.85rem;
  outline: none;
}

.chat-form button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}

/* ==================== BOTTOM JITSI TOOLBAR ==================== */
.bottom-bar {
  height: 64px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
}

.toolbar-left, .toolbar-right {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 120px;
}

.toolbar-right {
  text-align: right;
}

@media (max-width: 720px) {
  .toolbar-left, .toolbar-right {
    display: none;
  }
  .bottom-bar {
    justify-content: center;
  }
}

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

.toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 4px;
}

.tool-btn {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  height: 44px;
  padding: 0 13px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.tool-btn:hover {
  background: var(--bg-hover);
}

.tool-btn.active {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent);
}

.tool-btn.muted {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.tool-btn.danger-btn {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.tool-btn.danger-btn:hover {
  background: var(--danger-hover);
}

.unread-pill, .badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

/* ==================== JOIN / LEAVE TOASTS ==================== */
.toast-container {
  position: fixed;
  bottom: 76px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
}

.room-toast {
  background: rgba(26, 29, 36, 0.94);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.room-toast.toast-join {
  border-left: 3px solid var(--success);
}

.room-toast.toast-leave {
  border-left: 3px solid var(--text-muted);
}

.room-toast.fade-out {
  opacity: 0;
  transform: translateY(6px);
}


