/* KD Popup Frontend Styles */

/* Trigger Button */
.kd-popup-trigger-btn {
    background-color: #0073aa;
    color: #ffffff;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.kd-popup-trigger-btn:hover {
    background-color: #005a87;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Overlay */
.kd-popup-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 999999;
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow: visible !important;
}

.kd-popup-overlay.active {
    display: flex;
    opacity: 1;
}

/* Container positioning */
.kd-popup-container {
    position: relative;
    margin: auto;
    overflow: visible !important;
}

/* Vertical positioning */
.kd-popup-container.kd-popup-top {
    align-self: flex-start;
    margin-top: 5vh;
}

.kd-popup-container.kd-popup-middle {
    align-self: center;
}

.kd-popup-container.kd-popup-bottom {
    align-self: flex-end;
    margin-bottom: 5vh;
}

/* Horizontal positioning */
.kd-popup-container.kd-popup-left {
    margin-left: 5vw;
    margin-right: auto;
}

.kd-popup-container.kd-popup-center,
.kd-popup-container.kd-popup-middle {
    margin-left: auto;
    margin-right: auto;
}

.kd-popup-container.kd-popup-right {
    margin-left: auto;
    margin-right: 5vw;
}

/* Content wrapper - styles set via inline styles from settings */
.kd-popup-content-wrapper {
    position: relative;
    overflow: visible !important; /* Keep visible for outside close button (themes sometimes override) */
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    max-height: 90vh; /* Ensure popup doesn't get too tall */
}

/* Outside close positioning can be clipped if a theme forces overflow hidden up the tree */
.kd-popup-container {
    overflow: visible !important;
}

.kd-popup-overlay {
    overflow: visible !important;
}

/* Inner content with overflow control */
.kd-popup-content {
    overflow-y: auto; /* Vertical scroll when needed */
    overflow-x: hidden; /* Prevent horizontal scroll */
    flex: 1;
    max-height: calc(90vh - 80px); /* Account for padding and prevent infinite height */
}

/* Media image (Visual Builder "Media" section) */
.kd-popup-media {
    margin: 0;
    overflow: hidden;
}

/* Banner position - full width at top, bleeds to edges */
.kd-popup-media-banner {
    /* Inline styles from PHP handle the negative margins based on popup padding */
    /* This ensures full-bleed effect */
}

/* Below title position */
.kd-popup-media-below-title {
    margin-top: 15px;
    margin-bottom: 15px;
}

/* Below content position */
.kd-popup-media-below-content {
    margin-top: 15px;
    margin-bottom: 0;
}

/* Legacy class for backwards compatibility */
.kd-popup-media-below {
    margin: 15px 0 0 0;
}

.kd-popup-media img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: var(--kd-popup-media-fit, cover);
    border-radius: 0;
}

/* Allow shadows to extend beyond content boundaries */
.kd-popup-content > * {
    overflow: visible;
}

/* Button wrapper - use margin to create space for shadows */
.kd-popup-button-wrapper {
    margin-top: 20px;
    margin-bottom: 20px; /* Space for shadow at bottom */
    text-align: center;
}

.kd-popup-close {
    position: absolute;
    /*
     * Use CSS variables + !important to win against theme rules that often set icon/button
     * colors with !important.
     */
    background: transparent;
    background-color: var(--kd-close-bg, transparent) !important;
    border: none !important;
    border-radius: var(--kd-close-radius, 0px) !important;
    font-size: 24px;
    cursor: pointer;
    z-index: 9999999;
    transition: opacity 0.2s ease, transform 0.2s ease;
    padding: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.kd-popup-close i,
.kd-popup-close .kd-close-text {
    color: var(--kd-close-icon-color, inherit) !important;
    line-height: 1;
}

/* Fix for circle-xmark and square-xmark icons - the X cutout needs to be visible */
.kd-popup-close i.fa-circle-xmark,
.kd-popup-close i.fa-square-xmark {
    /* These icons have the X as a cutout, so we need to show the background through it */
    /* Use a filter to ensure the X is visible against any background */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.kd-close-icon-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--kd-close-wrapper-radius, 3px) !important;
    padding: 2px;
    line-height: 1;
    background-color: var(--kd-close-wrapper-bg, transparent) !important;
    border: var(--kd-close-wrapper-border, none) !important;
}

