
.bottom-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    z-index: var(--ui-z-sheet, 10000);
    visibility: hidden;
    transition: visibility 0s linear var(--ui-sheet-exit-duration, 360ms);
    pointer-events: none;
}

.bottom-panel.active,
.bottom-panel.preparing {
    visibility: visible;
    transition: visibility 0s linear 0s;
    pointer-events: auto;
}

.bottom-panel.preparing {
    pointer-events: none;
}

.bottom-panel.preparing .bottom-panel__content {
    transform: translateY(100%) !important;
    transition: none !important;
}

.bottom-panel.preparing .bottom-panel__overlay {
    opacity: 0 !important;
    transition: none !important;
}

.bottom-panel__overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: var(--ui-color-overlay, rgba(0, 0, 0, 0.5));
    z-index: calc(var(--ui-z-sheet, 10000) + 1);
    opacity: 0;

    transition: opacity var(--ui-sheet-exit-duration, 360ms) linear;

pointer-events: auto;
}

.bottom-panel.active .bottom-panel__overlay {
    opacity: 1;
    transition: opacity var(--ui-sheet-enter-duration, 460ms) linear;
}

/* Высота шторки задаётся ровно в одном месте — переменной ниже. Модификаторы и
   модули обязаны опираться на неё, а не вводить свои vh: несколько слоёв со
   своими ограничениями дают разную итоговую высоту в зависимости от контента.
   Единицы именно dvh: vh на мобильных считается без учёта адресной строки,
   поэтому смесь vh и dvh расходится при её появлении.

   Верхняя граница — не край экрана, а нижняя кромка занятого верха
   (--app-top-bar-inset): системный статус-бар нативной оболочки, хедер Telegram
   и наша веб-панель. Без этого высокая шторка на телефоне уезжает под них.
   Дальше 90dvh она всё равно не растёт: полоска фона над шторкой нужна, чтобы
   было видно, что за ней лежит страница, а не отдельный экран. */
