/* ==========================================================================
   Файл: assets/css/main.css
   Спринт 3: Зоны 1 и 2 (Reset & Layout)
   ========================================================================== */

/* --------------------------------------------------------------------------
   Зона 1: Reset & Base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    /* Блокируем pull-to-refresh на уровне браузера, чтобы ощущалось как аппка */
    overscroll-behavior-y: none;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-main);
    font-size: var(--text-base);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Убираем синюю подсветку при тапе на мобильных (Zero UI noise) */
    -webkit-tap-highlight-color: transparent;
    /* Запрет выделения текста для интерфейса, чтобы не было случайных синих пятен */
    user-select: none;
}

/* Возвращаем возможность выделять текст там, где это функционально нужно */
p, h1, h2, h3, span {
    user-select: auto;
}

button {
    font-family: inherit;
    color: inherit;
    border: none;
    background: none;
    cursor: pointer;
    outline: none;
}

a {
    text-decoration: none;
    color: inherit;
}

/* --------------------------------------------------------------------------
   Зона 2: Layout & Global Grid
   -------------------------------------------------------------------------- */

/* Главный контейнер на всю высоту экрана */
#app {
    display: flex;
    flex-direction: column;
    /* dvh решает проблему с прыгающим интерфейсом мобильных браузеров */
    height: 100dvh;
    width: 100%;
    max-width: 768px; /* Ограничиваем ширину для десктопа/планшета */
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-primary);
    /* Легкая тень для визуального отделения на широких экранах */
    box-shadow: 0 0 20px rgba(0,0,0,0.3);
}

/* Зона контента: занимает всё доступное место и скроллится независимо */
#grid-content {
    flex-grow: 1;
    overflow-y: auto;
    /* Нативный инерционный скролл для iOS */
    -webkit-overflow-scrolling: touch;
    /* Базовые отступы от краев */
    padding: var(--space-md);
    /* Дополнительный отступ снизу, чтобы последний элемент не лип к меню */
    padding-bottom: var(--space-xl);
    
    /* Сетка для будущих карточек */
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* Нижнее навигационное меню */
#bottom-nav {
    flex-shrink: 0;
    width: 100%;
    height: var(--nav-height);
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    
    /* Учет зоны Home Indicator на iOS (чтобы иконки не налезли на полоску) */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 10;
}

/* ==========================================================================
   Зона 3: Компоненты - Карточки (List Items)
   ========================================================================== */
.card {
    display: flex;
    align-items: center;
    background-color: var(--bg-secondary);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: transform var(--time-fast), border-color var(--time-fast);
    cursor: pointer;
    /* Запрет на сжатие карточки во флекс-контейнере */
    flex-shrink: 0; 
}

.card:active {
    transform: scale(0.98);
    background-color: var(--bg-hover);
    border-color: var(--accent-color);
}

.card__logo-box {
    width: 50px;  /* Расширили под горизонтальные логотипы */
    height: 50px;
    background-color: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-right: var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    padding: 4px; /* Чтобы лого не липло к краям */
}

.card__logo-box img {
    width: 90%;
    object-fit: contain; /* Лого впишется целиком, не обрезаясь */
}

.card__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0; /* Защита от вылета текста */
}

.card__top-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.card__bottom-row {
    width: 100%;
}

.card__title {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-main);
    /* Обрезка длинного текста многоточием */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tag {
    font-size: var(--text-xs);
    color: var(--text-muted);
    background-color: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    display: inline-block;
}

/* Модификатор для тегов, работающих как кнопки */
button.tag-btn {
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-main);
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 12px;
    transition: all var(--time-fast);
}

button.tag-btn:hover {
    background: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
}

.card__btn-go {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: 50%;
    margin-left: var(--space-sm);
    transition: color var(--time-fast), background-color var(--time-fast);
}

.card__btn-go:active {
    color: var(--text-main);
    background-color: var(--bg-primary);
}

/* ==========================================================================
   Зона 4: Компоненты - Навигация (Bottom Menu)
   ========================================================================== */
.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 4px;
    padding: 8px 0;
    color: var(--text-muted);
    transition: color var(--time-fast);
}

.nav-btn.is-active {
    color: var(--accent-color);
}

