/* ========================================= */
/* БАЗОВЫЕ ПЕРЕМЕННЫЕ И ТЕМЫ                 */
/* ========================================= */
:root {
    --bg-gradient: linear-gradient(135deg, #e0eafc 0%, #cfdef3 100%);
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    
    --text-color: #1d1d1f;
    --text-muted: #515154;
    
    --accent: #0066cc;
    --accent-hover: #004499;
    --accent-glow: rgba(0, 102, 204, 0.4);
    
    --btn-bg: rgba(255, 255, 255, 0.7);
    --btn-hover: rgba(255, 255, 255, 1);
    
    --radius: 20px;
}

body.dark-theme {
    --bg-gradient: linear-gradient(135deg, #1f1c2c 0%, #928dab 100%);
    --glass-bg: rgba(30, 30, 32, 0.4);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    
    --text-color: #f5f5f7;
    --text-muted: #a1a1a6;
    
    --accent: #2997ff;
    --accent-hover: #147ce6;
    --accent-glow: rgba(41, 151, 255, 0.4);
    
    --btn-bg: rgba(60, 60, 64, 0.6);
    --btn-hover: rgba(80, 80, 85, 0.8);
}

/* ========================================= */
/* АНИМАЦИИ (@keyframes)                     */
/* ========================================= */
@keyframes slideUpFade {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.9); }
    70% { transform: scale(1.02); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes softPulse {
    0% { box-shadow: 0 0 0 0 var(--accent-glow); }
    70% { box-shadow: 0 0 0 8px rgba(0, 0, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}

/* ========================================= */
/* ГЛАВНЫЙ КАРКАС                            */
/* ========================================= */
html, body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0; 
    padding: 0; 
    height: 100vh; 
    overflow: hidden; 
    background: var(--bg-gradient);
    color: var(--text-color);
    transition: background 0.6s ease, color 0.6s ease;
}

/* МАГИЯ ЗДЕСЬ: Ограничиваем ширину приложения, чтобы не ломать глаза! */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1800px; /* <-- МЕНЯЕМ ЗДЕСЬ на 1800px */
    width: 100%;       /* <-- ДОБАВЛЯЕМ ЭТУ СТРОКУ */
    margin: 0 auto; 
    padding: 20px;
    box-sizing: border-box;
    gap: 20px;
}

/* Общий эффект матового стекла */
.glass-effect {
    background: var(--glass-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: var(--radius);
    transition: background 0.4s ease, border 0.4s ease, box-shadow 0.4s ease;
    
    /* НОВЫЕ СТРОКИ: Фикс бага смешивания слоев */
    backface-visibility: hidden;
    transform: translate3d(0, 0, 0);
}
/* ========================================= */
/* ШАПКА И РАБОЧАЯ ЗОНА                      */
/* ========================================= */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 28px;
    flex-shrink: 0; 
    animation: slideUpFade 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.app-header h2 { margin: 0; font-size: 1.4rem; display: flex; align-items: center; gap: 12px; }
.header-actions { display: flex; align-items: center; gap: 16px; }
.status-text { color: var(--text-muted); font-size: 0.95rem; font-weight: 500;}

/* Кнопка смены темы */
.theme-toggle {
    position: fixed; top: 20px; right: 20px; width: 48px; height: 48px;
    border-radius: 50%; border: 1px solid var(--glass-border);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-color); z-index: 1000; padding: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.theme-toggle:hover { transform: scale(1.1) rotate(15deg); }

/* Рабочая зона */
.app-workspace {
    display: flex;
    flex-direction: row; 
    gap: 20px;
    flex-grow: 1; 
    min-height: 0;
    /* overflow: hidden;  <-- УДАЛИЛИ ЭТУ СТРОКУ */
    opacity: 0; 
    animation: slideUpFade 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.15s forwards; 
}

.viewer-area {
    flex-grow: 1; 
    padding: 10px; 
    display: flex;
    min-height: 0;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    
    /* НОВАЯ СТРОКА: Жестко запираем 3D-плеер внутри его рамки */
    contain: paint; 
}
#viewer { 
    width: 100%; height: 100%; 
    border-radius: 14px; background: #000; overflow: hidden;
    /* Убеждаемся, что плеер всегда поверх любых артефактов */
    position: relative;
    z-index: 1;
}

/* ========================================= */
/* БОКОВАЯ ПАНЕЛЬ И КАРТОЧКИ                 */
/* ========================================= */
.gallery-panel {
    width: 280px; /* <-- МЕНЯЕМ ЗДЕСЬ на 280px */
    flex-shrink: 0; 
    display: flex;
    flex-direction: column;
    padding: 20px;
    min-height: 0;
}

.gallery-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.gallery-header h3 { margin: 0; font-size: 1.2rem; font-weight: 600; }

.scenes-list { 
    display: flex; flex-direction: column; gap: 16px; 
    overflow-y: auto; flex-grow: 1; padding-right: 10px; padding-left: 2px;
    min-height: 0;
}

.scene-card {
    width: 100%; height: 120px; flex-shrink: 0;
    background-size: cover; background-position: center;
    border-radius: 14px; border: 2px solid transparent;
    cursor: pointer; display: flex; align-items: flex-end; padding: 10px; box-sizing: border-box;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.scene-card:hover { 
    /* Убрали scale(), оставили только поднятие на 4 пикселя вверх */
    transform: translateY(-4px); 
    box-shadow: 0 12px 24px rgba(0,0,0,0.12);
}

/* Анимация пульсации для активной карточки */
.scene-card.active { 
    border-color: var(--accent); 
    animation: softPulse 2s infinite; 
}

.scene-name-input {
    width: 100%; background: rgba(0,0,0,0.5); color: white; border: none;
    font-size: 0.9rem; font-weight: 500; border-radius: 8px; padding: 8px;
    backdrop-filter: blur(8px); outline: none; text-align: center;
    transition: background 0.3s;
}
.scene-name-input:focus { background: rgba(0,0,0,0.8); border: 1px solid var(--accent); }

/* ========================================= */
/* КНОПКИ И СКРОЛЛБАРЫ                       */
/* ========================================= */
.glass-btn {
    padding: 12px 24px; border-radius: 99px; border: 1px solid var(--glass-border);
    background: var(--btn-bg); color: var(--text-color);
    cursor: pointer; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    font-weight: 500;
}
.glass-btn:hover { background: var(--btn-hover); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08);}
.glass-btn:active { transform: translateY(1px) scale(0.96); } /* Эффект "вдавливания" */

.add-btn-small { padding: 10px 16px; margin: 0; display: flex; align-items: center; gap: 8px; font-size: 0.95rem;}

.accent-btn { background: var(--accent); color: white; border: none; box-shadow: 0 4px 15px var(--accent-glow); }
.accent-btn:hover { background: var(--accent-hover); box-shadow: 0 6px 20px var(--accent-glow); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(150, 150, 150, 0.4); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(150, 150, 150, 0.7); }

/* ========================================= */
/* МОДАЛЬНОЕ ОКНО (ВСПЛЫВАШКА)               */
/* ========================================= */
.modal-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.3); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    z-index: 2000; display: flex; align-items: center; justify-content: center; 
}

