/* ============================================================
   Нижняя панель навигации — общая для маркетплейса (body.mp)
   и магазинов. Разметка: resources/views/partials/tabbar.blade.php.
   Файл не зависит ни от style.css, ни от marketplace.css и не
   подключается в админке.
   ============================================================ */

:root {
    --tabbar-h: 58px;
    --tabbar-gap: 12px; /* отступ панели от краёв экрана */
}

/* ---------- Цвета по контекстам ----------
   Переменные заданы на body, чтобы их наследовали и панель, и окно магазинов.
   var(--accent) подхватывает цвет текущего магазина (в ASIYA он переопределён). */

/* магазин, тёмная тема (по умолчанию) */
body {
    --tabbar-bg: rgba(38, 38, 38, 0.94);
    --tabbar-ring: #262626;
    --tabbar-border: rgba(255, 255, 255, 0.1);
    --tabbar-icon: rgba(255, 251, 245, 0.6);
    --tabbar-icon-active: #FFFBF5;
    --tabbar-badge-bg: #FFFBF5;
    --tabbar-badge-text: var(--accent, #A03432);
    --tabbar-focus: #FFFBF5;

    --tabbar-sheet-bg: #FFFBF5;
    --tabbar-sheet-text: #2a2a2a;
    --tabbar-sheet-muted: #666;
    --tabbar-sheet-line: rgba(0, 0, 0, 0.1);
    --tabbar-sheet-accent: var(--accent, #A03432);
    --tabbar-sheet-tile: #fff;
}

/* магазин, светлая тема */
body.light-theme {
    --tabbar-bg: rgba(255, 255, 255, 0.86);
    --tabbar-ring: #fff;
    --tabbar-border: rgba(0, 0, 0, 0.08);
    --tabbar-icon: #5c5c5c;
    --tabbar-icon-active: var(--accent, #A03432);
    --tabbar-badge-bg: var(--accent, #A03432);
    --tabbar-badge-text: #fff;
    --tabbar-focus: var(--accent, #A03432);
}

/* ASIYA, тёмная тема */
body.asiya-catalog {
    --tabbar-bg: rgba(29, 20, 40, 0.95);
    --tabbar-ring: #1d1428;
    --tabbar-border: rgba(184, 153, 104, 0.22);
    --tabbar-icon: rgba(255, 255, 255, 0.6);
    --tabbar-icon-active: #d9c095;
    --tabbar-badge-bg: #b89968;
    --tabbar-badge-text: #1d1428;
    --tabbar-focus: #d9c095;
}

/* ASIYA, светлая тема — заново всё, что отличается: два селектора выше равны по весу */
body.asiya-catalog.light-theme {
    --tabbar-bg: rgba(255, 255, 255, 0.86);
    --tabbar-ring: #fff;
    --tabbar-border: rgba(74, 57, 96, 0.14);
    --tabbar-icon: #6b5a85;
    --tabbar-icon-active: #4a3960;
    --tabbar-badge-bg: #4a3960;
    --tabbar-badge-text: #fff;
    --tabbar-focus: #4a3960;
}

/* маркетплейс */
body.mp {
    --tabbar-bg: rgba(253, 250, 246, 0.94);
    --tabbar-ring: #FDFAF6;
    --tabbar-border: #E8DDCF;
    --tabbar-icon: #76656D;
    --tabbar-icon-active: #3A2036;
    --tabbar-badge-bg: #3A2036;
    --tabbar-badge-text: #fff;
    --tabbar-focus: #3A2036;

    --tabbar-sheet-bg: #FDFAF6;
    --tabbar-sheet-text: #3A2A35;
    --tabbar-sheet-muted: #76656D;
    --tabbar-sheet-line: #E8DDCF;
    --tabbar-sheet-accent: #3A2036;
    --tabbar-sheet-tile: #fff;
}

/* ---------- Панель ---------- */

.tabbar,
.tabbar *,
.tabbar-sheet,
.tabbar-sheet * {
    box-sizing: border-box;
}

/* «Плавающая» панель: отступы от краёв экрана и скруглённые углы */
.tabbar {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-gap) + env(safe-area-inset-bottom, 0px));
    z-index: 900; /* выше шапки (100), ниже cookie-баннера (9999) и окна записи (10000) */
    display: none; /* включается в медиа-блоках ниже */
    grid-template-columns: repeat(5, minmax(0, 1fr));
    /* на широких телефонах и планшетах панель не растягивается на весь экран */
    width: min(100% - 2 * var(--tabbar-gap), 460px);
    height: var(--tabbar-h);
    padding: 0 6px;
    border: 1px solid var(--tabbar-border);
    border-radius: calc(var(--tabbar-h) / 2);
    background: var(--tabbar-bg);
    box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.35);
    transform: translateX(-50%);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
}

/* a.… — чтобы перебить a:hover из Bootstrap в магазинах */
.tabbar a.tabbar__tab,
.tabbar a.tabbar__tab:hover {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tabbar-icon);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.tabbar a.tabbar__tab.is-active,
.tabbar a.tabbar__tab.is-active:hover,
.tabbar a.tabbar__tab[aria-expanded="true"] {
    color: var(--tabbar-icon-active);
}

/* Активная вкладка выделяется только самой иконкой (цвет и толщина линии) — без подложки.
   Рамка ниже появляется лишь при переходе с клавиатуры. */
/* a.… — тяжелее, чем .mp a:focus-visible на маркетплейсе, иначе рамок становится две */
.tabbar a.tabbar__tab:focus-visible {
    outline: none;
}

.tabbar__tab:focus-visible::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 48px;
    height: 40px;
    border-radius: 20px;
    box-shadow: 0 0 0 2px var(--tabbar-focus);
    transform: translate(-50%, -50%);
}

/* иконки приходят из marketplace/partials/icon: в магазинах класс .mp-icon ничем не размечен */
.tabbar .mp-icon,
.tabbar-sheet .mp-icon {
    position: relative;
    width: 24px;
    height: 24px;
    flex: none;
}

.tabbar .mp-icon {
    stroke-width: 1.5;
    transition: transform 0.2s ease;
}

.tabbar__tab.is-active .mp-icon,
.tabbar__tab[aria-expanded="true"] .mp-icon {
    stroke-width: 2.2;
    transform: scale(1.08);
}

.tabbar__badge {
    position: absolute;
    top: 7px;
    left: calc(50% + 4px);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--tabbar-badge-bg);
    box-shadow: 0 0 0 2px var(--tabbar-ring);
    color: var(--tabbar-badge-text);
    font-family: inherit;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}