.nav-btn__icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Жесткое управление инлайн SVG (Phosphor Icons) */
.nav-btn__icon svg {
    width: 100%;
    height: 100%;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-btn__text {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ==========================================================================
   Зона 5: Модальные окна и Шторки (Bottom Sheet)
   ========================================================================== */

#modal-root {
    position: fixed;
    inset: 0; /* Растягивает контейнер на весь экран (top: 0, right: 0, bottom: 0, left: 0) */
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    /* В скрытом состоянии пропускает клики сквозь себя на контент ниже */
    pointer-events: none; 
}

/* Затемняющий и размывающий фон */
.modal-overlay {
    position: absolute;
    inset: 0;
    background-color: var(--overlay-color);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity var(--time-normal) var(--ease-out-expo);
}

/* Сама выезжающая шторка */
/* Базовый контейнер модалки */
.modal-content {
    position: relative;
    z-index: 1001;
    background-color: var(--bg-secondary);
    width: calc(100% - 32px);
    max-height: calc(100vh - 32px);
    max-height: 90vh; /* Защита от вылезания за верхний край экрана */
    margin: auto 16px 0 16px;
    border-radius: var(--radius-md) var(--radius-md) 0 0; /* По умолчанию дизайн для мобилок (снизу) */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Обрезаем всё, что вываливается за скругления */
    opacity: 0;
    transform: translateY(100px) scale(0.95); 
    transition: opacity 0.2s ease, 
                transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}


/* Адаптив для ПК/Планшетов: делаем карточку плавающей по центру */
@media (min-width: 768px) {
    .modal-content {
        margin: auto;
        max-width: 600px;
        width: 100%;
        height: auto;
        border-radius: var(--radius-md);
    }
}

/* Шапка (Фиксированная) */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border-color); /* Отделяем шапку линией */
    flex-shrink: 0;
}

.modal-title-group {
    display: flex;
    align-items: center;
    gap: 16px;
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    margin-left: 20px;
    padding: 0 8px;
    transition: color var(--time-fast);
}

.modal-close-btn:hover {
    color: var(--text-main);
}

/* Тело (Скроллируемое) */
.modal-body-scrollable {
    padding: 24px;
    overflow-y: auto; /* Полоса прокрутки появится только если текста много */
    flex-grow: 1; /* Занимает всю доступную высоту между шапкой и подвалом */
}

.modal-body-scrollable::-webkit-scrollbar {
    width: 6px;
}
.modal-body-scrollable::-webkit-scrollbar-track {
    background: transparent;
}
.modal-body-scrollable::-webkit-scrollbar-thumb {
    background-color: var(--border-color); /* Используем цвет бордеров или задай свой HEX */
    border-radius: 10px;
}

.modal-description {
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0;
}

/* Подвал (Фиксированный) */
.modal-footer {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: row;
    gap: 16px;
    flex-shrink: 0;
}

.modal-footer button {
    flex: 1; /* Кнопки делят ширину поровну */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px; /* Отступ между иконкой и текстом */
}

.modal-footer button svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Контейнер логотипа в модалке */
.modal-logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px; /* Фиксированная высота шапки */
    min-width: 40px; /* Чтобы круглые иконки не сплющило */
}

/* Сама картинка Лого/Иконки/Заглушки */
.modal-logo-img {
    max-height: 100%;
    max-width: 150px; /* Ограничение по ширине для длинных логотипов */
    object-fit: contain; /* Сохраняем пропорции без обрезки */
}

/* Кнопки внутри модального окна */
.primary-btn {
    background-color: var(--accent-color);
    color: white;
    padding: 14px;
    border-radius: var(--radius-md);
    font-weight: 600;
    width: 100%;
}

.secondary-btn {
    background-color: var(--bg-primary);
    color: var(--text-main);
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    width: 100%;
}
.primary-btn, .secondary-btn {
    transition: background-color 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.primary-btn:hover {
    filter: brightness(1.2);
    box-shadow: 0 0 15px var(--accent-color);
}

.secondary-btn:hover {
    background-color: var(--bg-hover);
    box-shadow: inset 0 0 0 1px var(--border-color);
}

.primary-btn:active, .secondary-btn:active {
    filter: brightness(0.9);
}

.primary-btn svg, .secondary-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0; /* чтобы иконку не плющило */
}

/* --------------------------------------------------------------------------
   Активное состояние (Триггер анимации)
   -------------------------------------------------------------------------- */
#modal-root.is-open {
    pointer-events: auto; /* Включаем перехват кликов */
}

#modal-root.is-open .modal-overlay {
    opacity: 1;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px); /* Поддержка Safari */
}

#modal-root.is-open .modal-content {
    opacity: 1;
    transform: translateY(0) scale(1); /* Возвращаем в нормальное положение */
}

