/**
 * IndieTech Popup Frontend Styles
 */

// Variables
$popup-overlay-bg: rgba(0, 0, 0, 0.7);
$popup-bg: transparent;
$popup-border-radius: 8px;
$popup-padding: 30px;
$popup-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
$close-button-size: 40px;
$close-button-color: #666;
$close-button-hover-color: #333;

// Animations
$animation-duration: 0.3s;
$animation-easing: cubic-bezier(0.4, 0.0, 0.2, 1);

/**
 * Base Micromodal Styles
 */
.micromodal-slide {
    display: none;

    &.is-open {
        display: block;
    }

    &[aria-hidden="false"] {
        .indietech-popup__overlay {
            animation: mmfadeIn $animation-duration $animation-easing;
        }
    }

    &[aria-hidden="true"] {
        .indietech-popup__overlay {
            animation: mmfadeOut $animation-duration $animation-easing;
        }
    }
}

/**
 * Overlay
 */
.indietech-popup__overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: $popup-overlay-bg;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999999;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px;
}

/**
 * Container
 */
.indietech-popup__container {
    background-color: $popup-bg;
    border-radius: $popup-border-radius;
    // box-shadow: $popup-shadow;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;

    // ── 9-position grid (AlignmentMatrixControl values) ──
    &--top-left      { align-self: flex-start; margin-right: auto; }
    &--top-center    { align-self: flex-start; }
    &--top-right     { align-self: flex-start; margin-left: auto; }
    &--center-left   { margin-right: auto; }
    &--center-center { align-self: center; }
    &--center-right  { margin-left: auto; }
    &--bottom-left   { align-self: flex-end; margin-right: auto; }
    &--bottom-center { align-self: flex-end; }
    &--bottom-right  { align-self: flex-end; margin-left: auto; }

    // Legacy single-word positions (backward compatibility)
    &--top    { align-self: flex-start; }
    &--bottom { align-self: flex-end; }
    &--center { align-self: center; }
}

/**
 * Header
 */
// .indietech-popup__header {
//     padding: $popup-padding;
//     padding-bottom: 20px;
//     border-bottom: 1px solid #e0e0e0;
//     position: relative;
// }

.indietech-popup__title {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: #333;
    padding-right: 40px;
}

/**
 * Close Button
 */
.indietech-popup__close {
    position: absolute;
    z-index: 1000;
    top: 20px;
    right: 20px;
    width: $close-button-size;
    height: $close-button-size;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    color: $close-button-color;
    transition: all 0.2s ease;
    padding: 0;

    &:hover,
    &:focus {
        color: $close-button-hover-color;
        background-color: #f0f0f0;
        outline: none;
    }

    svg {
        width: 24px;
        height: 24px;
        fill: currentColor;
        pointer-events: none;
    }

    // Button Position: Inside (default - positioned relative to popup container)
    &--inside {
        // Already positioned relative to container by default
    }

    // Button Position: Outside (positioned relative to overlay/viewport)
    &--outside {
        position: fixed;
        top: 30px;
        right: 30px;
        background-color: rgba(255, 255, 255, 0.9);
        color: #333;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);

        &:hover,
        &:focus {
            background-color: rgba(255, 255, 255, 1);
            color: #000;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }
    }
}

/**
 * Content
 */
.indietech-popup__content {
    // padding: $popup-padding;
    // color: #555;
    // line-height: 1.6;

    // Gutenberg content styles
    // p {
    //     margin-bottom: 1em;

    //     &:last-child {
    //         margin-bottom: 0;
    //     }
    // }

    // h1, h2, h3, h4, h5, h6 {
    //     margin-top: 1.5em;
    //     margin-bottom: 0.5em;
    //     line-height: 1.3;

    //     &:first-child {
    //         margin-top: 0;
    //     }
    // }

    // img {
    //     max-width: 100%;
    //     height: auto;
    // }

    // // WordPress blocks
    // .wp-block-image {
    //     margin: 1em 0;
    // }

    // .wp-block-button {
    //     margin: 1em 0;
    // }

    // .wp-block-buttons {
    //     margin: 1em 0;
    // }
}

/**
 * Animation: Fade
 */
.indietech-popup__container--fade {
    &[aria-hidden="false"] {
        animation: mmslideIn $animation-duration $animation-easing;
    }

    &[aria-hidden="true"] {
        animation: mmslideOut $animation-duration $animation-easing;
    }
}

/**
 * Animation: Slide
 */
.indietech-popup__container--slide {
    &[aria-hidden="false"] {
        animation: mmslideInFromTop $animation-duration $animation-easing;
    }

    &[aria-hidden="true"] {
        animation: mmslideOutToTop $animation-duration $animation-easing;
    }
}

/**
 * Animation: Scale
 */
.indietech-popup__container--scale {
    &[aria-hidden="false"] {
        animation: mmscaleIn $animation-duration $animation-easing;
    }

    &[aria-hidden="true"] {
        animation: mmscaleOut $animation-duration $animation-easing;
    }
}

/**
 * Keyframes
 */
@keyframes mmfadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes mmfadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes mmslideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes mmslideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

@keyframes mmslideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-100px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes mmslideOutToTop {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-100px);
    }
}

@keyframes mmscaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes mmscaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

/**
 * Responsive
 */
@media (max-width: 768px) {
    .indietech-popup__overlay {
        padding: 10px;
    }

    .indietech-popup__container {
        max-width: 100%;
        border-radius: 4px;

        // Reset position-specific margins on small screens
        &--top, &--bottom,
        &--top-left, &--top-center, &--top-right,
        &--center-left, &--center-right,
        &--bottom-left, &--bottom-center, &--bottom-right {
            margin: 0 auto;
        }
    }

    .indietech-popup__header {
        padding: 20px;
        padding-bottom: 15px;
    }

    .indietech-popup__title {
        font-size: 20px;
        padding-right: 35px;
    }

    .indietech-popup__close {
        top: 15px;
        right: 15px;
        width: 35px;
        height: 35px;
        font-size: 28px;

        &--outside {
            top: 15px;
            right: 15px;
        }
    }

    .indietech-popup__content {
        padding: 20px;
    }
}

/**
 * Accessibility
 */
.indietech-popup__overlay:focus {
    outline: none;
}

.indietech-popup__container:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}

// Screen reader only text
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

