/* assets/css/layout.css */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: transparent; /* Никакого фона и линий, шапка парит */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 1000;
}

/* Логотип SVG */
.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    font-size: 24px;
    font-weight: bold;
    letter-spacing: 1px;
    text-decoration: none !important;
}

.logo-container:hover {
    text-decoration: none !important;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Парящий блок баланса */
.balance-pill {
    background: var(--bg-panel);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.balance-pill .tokens { color: var(--accent); font-weight: bold; }

.app-container {
    display: grid;
    grid-template-columns: 240px 1fr 380px; /* Правое ухо делаем чуть шире под карточки */
    gap: 20px; /* ПРОСТРАНСТВО МЕЖДУ ПАРЯЩИМИ БЛОКАМИ */
    padding: var(--header-height) 20px 20px 20px; 
    height: 100vh;
    height: 100dvh;
    transition: all var(--transition-speed) ease;
}

/* Класс для всех парящих блоков (Острова) */
.floating-island {
    background: var(--bg-panel);
    border-radius: var(--border-rad);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3); /* Легкая тень для объема */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-sidebar, .app-center, .app-right-sidebar { height: 100%; }

/* Обертка для контента на весь экран (для гостей) */
.app-center-full {
    height: 100%;
    grid-column: 1 / -1; /* Заставляет блок занять всю ширину сетки (все 3 колонки) */
}

/* ==========================================
   ГЛОБАЛЬНЫЕ КНОПКИ (BUTTONS) И АНИМАЦИИ
   ========================================== */
.btn {
    position: relative;
    overflow: hidden;
    padding: 12px 28px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    /* Пружинистая анимация (cubic-bezier) для плавности */
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease, background 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Эффект волны (Ripple) при нажатии */
.btn::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300%;
    padding-top: 300%;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.6s ease-out, opacity 0.6s ease-out;
}

.btn:active::after {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0.5;
    transition: 0s; /* Моментально появляется под кликом */
}

.btn:not(:active)::after {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0;
    transition: transform 0.6s ease-out, opacity 0.6s ease-out; /* Плавное расширение */
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(0, 168, 255, 0.2);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 168, 255, 0.4);
}

.btn-primary:active {
    transform: translateY(0) scale(0.95);
    box-shadow: 0 2px 10px rgba(0, 168, 255, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 168, 255, 0.15);
}

.btn-secondary:active {
    transform: translateY(0) scale(0.95);
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.3);
}

/* ==========================================
   ГОСТЕВАЯ СТРАНИЦА (GUEST CENTER)
   ========================================== */
.guest-promo-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
    width: 100%;
}

.guest-promo-icon {
    margin-bottom: 24px;
    background: rgba(0, 168, 255, 0.05); 
    padding: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 40px rgba(0, 168, 255, 0.1);
}

.guest-welcome-message {
    max-width: 400px;
    margin-bottom: 32px;
}

.guest-welcome-message h2 {
    margin: 0 0 12px 0;
    font-size: 26px;
    font-weight: 700;
    color: var(--text-main);
}

.guest-welcome-message p {
    margin: 0;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1.5;
}

.guest-actions {
    display: flex;
    gap: 16px;
}

/* Стили меню */
.sidebar-nav {
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 20px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    transition: var(--transition-speed);
}
.nav-item:hover {
    background: rgba(255,255,255,0.02);
    color: var(--text-main);
}
.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent);
}

.icon-btn {
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    transition: 0.2s;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { color: var(--accent); }

/* Мобильные вкладки скрыты по умолчанию */
.mobile-tabs { display: none; }

#toast-container {
    position: fixed;
    top: 60px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.toast {
    background: var(--bg-panel);
    border-left: 4px solid var(--accent);
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    transform: translateX(120%);
    transition: transform var(--transition-speed) cubic-bezier(0.175, 0.885, 0.32, 1.275);
    color: white;
}
.toast.show { transform: translateX(0); }

/* Выпадающее меню пользователя */
.user-menu-wrapper {
    position: relative;
}

.user-avatar-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px; /* Скругленный квадрат вместо круга (было 50%) */
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.user-avatar-btn:hover .user-avatar {
    background: var(--accent);
    color: white;
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-panel);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    min-width: 240px;
    margin-top: 10px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1001;
}