/* ==========================================================================
   Зона 6: Утилиты (Helpers)
   ========================================================================== */
.is-hidden {
    display: none !important;
}

.no-scroll {
    overflow: hidden !important;
}

/* ==========================================================================
   Зона 7: Динамическая Шторка Меню (Action Sheet)
   ========================================================================== */
#action-sheet {
    position: fixed;
    inset: 0;
    z-index: 90; /* Под модалкой карточки (100), но над всем остальным */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
}

#action-sheet.is-open { pointer-events: auto; }

.sheet-overlay {
    position: absolute;
    inset: 0;
    background-color: var(--overlay-color);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity var(--time-normal) ease;
}

#action-sheet.is-open .sheet-overlay { opacity: 1; }

.sheet-content {
    position: relative;
    z-index: 91;
    background-color: var(--bg-secondary);
    width: 100%;
    max-height: 60vh; /* Шторка не занимает весь экран */
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform var(--time-normal) var(--ease-out-expo);
}

#action-sheet.is-open .sheet-content { transform: translateY(0); }

/* Адаптив для ПК: делаем шторку плавающей панелью */
@media (min-width: 768px) {
    .sheet-content {
        margin: 0 auto 80px auto; /* Отступ от нижнего меню */
        max-width: 400px;
        border-radius: var(--radius-md);
    }
}

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
}

.sheet-title {
    font-size: 18px;
    margin: 0;
}

.sheet-close-btn {
    font-size: 28px;
    color: var(--text-muted);
    padding: 0 8px;
    margin-right: -8px;
}

.sheet-body {
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

/* Стили для элементов внутри шторки */
.sheet-chip {
    padding: 10px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-main);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.sheet-chip.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #fff;
}

/* Тумблер исключения универсальных */
.toggle-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 16px;
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
}
/* ==========================================================================
   Зона 8: Динамический фон (Изолированный)
   ========================================================================== */

.bg-fx {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.bg-bubbles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

.bg-bubbles li {
    position: absolute;
    list-style: none;
    display: block;
    width: 20px;
    height: 20px;
    background-color: rgba(139, 92, 246, 0.08);
    bottom: -150px;
    animation: animate-bubble 25s linear infinite;
}

/* Без запятых! */
@keyframes animate-bubble {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
        border-radius: 0;
    }
    100% {
        transform: translateY(-1000px) rotate(720deg);
        opacity: 0;
        border-radius: 50%;
    }
}

/* Размеры и тайминги адаптированы под ширину мобильного контейнера */
.bg-bubbles li:nth-child(1) { left: 25%; width: 60px; height: 60px; animation-delay: 0s; }
.bg-bubbles li:nth-child(2) { left: 10%; width: 20px; height: 20px; animation-delay: 2s; animation-duration: 12s; }
.bg-bubbles li:nth-child(3) { left: 70%; width: 20px; height: 20px; animation-delay: 4s; }
.bg-bubbles li:nth-child(4) { left: 40%; width: 50px; height: 50px; animation-delay: 0s; animation-duration: 18s; }
.bg-bubbles li:nth-child(5) { left: 65%; width: 20px; height: 20px; animation-delay: 0s; }
.bg-bubbles li:nth-child(6) { left: 75%; width: 80px; height: 80px; animation-delay: 3s; }
.bg-bubbles li:nth-child(7) { left: 35%; width: 100px; height: 100px; animation-delay: 7s; }
.bg-bubbles li:nth-child(8) { left: 50%; width: 25px; height: 25px; animation-delay: 15s; animation-duration: 45s; }
.bg-bubbles li:nth-child(9) { left: 20%; width: 15px; height: 15px; animation-delay: 2s; animation-duration: 35s; }
.bg-bubbles li:nth-child(10) { left: 85%; width: 100px; height: 100px; animation-delay: 0s; animation-duration: 11s; }

/* ==========================================================================
   Зона 9: Статистика (Счетчики)
   ========================================================================== */

.stats-container {
    display: inline-flex;
    gap: 12px;
    align-items: center;
    margin-left: auto; /* Прижимает стату к правому краю */
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-item svg {
    width: 14px;
    height: 14px;
    opacity: 0.6;
}

/* Модификатор для модального окна (чуть крупнее и с разделителем) */
.modal-stats {
    margin-left: 16px;
}

.modal-stats .stat-item {
    font-size: 14px;
}

.modal-stats .stat-item svg {
    width: 16px;
    height: 16px;
}