/* Демо ЛК: сетка с сайт-хедером (lk-page-site). Подключать после style.css */
/* ЛК со шапкой: у body в style.css задано overflow-x:hidden — это часто ломает
   position:sticky у сайдбара; clip отсекает горизонтальный вылет и даёт нормальный sticky. */
body.lk-page-site {
    overflow-x: clip;
}

/* Как в админ-консоли: узкий рейл 52px + контент */
.lk-body-wrap {
    max-width: 1120px;
    margin: 0 auto;
    padding: 1rem clamp(0.75rem, 2vw, 1.25rem) 2.5rem;
    display: grid;
    grid-template-columns: 52px 1fr;
    grid-template-rows: auto;
    gap: 0;
    align-items: stretch;
    min-height: min(100vh, 100dvh);
}

.lk-page-body {
    grid-column: 2;
    min-width: 0;
    padding-left: 1rem;
}

@media (max-width: 640px) {
    .lk-page-body {
        padding-left: 0.65rem;
    }
}

/* Боевой сайдбар: сетка и колонки (перебивает display:block из shell) */
.lk-body-wrap.lk-body-wrap--with-sidebar {
    display: grid;
    max-width: 1280px;
    grid-template-columns: minmax(200px, 248px) minmax(0, 1fr);
}

@media (min-width: 561px) {
    .lk-body-wrap.lk-body-wrap--with-sidebar {
        display: grid !important;
    }
}

/* Колонка сайдбара: sticky держит меню в зоне видимости при прокрутке контента */
.lk-body-wrap--with-sidebar .lk-sidebar-col {
    grid-column: 1;
    grid-row: 1;
    align-self: start;
    min-width: 0;
    width: 100%;
    max-width: 248px;
    position: sticky;
    top: 1rem;
    z-index: 8;
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.lk-page-site .lk-body-wrap--with-sidebar .lk-sidebar-col {
    top: calc(var(--header-h, 64px) + 0.75rem);
    max-height: calc(100vh - var(--header-h, 64px) - 1.5rem);
    max-height: calc(100dvh - var(--header-h, 64px) - 1.5rem);
}

.lk-sidebar svg.lk-ico {
    display: block;
    stroke: currentColor;
    fill: none;
}

.lk-sidebar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    position: relative;
    padding: 10px 0 14px;
    background: linear-gradient(180deg, var(--surface) 0%, #f5f1eb 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius, 12px);
    overflow-x: hidden;
    overflow-y: auto;
    box-shadow: var(--shadow, 0 2px 10px rgba(88, 82, 72, 0.05));
}

.lk-sidebar__item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 8px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-heading);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    border: 1px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.lk-sidebar__item:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.lk-sidebar__item[aria-current="page"] {
    background: var(--accent-soft);
    border-color: rgba(52, 143, 133, 0.35);
    color: var(--accent);
}

.lk-sidebar__item--muted {
    opacity: 0.5;
    cursor: not-allowed;
}

.lk-sidebar__item--exit:hover {
    color: #b91c1c;
    border-color: rgba(185, 28, 28, 0.32);
    background: #fef2f2;
}

