:root {
    --primary: #4361ee;
    --primary-light: #4895ef;
    --secondary: #3f37c9;
    --accent: #f72585;
    --light: #f8f9fa;
    --dark: #212529;
    --success: #4cc9f0;
    --warning: #fca311;
    --danger: #e63946;
    --gray: #adb5bd;
    --gray-light: #e9ecef;
    --border-radius: 8px;
    --box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--dark);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.card {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 30px;
    margin: 30px 0;
    transition: var(--transition);
}

.card:hover {
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.12);
}

/* Стили для страницы входа/регистрации */
.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 500px;
}

.tabs {
    display: flex;
    margin-bottom: 25px;
    border-bottom: 2px solid var(--gray-light);
}

.tab {
    flex: 1;
    padding: 15px;
    background: transparent;
    border: none;
    font-size: 18px;
    font-weight: 600;
    color: var(--gray);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    outline: none;
}

.tab.active {
    color: var(--primary);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--primary);
    border-radius: 3px;
}

.form-container {
    display: none;
    animation: fadeIn 0.5s ease;
}

.form-container.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.form-container h1 {
    text-align: center;
    margin-bottom: 25px;
    color: var(--secondary);
    font-weight: 700;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--dark);
}

.form-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--gray-light);
    border-radius: var(--border-radius);
    font-size: 16px;
    transition: var(--transition);
}

.form-group input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

button[type="submit"] {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border: none;
    border-radius: var(--border-radius);
    color: white;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 10px;
}

button[type="submit"]:hover {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(67, 97, 238, 0.25);
}

.error {
    background-color: rgba(230, 57, 70, 0.1);
    color: var(--danger);
    padding: 12px 15px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    border-left: 4px solid var(--danger);
    font-weight: 500;
}

/* Стили для личного кабинета */
.dashboard {
    flex: 1;
    padding: 20px 0;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--gray-light);
}

.header h1 {
    color: var(--secondary);
    font-size: 28px;
}

.logout-btn {
    padding: 10px 20px;
    background: var(--danger);
    color: white;
    text-decoration: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    transition: var(--transition);
    display: inline-block;
}

.logout-btn:hover {
    background: #c1121f;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(230, 57, 70, 0.3);
}

.video-container {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 25px;
    margin-bottom: 30px;
}

.video-container h2 {
    margin-bottom: 20px;
    color: var(--secondary);
    font-size: 24px;
}

#stream-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stream-card {
    background: var(--light);
    border-radius: var(--border-radius);
    padding: 20px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--gray-light);
}

.stream-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.stream-card h3 {
    color: var(--primary);
    margin-bottom: 10px;
}

.stream-card p {
    color: var(--dark);
    font-size: 14px;
}

#connection-status {
    padding: 12px 15px;
    border-radius: var(--border-radius);
    margin: 15px 0;
    font-weight: 500;
}

.status-connecting {
    background-color: rgba(252, 163, 17, 0.1);
    color: var(--warning);
    border-left: 4px solid var(--warning);
}

.status-connected {
    background-color: rgba(76, 201, 240, 0.1);
    color: var(--success);
    border-left: 4px solid var(--success);
}

.status-error {
    background-color: rgba(230, 57, 70, 0.1);
    color: var(--danger);
    border-left: 4px solid var(--danger);
}

#remoteVideo {
    width: 100%;
    border-radius: var(--border-radius);
    background: var(--dark);
    aspect-ratio: 16/9;
    display: block;
    margin-top: 20px;
}

/* Адаптивность */
@media (max-width: 768px) {
    .auth-container {
        max-width: 100%;
    }
    
    .header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .logout-btn {
        margin-top: 15px;
    }
    
    #stream-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .tabs {
        flex-direction: column;
    }
    
    .tab {
        padding: 12px;
    }
    
    .form-container {
        padding: 25px 20px;
    }
    
    .card, .video-container {
        padding: 20px 15px;
    }

    .header-buttons {
        flex-direction: column;
        width: 100%;
    }

    .download-btn, .logout-btn {
        width: 100%;
        margin-top: 10px;
    }
}

/* Анимация загрузки */
.loading {
    text-align: center;
    padding: 30px;
    color: var(--gray);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(67, 97, 238, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Stream Cards */
.stream-thumbnail {
    position: relative;
    aspect-ratio: 16/9;
    background: var(--dark);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    overflow: hidden;
}

.stream-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, var(--primary-light), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.viewers {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
}

.stream-info {
    padding: 15px;
}

.stream-info h3 {
    margin-bottom: 8px;
    color: var(--primary);
}

.stream-info p {
    color: var(--gray);
    font-size: 14px;
}

.stream-card.active {
    border: 2px solid var(--accent);
    transform: translateY(-5px);
}

/* Loading and error states */
.loading {
    text-align: center;
    padding: 30px;
    color: var(--gray);
}

.empty {
    text-align: center;
    padding: 30px;
    color: var(--gray);
}

.error button {
    margin-top: 15px;
    padding: 8px 20px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
}


/* Кнопка отключения */
#disconnect-btn {
    display: none;
    margin: 15px 0;
    padding: 10px 20px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
}

#disconnect-btn:hover {
    background: #c1121f;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(230, 57, 70, 0.3);
}

/* Плейсхолдер для видео */
.video-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-light);
    color: var(--gray);
    border-radius: var(--border-radius);
}

/* Плавные переходы */
#stream-list {
    transition: opacity 0.3s ease;
}

/* Индикатор загрузки */
.video-loading {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.7);
    color: white;
}

.video-loading .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 15px;
}


/* Стили для кнопки */
.header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.download-btn {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    transition: var(--transition);
}

.download-btn:hover {
    background: var(--secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(67, 97, 238, 0.3);
}

.icon-download {
    display: inline-block;
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
}


.device-item {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    font-size: 16px;
}

.device-item:hover {
    background: #f5f5f5;
}

.device-item.active {
    background: #e3f2fd;
    font-weight: bold;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 15px 0;
}

.button-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-btn {
    padding: 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    flex: 1;
}

.action-btn.primary {
    background: #1976d2;
    color: white;
}

.action-btn.secondary {
    background: #424242;
    color: white;
}

.tooltip-btn {
    width: 20px;
    height: 20px;
    background: #777;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: help;
}

.tooltip {
    position: absolute;
    background: #000;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 14px;
    z-index: 1000;
    pointer-events: none;
}

.device-item {
  padding: 12px 16px;
  margin: 4px 0;
  background: #f9f9f9;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
}

.device-item:hover {
  background: #eef2ff;
  border-color: #9fa8da;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.device-item.active {
  background: #bbdefb;
  border-color: #2196f3;
  font-weight: bold;
  position: relative;
}

.device-item.active::after {
  content: '✓';
  margin-left: auto;
  color: #1976d2;
  font-weight: bold;
}

.stream-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.stream-item {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9f9f9;
    transition: all 0.2s;
}

.stream-item:hover {
    background: #e9ecef;
    border-color: #007bff;
}

.stream-item.active {
    border-color: #007bff;
    background: #e7f3ff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

.stream-type-badge {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    color: white;
    background: #6c757d;
}

.stream-item-room .stream-type-badge {
    background: #28a745; /* зелёный для комнат */
}

.stream-item-device .stream-type-badge {
    background: #17a2b8; /* синий для устройств */
}

/* Кнопки действий */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 16px 0;
    justify-content: center;
}

.button-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

.action-btn.danger {
    background-color: #dc3545;
    border-color: #dc3545;
}

.action-btn.danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
}