/* на маркетплейсе нет Bootstrap с его [hidden]{display:none!important} */
.tabbar__badge[hidden],
.tabbar-sheet[hidden] {
    display: none;
}

.tabbar__tab.is-bumped .mp-icon,
.tabbar__tab.is-bumped .tabbar__badge {
    animation: tabbar-bump 0.45s ease;
}

@keyframes tabbar-bump {
    0% { transform: scale(1); }
    45% { transform: scale(1.22); }
    100% { transform: scale(1); }
}

/* ---------- Окно выбора магазина ---------- */

html.tabbar-sheet-open {
    overflow: hidden;
}

.tabbar-sheet {
    position: fixed;
    inset: 0;
    z-index: 10050; /* поверх cookie-баннера: иначе он закрывает список */
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.tabbar-sheet__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(18, 12, 18, 0.55);
    animation: tabbar-fade 0.2s ease;
}

.tabbar-sheet__panel {
    position: relative;
    width: min(100%, 560px);
    max-height: 86vh;
    overflow-y: auto;
    padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
    background: var(--tabbar-sheet-bg);
    box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.3);
    color: var(--tabbar-sheet-text);
    font-family: inherit;
    outline: none;
    animation: tabbar-rise 0.26s ease;
}

/* «ручка» листа */
.tabbar-sheet__panel::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    margin: 0 auto 8px;
    border-radius: 2px;
    background: var(--tabbar-sheet-line);
}

