/**
 * UDS Anchor Widget - Якорь программы лояльности
 * Фиксированная кнопка справа, которая раскрывается в панель
 */

/* Основной контейнер */
.uds-anchor-widget {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Кнопка якоря */
.uds-anchor-button {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: #4a4a4a;
    color: white;
    padding: 16px 12px;
    border-radius: 8px 0 0 8px;
    box-shadow: -2px 2px 12px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 60px;
    z-index: 10000;
}

.uds-anchor-button:hover {
    background: #3a3a3a;
    box-shadow: -4px 4px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-50%) scale(1.02);
}

.uds-anchor-icon {
    width: 28px;
    height: 28px;
    color: white;
}

.uds-anchor-text {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

.uds-anchor-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    writing-mode: horizontal-tb;
}

/* Оверлей (затемнение) */
.uds-anchor-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
    z-index: 9998;
}

.uds-anchor-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Боковая панель */
.uds-anchor-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    max-width: 90vw;
    height: 100vh;
    background: #ffffff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    pointer-events: auto;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.uds-anchor-panel.active {
    right: 0;
}

/* Заголовок панели */
.uds-anchor-panel-header {
    background: #4a4a4a;
    color: white;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.uds-anchor-panel-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.uds-anchor-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    color: white;
    padding: 0;
}

.uds-anchor-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.uds-anchor-close svg {
    width: 24px;
    height: 24px;
}

/* Контент панели */
.uds-anchor-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #f5f5f5 !important;
}

/* Скроллбар для панели */
.uds-anchor-panel-content::-webkit-scrollbar {
    width: 6px;
}

.uds-anchor-panel-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.uds-anchor-panel-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.uds-anchor-panel-content::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Контейнер информации */
.uds-user-balance-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Блок информации */
.uds-user-info-block {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: #ffffff !important;
    border-radius: 8px;
    transition: background 0.2s ease, border-color 0.2s ease;
    border: 1px solid #e0e0e0;
}

.uds-user-info-block:hover {
    background: #fafafa !important;
    border-color: #cccccc;
}

.uds-balance-highlight {
    background: #ffffff !important;
    border: 2px solid #d0d0d0;
}

.uds-balance-highlight:hover {
    background: #fafafa !important;
    border-color: #b0b0b0;
}

.uds-user-info-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: #f8f8f8;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #4a4a4a;
    border: 1px solid #e8e8e8;
}

.uds-balance-highlight .uds-user-info-icon {
    background: #4a4a4a;
    color: white;
    border-color: #4a4a4a;
}

.uds-user-info-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.uds-user-info-label {
    font-size: 13px;
    color: #6c757d;
    font-weight: 500;
}

.uds-user-info-value {
    font-size: 16px;
    color: #212529;
    font-weight: 600;
}

/* Значение баланса */
.uds-balance-value {
    font-size: 24px;
    color: #1a1a1a;
    font-weight: 700;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.uds-balance-currency {
    font-size: 14px;
    color: #6c757d;
    font-weight: 500;
}

/* Бадж статуса */
.uds-status-badge {
    display: inline-block;
    background: #4a4a4a;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
}

/* Значения кэшбэка/скидки */
.uds-cashback-value {
    color: #1a1a1a;
    font-weight: 700;
}

.uds-discount-value {
    color: #1a1a1a;
    font-weight: 700;
}

.uds-saved-value {
    color: #1a1a1a;
    font-weight: 700;
}

/* Секция следующего уровня */
.uds-next-level-section {
    margin-top: 8px;
    padding: 20px;
    background: #ffffff !important;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.uds-next-level-header {
    margin-bottom: 16px;
}

.uds-section-title {
    font-size: 16px;
    font-weight: 700;
    color: #212529;
}

/* Прогресс-бар */
.uds-progress-bar-wrapper {
    margin-bottom: 16px;
}

.uds-progress-bar-container {
    background: #f5f5f5;
    border-radius: 8px;
    overflow: hidden;
    height: 32px;
    border: 1px solid #e8e8e8;
}

.uds-progress-bar {
    width: 100%;
    height: 100%;
}

.uds-progress-bar-fill {
    height: 100%;
    background: #4a4a4a;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: width 0.3s ease;
    border-radius: 8px;
}

.uds-progress-bar-text {
    color: white;
    font-size: 13px;
    font-weight: 700;
}

/* Статистика следующего уровня */
.uds-next-level-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.uds-stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.uds-stat-label {
    font-size: 13px;
    color: #6c757d;
    font-weight: 500;
}

.uds-stat-value {
    font-size: 15px;
    color: #212529;
    font-weight: 600;
}

.uds-stat-remaining .uds-stat-value {
    color: #1a1a1a;
    font-weight: 700;
}

/* Секция сертификатов */
.uds-certificates-section {
    margin-top: 8px;
    padding: 20px;
    background: #ffffff !important;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.uds-certificates-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.uds-certificates-count {
    background: #4a4a4a;
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
}

.uds-certificates-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.uds-certificate-card {
    background: #fafafa;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    padding: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.uds-certificate-card:hover {
    background: #ffffff;
    border-color: #4a4a4a;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.uds-certificate-card.expiring-soon {
    border-color: #ffc107;
    background: #fff9e6;
}

.uds-certificate-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.uds-certificate-name {
    font-size: 14px;
    font-weight: 600;
    color: #212529;
}

.uds-certificate-value {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
}

.uds-certificate-expiry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #6c757d;
}

