/* Основные переменные и сброс стилей */
:root {
	--primary-color: #2563eb;
	--primary-dark: #1d4ed8;
	--secondary-color: #64748b;
	--background-color: #f8fafc;
	--surface-color: #ffffff;
	--text-primary: #1e293b;
	--text-secondary: #64748b;
	--border-color: #e2e8f0;
	--success-color: #10b981;
	--warning-color: #f59e0b;
	--error-color: #ef4444;
	--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
	--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
	--shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
	--border-radius: 8px;
	--border-radius-lg: 12px;
	--transition: all 0.2s ease-in-out;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body {
	font-family:
		-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	background: var(--background-color);
	color: var(--text-primary);
	line-height: 1.6;
	overflow-x: hidden;
}

/* Блокировка прокрутки при открытом модальном окне на мобильных */
@media (max-width: 480px) {
	html.modal-open,
	body.modal-open {
		overflow: hidden !important;
		position: fixed !important;
		width: 100% !important;
		height: 100% !important;
	}

	/* Гарантируем, что body может быть контейнером для absolute */
	body {
		position: relative;
	}
}

/* Утилиты */
.screen {
	display: none;
	min-height: 100vh;
}

.screen.active {
	display: block;
}

/* Экран входа */
#login-screen {
	display: none;
	align-items: center;
	justify-content: center;
	min-height: 100vh;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	padding: 20px;
}

#login-screen.active {
	display: flex;
}

.login-container {
	background: var(--surface-color);
	border-radius: var(--border-radius-lg);
	box-shadow: var(--shadow-lg);
	padding: 40px;
	width: 100%;
	max-width: 400px;
	text-align: center;
}

.logo h1 {
	font-size: 2rem;
	font-weight: 700;
	color: var(--primary-color);
	margin-bottom: 8px;
}

.logo p {
	color: var(--text-secondary);
	margin-bottom: 32px;
}

.login-form {
	margin-bottom: 32px;
}

.input-group {
	margin-bottom: 20px;
	text-align: left;
}

.input-group label {
	display: block;
	font-weight: 500;
	color: var(--text-primary);
	margin-bottom: 8px;
}

.input-group input {
	width: 100%;
	padding: 12px 16px;
	border: 2px solid var(--border-color);
	border-radius: var(--border-radius);
	font-size: 16px;
	transition: var(--transition);
	background: var(--surface-color);
}

.input-group input:focus {
	outline: none;
	border-color: var(--primary-color);
	box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.btn-primary {
	width: 100%;
	padding: 12px 24px;
	background: var(--primary-color);
	color: white;
	border: none;
	border-radius: var(--border-radius);
	font-size: 16px;
	font-weight: 600;
	cursor: pointer;
	transition: var(--transition);
	position: relative;
}

.btn-primary:hover {
	background: var(--primary-dark);
	transform: translateY(-1px);
	box-shadow: var(--shadow-md);
}

.btn-primary:disabled {
	opacity: 0.6;
	cursor: not-allowed;
	transform: none;
}

.features {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.feature {
	display: flex;
	align-items: center;
	gap: 12px;
	color: var(--text-secondary);
	font-size: 14px;
}

.feature-icon {
	font-size: 18px;
}

/* Экран конференции */
#conference-screen {
	display: none;
	flex-direction: column;
	height: 100vh;
	background: var(--background-color);
}

#conference-screen.active {
	display: flex;
}

.conference-header {
	background: var(--surface-color);
	border-bottom: 1px solid var(--border-color);
	padding: 16px 24px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	box-shadow: var(--shadow-sm);
}

.room-info h2 {
	font-size: 1.25rem;
	font-weight: 600;
	color: var(--text-primary);
}

.room-info p {
	color: var(--text-secondary);
	font-size: 14px;
	margin-top: 4px;
}

.controls {
	display: flex;
	gap: 8px;
}