.modal-content { 
    padding: 30px; width: 340px; display: flex; flex-direction: column; 
    /* Пружинистая анимация появления */
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; 
}

.modal-content h3 { margin-top: 0; margin-bottom: 24px; color: var(--text-color); font-size: 1.3rem; }
.modal-content label { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 8px; display: block; font-weight: 500;}
.glass-input { 
    width: 100%; box-sizing: border-box; padding: 12px; border-radius: 12px; 
    border: 1px solid var(--glass-border); background: var(--glass-bg); 
    color: var(--text-color); outline: none; margin-bottom: 16px; font-size: 0.95rem;
    transition: all 0.3s ease;
}
.glass-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.modal-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; }
.modal-actions button { flex: 1; }

/* ========================================= */
/* АДАПТИВНОСТЬ ДЛЯ ТЕЛЕФОНОВ (NATIVE APP)   */
/* ========================================= */
@media (max-width: 900px) {
    /* 1. Возвращаем монолитность и блокируем скролл всей страницы */
    html, body {
        height: 100%;
        height: 100dvh; /* Используем dvh, чтобы интерфейс не прыгал из-за адресной строки браузера */
        overflow: hidden;
    }

    /* 2. Каркас приложения жестко вписан в экран */
    .app-shell {
        height: 100%;
        height: 100dvh;
        padding: 10px; /* Чуть уменьшаем отступы по краям для экономии места */
        gap: 10px;
    }

    .app-header {
        padding: 12px 16px;
    }

    .app-header h2 { font-size: 1.2rem; }

    /* 3. Рабочая зона сжимается пропорционально */
    .app-workspace { 
        flex-direction: column; 
        gap: 10px;
        overflow: hidden; /* Запрещаем вылезать за пределы */
    }
    
    /* 4. Плеер 360 работает как пружина: забирает ВСЁ свободное место */
    .viewer-area {
        flex-grow: 1; /* Растягивается на максимум */
        min-height: 0; /* Хак для flexbox, чтобы плеер не распирал экран */
        padding: 5px;
    }
    
    #viewer { border-radius: 12px; }

    /* 5. Нижняя панель (Галерея) жестко сидит внизу и подстраивается под контент */
    .gallery-panel { 
        width: 100%; 
        height: auto; 
        flex-shrink: 0; /* Запрещаем сплющивать саму панель */
        flex-direction: column; 
        padding: 12px; 
        box-sizing: border-box;
    }
    
    .gallery-header { margin-bottom: 8px; }
    
    .scenes-list { 
        flex-direction: row; 
        overflow-x: auto; /* Включаем горизонтальный скролл для карточек (как лента в Instagram) */
        overflow-y: hidden; 
        padding-bottom: 4px; 
        align-items: center;
        gap: 10px;
    }
    
    /* Делаем карточки комнат более компактными */
    .scene-card { 
        width: 110px; 
        height: 75px; 
        flex-shrink: 0; /* Запрещаем сплющивать сами карточки, пусть лучше скроллятся вбок */
    }
    
    /* Шапка и кнопки */
    .header-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; margin-top: 4px; }
    .status-text { width: 100%; text-align: center; margin-bottom: 8px; font-size: 0.85rem;}
    
    .theme-toggle { top: 12px; right: 12px; width: 40px; height: 40px; }
    .add-btn-small { padding: 6px 14px; font-size: 0.95rem; }
}