.uds-expiry-warning {
    color: #ffc107;
    font-size: 16px;
}

/* Ошибка */
.uds-user-balance-error {
    padding: 16px;
    background: #fee;
    border: 1px solid #fcc;
    border-radius: 8px;
    color: #c33;
    text-align: center;
    font-size: 14px;
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    .uds-anchor-panel {
        width: 100%;
        max-width: 100%;
        right: -100%;
    }

    .uds-anchor-button {
        min-width: 50px;
        padding: 12px 8px;
    }

    .uds-anchor-icon {
        width: 24px;
        height: 24px;
    }

    .uds-anchor-panel-content {
        padding: 16px;
    }

    .uds-user-info-block {
        padding: 12px;
    }

    .uds-balance-value {
        font-size: 20px;
    }
}

/* ===== ПОЗИЦИОНИРОВАНИЕ ЯКОРЯ ===== */

/* Desktop позиции */
@media (min-width: 769px) {
    /* Top Left */
    .uds-anchor-widget[data-position-desktop="top-left"] .uds-anchor-button {
        top: 20px;
        left: 0;
        right: auto;
        bottom: auto;
        transform: translateY(0);
        border-radius: 0 8px 8px 0;
    }

    /* Top Center */
    .uds-anchor-widget[data-position-desktop="top-center"] .uds-anchor-button {
        top: 0;
        left: 50%;
        right: auto;
        bottom: auto;
        transform: translateX(-50%);
        border-radius: 0 0 8px 8px;
        writing-mode: horizontal-tb;
        flex-direction: row;
        padding: 12px 16px;
    }

    .uds-anchor-widget[data-position-desktop="top-center"] .uds-anchor-text {
        writing-mode: horizontal-tb;
        text-orientation: mixed;
    }

    /* Top Right */
    .uds-anchor-widget[data-position-desktop="top-right"] .uds-anchor-button {
        top: 20px;
        right: 0;
        bottom: auto;
        transform: translateY(0);
    }

    /* Left Center */
    .uds-anchor-widget[data-position-desktop="left-center"] .uds-anchor-button {
        top: 50%;
        left: 0;
        right: auto;
        bottom: auto;
        transform: translateY(-50%);
        border-radius: 0 8px 8px 0;
    }

    .uds-anchor-widget[data-position-desktop="left-center"] .uds-anchor-panel {
        right: auto;
        left: -400px;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    }

    .uds-anchor-widget[data-position-desktop="left-center"] .uds-anchor-panel.active {
        left: 0;
        right: auto;
    }

    /* Middle Right (по умолчанию) */
    .uds-anchor-widget[data-position-desktop="middle-right"] .uds-anchor-button {
        top: 50%;
        right: 0;
        transform: translateY(-50%);
    }

    /* Middle Left */
    .uds-anchor-widget[data-position-desktop="middle-left"] .uds-anchor-button {
        top: 50%;
        left: 0;
        right: auto;
        transform: translateY(-50%);
        border-radius: 0 8px 8px 0;
    }

    .uds-anchor-widget[data-position-desktop="middle-left"] .uds-anchor-panel {
        right: auto;
        left: -400px;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    }

    .uds-anchor-widget[data-position-desktop="middle-left"] .uds-anchor-panel.active {
        left: 0;
        right: auto;
    }

    /* Right Center (аналог middle-right) */
    .uds-anchor-widget[data-position-desktop="right-center"] .uds-anchor-button {
        top: 50%;
        right: 0;
        transform: translateY(-50%);
    }

    /* Bottom Left */
    .uds-anchor-widget[data-position-desktop="bottom-left"] .uds-anchor-button {
        top: auto;
        bottom: 20px;
        left: 0;
        right: auto;
        transform: translateY(0);
        border-radius: 0 8px 8px 0;
    }

    .uds-anchor-widget[data-position-desktop="bottom-left"] .uds-anchor-panel {
        right: auto;
        left: -400px;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    }

    .uds-anchor-widget[data-position-desktop="bottom-left"] .uds-anchor-panel.active {
        left: 0;
        right: auto;
    }

    /* Bottom Center */
    .uds-anchor-widget[data-position-desktop="bottom-center"] .uds-anchor-button {
        top: auto;
        bottom: 0;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        border-radius: 8px 8px 0 0;
        writing-mode: horizontal-tb;
        flex-direction: row;
        padding: 12px 16px;
    }

    .uds-anchor-widget[data-position-desktop="bottom-center"] .uds-anchor-text {
        writing-mode: horizontal-tb;
        text-orientation: mixed;
    }

    /* Bottom Right */
    .uds-anchor-widget[data-position-desktop="bottom-right"] .uds-anchor-button {
        top: auto;
        bottom: 20px;
        right: 0;
        transform: translateY(0);
    }

    /* Убираем hover сдвиг для левых позиций */
    .uds-anchor-widget[data-position-desktop$="-left"] .uds-anchor-button:hover,
    .uds-anchor-widget[data-position-desktop="left-center"] .uds-anchor-button:hover {
        transform: translateY(-50%) scale(1.02);
    }

    .uds-anchor-widget[data-position-desktop="top-left"] .uds-anchor-button:hover,
    .uds-anchor-widget[data-position-desktop="bottom-left"] .uds-anchor-button:hover {
        transform: translateY(0) scale(1.02);
    }

    /* Hover для центральных позиций */
    .uds-anchor-widget[data-position-desktop="top-center"] .uds-anchor-button:hover,
    .uds-anchor-widget[data-position-desktop="bottom-center"] .uds-anchor-button:hover {
        transform: translateX(-50%) scale(1.02);
    }
}