.user-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    padding: 12px 16px;
    text-align: center;
}

.user-email {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
}

.dropdown-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-main);
    text-decoration: none;
    transition: all 0.2s ease;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--accent);
}

.dropdown-item svg {
    flex-shrink: 0;
}

.logout-item {
    color: #ef4444;
}

.logout-item:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* ==========================================
   ПЕРЕКЛЮЧАТЕЛЬ ЯЗЫКА
   ========================================== */
.lang-switcher {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-panel);
    padding: 4px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.lang-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-muted);
    background: transparent;
    border-radius: 6px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.lang-btn:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.05);
}

.lang-btn.active {
    color: var(--accent);
    background: var(--accent-glow);
    cursor: default;
}


/* ==========================================
   СИММЕТРИЧНЫЕ ЯЗЫЧКИ (HANDLES) — ПРЕМИУМ ДИЗАЙН
   ========================================== */
@keyframes handle-glow {
    0% { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255,255,255,0.05) inset; }
    50% { box-shadow: 0 4px 20px rgba(0, 168, 255, 0.3), 0 0 0 1px rgba(0, 168, 255, 0.25) inset; }
    100% { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255,255,255,0.05) inset; }
}

.sidebar-handle {
    display: none; /* По умолчанию скрыты */
    position: fixed;
    top: 20%; 
    transform: translateY(-50%);
    width: 18px; 
    height: 76px; 
    
    /* Премиальный глассморфизм */
    background: rgba(15, 15, 20, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    
    /* Жесткая рамка, чтобы элемент не сливался с контентом */
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    
    align-items: center;
    justify-content: center;
    z-index: 900;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    
    /* Анимация пульсации, чтобы привлекать внимание пользователя */
    animation: handle-glow 3s infinite alternate ease-in-out;
}

/* Эффект объема (внутренний блик по верхнему краю) */
.sidebar-handle::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, transparent 40%, rgba(0,0,0,0.5) 100%);
    border-radius: inherit;
    pointer-events: none;
}

.sidebar-handle.right-handle {
    right: 0;
    border-right: none;
    border-radius: 16px 0 0 16px;
    padding-left: 4px;
}

.sidebar-handle.left-handle {
    left: 0;
    border-left: none;
    border-radius: 0 16px 16px 0;
    padding-right: 4px;
}

