/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1f2937;
  --text-primary: #ffffff;
  --text-secondary: #9ca3af;
  --accent-primary: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --border-radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

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

/* Landing Page */
.landing-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.landing-card {
  background: var(--bg-card);
  padding: 40px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
}

.landing-card h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 2rem;
}

.subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #374151;
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--accent-primary);
}

.divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #374151;
}

.divider span {
  padding: 0 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

.btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

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

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

.btn-secondary {
  background: #374151;
  color: white;
}

.btn-secondary:hover {
  background: #4b5563;
}

/* Room Page */
.room-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
}

/* Video Grid */
.video-grid {
  flex: 1;
  display: grid;
  gap: 8px;
  padding: 8px;
  padding-bottom: 80px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: 1fr;
  overflow-y: auto;
}

/* Adjust grid for different participant counts */
.video-grid.participants-1 {
  grid-template-columns: 1fr;
}

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

@media (max-width: 600px) {
  .video-grid.participants-2 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
}

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

.video-container {
  position: relative;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  overflow: hidden;
  min-height: 200px;
}

.video-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-container.local video {
  transform: scaleX(-1); /* Mirror local video */
}

.video-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 14px;
}

.video-status {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
}

.status-icon {
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.status-icon.muted {
  color: var(--danger);
}

/* Screen share video */
.video-container.screen-share {
  grid-column: 1 / -1;
  max-height: 60vh;
}

.video-container.screen-share video {
  object-fit: contain;
  background: #000;
}

/* Controls */
.controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  z-index: 100;
}

.control-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.control-btn:hover {
  background: #374151;
}

.control-btn:active {
  transform: scale(0.95);
}

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

.control-btn.muted {
  background: var(--danger);
}

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

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

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge.hidden {
  display: none;
}

/* Room Info */
.room-info {
  position: fixed;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 12px;
  z-index: 100;
}

.room-info span {
  background: rgba(0, 0, 0, 0.6);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
}

/* Chat Sidebar */
.chat-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  max-width: 100vw;
  height: 100%;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transform: translateX(0);
  transition: transform 0.3s ease;
}

.chat-sidebar.hidden {
  transform: translateX(100%);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #374151;
}

.chat-header h3 {
  font-size: 18px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: #374151;
}

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

.chat-message {
  max-width: 85%;
}

.chat-message.own {
  align-self: flex-end;
}

.chat-message .sender {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.chat-message .content {
  background: var(--bg-secondary);
  padding: 10px 14px;
  border-radius: 12px;
  word-wrap: break-word;
}

.chat-message.own .content {
  background: var(--accent-primary);
}

.chat-message .time {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 4px;
  text-align: right;
}

.chat-input-container {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid #374151;
}

.chat-input-container input {
  flex: 1;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
}

.toast.success {
  border-left: 4px solid var(--success);
}

.toast.error {
  border-left: 4px solid var(--danger);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Permission Prompt */
.permission-prompt {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.permission-card {
  background: var(--bg-card);
  padding: 32px;
  border-radius: var(--border-radius);
  text-align: center;
  max-width: 400px;
}

.permission-card h2 {
  margin-bottom: 16px;
}

.permission-card p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.permission-card .btn {
  margin-bottom: 16px;
}

.permission-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Hidden utility */
.hidden {
  display: none !important;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .landing-card {
    padding: 24px;
  }

  .control-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  .controls {
    gap: 8px;
    padding: 12px;
  }

  .chat-sidebar {
    width: 100%;
  }

  .video-grid {
    grid-template-columns: 1fr;
    padding: 4px;
    gap: 4px;
  }

  .video-container {
    min-height: 150px;
  }
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
  .controls {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .room-info {
    top: max(8px, env(safe-area-inset-top));
  }
}
