/* ============================================================
   WebRTC-Chat — Modern Dark Theme
   ============================================================ */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242836;
  --bg-hover: #2e3344;
  --text-primary: #e4e6ed;
  --text-secondary: #9ca0ad;
  --text-muted: #6b7084;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-dim: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #2e3344;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --transition: 200ms ease;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Landing View ---- */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.landing-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}

.landing-logo {
  font-size: 48px;
  margin-bottom: 8px;
}

.landing-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

.landing-card .tagline {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.landing-card label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.landing-card input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 16px;
}

.landing-card input:focus {
  border-color: var(--accent);
}

.landing-card .btn-primary {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  margin-top: 8px;
}

.landing-card .features {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 28px;
  flex-wrap: wrap;
}

.landing-card .feature-tag {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 4px 12px;
  border-radius: 20px;
}

/* ---- App Layout ---- */
.app {
  display: none;
  height: 100vh;
  flex-direction: column;
  overflow: hidden;
}

.app.active {
  display: flex;
}

/* ---- Top Bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 56px;
}

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

.topbar-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
}

.topbar-room {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}

.topbar-room code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent);
}

.btn-copy {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  font-size: 14px;
  transition: color var(--transition);
}

.btn-copy:hover {
  color: var(--accent);
}

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

/* ---- Status Indicator ---- */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

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

.status-dot.connecting {
  background: var(--warning);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.connected {
  background: var(--success);
}

.status-dot.disconnected {
  background: var(--danger);
}

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

/* ---- Main Content ---- */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- Video Area ---- */
.video-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  position: relative;
  min-width: 0;
}

.video-grid {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  gap: 16px;
  position: relative;
}

.video-wrapper {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-wrapper.remote {
  flex: 1;
  max-height: 100%;
  aspect-ratio: 16/9;
}

.video-wrapper.local {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 220px;
  border: 2px solid var(--border);
  z-index: 10;
  cursor: grab;
  box-shadow: var(--shadow);
}

.video-wrapper.local:active {
  cursor: grabbing;
}

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

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

.video-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  padding: 3px 10px;
  border-radius: 20px;
  backdrop-filter: blur(4px);
}

.video-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  padding: 40px;
  text-align: center;
}

.video-placeholder .icon {
  font-size: 48px;
  opacity: 0.5;
}

.video-placeholder p {
  font-size: 14px;
}

/* ---- Media Controls ---- */
.media-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.media-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  position: relative;
}

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

.media-btn.active {
  background: var(--danger);
  color: #fff;
}

.media-btn.screen-share.sharing {
  background: var(--accent);
  color: #fff;
}

.media-btn .tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  border: 1px solid var(--border);
}

.media-btn:hover .tooltip {
  opacity: 1;
}

.media-btn.end-call {
  background: var(--danger);
  color: #fff;
  width: 56px;
  height: 48px;
  border-radius: 24px;
}

.media-btn.end-call:hover {
  background: #dc2626;
}

/* ---- Fullscreen button ---- */
.btn-fullscreen {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
}

/* ---- Chat Sidebar ---- */
.chat-sidebar {
  width: 340px;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  flex-shrink: 0;
  transition: width var(--transition);
}

.chat-sidebar.collapsed {
  width: 0;
  overflow: hidden;
  border-left: none;
}

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

.chat-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.chat-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  transition: color var(--transition);
}

.chat-toggle:hover {
  color: var(--text-primary);
}

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

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px 12px 12px 4px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.chat-msg.own {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 12px 12px 4px 12px;
}

.chat-msg.peer {
  align-self: flex-start;
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.chat-msg .msg-author {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 2px;
  opacity: 0.8;
}

.chat-msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 0;
  text-align: center;
}

/* ---- Chat Input ---- */
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}

.chat-input-area input:focus {
  border-color: var(--accent);
}

.chat-input-area input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background var(--transition);
}

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

/* ---- Shared Button Styles ---- */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  transition: background var(--transition);
}

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

/* ---- Connection Quality ---- */
.connection-quality {
  display: flex;
  align-items: center;
  gap: 4px;
}

.quality-bar {
  width: 3px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: background var(--transition);
}

.quality-bar:nth-child(1) { height: 6px; }
.quality-bar:nth-child(2) { height: 10px; }
.quality-bar:nth-child(3) { height: 14px; }

.quality-good .quality-bar { background: var(--success); }
.quality-fair .quality-bar:nth-child(1),
.quality-fair .quality-bar:nth-child(2) { background: var(--warning); }
.quality-poor .quality-bar:nth-child(1) { background: var(--danger); }

/* ---- Toast Notification ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 1000;
  opacity: 0;
  transition: all 300ms ease;
  pointer-events: none;
}

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

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
  }

  .video-area {
    flex: none;
    height: 55vh;
  }

  .chat-sidebar {
    width: 100%;
    flex: 1;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .chat-sidebar.collapsed {
    height: 0;
    flex: none;
  }

  .video-wrapper.local {
    width: 120px;
    bottom: 12px;
    right: 12px;
  }

  .topbar-room {
    display: none;
  }

  .media-btn {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }

  .landing-card {
    padding: 32px 24px;
  }
}

@media (max-width: 480px) {
  .media-controls {
    gap: 8px;
    padding: 12px;
  }

  .media-btn {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }

  .media-btn.end-call {
    width: 48px;
    height: 38px;
  }
}

/* ---- Fullscreen Mode ---- */
.video-area.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 100;
  background: #000;
}

/* ---- Utilities ---- */
.hidden {
  display: none !important;
}
