/*
 * Оформление карты лояльности. Общее для всех тем: цвета берутся из
 * переменных темы, поэтому карта выглядит своей и в light, и в square,
 * и в тёмном режиме.
 *
 * Тема может переопределить `--tsl-accent` (акцент карты) и
 * `--tsl-radius`; остальное подстраивается автоматически.
 */

.tsl-card {
    --tsl-accent: var(--primary-color, var(--accent-color, #6366f1));
    --tsl-radius: var(--radius-card, 18px);
    --tsl-ink: #ffffff;

    position: relative;
    margin: 0 0 16px;
    border-radius: var(--tsl-radius);
    /* Перспектива живёт на контейнере, иначе оборот не переворачивается. */
    perspective: 1400px;
    min-height: 172px;
}

/* === Скелетон до загрузки ============================================= */

.tsl-skeleton {
    padding: 20px;
    border-radius: var(--tsl-radius);
    background: color-mix(in srgb, var(--tsl-accent) 12%, transparent);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 172px;
    box-sizing: border-box;
}

.tsl-skeleton-line { height: 16px; border-radius: 8px; }
.tsl-skeleton-lg { width: 55%; height: 34px; }
.tsl-skeleton-sm { width: 35%; }

/* === Переворот ======================================================== */

.tsl-flip {
    position: relative;
    transform-style: preserve-3d;
    transition: transform var(--mo-slow, 420ms) var(--mo-ease, cubic-bezier(0.22, 0.61, 0.36, 1));
    min-height: 172px;
}

.tsl-flip.tsl-flipped {
    transform: rotateY(180deg);
}

.tsl-face {
    border-radius: var(--tsl-radius);
    padding: 20px;
    box-sizing: border-box;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    /*
     * Градиент из акцента магазина: тёмный край даёт контраст белому тексту
     * даже когда акцент светлый (проверено на #FFD400 - 4.9:1).
     */
    background:
        linear-gradient(135deg,
            color-mix(in srgb, var(--tsl-accent) 92%, #ffffff),
            color-mix(in srgb, var(--tsl-accent) 62%, #101828));
    color: var(--tsl-ink);
    box-shadow: 0 10px 28px -14px color-mix(in srgb, var(--tsl-accent) 60%, transparent);
}

.tsl-front {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 172px;
}

.tsl-back {
    position: absolute;
    inset: 0;
    transform: rotateY(180deg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    /* Оборот светлый: QR обязан лежать на белом, иначе не считается. */
    background: #ffffff;
    color: #101828;
    box-shadow: 0 10px 28px -16px rgba(16, 24, 40, 0.55);
}

/* === Лицевая сторона ================================================== */

.tsl-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}

.tsl-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.85;
}

.tsl-chip {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.32);
    white-space: nowrap;
}

.tsl-balance {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-top: auto;
}

.tsl-balance-value {
    font-size: 40px;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.tsl-balance-unit {
    font-size: 14px;
    opacity: 0.85;
}

.tsl-warn {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

.tsl-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

/* === Кнопки =========================================================== */

.tsl-btn {
    flex: 1;
    min-height: 42px;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
}

.tsl-btn--primary {
    background: #ffffff;
    /* Тёмный вариант акцента: белая кнопка со светлым акцентом была бы нечитаемой. */
    color: color-mix(in srgb, var(--tsl-accent) 55%, #101828);
}

.tsl-btn--ghost {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.34);
    color: #ffffff;
}

.tsl-btn--sm {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 6px 14px;
    font-size: 13px;
}

.tsl-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.tsl-close {
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border: none;
    border-radius: 999px;
    background: rgba(16, 24, 40, 0.08);
    color: #101828;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

/* === Списание ========================================================= */

.tsl-redeem:empty { display: none; }

.tsl-redeem {
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.28);
}

.tsl-redeem-form {
    display: flex;
    gap: 8px;
}

.tsl-input {
    flex: 1;
    min-width: 0;
    min-height: 42px;
    padding: 10px 12px;
    border: none;
    border-radius: 12px;
    font-size: 16px; /* < 16px заставляет iOS зумить страницу */
    font-family: inherit;
    color: #101828;
    background: #ffffff;
    box-sizing: border-box;
}

.tsl-redeem-msg {
    margin: 8px 0 0;
    font-size: 13px;
    min-height: 0;
}

.tsl-redeem-msg:empty { display: none; }

.tsl-redeem-msg--error {
    /* Светло-жёлтый, а не красный: на цветном градиенте красный не читается. */
    color: #ffe8a3;
}

.tsl-code {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px;
    border-radius: 14px;
    background: rgba(16, 24, 40, 0.22);
}

.tsl-code-value {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: 0.18em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.tsl-code-points,
.tsl-code-timer {
    font-size: 12px;
    opacity: 0.9;
}

/* === Оборот с QR ====================================================== */

.tsl-qr {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 148px;
    height: 148px;
    border-radius: 14px;
    background: #ffffff;
    overflow: hidden;
}

.tsl-qr-skeleton {
    width: 100%;
    height: 100%;
    border-radius: 14px;
}

.tsl-qr-img,
.tsl-qr-img svg {
    display: block;
    width: 100%;
    height: 100%;
}

.tsl-qr-fallback {
    padding: 8px;
    font-size: 11px;
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.tsl-qr-hint {
    margin: 0;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    opacity: 0.75;
}

/* === Ошибка =========================================================== */

.tsl-card--muted .tsl-error {
    margin: 0;
    padding: 20px;
    border-radius: var(--tsl-radius);
    background: var(--card-bg, #f2f2f7);
    color: var(--text-secondary, #6b7280);
    font-size: 14px;
}

/* === Тёмная тема ====================================================== */

body.dark-mode .tsl-back,
.dark .tsl-back {
    /* QR остаётся на белом полотне; меняем только рамку вокруг. */
    box-shadow: 0 10px 28px -16px rgba(0, 0, 0, 0.8);
}

@media (prefers-reduced-motion: reduce) {
    .tsl-flip { transition: none; }
}