/* --- Стеклянные стили для списка туров (Apple Glass) --- */
.tour-list-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    box-sizing: border-box; /* Добавили вот эту строчку! */
    width: 100%; /* Гарантируем, что ширина не выпрыгнет за пределы списка */
    transition: transform 0.25s ease-out, background 0.25s ease-out, box-shadow 0.25s ease-out, border-color 0.25s ease-out;
}

body.dark-theme .tour-list-item { 
    background: rgba(0, 0, 0, 0.2); /* Темное стекло для ночной темы */
}

.tour-list-item:hover {
    background: var(--glass-bg); /* При наведении стекло становится чуть более плотным */
    border-color: var(--accent);
    transform: scale(1.02); /* Мягкое "дыхание" (увеличение) вместо бокового сдвига */
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08); /* Мягкая тень */
}

.tour-list-item:active {
    transform: scale(0.98); /* Приятный эффект физического вдавливания при клике */
}

.tour-list-item img {
    width: 90px; 
    height: 60px; 
    object-fit: cover; 
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1); /* Легкая тень у самой картинки */
}

.tour-info { flex-grow: 1; display: flex; flex-direction: column; gap: 6px; }
.tour-info strong { color: var(--text-color); font-size: 1.05rem; font-weight: 600; }
.tour-info span { color: var(--text-muted); font-size: 0.85rem; font-weight: 500; }

/* Кнопка удаления тура в списке */
.delete-tour-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 10px;
    border-radius: 10px;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin-left: auto; /* Прижимаем кнопку к правому краю карточки */
}

.delete-tour-btn:hover {
    color: #EF4444; /* Красный цвет опасности при наведении */
    background: rgba(239, 68, 68, 0.1);
    transform: scale(1.1);
}

