/* ==========================================================================
   Base & Design System Tokens (Zinc / Slate Neutral Palette)
   ========================================================================== */
:root {
  --bg-app: #09090b;
  --bg-surface: #121215;
  --bg-card: #18181b;
  --bg-card-hover: #202024;
  --bg-muted: #27272a;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #0284c7;
  
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  
  --accent-primary: #0284c7;
  --accent-hover: #0369a1;
  --accent-active: #075985;
  
  --status-online: #10b981;
  --status-danger: #ef4444;
  --status-danger-hover: #dc2626;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-stack);
  letter-spacing: -0.01em;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  display: flex;
}

.app-root {
  width: 100%;
  height: 100vh;
  display: flex;
  position: relative;
}

.hidden {
  display: none !important;
}

/* Icons styling */
.icon-xs { width: 14px; height: 14px; }
.icon-sm { width: 16px; height: 16px; }
.icon-md { width: 20px; height: 20px; }
.icon-lg { width: 32px; height: 32px; }

/* SVG Stroke adjustments */
svg {
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ==========================================================================
   View Panels Switcher
   ========================================================================== */
.view-panel {
  display: none;
  width: 100%;
  height: 100%;
}

.view-panel.active {
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   1. Pre-Call Lobby View (Green Room)
   ========================================================================== */
#lobbyView {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 20%, #171d28 0%, #09090b 70%);
}

.lobby-card {
  width: 100%;
  max-width: 980px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 24px;
  height: 24px;
  color: var(--accent-primary);
}

.brand h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.secure-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--status-online);
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.lobby-body {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 24px;
  padding: 24px;
}

/* Video Preview Box */
.lobby-preview-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #020203;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

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

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-surface);
  color: var(--text-dim);
  font-size: 0.85rem;
}

.lobby-quick-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  background: rgba(9, 9, 11, 0.75);
  backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

.ctrl-btn {
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.ctrl-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.ctrl-btn.off {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--status-danger);
}

/* Audio Meter */
.audio-meter-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.05);
}

.meter-fill {
  width: 0%;
  height: 100%;
  background: var(--status-online);
  transition: width 80ms ease-out;
}

/* Form Area */
.lobby-form-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}

.sub-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"], .form-select {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 9px 12px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

input[type="text"]:focus, .form-select:focus {
  border-color: var(--border-focus);
}

.form-select {
  cursor: pointer;
}

.device-selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.peer-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.my-id-container, .call-action-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.id-row, .call-row {
  display: flex;
  gap: 8px;
}

.id-row input {
  flex: 1;
  color: var(--text-muted);
  cursor: default;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
}

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

.btn-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-primary);
  border: none;
  color: #ffffff;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
  white-space: nowrap;
}

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

/* ==========================================================================
   2. Active Call View
   ========================================================================== */
#callView {
  background: var(--bg-app);
}

/* Top Bar */
.call-top-bar {
  height: 56px;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.call-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.room-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-online);
}

.call-timer {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  padding-left: 12px;
  border-left: 1px solid var(--border-subtle);
}

.quality-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-dim);
  background: var(--bg-card);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-subtle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  position: relative;
  transition: background var(--transition-fast);
}

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

.unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent-primary);
  color: white;
  font-size: 0.65rem;
  font-weight: 600;
  min-width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Workspace Area */
.call-workspace {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  padding: 16px 20px 84px 20px;
  gap: 16px;
}

.video-grid-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #020204;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.video-cell {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #0d0e12;
}

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

/* Remote (Main) Video */
.remote-cell {
  width: 100%;
  height: 100%;
}

/* Local Video (PiP) */
.local-cell {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 240px;
  height: 145px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6);
  z-index: 10;
  transition: width var(--transition-fast), height var(--transition-fast);
}

.local-cell video {
  transform: scaleX(-1);
}

/* Avatar Placeholders */
.avatar-cell-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.avatar-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg-muted);
  border: 2px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Overlay Participant Tag */
.participant-overlay {
  position: absolute;
  bottom: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(9, 9, 11, 0.7);
  backdrop-filter: blur(6px);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-main);
  z-index: 5;
}

/* Speaking Wave Indicator */
.audio-wave-indicator {
  display: none;
  align-items: center;
  gap: 2px;
  height: 12px;
}

.audio-wave-indicator.active {
  display: flex;
}

.audio-wave-indicator span {
  width: 2px;
  height: 100%;
  background: var(--status-online);
  border-radius: 2px;
  animation: wave 0.8s ease-in-out infinite alternate;
}

.audio-wave-indicator span:nth-child(2) { animation-delay: 0.2s; }
.audio-wave-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes wave {
  0% { transform: scaleY(0.3); }
  100% { transform: scaleY(1); }
}

/* ==========================================================================
   Chat Sidebar (In-call P2P)
   ========================================================================== */
.chat-sidebar {
  width: 320px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition-fast), opacity var(--transition-fast);
}

.chat-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.chat-sidebar-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  color: var(--text-main);
  background: var(--bg-muted);
}

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

.chat-system-notice {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.chat-bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-bubble.mine {
  align-self: flex-end;
  background: var(--accent-primary);
  color: white;
}

.chat-bubble.theirs {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.chat-sender {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
}

.chat-time {
  font-size: 0.65rem;
  align-self: flex-end;
  opacity: 0.7;
}

.chat-input-bar {
  display: flex;
  padding: 10px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-card);
  gap: 8px;
}

.chat-input-bar input {
  flex: 1;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.btn-send {
  background: var(--accent-primary);
  border: none;
  color: white;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

/* ==========================================================================
   Bottom Floating Control Deck
   ========================================================================== */
.call-control-dock {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(18, 18, 21, 0.9);
  backdrop-filter: blur(12px);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  z-index: 50;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.5);
}

.dock-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.dock-action:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.dock-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
}

.dock-action.off {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--status-danger);
}

.dock-action.danger {
  background: var(--status-danger);
  border-color: transparent;
  color: #ffffff;
  width: 60px;
  height: 52px;
  border-radius: var(--radius-full);
}

.dock-action.danger:hover {
  background: var(--status-danger-hover);
}

.dock-action.active {
  background: rgba(2, 132, 199, 0.2);
  border-color: var(--border-focus);
  color: var(--accent-primary);
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

.modal-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(2, 132, 199, 0.15);
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-pulse {
  animation: ring 1.5s infinite;
}

@keyframes ring {
  0% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.7; }
}

.modal-action-row {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
}

.btn-reject {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  cursor: pointer;
  font-weight: 500;
}

.btn-accept {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--status-online);
  border: none;
  color: #ffffff;
  cursor: pointer;
  font-weight: 500;
}

.settings-card {
  align-items: stretch;
  text-align: left;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Toast Notifications */
.toast-box {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-30px);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
  z-index: 2000;
}

.toast-box.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 820px) {
  .lobby-body {
    grid-template-columns: 1fr;
  }
  
  .local-cell {
    width: 140px;
    height: 95px;
    bottom: 12px;
    right: 12px;
  }
  
  .chat-sidebar {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 74px;
    width: 290px;
    z-index: 60;
  }
  
  .call-control-dock {
    width: 92%;
    justify-content: space-around;
    padding: 8px 10px;
  }
}
