/**
 * Frontend Styles for SP Custom Button & Modal Pro
 */

/* =============================================
   ОБЩИЕ СТИЛИ (применяются везде)
   ============================================= */

/* Переменные CSS для общего использования */
:root {
    --sp-button-padding: 10px 20px;
    --sp-button-border-radius: 4px;
    --sp-button-font-size: 16px;
    --sp-button-margin: 5px 0;
    --sp-icon-gap: 8px;
    --sp-transition: all 0.3s ease;
}

/* Стили для кнопок с использованием CSS переменных */
.sp-custom-button {
    /* Мобильные CSS переменные */
    --mobile-bg-color: initial;
    --mobile-text-color: initial;
    --mobile-border-color: initial;
    --mobile-border-radius: initial;
    --mobile-icon-size: initial;
    --mobile-icon-width: auto;
    --mobile-icon-height: auto;
    --mobile-icon-color: inherit;
    --mobile-icon-gap: var(--sp-icon-gap);

    /* Планшетные CSS переменные */
    --tablet-bg-color: initial;
    --tablet-text-color: initial;
    --tablet-border-color: initial;
    --tablet-border-radius: initial;
    --tablet-icon-size: initial;
    --tablet-icon-width: auto;
    --tablet-icon-height: auto;
    --tablet-icon-color: inherit;
    --tablet-icon-gap: var(--sp-icon-gap);

    /* Десктопные CSS переменные */
    --desktop-icon-gap: var(--sp-icon-gap);
}

/* Общие стили для всех кнопок */
.sp-custom-button {
    display: inline-flex; 
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    box-sizing: border-box;
    text-decoration: none;
    white-space: nowrap;
    transition: var(--sp-transition);
}

.sp-custom-button:hover,
.sp-custom-button:focus {
    opacity: 0.9;
    outline: none;
    text-decoration: none;
}

/* Модальное окно и оверлей */
.sp-custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 99998;
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

.sp-custom-modal-overlay.sp-active {
    display: block;
    opacity: 1;
}

.sp-custom-modal {
    position: fixed;
    background-color: #fff;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 99999;
    display: none;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 90vh;
    overflow-y: auto;
    will-change: transform, opacity;
    width: 90%;
    max-width: 800px;
}