.sidebar-handle svg {
    position: relative;
    z-index: 2;
    width: 12px; 
    height: auto;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Ховер / Тап эффекты */
.sidebar-handle:hover {
    background: rgba(0, 168, 255, 0.15);
    color: #ffffff;
    border-color: rgba(0, 168, 255, 0.5);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 0 0 20px rgba(0, 168, 255, 0.4), 0 0 0 1px rgba(0, 168, 255, 0.5) inset;
    animation: none; /* Отключаем пульсацию при наведении */
}

.sidebar-handle.right-handle:hover {
    transform: translateY(-50%) translateX(-4px); 
    width: 22px;
}
.sidebar-handle.right-handle:hover svg {
    transform: translateX(-1px) scale(1.15);
}

.sidebar-handle.left-handle:hover {
    transform: translateY(-50%) translateX(4px); 
    width: 22px;
}
.sidebar-handle.left-handle:hover svg {
    transform: translateX(1px) scale(1.15);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}


/* --- АДАПТИВНОСТЬ --- */

/* Плавное сжатие для экранов < 1400px */
@media (max-width: 1400px) {
    .app-container {
        grid-template-columns: 200px 1fr 320px; 
        gap: 12px; 
        padding: var(--header-height) 12px 12px 12px;
    }
    .sidebar-nav {
        padding: 15px 5px; 
    }
    .nav-item {
        padding: 10px 15px;
        font-size: 14px;
    }
}

/* Планшеты: Левое меню сворачивается до иконок */
@media (max-width: 1200px) {
    .app-container {
        grid-template-columns: 80px 1fr 320px;
    }
    .sidebar-nav .label { display: none; }
    .sidebar-nav .nav-item { padding: 12px; justify-content: center; }
    .app-sidebar > div:not(.sidebar-nav) { display: none; }
}

/* Экраны < 1000px: правый сайдбар уходит в шторку, появляется правый "язычок" */
@media (max-width: 1000px) {
    .app-container {
        grid-template-columns: 80px 1fr; /* Левое свернутое меню + расширенный центр */
    }

    /* Включаем правый язычок */
    .sidebar-handle.right-handle {
        display: flex;
    }

    .app-right-sidebar {
        position: fixed;
        top: 0;
        right: -400px; /* Прячем за правый край */
        width: 340px;
        height: 100vh;
        z-index: 1050; /* Поверх оверлея */
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 0;
        border-top-left-radius: var(--border-rad);
        border-bottom-left-radius: var(--border-rad);
        box-shadow: -10px 0 40px rgba(0,0,0,0.6);
    }

    .app-right-sidebar.open {
        right: 0;
        display: flex !important; /* Гарантия видимости поверх других правил */
    }
}

/* Мобильные экраны: Меню прячется, Центр занимает всё место, появляется левый "язычок" */
@media (max-width: 768px) {
    /* Переопределяем высоту шапки для мобильных (в 1.5 раза меньше) */
    :root {
        --header-height: 48px;
    }

    /* Уменьшаем иконку юзер-профиля */
    .user-avatar {
        width: 28px;
        height: 28px;
        border-radius: 8px; /* Немного уменьшаем радиус скругления пропорционально размеру */
    }
    
    /* Уменьшаем сам SVG внутри иконки профиля */
    .user-avatar svg {
        width: 16px;
        height: 16px;
    }

    /* Скрываем текстовую часть логотипа */
    .logo-container span { display: none; }

    /* Скрываем старый гамбургер в шапке */
    #mobile-menu-btn { display: none !important; }
    /* Включаем левый язычок */
    .sidebar-handle.left-handle { display: flex; }
    
    .app-container {
        display: flex; 
        flex-direction: column;
        padding: var(--header-height) 0 0 0; 
        gap: 0; 
    }
    
    /* Скрытое левое меню */
    .app-sidebar {
        position: fixed;
        left: -100%;
        top: 0; 
        width: 240px;
        height: 100vh; 
        z-index: 1050; 
        transition: left 0.3s ease;
        border-radius: 0;
        border-top-right-radius: var(--border-rad);
        border-bottom-right-radius: var(--border-rad);
        box-shadow: 10px 0 40px rgba(0,0,0,0.6);
    }
    .app-sidebar.open { left: 0; }
    .sidebar-nav .label { display: inline; }
    .sidebar-nav .nav-item { justify-content: flex-start; }

    /* Табы */
    .mobile-tabs {
        display: flex;
        position: fixed;
        top: var(--header-height);
        left: 0; right: 0;
        background: var(--bg-body);
        padding: 10px;
        z-index: 800;
        gap: 10px;
    }
    .mobile-tabs .tab-btn {
        flex-grow: 1;
        padding: 10px;
        background: var(--bg-panel);
        color: var(--text-muted);
        border: none;
        border-radius: 8px;
        font-weight: 500;
    }
    .mobile-tabs .tab-btn.active {
        background: var(--accent-glow);
        color: var(--accent);
    }
    
    .app-center {
        width: 100%;
        height: 100%;
        flex: 1; 
        display: flex; 
    }

    .app-center.floating-island {
        border-radius: 0; 
        overflow: visible; 
    }

    .lang-switcher {
        padding: 3px;
    }
    
    .lang-btn {
        padding: 5px 10px;
        font-size: 11px;
    }
    
    /* Гостевые стили под мобильные */
    .guest-actions {
        flex-direction: column;
        width: 100%;
        max-width: 280px;
    }
    
    .guest-actions .btn {
        width: 100%;
    }
    
    .guest-promo-wrapper {
        border-radius: 0;
        box-shadow: none;
        background: transparent;
    }
}