/**
 * UStyle Popup Styles (chat button + modal)
 *
 * Loaded on all pages when the popup feature is ON.
 * Served from backend — deploy = all stores updated instantly.
 *
 * Uses CSS custom property --ustyle-popup-height (set by PHP on the overlay
 * element) for dynamic iframe height. Default: 700px.
 */

:root {
    --ustyle-popup-height: 700px;
}

.ustyle-popup-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ustyle-popup-overlay.active {
    display: block;
    opacity: 1;
}

.ustyle-popup-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 48px);
    max-width: 811px;
    max-height: calc(100vh - 48px);
    background: transparent;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.ustyle-popup-overlay.active .ustyle-popup-container {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.ustyle-popup-content-wrapper {
    background: transparent;
    border: none;
    border-radius: 16px;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    clip-path: inset(0 round 16px);
    position: relative;
    max-height: inherit;
    pointer-events: auto;
}

.ustyle-popup-header {
    position: absolute;
    top: 2px;
    left: 3px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0;
    background: transparent;
    border-radius: 0;
    backdrop-filter: none;
    z-index: 2;
}

.ustyle-popup-title {
    display: none;
}

.ustyle-popup-close {
    appearance: none;
    border: none;
    background: transparent;
    font-size: 32px !important;
    line-height: 1;
    cursor: pointer;
    color: #333;
    padding: 4px 8px;
    right: 0px !important;
}

.ustyle-popup-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: transparent;
    max-height: inherit;
}

.ustyle-popup-iframe {
    width: 100%;
    height: min(var(--ustyle-popup-height), calc(100vh - 48px));
    border: none;
    display: block;
    border-radius: 16px;
}

/* ========================
   Mobile responsive
   ======================== */

@media (max-width: 768px) {
    .ustyle-popup-container {
        width: calc(100% - 20px);
        max-width: 530px;
        max-height: min(92vh, calc(100vh - 20px));
        max-height: min(92dvh, calc(100dvh - 20px));
    }

    .ustyle-popup-container.ustyle-mode-intro {
        width: calc(100% - 34px);
        max-width: 500px;
    }

    .ustyle-popup-container.ustyle-mode-outfit {
        width: calc(100% - 60px);
        max-width: 400px;
        max-height: min(97vh, calc(100vh - 8px));
        max-height: min(97dvh, calc(100dvh - 8px));
    }

    .ustyle-popup-content-wrapper {
        max-height: min(92vh, calc(100vh - 20px));
        max-height: min(92dvh, calc(100dvh - 20px));
    }

    .ustyle-popup-container.ustyle-mode-outfit .ustyle-popup-content-wrapper {
        max-height: min(97vh, calc(100vh - 8px));
        max-height: min(97dvh, calc(100dvh - 8px));
    }

    .ustyle-popup-iframe {
        height: min(calc(var(--ustyle-popup-height) * 0.8), calc(92vh - 8px));
        height: min(calc(var(--ustyle-popup-height) * 0.8), calc(92dvh - 8px));
    }

    .ustyle-popup-container.ustyle-mode-full {
        width: calc(100% - 60px);
        max-width: 400px;
        max-height: min(96dvh, calc(100dvh - 8px));
        max-height: min(96vh, calc(100vh - 8px));
    }

    .ustyle-popup-container.ustyle-mode-full .ustyle-popup-content-wrapper {
        max-height: min(96dvh, calc(100dvh - 8px));
        max-height: min(96vh, calc(100vh - 8px));
    }

    .ustyle-popup-container.ustyle-mode-full .ustyle-popup-iframe,
    .ustyle-popup-container.ustyle-mode-outfit .ustyle-popup-iframe {
        min-height: 320px;
    }

    .ustyle-popup-title {
        font-size: 18px;
    }
}

/* Short mobile viewport */
@media (max-width: 768px) and (max-height: 700px) {
    .ustyle-popup-container {
        max-height: min(88vh, calc(100vh - 20px));
        max-height: min(88dvh, calc(100dvh - 20px));
    }

    .ustyle-popup-container.ustyle-mode-outfit {
        max-height: min(95vh, calc(100vh - 8px));
        max-height: min(95dvh, calc(100dvh - 8px));
    }

    .ustyle-popup-container.ustyle-mode-full {
        max-height: min(94vh, calc(100vh - 8px));
        max-height: min(94dvh, calc(100dvh - 8px));
    }

    .ustyle-popup-content-wrapper {
        max-height: min(88vh, calc(100vh - 20px));
        max-height: min(88dvh, calc(100dvh - 20px));
    }

    .ustyle-popup-container.ustyle-mode-outfit .ustyle-popup-content-wrapper {
        max-height: min(95vh, calc(100vh - 8px));
        max-height: min(95dvh, calc(100dvh - 8px));
    }

    .ustyle-popup-container.ustyle-mode-full .ustyle-popup-content-wrapper {
        max-height: min(94vh, calc(100vh - 8px));
        max-height: min(94dvh, calc(100dvh - 8px));
    }

    .ustyle-popup-iframe {
        height: min(calc(var(--ustyle-popup-height) * 0.72), calc(88vh - 8px));
        height: min(calc(var(--ustyle-popup-height) * 0.72), calc(88dvh - 8px));
    }
}

/* ========================
   Chat button
   ======================== */

.ustyle-chat-button {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: transparent;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 999997;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: none;
    padding: 0;
}

.ustyle-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.ustyle-chat-button:active {
    transform: scale(0.95);
}

.ustyle-chat-button img {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    display: block;
}

@media (max-width: 768px) {
    .ustyle-chat-button {
        width: 56px;
        height: 56px;
        bottom: 15px;
        right: 15px;
    }

    .ustyle-chat-button img {
        width: 56px;
        height: 56px;
    }
}