/* Базовая анимация появления (fade) */
.sp-custom-modal[data-animation="fade"] {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.sp-custom-modal[data-animation="fade"].sp-active {
    transform: translate(-50%, -50%);
    opacity: 1;
}

/* Анимация slide_top */
.sp-custom-modal[data-animation="slide_top"] {
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
}

.sp-custom-modal[data-animation="slide_top"].sp-active {
    top: 5%;
    transform: translateX(-50%);
    opacity: 1;
}

/* Анимация slide_bottom */
.sp-custom-modal[data-animation="slide_bottom"] {
    bottom: -100%;
    left: 50%;
    transform: translateX(-50%);
}

.sp-custom-modal[data-animation="slide_bottom"].sp-active {
    bottom: 5%;
    transform: translateX(-50%);
    opacity: 1;
}

/* Анимация slide_left */
.sp-custom-modal[data-animation="slide_left"] {
    top: 0 !important;
    left: -100% !important;
    right: auto !important;
    transform: none !important;
    margin: 0 !important;
    height: 100vh !important;
    max-height: 100vh !important;
    width: 90% !important;
    border-radius: 0 !important;
}

.sp-custom-modal[data-animation="slide_left"].sp-active {
    left: 0 !important;
    transform: none !important;
    opacity: 1 !important;
}

/* Анимация slide_right */
.sp-custom-modal[data-animation="slide_right"] {
    top: 0 !important;
    right: -100% !important;
    left: auto !important;
    transform: none !important;
    margin: 0 !important;
    height: 100vh !important;
    max-height: 100vh !important;
    width: 90% !important;
    border-radius: 0 !important;
}

.sp-custom-modal[data-animation="slide_right"].sp-active {
    right: 0 !important;
    transform: none !important;
    opacity: 1 !important;
}

/* RTL поддержка для анимаций */
html[dir="rtl"] .sp-custom-modal[data-animation="slide_left"] {
    left: auto !important;
    right: -100% !important;
    transform: none !important;
}

html[dir="rtl"] .sp-custom-modal[data-animation="slide_left"].sp-active {
    right: 0 !important;
    left: auto !important;
    transform: none !important;
    opacity: 1 !important;
}

html[dir="rtl"] .sp-custom-modal[data-animation="slide_right"] {
    right: auto !important;
    left: -100% !important;
    transform: none !important;
}

html[dir="rtl"] .sp-custom-modal[data-animation="slide_right"].sp-active {
    left: 0 !important;
    right: auto !important;
    transform: none !important;
    opacity: 1 !important;
}

.sp-custom-modal .sp-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    z-index: 1;
    color: #444;
    background: none;
    border: none;
    padding: 5px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

html[dir="rtl"] .sp-custom-modal .sp-modal-close {
    right: auto;
    left: 10px;
}

.sp-custom-modal .sp-modal-close:hover,
.sp-custom-modal .sp-modal-close:focus {
    color: #000;
    background-color: rgba(0, 0, 0, 0.05);
}

.sp-custom-modal .sp-modal-content {
    padding: 20px;
    position: relative;
}

/* RTL поддержка для general-purpose */
.rtl .sp-button-icon-pos-left .sp-button-icon,
.sp-rtl.sp-button-icon-pos-left .sp-button-icon {
    margin-right: 0;
    margin-left: var(--desktop-icon-gap);
}

.rtl .sp-button-icon-pos-right .sp-button-icon,
.sp-rtl.sp-button-icon-pos-right .sp-button-icon {
    margin-left: 0;
    margin-right: var(--desktop-icon-gap);
}

/* =============================================
   ДЕСКТОПНЫЕ СТИЛИ (применяются только на десктопе)
   ============================================= */
.sp-custom-button {
    /* Дефолтные стили для кнопки на десктопе */
    padding: var(--sp-button-padding);
    font-size: var(--sp-button-font-size);
    line-height: 1.5;
    border: 1px solid #0073aa;
    background-color: #0073aa;
    color: #ffffff;
    border-radius: var(--sp-button-border-radius);
    margin: var(--sp-button-margin);
}

/* Стили для иконок на десктопе */
.sp-custom-button .sp-button-icon {
    line-height: 1;
    vertical-align: middle;
    display: inline-block;
}

/* Кастомные изображения на десктопе */
.sp-custom-button .sp-button-icon-custom {
    object-fit: contain;
    max-width: 100%;
    max-height: 100%;
}

/* Если указана только ширина для десктопного изображения */
.sp-custom-button .sp-button-icon-custom[style*="width:"] {
    height: auto;
}

/* Если указана только высота для десктопного изображения */
.sp-custom-button .sp-button-icon-custom[style*="height:"] {
    width: auto;
}

/* Дашиконки на десктопе */
.sp-custom-button .sp-button-icon.dashicons {
    width: 1em;
    height: 1em;
    font-size: 1.2em;
    vertical-align: text-bottom;
    line-height: 1;
    transition: var(--sp-transition);
}

/* Позиционирование иконок на десктопе */
.sp-custom-button.sp-button-icon-pos-left .sp-button-icon {
    margin-right: var(--desktop-icon-gap) !important;
    margin-left: 0 !important;
}

.sp-custom-button.sp-button-icon-pos-right .sp-button-icon {
    margin-left: var(--desktop-icon-gap) !important;
    margin-right: 0 !important;
}

/* Режимы отображения на десктопе */
.sp-button-display-text_only .sp-button-icon {
    display: none;
}

.sp-button-display-icon_only .sp-button-text {
    display: none;
}

.sp-button-display-icon_only .sp-button-icon {
    margin-left: 0;
    margin-right: 0;
}

/* =============================================
   МОБИЛЬНЫЕ СТИЛИ (применяются только на мобильных)
   ============================================= */
@media (max-width: 767px) {
    /* Скрываем/показываем мобильные/десктопные элементы */
    .sp-cbmp-desktop-only {
        display: none !important;
    }

    .sp-cbmp-mobile-only {
        display: inline-flex !important;
    }

    /* Мобильные стили для модального окна */
    .sp-custom-modal {
        width: 90% !important;
        max-width: 90% !important;
        height: auto !important;
        max-height: 80vh !important;
        margin: 0 !important;
        border-radius: 8px !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Базовая анимация появления (fade) для мобильных */
    .sp-custom-modal[data-animation="fade"] {
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
    }

    .sp-custom-modal[data-animation="fade"].sp-active {
        transform: translate(-50%, -50%) !important;
        opacity: 1 !important;
    }

    /* Анимация slide_top для мобильных */
    .sp-custom-modal[data-animation="slide_top"] {
        top: -100% !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }

    .sp-custom-modal[data-animation="slide_top"].sp-active {
        top: 5% !important;
        transform: translateX(-50%) !important;
        opacity: 1 !important;
    }

    /* Анимация slide_bottom для мобильных */
    .sp-custom-modal[data-animation="slide_bottom"] {
        bottom: -100% !important;
        left: 50% !important;
        top: auto !important;
        transform: translateX(-50%) !important;
    }

    .sp-custom-modal[data-animation="slide_bottom"].sp-active {
        bottom: 5% !important;
        transform: translateX(-50%) !important;
        opacity: 1 !important;
    }

    /* Анимация slide_left для мобильных */
    .sp-custom-modal[data-animation="slide_left"] {
        top: 0 !important;
        left: -100% !important;
        right: auto !important;
        transform: none !important;
        margin: 0 !important;
        height: 100vh !important;
        max-height: 100vh !important;
        width: 90% !important;
        border-radius: 0 !important;
    }

    .sp-custom-modal[data-animation="slide_left"].sp-active {
        left: 0 !important;
        transform: none !important;
        opacity: 1 !important;
    }

    /* Анимация slide_right для мобильных */
    .sp-custom-modal[data-animation="slide_right"] {
        top: 0 !important;
        right: -100% !important;
        left: auto !important;
        transform: none !important;
        margin: 0 !important;
        height: 100vh !important;
        max-height: 100vh !important;
        width: 90% !important;
        border-radius: 0 !important;
    }

    .sp-custom-modal[data-animation="slide_right"].sp-active {
        right: 0 !important;
        transform: none !important;
        opacity: 1 !important;
    }

    /* RTL поддержка для анимаций на мобильных */
    html[dir="rtl"] .sp-custom-modal[data-animation="slide_left"] {
        left: auto !important;
        right: -100% !important;
        transform: none !important;
    }

    html[dir="rtl"] .sp-custom-modal[data-animation="slide_left"].sp-active {
        right: 0 !important;
        left: auto !important;
        transform: none !important;
        opacity: 1 !important;
    }

    html[dir="rtl"] .sp-custom-modal[data-animation="slide_right"] {
        right: auto !important;
        left: -100% !important;
        transform: none !important;
    }

    html[dir="rtl"] .sp-custom-modal[data-animation="slide_right"].sp-active {
        left: 0 !important;
        right: auto !important;
        transform: none !important;
        opacity: 1 !important;
    }

    .sp-custom-modal .sp-modal-content {
        padding: 15px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Увеличиваем область нажатия для кнопки закрытия на мобильных */
    .sp-custom-modal .sp-modal-close {
        top: 5px !important;
        right: 5px !important;
        width: 40px !important;
        height: 40px !important;
        padding: 8px !important;
    }

    html[dir="rtl"] .sp-custom-modal .sp-modal-close {
        right: auto !important;
        left: 5px !important;
    }

    /* Применяем мобильные стили на основе CSS переменных */

    /* Основные свойства кнопки */
    .sp-custom-button {
        background-color: var(--mobile-bg-color);
        color: var(--mobile-text-color);
        /* Убираем border-color отсюда, так как он устанавливается через JS */
        border-radius: var(--mobile-border-radius, inherit);
    }

    /* Стиль для рамки, если установлен цвет рамки через переменную */
    .sp-custom-button[style*="--mobile-border-color"] {
        border-style: solid;
        border-width: 1px;
    }

    /* Стили для иконок на мобильных */
    .sp-custom-button .sp-button-icon {
        color: var(--mobile-icon-color);
        font-size: var(--mobile-icon-size);
        width: var(--mobile-icon-size);
        height: var(--mobile-icon-size);
    }

    /* Пользовательские изображения на мобильных */
    .sp-custom-button .sp-button-icon-custom {
        object-fit: contain;
        max-width: 100%;
        max-height: 100%;
        width: var(--mobile-icon-width, auto);
        height: var(--mobile-icon-height, auto);
    }

    /* Если указана только ширина */
    .sp-custom-button .sp-button-icon-custom[style*="width:"] {
        height: auto;
    }

    /* Если указана только высота */
    .sp-custom-button .sp-button-icon-custom[style*="height:"] {
        width: auto;
    }

    /* Режимы отображения для мобильной версии */
    .sp-custom-button[data-mobile-display="text_only"] .sp-button-icon {
        display: none !important;
    }

    .sp-custom-button[data-mobile-display="icon_only"] .sp-button-text {
        display: none !important;
    }

    .sp-custom-button[data-mobile-display="icon_only"] .sp-button-icon {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .sp-custom-button[data-mobile-display="text_icon"] .sp-button-icon,
    .sp-custom-button[data-mobile-display="text_icon"] .sp-button-text {
        display: inline-block !important;
    }

    /* Мобильное позиционирование иконок */
    .sp-custom-button[data-mobile-icon-position="left"] .sp-button-icon {
        margin-right: var(--mobile-icon-gap) !important;
        margin-left: 0 !important;
        order: -1;
    }

    .sp-custom-button[data-mobile-icon-position="right"] .sp-button-icon {
        margin-left: var(--mobile-icon-gap) !important;
        margin-right: 0 !important;
        order: 1;
    }

    /* RTL поддержка для мобильных устройств */
    html[dir="rtl"] .sp-custom-button[data-mobile-icon-position="left"] .sp-button-icon,
    .sp-custom-button[data-rtl="true"][data-mobile-icon-position="left"] .sp-button-icon {
        margin-right: 0 !important;
        margin-left: var(--mobile-icon-gap) !important;
    }

    html[dir="rtl"] .sp-custom-button[data-mobile-icon-position="right"] .sp-button-icon,
    .sp-custom-button[data-rtl="true"][data-mobile-icon-position="right"] .sp-button-icon {
        margin-left: 0 !important;
        margin-right: var(--mobile-icon-gap) !important;
    }
}

/* =============================================
   ПЛАНШЕТНЫЕ СТИЛИ (применяются только на планшетах)
   ============================================= */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Применяем планшетные стили на основе CSS переменных */

    /* Основные свойства кнопки */
    .sp-custom-button {
        background-color: var(--tablet-bg-color);
        color: var(--tablet-text-color);
        /* Убираем border-color отсюда, так как он устанавливается через JS */
        border-radius: var(--tablet-border-radius, inherit);
    }

    /* Стиль для рамки, если установлен цвет рамки через переменную */
    .sp-custom-button[style*="--tablet-border-color"] {
        border-style: solid;
        border-width: 1px;
    }

    /* Стили для иконок на планшетах */
    .sp-custom-button .sp-button-icon {
        color: var(--tablet-icon-color);
        font-size: var(--tablet-icon-size);
        width: var(--tablet-icon-size);
        height: var(--tablet-icon-size);
    }

    /* Пользовательские изображения на планшетах */
    .sp-custom-button .sp-button-icon-custom {
        object-fit: contain;
        max-width: 100%;
        max-height: 100%;
        width: var(--tablet-icon-width, auto);
        height: var(--tablet-icon-height, auto);
    }

    /* Режимы отображения для планшетной версии */
    .sp-custom-button[data-tablet-display="text_only"] .sp-button-icon {
        display: none !important;
    }

    .sp-custom-button[data-tablet-display="icon_only"] .sp-button-text {
        display: none !important;
    }

    .sp-custom-button[data-tablet-display="icon_only"] .sp-button-icon {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .sp-custom-button[data-tablet-display="text_icon"] .sp-button-icon,
    .sp-custom-button[data-tablet-display="text_icon"] .sp-button-text {
        display: inline-block !important;
    }

    /* Планшетное позиционирование иконок */
    .sp-custom-button[data-tablet-icon-position="left"] .sp-button-icon {
        margin-right: var(--tablet-icon-gap) !important;
        margin-left: 0 !important;
        order: -1;
    }

    .sp-custom-button[data-tablet-icon-position="right"] .sp-button-icon {
        margin-left: var(--tablet-icon-gap) !important;
        margin-right: 0 !important;
        order: 1;
    }

    /* RTL поддержка для планшетных устройств */
    html[dir="rtl"] .sp-custom-button[data-tablet-icon-position="left"] .sp-button-icon,
    .sp-custom-button[data-rtl="true"][data-tablet-icon-position="left"] .sp-button-icon {
        margin-right: 0 !important;
        margin-left: var(--tablet-icon-gap) !important;
    }

    html[dir="rtl"] .sp-custom-button[data-tablet-icon-position="right"] .sp-button-icon,
    .sp-custom-button[data-rtl="true"][data-tablet-icon-position="right"] .sp-button-icon {
        margin-left: 0 !important;
        margin-right: var(--tablet-icon-gap) !important;
    }

    /* Планшетные стили для модального окна */
    .sp-custom-modal {
        width: var(--sp-tablet-modal-width, 80%) !important;
        max-width: 90% !important;
        height: auto !important;
        max-height: 85vh !important;
        margin: 0 !important;
        border-radius: 6px !important;
    }
}

/* Специальные стили для RTL, которые гарантированно переопределят стандартные */
[data-rtl="true"].sp-custom-button.sp-button-icon-pos-left .sp-button-icon {
    margin-right: 0 !important;
    margin-left: var(--desktop-icon-gap) !important;
}

[data-rtl="true"].sp-custom-button.sp-button-icon-pos-right .sp-button-icon {
    margin-left: 0 !important;
    margin-right: var(--desktop-icon-gap) !important;
}

/* Обеспечиваем правильное расположение иконок внутри кнопки для LTR */
.sp-ltr.sp-custom-button.sp-button-icon-pos-left .sp-button-icon {
    order: -1;
}

.sp-ltr.sp-custom-button.sp-button-icon-pos-right .sp-button-icon {
    order: 1;
}

/* Обеспечиваем правильное расположение иконок внутри кнопки для RTL */
.sp-rtl.sp-custom-button.sp-button-icon-pos-left .sp-button-icon {
    order: 1;
}

.sp-rtl.sp-custom-button.sp-button-icon-pos-right .sp-button-icon {
    order: -1;
}

/* Flex-контейнер для кнопки */
.sp-custom-button .sp-button-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* RTL контейнеры */
.sp-rtl .sp-button-inner {
    flex-direction: row-reverse;
}

/* Предотвращаем скролл body при открытом модальном окне */
body.sp-modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}