.control-btn {
	width: 44px;
	height: 44px;
	border: none;
	border-radius: var(--border-radius);
	background: var(--background-color);
	color: var(--text-primary);
	cursor: pointer;
	transition: var(--transition);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 18px;
}

.control-btn:hover {
	background: var(--primary-color);
	color: white;
	transform: translateY(-1px);
}

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

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

.conference-main {
	flex: 1;
	display: flex;
	gap: 16px;
	padding: 16px;
	overflow: hidden;
}

/* Видео секция */
.video-section {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.main-video-container {
	flex: 1;
	background: #000;
	border-radius: var(--border-radius-lg);
	position: relative;
	overflow: hidden;
	box-shadow: var(--shadow-md);
}

#remote-video {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.no-video-placeholder {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
	color: white;
}

.placeholder-content {
	text-align: center;
}

.placeholder-icon {
	font-size: 4rem;
	margin-bottom: 16px;
	display: block;
}

.local-video-container {
	width: 200px;
	height: 150px;
	background: #000;
	border-radius: var(--border-radius);
	position: relative;
	overflow: hidden;
	box-shadow: var(--shadow-md);
	align-self: flex-end;
}

#local-video {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.video-overlay {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
	color: white;
	padding: 8px 12px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 12px;
}

.video-controls {
	display: flex;
	gap: 4px;
}

.mini-btn {
	width: 24px;
	height: 24px;
	border: none;
	border-radius: 4px;
	background: rgba(255, 255, 255, 0.2);
	color: white;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 12px;
	transition: var(--transition);
}

.mini-btn:hover {
	background: rgba(255, 255, 255, 0.3);
}

/* Чат секция */
.chat-section {
	width: 350px;
	background: var(--surface-color);
	border-radius: var(--border-radius-lg);
	box-shadow: var(--shadow-md);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

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

.chat-header h3 {
	font-size: 1.1rem;
	font-weight: 600;
	color: var(--text-primary);
}

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

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

.message {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.message-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.message-user {
	font-weight: 600;
	color: var(--primary-color);
	font-size: 14px;
}

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

.message-content {
	background: var(--background-color);
	padding: 8px 12px;
	border-radius: var(--border-radius);
	font-size: 14px;
	line-height: 1.4;
}

.message.own .message-content {
	background: var(--primary-color);
	color: white;
}

.system-message {
	text-align: center;
	font-size: 12px;
	color: var(--text-secondary);
	font-style: italic;
}

.chat-input-container {
	padding: 16px;
	border-top: 1px solid var(--border-color);
}

.chat-input-wrapper {
	display: flex;
	gap: 8px;
	margin-bottom: 8px;
}

#chat-input {
	flex: 1;
	padding: 10px 12px;
	border: 1px solid var(--border-color);
	border-radius: var(--border-radius);
	font-size: 14px;
	transition: var(--transition);
}

#chat-input:focus {
	outline: none;
	border-color: var(--primary-color);
}

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

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

.chat-hint {
	font-size: 11px;
	color: var(--text-secondary);
	text-align: center;
}

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

.modal.active,
#settings-modal.active {
	display: flex !important;
	align-items: center;
	justify-content: center;
}

.modal-content {
	background: var(--surface-color);
	border-radius: var(--border-radius-lg);
	box-shadow: var(--shadow-lg);
	width: 100%;
	max-width: 500px;
	max-height: 90vh;
	overflow: hidden;
}