.bottom-panel__content {
    --sheet-max-height: min(90dvh, calc(100dvh - max(var(--app-top-bar-inset, 0px), 0.5rem)));
    /* Снизу шторка прижата к кромке экрана — иначе под ней вылезет полоса
       страницы, а углы у неё скруглены только сверху. Поэтому системную зону
       (home indicator) отдаём внутренним отступом. Поднятая клавиатурой шторка
       эту зону уже не задевает, и отступ вычитается обратно. */
    --sheet-safe-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
    position: fixed;

    bottom: var(--kb-inset, 0px);
    left: 0;
    width: 100%;
    background: var(--ui-color-surface, #16181c);
    border-top-left-radius: var(--ui-radius-lg, 1.25rem);
    border-top-right-radius: var(--ui-radius-lg, 1.25rem);
    z-index: calc(var(--ui-z-sheet, 10000) + 2);
    transform: translateY(100%);
    /* Только transform: анимация height/max-height превращает любой пересчёт
       вьюпорта (поворот, адресная строка, клавиатура) в полсекунды дёргания.
       Переход объявлен здесь, в закрытом состоянии, поэтому им управляется
       именно закрытие; открытие берёт свои тайминги ниже, в .active. */
    transition: transform var(--ui-sheet-exit-duration, 360ms) var(--ui-sheet-exit-ease, ease-in);
    will-change: transform;
    padding: 0 0 max(0px, calc(var(--sheet-safe-bottom, 0px) - var(--kb-inset, 0px)));
    display: flex;
    flex-direction: column;
    max-height: var(--sheet-max-height);
    overflow: hidden;
}

/* Прокрутка живёт здесь, и только здесь: min-height нужен, чтобы flex-элемент
   мог сжаться ниже высоты контента, иначе шторка вылезает за свой максимум. */
.bottom-panel__content-inner {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.bottom-panel__content-inner::-webkit-scrollbar {
    display: none;
    width: 0px;
    height: 0px;
}

.bottom-panel__content-inner > div {
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    opacity: 1;
    transform: translateY(0);
}

.bottom-panel__content-inner.changing > div {
    opacity: 0;
    transform: translateY(0.9375rem);
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

.bottom-panel.active .bottom-panel__content {
    transform: translateY(0);
    transition: transform var(--ui-sheet-enter-duration, 460ms) var(--ui-sheet-enter-ease, ease-out);
}

@media (min-width: 600px) {
    .bottom-panel__content {
        --sheet-max-height: min(75dvh, calc(100dvh - max(var(--app-top-bar-inset, 0px), 1.5rem)));
        max-width: var(--app-column-width);
        left: calc(50% - var(--app-column-width) / 2);
    }
}

/* На десктопе шторка становится модалкой. Причина не в эстетике: снизу она
   приезжает потому, что там большой палец, а у мыши такого края нет — зато есть
   центр экрана, куда и так смотрят. Плюс боковое меню на десктопе не прячется
   под шторку, и висящая у нижней кромки панель спорила с ним по месту.
   Меняется только геометрия и направление въезда; разметка, слушатели и
   completion по transitionend в ui.js остаются прежними — transform
   по-прежнему анимируется, просто другой. */
body.web-desktop .bottom-panel__content {
    /* Ширина модалки отдельная от колонки контента: по ширине колонки (45rem)
       диалог читается как ещё одна страница, а не как ответ на действие.
       Модуль вправе её переопределить — так делает магазин AID PAY. */
    --sheet-modal-width: 32rem;
    --sheet-max-height: min(80dvh, calc(100dvh - 6rem));
    /* Модалка висит по центру и системных зон не касается. */
    --sheet-safe-bottom: 0px;
    top: 50%;
    bottom: auto;
    left: 50%;
    width: min(var(--sheet-modal-width), calc(100vw - 4rem));
    max-width: none;
    border-radius: var(--ui-radius-lg, 1.375rem);
    box-shadow: var(--ui-shadow-modal, 0 1.125rem 3rem rgba(0, 0, 0, 0.38));
    transform: translate(-50%, -50%) scale(0.96);
    opacity: 0;
    transition:
        transform var(--ui-sheet-exit-duration, 360ms) var(--ui-sheet-exit-ease, ease-in),
        opacity var(--ui-sheet-exit-duration, 360ms) ease-in;
}

body.web-desktop .bottom-panel.active .bottom-panel__content {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    transition:
        transform var(--ui-sheet-enter-duration, 460ms) var(--ui-sheet-enter-ease, ease-out),
        opacity var(--ui-sheet-enter-duration, 460ms) ease-out;
}

/* Кадр перед открытием: модалка обязана стоять в своей стартовой точке, а не
   за нижней кромкой, иначе она въезжает снизу и только потом становится
   модалкой. Важность — против такой же важности в общем правиле. */
body.web-desktop .bottom-panel.preparing .bottom-panel__content {
    transform: translate(-50%, -50%) scale(0.96) !important;
}

.bottom-panel__header {
    display: none;
}

.bottom-panel__header h3 {
    margin: 0;
    color: var(--ui-color-text, #fff);
    font-size: 1rem;
}

.bottom-panel__list {
    padding: 0.9375rem 0 2rem 0;
}

.panel-item {
    display: flex;
    align-items: center;
    padding: 0.3125rem 1.25rem;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.panel-item:not(:last-child)::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 1.25rem;
    right: 1.25rem;
    height: 0.0625rem;
    background: var(--ui-color-border, rgba(255, 255, 255, 0.08));
}

.panel-item:hover {
    background: var(--ui-color-surface-3, #2a2a2a);
}

.panel-item__icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    overflow: hidden;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.9375rem;
}

.panel-item__icon img {
    width: 70%;
    height: auto;
}

.panel-item__info {
    flex: 1;
}

.panel-item__title {
    color: var(--ui-color-text, #fff);
    font-size: 1rem;
    margin-bottom: 0.3125rem;
}

.panel-item__subtitle {
    color: var(--ui-color-text-muted, #999);
    font-size: 0.875rem;
}