.lk-sidebar__ico {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.lk-sidebar__item[aria-current="page"] .lk-sidebar__ico {
    color: var(--accent-hover);
}

.lk-sidebar__item--exit .lk-sidebar__ico {
    color: #b91c1c;
}

.lk-sidebar__text {
    flex: 1;
    min-width: 0;
}

.lk-sidebar__sep {
    border: none;
    border-top: 1px solid var(--border);
    margin: 10px 12px;
}

.lk-sidebar__spacer {
    flex: 1;
    min-height: 1.5rem;
}

.lk-sidebar .lk-ico {
    width: 22px;
    height: 22px;
}

/* Рейл — демо и старые страницы: узкий столбец 52px */
.lk-rail {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    gap: 4px;
    background: linear-gradient(180deg, var(--surface) 0%, #f0ebe3 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    align-self: start;
    position: sticky;
    top: 1rem;
    z-index: 8;
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
}

.lk-page-site .lk-rail {
    top: calc(var(--header-h, 64px) + 0.75rem);
    max-height: calc(100vh - var(--header-h, 64px) - 1.5rem);
    max-height: calc(100dvh - var(--header-h, 64px) - 1.5rem);
}

.lk-rail-spacer {
    flex: 1;
    min-height: 0.5rem;
}

.lk-rail-btn {
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    flex-shrink: 0;
}

.lk-rail-btn:hover {
    background: var(--accent-soft);
    border-color: var(--border);
    color: var(--text-heading);
}

.lk-rail-btn[aria-current="page"] {
    background: var(--accent-soft);
    border-color: rgba(52, 143, 133, 0.35);
    color: var(--accent);
}

.lk-rail-btn--exit:hover {
    color: #b91c1c;
    border-color: rgba(185, 28, 28, 0.32);
    background: #fef2f2;
}

.lk-ico {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lk-main {
    min-width: 0;
}

.lk-page-site .site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

/* —— Мобильные: нижний тулбар (фиксированная панель) —— */
@media (max-width: 560px) {
    .lk-page-site {
        --lk-tabbar-pad-y: 6px;
        --lk-tabbar-btn: 44px;
        --lk-tabbar-h: calc(var(--lk-tabbar-pad-y) + var(--lk-tabbar-btn) + max(var(--lk-tabbar-pad-y), env(safe-area-inset-bottom, 0px)));
        scroll-padding-top: calc(var(--header-h, 64px) + 8px);
        scroll-padding-bottom: calc(var(--lk-tabbar-h) + 12px);
    }

    .lk-body-wrap--with-sidebar {
        --lk-tabbar-pad-y: 6px;
        --lk-tabbar-btn: 44px;
        --lk-tabbar-h: calc(var(--lk-tabbar-pad-y) + var(--lk-tabbar-btn) + max(var(--lk-tabbar-pad-y), env(safe-area-inset-bottom, 0px)));
    }

    .lk-body-wrap {
        display: block;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        padding: 0.5rem max(0.5rem, env(safe-area-inset-left, 0px)) calc(var(--lk-tabbar-h) + 0.85rem) max(0.5rem, env(safe-area-inset-right, 0px));
    }

    /* Иначе .lk-body-wrap.lk-body-wrap--with-sidebar (display:grid + 248px колонка) перебивает правило выше по специфичности */
    .lk-body-wrap.lk-body-wrap--with-sidebar {
        display: block !important;
    }

    .lk-page-body {
        padding-left: 0;
        padding-top: 0.35rem;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    body.lk-page-site .site-account-main {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Не display:contents — в части движков ломает ширину потока рядом с position:fixed */
    .lk-body-wrap--with-sidebar .lk-sidebar-col {
        display: block;
        width: 100%;
        max-width: 100%;
        height: 0;
        min-height: 0;
        margin: 0;
        padding: 0;
        overflow: visible;
        position: relative;
        z-index: 96;
        pointer-events: none;
    }

    .lk-body-wrap--with-sidebar .lk-sidebar-col .lk-sidebar {
        pointer-events: auto;
    }

    .lk-page-site .lk-rail {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        grid-column: unset;
        grid-row: unset;
        z-index: 96;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-start;
        align-self: stretch;
        width: auto;
        max-width: none;
        max-height: none;
        padding: var(--lk-tabbar-pad-y) max(8px, env(safe-area-inset-left, 0px)) max(var(--lk-tabbar-pad-y), env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-right, 0px));
        gap: 4px;
        margin: 0;
        border-radius: 0;
        border-top: 1px solid var(--border);
        border-left: none;
        border-right: none;
        border-bottom: none;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        box-shadow: 0 -8px 28px rgba(88, 82, 72, 0.14);
        background: linear-gradient(180deg, #f3efe8 0%, var(--surface) 35%, var(--surface) 100%);
        box-sizing: border-box;
    }

    .lk-page-site .lk-rail::-webkit-scrollbar {
        display: none;
    }

    .lk-page-site .lk-rail .lk-rail-spacer {
        flex: 1 1 auto;
        min-width: 0.5rem;
        min-height: 0;
        width: auto;
    }

    .lk-rail-btn {
        width: var(--lk-tabbar-btn);
        height: var(--lk-tabbar-btn);
    }

    .lk-ico {
        width: 20px;
        height: 20px;
    }

    /* Нижняя панель ЛК: 4 пункта на всю ширину, порядок Главная — Бронирование — Профиль — Выйти */
    .lk-page-site .lk-sidebar,
    .lk-body-wrap--with-sidebar .lk-sidebar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        grid-column: unset;
        grid-row: unset;
        z-index: 96;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: stretch;
        justify-content: space-between;
        width: auto;
        max-width: none;
        max-height: none;
        min-height: var(--lk-tabbar-h);
        padding: var(--lk-tabbar-pad-y) env(safe-area-inset-right, 0px) max(var(--lk-tabbar-pad-y), env(safe-area-inset-bottom, 0px)) env(safe-area-inset-left, 0px);
        gap: 0;
        margin: 0;
        border-radius: 0;
        border-top: 1px solid var(--border);
        border-left: none;
        border-right: none;
        border-bottom: none;
        overflow: hidden;
        box-shadow: 0 -8px 28px rgba(88, 82, 72, 0.14);
        background: linear-gradient(180deg, #f3efe8 0%, var(--surface) 35%, var(--surface) 100%);
        align-self: stretch;
        box-sizing: border-box;
    }

    .lk-page-site .lk-sidebar::-webkit-scrollbar,
    .lk-body-wrap--with-sidebar .lk-sidebar::-webkit-scrollbar {
        display: none;
    }

    .lk-sidebar__sep,
    .lk-sidebar__spacer {
        display: none !important;
    }

    .lk-sidebar__item:not(.lk-sidebar__item--mob-tab) {
        display: none !important;
    }

    .lk-sidebar__item--mob-tab-main {
        order: 1;
    }

    .lk-sidebar__item--mob-tab-book {
        order: 2;
    }

    .lk-sidebar__item--mob-tab-profile {
        order: 3;
    }

    .lk-sidebar__item--mob-tab-exit {
        order: 4;
    }

    .lk-sidebar__item.lk-sidebar__item--mob-tab {
        flex: 1 1 0;
        flex-direction: column;
        gap: 2px;
        margin: 0;
        padding: 0 2px;
        min-width: 0;
        max-width: none;
        justify-content: center;
        align-items: center;
        text-align: center;
        font-size: 0.62rem;
        font-weight: 600;
        line-height: 1.05;
        border-radius: 0;
    }

    .lk-sidebar__text {
        flex: none;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    .lk-sidebar__ico {
        width: 24px;
        height: 24px;
    }

    .lk-sidebar .lk-ico {
        width: 20px;
        height: 20px;
    }
}