.modal-header {
	padding: 20px 24px;
	border-bottom: 1px solid var(--border-color);
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.modal-header h3 {
	font-size: 1.25rem;
	font-weight: 600;
	color: var(--text-primary);
}

.close-btn {
	width: 32px;
	height: 32px;
	border: none;
	background: none;
	font-size: 24px;
	color: var(--text-secondary);
	cursor: pointer;
	border-radius: var(--border-radius);
	transition: var(--transition);
}

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

.modal-body {
	padding: 24px;
	overflow-y: auto;
}

.settings-group {
	margin-bottom: 24px;
}

.settings-group h4 {
	font-size: 1rem;
	font-weight: 600;
	color: var(--text-primary);
	margin-bottom: 12px;
}

.settings-group select {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid var(--border-color);
	border-radius: var(--border-radius);
	font-size: 14px;
	background: var(--surface-color);
	transition: var(--transition);
}

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

.settings-hint {
	font-size: 0.875rem;
	color: var(--text-secondary);
	margin-top: 8px;
	margin-bottom: 0;
	line-height: 1.4;
}

.modal-footer {
	padding: 20px 24px;
	border-top: 1px solid var(--border-color);
	display: flex;
	gap: 12px;
	justify-content: flex-end;
}

.btn-secondary {
	padding: 10px 20px;
	background: var(--background-color);
	color: var(--text-primary);
	border: 1px solid var(--border-color);
	border-radius: var(--border-radius);
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
	transition: var(--transition);
}

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

/* Уведомления */
.notifications {
	position: fixed;
	top: 20px;
	right: 20px;
	z-index: 1001;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.notification {
	background: var(--surface-color);
	border: 1px solid var(--border-color);
	border-radius: var(--border-radius);
	padding: 12px 16px;
	box-shadow: var(--shadow-md);
	min-width: 300px;
	animation: slideIn 0.3s ease-out;
}

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

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

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

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

/* Адаптивный дизайн */
@media (max-width: 768px) {
	.conference-main {
		flex-direction: column;
		padding: 8px;
		gap: 8px;
	}

	.chat-section {
		width: 100%;
		height: 300px;
	}

	.local-video-container {
		width: 120px;
		height: 90px;
	}

	.conference-header {
		padding: 12px 16px;
		flex-direction: column;
		gap: 12px;
	}

	.controls {
		flex-wrap: wrap;
		justify-content: center;
	}

	.control-btn {
		width: 40px;
		height: 40px;
		font-size: 16px;
	}

	.login-container {
		padding: 24px;
		margin: 16px;
	}

	.logo h1 {
		font-size: 1.5rem;
	}

	.features {
		gap: 8px;
	}

	.feature {
		font-size: 13px;
	}

	/* Модальное окно для планшетов */
	#settings-modal {
		padding: 10px !important;
	}

	#settings-modal.active {
		display: flex !important;
		align-items: center !important;
		justify-content: center !important;
	}

	/* Дополнительная специфичность */
	.modal.active {
		display: flex !important;
	}

	.modal-content {
		max-width: 100%;
		max-height: 95vh;
		border-radius: var(--border-radius);
	}

	.modal-header {
		padding: 16px 20px;
	}

	.modal-header h3 {
		font-size: 1.1rem;
	}

	.modal-body {
		padding: 20px;
		max-height: calc(95vh - 140px);
	}

	.settings-group {
		margin-bottom: 20px;
	}

	.settings-group h4 {
		font-size: 0.95rem;
		margin-bottom: 10px;
	}

	.settings-group select {
		padding: 12px;
		font-size: 15px;
	}

	.modal-footer {
		padding: 16px 20px;
		flex-direction: column;
		gap: 10px;
	}

	.btn-primary,
	.btn-secondary {
		width: 100%;
		padding: 12px 20px;
		font-size: 15px;
	}
}

