/* Резерв мобильной сводки получает безопасное значение до первого измерения JavaScript */
:root {
    --certificate-summary-height: calc(55px + max(10px, env(safe-area-inset-bottom, 0px)));
}

/* Группа сертификатов сохраняет доступное описание без отдельного визуального заголовка */
#organisation .certificate-selection {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

#organisation .certificate-selection__list {
    display: grid;
    gap: var(--quick-tickets-space-3);
    margin: 0 10px;
}

/* Пустое состояние сохраняет такие же внешние поля, как список карточек сертификатов */
#organisation .certificate-empty {
    width: auto;
    margin: 10px 10px var(--quick-tickets-space-5);
}

/* Серверные сообщения сохраняют переносы без вставки небезопасной HTML-разметки */
#organisation .certificate-error {
    white-space: pre-line;
}

#organisation #error:focus {
    outline: 2px solid var(--quick-tickets-color-focus);
    outline-offset: 2px;
}

/* Каждая строка становится самостоятельной карточкой с настоящим вертикальным центрированием */
#organisation .certificate {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 184px;
    align-items: center;
    gap: var(--quick-tickets-space-5);
    min-height: 108px;
    padding: 14px;
    border: 1px solid var(--quick-tickets-color-border);
    border-radius: 10px;
    background: var(--quick-tickets-color-surface);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Цветной номинал выравнивает иконку и цену по центру единого блока */
#organisation .certificate .iconAndPrice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    isolation: isolate;
    min-width: 0;
    min-height: 80px;
    padding: var(--quick-tickets-space-3);
    border-radius: 8px;
    overflow: hidden;
    background: var(--certificate-tier-background, var(--quick-tickets-color-surface-muted));
    color: var(--certificate-tier-color, var(--quick-tickets-color-text));
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
}

#organisation .certificate .iconAndPrice > * {
    position: relative;
    z-index: 1;
}

#organisation .certificate .iconAndPrice .balance {
    min-width: 0;
    white-space: nowrap;
}

#organisation .certificate .iconAndPrice .qxf-certificate {
    flex: 0 0 auto;
    font-size: 1.2em;
    line-height: 1;
}

/* Первые три номинала получают самостоятельные градиенты золота, розового золота и серебра */
#organisation .certificate--palette-1 {
    --certificate-tier-background: linear-gradient(135deg, #b7872f 0%, #f0d384 52%, #c69b45 100%);
    --certificate-tier-color: #302714;
}

#organisation .certificate--palette-2 {
    --certificate-tier-background: linear-gradient(135deg, #b76e79 0%, #f2c9ba 52%, #c9867f 100%);
    --certificate-tier-color: #342329;
}

#organisation .certificate--palette-3 {
    --certificate-tier-background: linear-gradient(135deg, #96a4b0 0%, #eef2f5 52%, #b5c0c9 100%);
    --certificate-tier-color: #25313a;
}

/* Остальные номиналы используют очень светлые пастельные цвета без металлических оттенков */
#organisation .certificate--palette-4 {
    --certificate-tier-background: #eee9f8;
    --certificate-tier-color: #312d3c;
}

#organisation .certificate--palette-5 {
    --certificate-tier-background: #e5f3eb;
    --certificate-tier-color: #29372f;
}

#organisation .certificate--palette-6 {
    --certificate-tier-background: #e4f1f8;
    --certificate-tier-color: #293740;
}

#organisation .certificate--palette-7 {
    --certificate-tier-background: #f6e9f0;
    --certificate-tier-color: #3b2d35;
}

/* Описание центрируется по высоте и допускает безопасный перенос длинного текста */
#organisation .certificate .description {
    display: flex;
    align-self: stretch;
    flex-direction: column;
    justify-content: center;
    gap: var(--quick-tickets-space-1);
    min-width: 0;
}

#organisation .certificate .description .name {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

#organisation .certificate .description .restrictions {
    color: var(--quick-tickets-color-text-muted);
    font-size: 14px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

/* Степпер использует привычный порядок минус, значение и плюс */
#organisation .certificate .choice {
    display: grid;
    grid-template-columns: 48px minmax(56px, 64px) 48px;
    align-items: center;
    justify-content: end;
    gap: var(--quick-tickets-space-2);
    min-width: 0;
}

#organisation .certificate .choice__control,
#organisation .certificate .choice__value {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

#organisation .certificate .choice .value {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    color: var(--quick-tickets-color-text);
    font-size: 28px;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    transition: color 0.2s ease;
}