/* Mobile позиции */
@media (max-width: 768px) {
    /* Top Left */
    .uds-anchor-widget[data-position-mobile="top-left"] .uds-anchor-button {
        top: 10px;
        left: 0;
        right: auto;
        bottom: auto;
        transform: translateY(0);
        border-radius: 0 8px 8px 0;
    }

    /* Top Center */
    .uds-anchor-widget[data-position-mobile="top-center"] .uds-anchor-button {
        top: 0;
        left: 50%;
        right: auto;
        bottom: auto;
        transform: translateX(-50%);
        border-radius: 0 0 8px 8px;
        writing-mode: horizontal-tb;
        flex-direction: row;
        padding: 10px 14px;
    }

    .uds-anchor-widget[data-position-mobile="top-center"] .uds-anchor-text {
        writing-mode: horizontal-tb;
        text-orientation: mixed;
    }

    /* Top Right */
    .uds-anchor-widget[data-position-mobile="top-right"] .uds-anchor-button {
        top: 10px;
        right: 0;
        bottom: auto;
        transform: translateY(0);
    }

    /* Left Center */
    .uds-anchor-widget[data-position-mobile="left-center"] .uds-anchor-button {
        top: 50%;
        left: 0;
        right: auto;
        bottom: auto;
        transform: translateY(-50%);
        border-radius: 0 8px 8px 0;
    }

    /* Middle Right */
    .uds-anchor-widget[data-position-mobile="middle-right"] .uds-anchor-button {
        top: 50%;
        right: 0;
        bottom: auto;
        transform: translateY(-50%);
    }

    /* Middle Left */
    .uds-anchor-widget[data-position-mobile="middle-left"] .uds-anchor-button {
        top: 50%;
        left: 0;
        right: auto;
        bottom: auto;
        transform: translateY(-50%);
        border-radius: 0 8px 8px 0;
    }

    /* Right Center (аналог middle-right) */
    .uds-anchor-widget[data-position-mobile="right-center"] .uds-anchor-button {
        top: 50%;
        right: 0;
        bottom: auto;
        transform: translateY(-50%);
    }

    /* Bottom Left */
    .uds-anchor-widget[data-position-mobile="bottom-left"] .uds-anchor-button {
        top: auto;
        bottom: 10px;
        left: 0;
        right: auto;
        transform: translateY(0);
        border-radius: 0 8px 8px 0;
    }

    /* Bottom Center */
    .uds-anchor-widget[data-position-mobile="bottom-center"] .uds-anchor-button {
        top: auto;
        bottom: 0;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        border-radius: 8px 8px 0 0;
        writing-mode: horizontal-tb;
        flex-direction: row;
        padding: 10px 14px;
    }

    .uds-anchor-widget[data-position-mobile="bottom-center"] .uds-anchor-text {
        writing-mode: horizontal-tb;
        text-orientation: mixed;
    }

    /* Bottom Right */
    .uds-anchor-widget[data-position-mobile="bottom-right"] .uds-anchor-button {
        top: auto;
        bottom: 10px;
        right: 0;
        transform: translateY(0);
    }

    /* Убираем hover сдвиг для левых позиций на мобильном */
    .uds-anchor-widget[data-position-mobile$="-left"] .uds-anchor-button:hover,
    .uds-anchor-widget[data-position-mobile="left-center"] .uds-anchor-button:hover {
        transform: translateY(-50%) scale(1.02);
    }

    .uds-anchor-widget[data-position-mobile="top-left"] .uds-anchor-button:hover,
    .uds-anchor-widget[data-position-mobile="bottom-left"] .uds-anchor-button:hover {
        transform: translateY(0) scale(1.02);
    }

    /* Hover для центральных позиций на мобильном */
    .uds-anchor-widget[data-position-mobile="top-center"] .uds-anchor-button:hover,
    .uds-anchor-widget[data-position-mobile="bottom-center"] .uds-anchor-button:hover {
        transform: translateX(-50%) scale(1.02);
    }
}