.tabbar-sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.tabbar-sheet__title {
    margin: 0;
    color: inherit;
    font-family: inherit;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0;
}

.tabbar-sheet__close {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-right: -10px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--tabbar-sheet-muted);
    cursor: pointer;
}

.tabbar-sheet__list {
    display: grid;
    gap: 10px;
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
}

.tabbar-sheet a.tabbar-shop,
.tabbar-sheet a.tabbar-shop:hover {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border: 1px solid var(--tabbar-sheet-line);
    border-radius: 16px;
    color: var(--tabbar-sheet-text);
    text-decoration: none;
}

.tabbar-sheet a.tabbar-shop[aria-current="true"] {
    border-color: var(--tabbar-sheet-accent);
}

.tabbar-shop:focus-visible,
.tabbar-sheet__close:focus-visible {
    outline: 2px solid var(--tabbar-sheet-accent);
    outline-offset: 2px;
}

/* плашка всегда светлая: оба логотипа рассчитаны на светлый фон */
.tabbar-shop__logo {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    flex: none;
    overflow: hidden;
    border: 1px solid var(--tabbar-sheet-line);
    border-radius: 14px;
    background: var(--tabbar-sheet-tile);
}

.tabbar-shop__logo img {
    display: block;
    max-width: 52px;
    max-height: 44px;
}

/* у знака ASIYA в файле большие прозрачные поля — увеличиваем */
.tabbar-shop--asiya .tabbar-shop__logo img {
    width: 72px;
    max-width: none;
    max-height: none;
}

.tabbar-shop__text {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.tabbar-shop__name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.25;
}

.tabbar-shop__desc {
    color: var(--tabbar-sheet-muted);
    font-size: 12px;
    line-height: 1.35;
}

.tabbar-shop__here {
    flex: none;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--tabbar-sheet-accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.tabbar-shop .mp-icon {
    width: 18px;
    height: 18px;
    color: var(--tabbar-sheet-muted);
}

@keyframes tabbar-rise {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes tabbar-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---------- Когда панель видна ----------
   Всё, что затрагивает существующие элементы страницы, живёт только в этих блоках:
   на десктопе нет ни панели, ни отступов, ни сдвига cookie-баннера.
   Границы совпадают с мобильными шапками: магазины — 992px, маркетплейс — 900px. */

@media (max-width: 992px) {
    body:not(.mp) {
        --tabbar-space: calc(var(--tabbar-h) + var(--tabbar-gap) + env(safe-area-inset-bottom, 0px));
        padding-bottom: calc(20px + var(--tabbar-space));
    }

    body:not(.mp) .tabbar {
        display: grid;
    }

    /* стили баннера — инлайновый <style> в конце страницы; селектор тяжелее, поэтому порядок не важен */
    body:not(.mp) .rkn-cookie-banner {
        bottom: calc(var(--tabbar-space) + 8px);
    }

    /* пока открыто окно записи, панель не нужна */
    body.modal-open:not(.mp) .tabbar {
        display: none;
    }
}

@media (max-width: 900px) {
    body.mp {
        --tabbar-space: calc(var(--tabbar-h) + var(--tabbar-gap) + env(safe-area-inset-bottom, 0px));
        padding-bottom: calc(var(--tabbar-space) + 10px);
    }

    body.mp .tabbar {
        display: grid;
    }

    body.mp .rkn-cookie-banner {
        bottom: calc(var(--tabbar-space) + 8px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .tabbar__tab.is-bumped .mp-icon,
    .tabbar__tab.is-bumped .tabbar__badge,
    .tabbar-sheet__panel,
    .tabbar-sheet__backdrop {
        animation: none;
    }
}

@media print {
    .tabbar,
    .tabbar-sheet {
        display: none !important;
    }
}