/* Выбранный номинал отмечается только цветом центрального числа без рамки карточки */
#organisation .certificate .choice .value--selected {
    color: var(--quick-tickets-color-brand-active);
}

#organisation .certificate .choice .plus,
#organisation .certificate .choice .minus {
    width: 48px;
    height: 48px;
    min-height: var(--quick-tickets-touch-target);
    padding: 0;
    border-radius: var(--quick-tickets-radius-medium);
    font-size: 26px;
    line-height: 1;
}

#organisation .certificate .choice .plus {
    border-color: var(--quick-tickets-color-brand);
    background: var(--quick-tickets-color-surface);
    color: var(--quick-tickets-color-text);
}

#organisation .certificate .choice .plus:hover:not([disabled]) {
    border-color: var(--quick-tickets-color-brand-hover);
    background: #fff7f2;
    color: var(--quick-tickets-color-text);
}

#organisation .certificate .choice .plus:active:not([disabled]) {
    border-color: var(--quick-tickets-color-brand-active);
    background: #ffede4;
    color: var(--quick-tickets-color-text);
}

#organisation .certificate .choice .minus {
    border-color: #ccc;
    background: var(--quick-tickets-color-surface);
    color: var(--quick-tickets-color-text-muted);
}

#organisation .certificate .choice .minus:hover:not([disabled]) {
    border-color: #b8b8b8;
    background: var(--quick-tickets-color-surface-muted);
    color: var(--quick-tickets-color-text);
}

#organisation .certificate .choice .minus:active:not([disabled]) {
    border-color: #adadad;
    background: #e6e6e6;
    color: var(--quick-tickets-color-text);
}

#organisation .certificate .choice .plus[disabled],
#organisation .certificate .choice .minus[disabled] {
    border-color: var(--quick-tickets-color-border);
    background: var(--quick-tickets-color-surface);
    color: #999;
}

#organisation .certificate-summary #sell {
    border-color: var(--quick-tickets-color-brand);
    background-color: var(--quick-tickets-color-brand);
}

#organisation .certificate-summary #sell:hover:not([disabled]) {
    border-color: var(--quick-tickets-color-brand-hover);
    background-color: var(--quick-tickets-color-brand-hover);
}

#organisation .certificate-summary #sell:active:not([disabled]) {
    border-color: var(--quick-tickets-color-brand-active);
    background-color: var(--quick-tickets-color-brand-active);
}

#organisation .certificate .choice button:focus-visible,
#organisation .certificate-summary button:focus-visible {
    outline: 2px solid var(--quick-tickets-color-text) !important;
    outline-offset: 2px !important;
}

/* На широких экранах сводка завершает форму в потоке документа и не перекрывает содержимое */
#organisation #form {
    padding-bottom: var(--quick-tickets-space-5);
}

#organisation .certificate-summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--quick-tickets-space-4);
    width: fit-content;
    max-width: calc(100% - 20px);
    margin: var(--quick-tickets-space-5) auto 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

#organisation .total {
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 52px;
    margin: 0;
    line-height: 1;
    text-align: left;
}

#organisation .total__label {
    display: none;
    color: var(--quick-tickets-color-text-muted);
    font-size: 14px;
    font-weight: 600;
}

/* Подсказка первого шага используется только в пустой мобильной сводке */
#organisation .total__empty {
    display: none;
}

/* Краткая подпись объясняет отключение всех плюсов после достижения общего лимита */
#organisation .total__limit {
    display: none;
    color: var(--quick-tickets-color-text-muted);
    font-size: 13px;
    font-weight: 600;
}

#organisation .total--limit .total__limit {
    display: block;
}

#organisation .total__values {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--quick-tickets-space-1);
    min-width: 0;
}

/* Основная строка сохраняет количество, разделитель и сумму на одном визуальном уровне */
#organisation .total__main {
    display: flex;
    align-items: center;
    gap: var(--quick-tickets-space-3);
    min-width: 0;
}

#organisation .total .count {
    font-size: 24px;
    font-weight: 700;
}

#organisation .total .amount {
    font-size: 30px;
    font-weight: 700;
    white-space: nowrap;
}

#organisation .total__separator {
    color: var(--quick-tickets-color-text-muted);
    font-size: 24px;
}

#organisation .buttons {
    flex: 0 0 auto;
    margin: 0;
}