@media (max-width: 480px) {
	.conference-main {
		padding: 4px;
	}

	.video-section {
		gap: 8px;
	}

	.chat-section {
		height: 250px;
	}

	.chat-messages {
		padding: 12px;
	}

	.chat-input-container {
		padding: 12px;
	}

	/* Модальное окно для мобильных - используем fixed с правильными настройками */
	#settings-modal {
		position: fixed !important;
		top: 0 !important;
		left: 0 !important;
		right: 0 !important;
		bottom: 0 !important;
		padding: 0 !important;
		align-items: flex-end !important;
		justify-content: flex-end !important;
		background: rgba(0, 0, 0, 0.5) !important;
		z-index: 99999 !important;
		-webkit-overflow-scrolling: touch;
		/* Исправление для iOS Safari */
		-webkit-transform: translateZ(0);
		transform: translateZ(0);
		will-change: transform;
	}

	#settings-modal.active {
		display: flex !important;
		position: fixed !important;
		align-items: flex-end !important;
		justify-content: flex-end !important;
	}

	/* Дополнительная специфичность для гарантии отображения */
	.modal.active {
		display: flex !important;
	}

	#settings-modal .modal-content,
	.modal-content {
		width: 100% !important;
		max-width: 100% !important;
		max-height: 90vh !important;
		border-radius: 16px 16px 0 0 !important;
		margin: 0 !important;
		display: flex !important;
		flex-direction: column !important;
	}

	/* Убираем transform с родительских элементов, которые могут мешать */
	.screen.active {
		transform: none !important;
	}

	.modal-header {
		padding: 16px;
		flex-shrink: 0;
		border-bottom: 1px solid var(--border-color);
	}

	.modal-header h3 {
		font-size: 1.1rem;
		margin: 0;
	}

	.close-btn {
		width: 36px;
		height: 36px;
		font-size: 28px;
		display: flex;
		align-items: center;
		justify-content: center;
		-webkit-tap-highlight-color: transparent;
	}

	.modal-body {
		padding: 16px;
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		flex: 1;
		min-height: 0;
	}

	.settings-group {
		margin-bottom: 20px;
	}

	.settings-group:last-child {
		margin-bottom: 0;
	}

	.settings-group h4 {
		font-size: 0.9rem;
		font-weight: 600;
		margin-bottom: 8px;
		color: var(--text-primary);
	}

	.settings-group select {
		width: 100%;
		padding: 14px 12px;
		font-size: 16px; /* Предотвращает зум на iOS */
		border: 1px solid var(--border-color);
		border-radius: var(--border-radius);
		background: var(--surface-color);
		-webkit-appearance: none;
		-moz-appearance: none;
		appearance: none;
		background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
		background-repeat: no-repeat;
		background-position: right 12px center;
		padding-right: 36px;
	}

	.settings-hint {
		font-size: 0.8rem;
		margin-top: 6px;
		line-height: 1.3;
	}

	.modal-footer {
		padding: 16px;
		border-top: 1px solid var(--border-color);
		display: flex;
		flex-direction: column;
		gap: 10px;
		flex-shrink: 0;
		background: var(--surface-color);
	}

	.btn-primary,
	.btn-secondary {
		width: 100%;
		padding: 14px 20px;
		font-size: 16px;
		font-weight: 500;
		border-radius: var(--border-radius);
		-webkit-tap-highlight-color: transparent;
		touch-action: manipulation;
	}

	.btn-primary {
		order: 1;
	}

	.btn-secondary {
		order: 2;
	}
}

/* Полноэкранный режим */
.fullscreen {
	position: fixed !important;
	top: 0 !important;
	left: 0 !important;
	width: 100vw !important;
	height: 100vh !important;
	z-index: 999 !important;
	background: #000 !important;
}

.fullscreen #remote-video {
	width: 100vw !important;
	height: 100vh !important;
	object-fit: contain !important;
}

/* Состояния загрузки */
.loading {
	opacity: 0.6;
	pointer-events: none;
}

.btn-loading {
	display: none;
}

.btn-primary.loading .btn-text {
	display: none;
}

.btn-primary.loading .btn-loading {
	display: inline;
}

/* Скрытие элементов */
.hidden {
	display: none !important;
}