.delete-tour-btn:active {
    transform: scale(0.9);
}
/* Кнопка опасного действия (Удаление) */
.danger-btn {
    background: #EF4444;
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.danger-btn:hover {
    background: #DC2626; /* Чуть темнее при наведении */
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

/* ========================================= */
/* КАСТОМНЫЕ ВЫПАДАЮЩИЕ СПИСКИ (APPLE GLASS) */
/* ========================================= */
.custom-dropdown {
    position: relative;
    width: 100%;
    user-select: none;
}

.dropdown-selected {
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; transition: border-color 0.3s, box-shadow 0.3s;
}

.dropdown-selected:hover { border-color: var(--accent); }

.dropdown-arrow { font-size: 0.8rem; color: var(--text-muted); transition: transform 0.3s ease; }
.custom-dropdown.open .dropdown-arrow { transform: rotate(180deg); color: var(--accent); }

/* Само всплывающее меню */
.dropdown-list {
    position: absolute;
    top: calc(100% + 8px); left: 0; width: 100%;
    z-index: 2001;
    opacity: 0; visibility: hidden; transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex; flex-direction: column; padding: 8px; box-sizing: border-box;
    border-radius: 12px; max-height: 200px; overflow-y: auto;
}

.custom-dropdown.open .dropdown-list { opacity: 1; visibility: visible; transform: translateY(0); }

/* Элементы внутри меню */
.dropdown-item {
    padding: 10px 12px; border-radius: 8px; cursor: pointer;
    transition: background 0.2s, color 0.2s; color: var(--text-color); font-size: 0.95rem;
}

.dropdown-item:hover { background: var(--accent); color: white; }

/* Подсветка выбранного пункта */
.dropdown-item.active {
    background: rgba(0, 102, 204, 0.1); color: var(--accent); font-weight: 600;
}
body.dark-theme .dropdown-item.active { background: rgba(41, 151, 255, 0.15); }

/* --- Кнопка удаления сцены на карточке --- */
.delete-scene-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #EF4444;
    color: white;
    border: 2px solid var(--glass-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    cursor: pointer;
    opacity: 0; /* Скрыта по умолчанию */
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.4);
    z-index: 10;
}

/* Показываем крестик при наведении на карточку (на ПК) */
.scene-card:hover .delete-scene-btn {
    opacity: 1;
    transform: scale(1);
}

.delete-scene-btn:hover {
    background: #DC2626;
    transform: scale(1.15) !important;
}

/* На телефонах нет мышки, поэтому крестик показываем всегда */
@media (max-width: 900px) {
    .delete-scene-btn { opacity: 1; }
}

/* ========================================= */
/* ЗАГЛУШКА ДЛЯ ПЛЕЕРА (EMPTY STATE)         */
/* ========================================= */
.viewer-placeholder {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: var(--glass-bg);
    border-radius: 12px;
    
    /* Добавляем аппаратное ускорение, чтобы отделить от WebGL */
    transform: translateZ(0); 
    
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    
    /* Анимируем не только прозрачность, но и само размытие */
    transition: opacity 0.4s ease, visibility 0.4s ease, backdrop-filter 0.4s ease, -webkit-backdrop-filter 0.4s ease;
}

/* Класс, который JS добавляет, чтобы скрыть заглушку */
.viewer-placeholder.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none; /* Жестко запрещаем перехватывать клики мышки */
    
    /* УБИВАЕМ размытие, чтобы оно не баговало поверх 360-картинки */
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
}

/* --- Эффекты для перетаскивания (Drag & Drop) --- */
.scene-card.dragging {
    opacity: 0.4;
    transform: scale(0.9) rotate(-3deg); /* Эффект "взяли в руку": карточка чуть уменьшается и наклоняется */
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    border: 2px dashed var(--accent);
    z-index: 100;
}

.scene-card.drag-over {
    transform: scale(1.05); /* Карточка под курсором плавно "вздувается", приглашая положить рядом */
    border: 2px solid var(--accent);
    box-shadow: 0 10px 25px var(--accent-glow);
    filter: brightness(1.2); /* Делаем её чуть светлее */
}

/* ========================================= */
/* МЕНЮ ДЛЯ МАРКЕРОВ В РЕДАКТОРЕ             */
/* ========================================= */
.editor-marker-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.editor-marker-menu {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    display: none; 
    gap: 6px;
    background: rgba(0,0,0,0.8);
    padding: 6px;
    border-radius: 12px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 999999 !important; /* 1. МАГИЯ: Задираем слой выше любых тултипов! */
    margin-bottom: 8px; 
}

/* 2. МАГИЯ: Невидимый мост, чтобы мышка не "соскальзывала" в пустоту при наведении */
.editor-marker-menu::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: 15px; 
    background: transparent;
}

/* Показываем меню с плавной анимацией */
.app-workspace .editor-marker-wrap:hover .editor-marker-menu {
    display: flex;
    animation: popUp 0.15s ease forwards;
}

@keyframes popUp {
    from { opacity: 0; transform: translateX(-50%) translateY(5px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.marker-action-btn {
    width: 32px; height: 32px;
    border-radius: 50%; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: white; background: rgba(255,255,255,0.2);
    font-size: 0.9rem; transition: 0.2s;
}

.marker-action-btn:hover { background: var(--accent); transform: scale(1.15); }
.marker-action-btn.delete-btn:hover { background: #EF4444; }

/* ========================================= */
/* ТОЧКА ПЕРЕХОДА НА ПОЛУ (УМНЫЕ СТИЛИ)      */
/* ========================================= */
.floor-point {
    width: var(--point-size, 45px);
    height: var(--point-size, 45px);
    background-color: var(--point-color, #ffffff);
    opacity: var(--point-opacity, 0.5);
    border: 4px solid white;
    border-radius: 50%;
    transform: perspective(500px) rotateX(65deg);
    box-shadow: 0 5px 15px rgba(0,0,0,0.5), inset 0 0 10px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: all 0.2s ease;
}

.floor-point:hover {
    opacity: calc(var(--point-opacity, 0.5) + 0.3);
    transform: perspective(500px) rotateX(65deg) scale(1.15);
}