#organisation .buttons button {
    min-width: 160px;
    min-height: 52px;
    padding: 10px var(--quick-tickets-space-5);
    font-size: 20px;
}

/* На средних экранах карточка сохраняет одну строку с более компактными колонками */
@media (max-width: 991.999px) {
    #organisation .certificate {
        grid-template-columns: 180px minmax(0, 1fr) 168px;
        gap: var(--quick-tickets-space-4);
        padding: var(--quick-tickets-space-3);
    }

    #organisation .certificate .iconAndPrice {
        min-height: 72px;
        font-size: 24px;
    }
}

/* На узких экранах номинал и описание образуют верх карточки, а степпер занимает отдельную строку */
@media (max-width: 767.999px) {
    /* Общая оболочка остаётся единым слоем над подвалом и сохраняет фоновый переход страницы */
    body > #wrap {
        z-index: 1;
    }

    #organisation #form {
        /* Измеренный резерв сохраняет последнюю строку формы над мобильной сводкой */
        padding-bottom: 78px;
        padding-bottom: calc(var(--certificate-summary-height) + var(--quick-tickets-space-3));
    }

    /* Подвал использует ту же фактическую высоту для доступа к нижним ссылкам и логотипам */
    #footer {
        padding-bottom: 78px;
        padding-bottom: calc(var(--certificate-summary-height) + var(--quick-tickets-space-3));
    }

    #organisation .certificate {
        grid-template-columns: 112px minmax(0, 1fr);
        grid-template-areas:
            "price description"
            "choice choice";
        align-items: stretch;
        gap: var(--quick-tickets-space-3);
        min-height: 0;
        padding: var(--quick-tickets-space-3);
    }

    #organisation .certificate .iconAndPrice {
        grid-area: price;
        flex-direction: column;
        gap: var(--quick-tickets-space-1);
        min-height: 76px;
        padding: var(--quick-tickets-space-2);
        font-size: 22px;
    }

    #organisation .certificate .description {
        grid-area: description;
        text-align: left;
    }

    #organisation .certificate .description .name {
        font-size: 18px;
    }

    #organisation .certificate .description .restrictions {
        font-size: 13px;
    }

    #organisation .certificate .choice {
        grid-area: choice;
        grid-template-columns: 48px 56px 48px;
        justify-content: end;
    }

    /* Мобильная сводка повторяет закреплённый паттерн зрительского оформления заказа */
    #organisation .certificate-summary {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1030;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: center;
        gap: 10px;
        width: auto;
        max-width: none;
        margin: 0;
        padding: 10px;
        padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
        border: 0;
        border-top: 1px solid var(--quick-tickets-color-border);
        border-radius: 0;
        background: rgba(255, 255, 255, 0.97);
        box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.1);
        transform: none;
    }

    #organisation .total {
        display: flex;
        align-items: center;
        min-height: 44px;
        gap: 0;
        line-height: 1.25;
    }

    /* При запрещённой покупке единственный итог занимает всю ширину закреплённой плашки */
    #organisation .total:only-child {
        grid-column: 1 / -1;
    }

    #organisation .total__values {
        gap: 2px;
    }

    #organisation .total__main {
        gap: 4px;
        flex-wrap: wrap;
        white-space: normal;
    }

    #organisation .total--empty .total__empty {
        display: block;
        min-width: 0;
        font-size: 16px;
        font-weight: 600;
        line-height: 1.25;
        overflow-wrap: break-word;
    }

    #organisation .total--empty .total__values {
        display: none;
    }

    #organisation .total__label,
    #organisation .total .count {
        font-size: 16px;
    }

    #organisation .total .amount {
        color: var(--quick-tickets-color-brand);
        font-size: 16px;
        white-space: normal;
    }

    #organisation .total__separator {
        font-size: 16px;
    }

    #organisation .buttons {
        width: 100%;
    }

    #organisation .buttons button {
        width: 100%;
        min-width: 0;
        min-height: 44px;
        padding: 6px 12px;
        font-size: 14px;
        overflow-wrap: anywhere;
        white-space: normal;
    }
}

/* На самых узких экранах карточка становится одной колонкой */
@media (max-width: 359px) {
    #organisation .certificate {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "price"
            "description"
            "choice";
    }

    #organisation .certificate .iconAndPrice {
        flex-direction: row;
    }

    #organisation .certificate .description {
        text-align: center;
    }

    #organisation .certificate .choice {
        justify-content: center;
    }

}
