/* Mobile-first подход */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #2196F3;
  --primary-dark: #1976D2;
  --danger-color: #F44336;
  --success-color: #4CAF50;
  --bg-color: #F5F5F5;
  --surface-color: #FFFFFF;
  --text-primary: #212121;
  --text-secondary: #757575;
  --border-color: #E0E0E0;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Экраны */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
}

.screen.active {
  display: flex;
}

/* Загрузка */
#loading-screen {
  justify-content: center;
  align-items: center;
  gap: 1rem;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Шапка */
.header {
  background: var(--surface-color);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Кнопки */
.btn-icon {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.btn-icon:active {
  background-color: var(--bg-color);
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background-color 0.2s;
}

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

.btn-secondary {
  background: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

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

/* Информация о пространстве */
.space-info {
  background: var(--surface-color);
  padding: 1rem;
  margin: 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hash-display {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hash-display label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.hash-display code {
  background: var(--bg-color);
  padding: 0.5rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.875rem;
  word-break: break-all;
  color: var(--primary-color);
}

/* Секция комнат */
.rooms-section {
  flex: 1;
  padding: 0 1rem 1rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.room-card {
  background: var(--surface-color);
  padding: 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.room-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-lg);
}

.room-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}

.room-card-name-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.room-card-name {
  font-weight: 500;
  font-size: 1rem;
  flex: 1;
}

.btn-edit-room {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
  flex-shrink: 0;
  opacity: 0.7;
  min-width: 32px;
  min-height: 32px;
}

.btn-edit-room:hover {
  background-color: var(--bg-color);
  color: var(--primary-color);
  opacity: 1;
}

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

.btn-edit-room svg {
  width: 16px;
  height: 16px;
}

.btn-delete-room {
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-delete-room:hover {
  background-color: var(--danger-color);
  color: white;
}

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

.room-card-hash {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: 'Courier New', monospace;
  word-break: break-all;
}

/* Видео контейнер */
.video-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.video-wrapper {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  width: 100%;
}

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

.video-label {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  font-size: 0.875rem;
}

.remote-videos {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

/* На десктопе - сетка для удалённых видео */
@media (min-width: 768px) {
  .remote-videos {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
  
  .video-container {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  #local-video-wrapper {
    max-width: 300px;
  }
}

/* Элементы управления */
.controls {
  background: var(--surface-color);
  padding: 1rem;
  display: flex;
  justify-content: center;
  gap: 1rem;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
}

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

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

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

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

.btn-control.btn-danger:active {
  background: #D32F2F;
}

/* Модальное окно */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--surface-color);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.modal-content h2 {
  margin-bottom: 1rem;
  font-size: 1.25rem;
}

.modal-content input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 1rem;
}

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

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.modal-actions button {
  flex: 1;
}

/* Уведомления */
.notifications {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: calc(100% - 2rem);
}

.notification {
  background: var(--surface-color);
  padding: 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease-out;
  max-width: 300px;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

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

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

/* Адаптация для больших экранов */
@media (min-width: 768px) {
  .screen {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
  }
  
  .header {
    padding: 1.5rem;
  }
  
  .header h1 {
    font-size: 1.5rem;
  }
  
  .space-info,
  .rooms-section {
    padding: 1.5rem;
  }
}

/* Поддержка safe-area для iOS */
@supports (padding: max(0px)) {
  .header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  
  .controls {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