/* Close button hover effects */
.kd-popup-close {
    transition: opacity 0.2s ease, transform 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

/* Default/Fade hover */
.kd-popup-close:hover,
.kd-popup-close.kd-close-hover-fade:hover {
    opacity: 0.7;
}

/* No hover effect */
.kd-popup-close.kd-close-hover-none:hover {
    opacity: 1;
    transform: var(--kd-close-position-transform, none);
}

/* Grow hover - combine with position transform */
.kd-popup-close.kd-close-hover-grow:hover {
    opacity: 1;
    transform: var(--kd-close-position-transform, none) scale(1.15);
}

/* Shrink hover - combine with position transform */
.kd-popup-close.kd-close-hover-shrink:hover {
    opacity: 1;
    transform: var(--kd-close-position-transform, none) scale(0.9);
}

/* Rotate hover - combine with position transform */
.kd-popup-close.kd-close-hover-rotate:hover {
    opacity: 1;
    transform: var(--kd-close-position-transform, none) rotate(90deg);
}

/* Color hover - uses CSS variable for hover color */
.kd-popup-close.kd-close-hover-color:hover {
    opacity: 1;
    background-color: var(--kd-close-hover-bg-color, var(--kd-close-bg, transparent)) !important;
}

.kd-popup-close.kd-close-hover-color:hover i {
    color: var(--kd-close-hover-color, #000000) !important;
}

/* Remove browser default focus and active styles */
.kd-popup-close:focus,
.kd-popup-close:active {
    outline: none !important;
    box-shadow: none !important;
}

.kd-popup-close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Remove focus outline from wrapper */
.kd-close-icon-wrapper:focus {
    outline: none;
}

/* Close button positions - always top-right */

/* Inside position (default) - inset from corner */
.kd-popup-close,
.kd-popup-close.kd-popup-close-inside {
    top: 12px;
    right: 12px;
    --kd-close-position-transform: none;
}

/* Border position - centered on the corner edge */
.kd-popup-close.kd-popup-close-border {
    top: 0;
    right: 0;
    --kd-close-position-transform: translate(50%, -50%);
    transform: var(--kd-close-position-transform);
}

/* Outside position - fully outside the popup border */
.kd-popup-close.kd-popup-close-outside {
    top: -8px;
    right: -8px;
    --kd-close-position-transform: translate(100%, -100%);
    transform: var(--kd-close-position-transform);
}

/* 
 * Popup Title - Override theme h2 styles
 * We use !important on resets, inline styles also use !important to win
 */
.kd-popup-content-wrapper .kd-popup-title,
.kd-popup-content-wrapper h2.kd-popup-title,
h2.kd-popup-title {
    /* Reset common theme overrides - use unset to allow inline styles through */
    letter-spacing: normal !important;
    line-height: 1.3 !important;
    margin: 0 0 15px 0 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    text-shadow: none !important;
    -webkit-text-stroke: unset !important;
}

/* 
 * Popup Content - Override theme paragraph styles 
 */
.kd-popup-content-wrapper .kd-popup-content {
    line-height: 1.6;
}

.kd-popup-content-wrapper .kd-popup-content p,
.kd-popup-content p {
    /* Let parent's inline styles flow through */
    font-family: inherit !important;
    font-size: inherit !important;
    font-weight: inherit !important;
    font-style: inherit !important;
    color: inherit !important;
    text-align: inherit !important;
    text-transform: inherit !important;
    text-decoration: inherit !important;
    line-height: inherit !important;
    letter-spacing: normal !important;
    margin: 0 0 1em 0;
}

.kd-popup-content-wrapper .kd-popup-content p:last-child,
.kd-popup-content p:last-child {
    margin-bottom: 0;
}

/* Content headings within popup content area */
.kd-popup-content h1,
.kd-popup-content h2,
.kd-popup-content h3,
.kd-popup-content h4,
.kd-popup-content h5,
.kd-popup-content h6 {
    margin-top: 0;
}

.kd-popup-content p:last-child {
    margin-bottom: 0;
}

.kd-popup-content img {
    max-width: 100%;
    height: auto;
}

/* Button */
.kd-popup-button {
    display: inline-block;
    padding: 12px 30px;
    background-color: #0073aa;
    color: #ffffff;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    transition: all 0.3s ease;
    border: none;
    font-size: 16px;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --kd-btn-hover-color: #ffffff;
    --kd-btn-hover-bg-color: #005a87;
}

/* Default button hover - fade */
.kd-popup-button:hover {
    opacity: 0.85;
}

/* Button hover effect classes */
.kd-popup-button.kd-btn-hover-none:hover {
    opacity: 1;
    transform: none;
}

.kd-popup-button.kd-btn-hover-fade:hover {
    opacity: 0.85;
}

.kd-popup-button.kd-btn-hover-grow:hover {
    opacity: 1;
    transform: scale(1.05);
}

.kd-popup-button.kd-btn-hover-shrink:hover {
    opacity: 1;
    transform: scale(0.95);
}

.kd-popup-button.kd-btn-hover-color:hover {
    opacity: 1;
    background-color: var(--kd-btn-hover-bg-color) !important;
    color: var(--kd-btn-hover-color) !important;
}

.kd-popup-button:active {
    outline: none !important;
    border: none !important;
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

.kd-popup-button:focus {
    outline: none !important;
    border: none !important;
}

/* Animation */
@keyframes kdPopupSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Entrance Animations */
@keyframes kd-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes kd-slide-up {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes kd-slide-down {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes kd-slide-left {
    from {
        opacity: 0;
        transform: translateX(50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes kd-slide-right {
    from {
        opacity: 0;
        transform: translateX(-50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes kd-zoom {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Legacy alias for backwards compatibility */
@keyframes kd-zoom-in {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes kd-zoom-out {
    from {
        opacity: 0;
        transform: scale(1.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes kd-bounce {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.1);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes kd-none {
    from { opacity: 1; }
    to { opacity: 1; }
}

/* Responsive styles */
@media (max-width: 768px) {
    .kd-popup-overlay {
        padding: 15px;
        box-sizing: border-box;
    }
    
    .kd-popup-container {
        max-width: 100% !important;
        margin: 0 auto !important;
        width: 100%;
    }
    
    .kd-popup-content-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto;
    }
    
    .kd-popup-content {
        padding: 20px;
        max-height: 80vh;
    }
    
    .kd-popup-close {
        font-size: 20px;
        width: 36px;
        height: 36px;
    }
    
    .kd-popup-close.kd-popup-close-outside,
    .kd-popup-close.kd-popup-close-border {
        /* Keep transform positioning on mobile */
    }
    
    .kd-popup-trigger-btn {
        padding: 10px 20px;
        font-size: 14px;
    }
    
    .kd-popup-button {
        padding: 10px 24px;
        font-size: 14px;
    }
    
    /* Force center positioning on mobile */
    .kd-popup-container.kd-popup-left,
    .kd-popup-container.kd-popup-right {
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

@media (max-width: 480px) {
    .kd-popup-overlay {
        padding: 10px;
    }
    
    .kd-popup-content {
        padding: 15px;
    }
    
    .kd-popup-close {
        font-size: 18px;
        width: 32px;
        height: 32px;
    }
}

/* Prevent body scroll when popup is open */
body.kd-popup-open {
    overflow: hidden;
}

/* Close icon custom text styles */
.kd-popup-close .kd-close-text {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

/* Custom text - adjust button sizing */
.kd-popup-close:has(.kd-close-text) {
    padding: 6px 12px;
    width: auto;
    height: auto;
}

/* Accessibility - Clean focus states without browser defaults */
.kd-popup-trigger-btn:focus,
.kd-popup-trigger-btn:active {
    outline: none !important;
    box-shadow: none !important;
}

/* Better focus visible for keyboard navigation */
.kd-popup-trigger-btn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}