/* Анимации */
.fade-in {
	animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

.slide-up {
	animation: slideUp 0.3s ease-out;
}

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

/* ========================================
   MESH TOPOLOGY - Multiple Participants Grid
   ======================================== */

/* Grid контейнер для множественных участников */
.remote-videos-grid {
	display: grid;
	gap: 10px;
	padding: 10px;
	width: 100%;
	height: auto;
	max-height: calc(100vh - 200px);
}

/* Layout для 1 участника */
.remote-videos-grid.grid-1 {
	grid-template-columns: 1fr;
	grid-template-rows: 1fr;
}

/* Layout для 2 участников */
.remote-videos-grid.grid-2 {
	grid-template-columns: repeat(2, 1fr);
	grid-template-rows: 1fr;
}

/* Layout для 3 участников */
.remote-videos-grid.grid-3 {
	grid-template-columns: repeat(2, 1fr);
	grid-template-rows: repeat(2, 1fr);
}

/* Layout для 4 участников */
.remote-videos-grid.grid-4 {
	grid-template-columns: repeat(2, 1fr);
	grid-template-rows: repeat(2, 1fr);
}

/* Контейнер для видео каждого участника */
.remote-video-item {
	position: relative;
	background: #000;
	border-radius: var(--border-radius);
	overflow: hidden;
	aspect-ratio: 16 / 9;
	min-height: 200px;
}

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

/* Overlay с именем участника */
.remote-video-item .video-overlay {
	position: absolute;
	bottom: 10px;
	left: 10px;
	background: rgba(0, 0, 0, 0.7);
	color: white;
	padding: 5px 10px;
	border-radius: 5px;
	font-size: 14px;
	font-weight: 500;
	z-index: 10;
}

/* Индикатор качества соединения */
.quality-indicator {
	position: absolute;
	top: 10px;
	right: 10px;
	font-size: 20px;
	z-index: 11;
	background: rgba(0, 0, 0, 0.6);
	border-radius: 50%;
	width: 36px;
	height: 36px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: help;
	transition: all 0.3s ease;
}

.quality-indicator:hover {
	transform: scale(1.1);
	background: rgba(0, 0, 0, 0.8);
}

/* Цвета для разных уровней качества */
.quality-indicator.excellent {
	border: 2px solid #4caf50;
	box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
}

.quality-indicator.good {
	border: 2px solid #8bc34a;
	box-shadow: 0 0 8px rgba(139, 195, 74, 0.5);
}

.quality-indicator.fair {
	border: 2px solid #ffc107;
	box-shadow: 0 0 8px rgba(255, 193, 7, 0.5);
}

.quality-indicator.poor {
	border: 2px solid #ff9800;
	box-shadow: 0 0 8px rgba(255, 152, 0, 0.5);
}

.quality-indicator.terrible {
	border: 2px solid #f44336;
	box-shadow: 0 0 8px rgba(244, 67, 54, 0.5);
	animation: pulse-red 2s infinite;
}

.quality-indicator.unknown {
	border: 2px solid #9e9e9e;
}

@keyframes pulse-red {
	0%,
	100% {
		box-shadow: 0 0 8px rgba(244, 67, 54, 0.5);
	}
	50% {
		box-shadow: 0 0 16px rgba(244, 67, 54, 0.8);
	}
}

/* Reconnecting Indicator */
.reconnecting-indicator {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.8);
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	z-index: 20;
	backdrop-filter: blur(2px);
}

.reconnecting-spinner {
	width: 40px;
	height: 40px;
	border: 4px solid rgba(255, 255, 255, 0.3);
	border-top-color: var(--primary-color);
	border-radius: 50%;
	animation: spin 1s linear infinite;
}

.reconnecting-text {
	margin-top: 15px;
	color: white;
	font-size: 14px;
	font-weight: 500;
	text-align: center;
	padding: 0 20px;
}

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

/* Responsive adjustments */
@media (max-width: 768px) {
	.remote-videos-grid {
		gap: 5px;
		padding: 5px;
	}

	.remote-videos-grid.grid-2,
	.remote-videos-grid.grid-3,
	.remote-videos-grid.grid-4 {
		grid-template-columns: 1fr;
		grid-template-rows: auto;
	}

	.remote-video-item {
		min-height: 150px;
	}

	.remote-video-item .video-overlay {
		font-size: 12px;
		padding: 4px 8px;
	}
}
