/* Reset и базовые стили */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --danger: #DC2626;
  --danger-hover: #B91C1C;
  --success: #10B981;
  --bg: #0F172A;
  --bg-card: #1E293B;
  --bg-hover: #334155;
  --text: #F8FAFC;
  --text-muted: #94A3B8;
  --border: #334155;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Страница входа */
.container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.main-header h1 {
  margin: 0;
  font-size: 28px;
}

/* Переключатель языка */
.lang-switcher {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}

.lang-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.lang-btn:hover {
  color: var(--text);
}

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

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

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

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

/* Формы */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 14px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

/* Сообщения об ошибках */
.error-message {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 16px;
  padding: 10px;
  background: rgba(220, 38, 38, 0.1);
  border-radius: 6px;
}

/* Кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-small {
  width: auto;
  padding: 8px 16px;
  font-size: 14px;
}

.divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  padding: 0 16px;
}

/* Страница комнаты */
.room-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Заголовок комнаты */
.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.room-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.room-info #room-name {
  font-weight: 600;
}

.room-info #participants-count {
  font-size: 14px;
  color: var(--text-muted);
}

/* Контейнер видео - FaceTime стиль */
.videos-container {
  flex: 1;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

/* Удалённые видео на весь экран */
.video-wrapper {
  position: absolute;
  inset: 0;
  background: var(--bg-card);
}

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

/* Локальное видео - маленькое в углу (PiP) */
.video-wrapper.local {
  position: absolute;
  top: auto;
  bottom: 100px;
  right: 20px;
  left: auto;
  width: 150px;
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  cursor: grab;
}

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

.video-wrapper.local video {
  border-radius: var(--radius);
}

/* Когда ты один - локальное видео по центру */
.videos-container.alone .video-wrapper.local {
  position: relative;
  top: auto;
  bottom: auto;
  right: auto;
  left: auto;
  width: 100%;
  max-width: 800px;
  height: auto;
  aspect-ratio: 16 / 9;
  margin: auto;
  box-shadow: none;
}

/* Сетка для 3+ участников */
.videos-container.grid-mode {
  display: grid;
  gap: 8px;
  padding: 8px;
}

.videos-container.grid-mode .video-wrapper {
  position: relative;
  inset: auto;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
}

.videos-container.grid-mode .video-wrapper.local {
  width: auto;
  height: auto;
  bottom: auto;
  right: auto;
  box-shadow: none;
}

.videos-container.grid-mode.participants-3 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.videos-container.grid-mode.participants-4 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.videos-container.grid-mode.participants-5,
.videos-container.grid-mode.participants-6 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-wrapper.local video {
  transform: scaleX(-1); /* Зеркалим локальное видео */
}

/* Портретная ориентация видео (с телефона) */
.video-wrapper.portrait video {
  object-fit: contain; /* Показываем всё видео без обрезки */
  background: var(--bg);
}

/* Локальное видео в портретном режиме */
.video-wrapper.local.portrait {
  aspect-ratio: 3 / 4;
  width: 120px;
}

/* Когда один с портретным видео */
.videos-container.alone .video-wrapper.local.portrait {
  aspect-ratio: 9 / 16;
  max-width: 450px;
}

/* Удалённое портретное видео - центрируем */
.video-wrapper.portrait:not(.local) {
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

.video-status .status-icon {
  background: rgba(0, 0, 0, 0.6);
  padding: 6px;
  border-radius: 50%;
}

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

/* Заглушка когда видео выключено */
.video-wrapper.video-off::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-wrapper.video-off::after {
  content: attr(data-name);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Панель управления */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.control-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

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

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

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

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

.control-btn .icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.control-btn .hidden {
  display: none;
}

/* Кнопка переключения камеры - только на мобильных */
.control-btn.mobile-only {
  display: none;
}

@media (max-width: 768px), (pointer: coarse) {
  .control-btn.mobile-only {
    display: flex;
  }
}

/* Кнопка fullscreen */
.fullscreen-btn {
  position: fixed;
  top: 70px;
  left: 20px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.fullscreen-btn:hover {
  background: rgba(0, 0, 0, 0.7);
}

.fullscreen-btn .icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.fullscreen-btn .hidden {
  display: none;
}

/* Статус соединения */
.connection-status {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-card);
  border-radius: 20px;
  font-size: 14px;
  z-index: 100;
  transition: opacity 0.3s;
}

.connection-status.hidden {
  opacity: 0;
  pointer-events: none;
}

.connection-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #FCD34D;
  animation: pulse 1.5s infinite;
}

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

.connection-status.error .status-dot {
  background: var(--danger);
  animation: none;
}

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

/* Уведомления */
.notifications {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.notification {
  padding: 12px 20px;
  background: var(--bg-card);
  border-radius: 8px;
  font-size: 14px;
  animation: slideUp 0.3s ease;
  box-shadow: var(--shadow);
}

.notification.success {
  border-left: 3px solid var(--success);
}

.notification.error {
  border-left: 3px solid var(--danger);
}

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

/* Мобильная адаптация */
@media (max-width: 768px) {
  .card {
    padding: 24px;
  }

  .card h1 {
    font-size: 24px;
  }

  .room-header {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .videos-container {
    padding: 8px;
    gap: 8px;
  }

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

  .control-btn {
    width: 48px;
    height: 48px;
  }

  .control-btn .icon {
    width: 20px;
    height: 20px;
  }
}

/* Мобильный ландшафтный режим */
@media (max-height: 500px) and (orientation: landscape) {
  .videos-container {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    grid-template-rows: 1fr;
  }

  .controls {
    padding: 12px;
  }

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