/* WooCommerce Custom Popup Styles */

/* CSS Custom Properties for Theme Color Management */
:root {
    /* Default colors - will be overridden by theme detection */
    --wc-popup-primary-color: #667eea;
    --wc-popup-secondary-color: #764ba2;
    --wc-popup-text-color: #333333;
    --wc-popup-text-light: #666666;
    --wc-popup-bg-color: #ffffff;
    --wc-popup-border-color: #e1e5e9;
    --wc-popup-error-color: #e74c3c;
    --wc-popup-success-color: #27ae60;
    --wc-popup-shadow-color: rgba(0, 0, 0, 0.1);
    --wc-popup-overlay-color: rgba(0, 0, 0, 0.6);

    /* Fallback colors for older browsers */
    --wc-popup-primary-light: rgba(102, 126, 234, 0.1);
    --wc-popup-error-light: rgba(231, 76, 60, 0.1);
    --wc-popup-border-light: #f8f9fa;
}

/* Browser feature detection and fallbacks */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
    :root {
        --wc-popup-primary-light: rgba(102, 126, 234, 0.1);
        --wc-popup-error-light: rgba(231, 76, 60, 0.1);
        --wc-popup-file-bg: #f8f9fa;
        --wc-popup-file-hover-bg: #f0f2ff;
    }

    .wc-custom-popup-input:focus,
    .wc-custom-popup-textarea:focus {
        box-shadow: 0 0 0 3px var(--wc-popup-primary-light);
    }

    .wc-custom-popup-error {
        box-shadow: 0 0 0 3px var(--wc-popup-error-light) !important;
    }

    .wc-custom-popup-file-label {
        background: var(--wc-popup-file-bg);
    }

    .wc-custom-popup-file-label:hover {
        background: var(--wc-popup-file-hover-bg);
    }

    .wc-custom-popup-submit:hover:not(:disabled) {
        box-shadow: 0 5px 15px var(--wc-popup-primary-light);
    }
}

/* Modern browser support with color-mix */
@supports (color: color-mix(in srgb, red 50%, blue)) {

    .wc-custom-popup-input:focus,
    .wc-custom-popup-textarea:focus {
        box-shadow: 0 0 0 3px color-mix(in srgb, var(--wc-popup-primary-color) 10%, transparent);
    }

    .wc-custom-popup-error {
        box-shadow: 0 0 0 3px color-mix(in srgb, var(--wc-popup-error-color) 10%, transparent) !important;
    }

    .wc-custom-popup-file-label {
        background: color-mix(in srgb, var(--wc-popup-border-color) 5%, var(--wc-popup-bg-color));
    }

    .wc-custom-popup-file-label:hover {
        background: color-mix(in srgb, var(--wc-popup-primary-color) 5%, var(--wc-popup-bg-color));
    }

    .wc-custom-popup-submit:hover:not(:disabled) {
        box-shadow: 0 5px 15px color-mix(in srgb, var(--wc-popup-primary-color) 40%, transparent);
    }
}

/* Theme Color Detection - Inherit from common WordPress/WooCommerce elements */
.wc-custom-popup-theme-detector {
    position: absolute;
    visibility: hidden;
    pointer-events: none;
    top: -9999px;
}

/* Try to inherit theme colors from various elements */
body.woocommerce-page:root,
body.single-product:root,
body.woocommerce:root {
    /* Try to detect WooCommerce button colors */
    --wc-popup-primary-color: var(--wc-button-color, var(--button-color, #667eea));
    --wc-popup-text-color: var(--body-color, var(--text-color, #333333));
    --wc-popup-bg-color: var(--body-bg, var(--bg-color, #ffffff));
    --wc-popup-border-color: var(--border-color, var(--input-border-color, #e1e5e9));
}

/* Detect theme from WooCommerce buttons if they exist */
.woocommerce .button.alt,
.woocommerce button.button.alt,
.woocommerce input.button.alt,
.woocommerce #respond input#submit.alt {
    --wc-popup-primary-color: currentColor;
}

/* Popup Overlay */
#wc-custom-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--wc-popup-overlay-color);
    z-index: 999999;
    display: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
    /* Ensure popup can be interacted with */
}

.wc-custom-popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

/* Popup Container */
.wc-custom-popup-container {
    position: relative;
    max-width: 600px;
    margin: 50px auto;
    background: var(--wc-popup-bg-color);
    color: var(--wc-popup-text-color);
    border-radius: 8px;
    box-shadow: 0 10px 30px var(--wc-popup-shadow-color);
    overflow: hidden;
    animation: wc-custom-popup-slide-in 0.3s ease-out;
}

@keyframes wc-custom-popup-slide-in {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Popup Header */
.wc-custom-popup-header {
    background: linear-gradient(135deg, var(--wc-popup-primary-color) 0%, var(--wc-popup-secondary-color) 100%);
    color: #fff;
    padding: 20px 25px;
    position: relative;
}

.wc-custom-popup-title {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    line-height: 1.3;
}

.wc-custom-popup-subtitle {
    margin: 5px 0 0;
    font-size: 14px;
    opacity: 0.9;
    font-weight: 400;
}

.wc-custom-popup-close {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.wc-custom-popup-close:hover {
    opacity: 1;
}

/* Popup Content */
.wc-custom-popup-content {
    padding: 30px 25px;
}

/* Form Styles */
.wc-custom-popup-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.wc-custom-popup-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wc-custom-popup-label {
    font-weight: 600;
    color: var(--wc-popup-text-color);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.wc-custom-popup-required {
    color: var(--wc-popup-error-color);
    font-size: 12px;
}

.wc-custom-popup-input,
.wc-custom-popup-textarea {
    padding: 12px 15px;
    border: 2px solid var(--wc-popup-border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: var(--wc-popup-bg-color);
    color: var(--wc-popup-text-color);
}

.wc-custom-popup-input:focus,
.wc-custom-popup-textarea:focus {
    outline: none;
    border-color: var(--wc-popup-primary-color);
    /* Box-shadow handled by @supports rules above */
}

.wc-custom-popup-textarea {
    min-height: 100px;
    resize: vertical;
    font-family: inherit;
}

/* File Input Styling */
.wc-custom-popup-file-input {
    position: relative;
    display: inline-block;
    width: 100%;
}

.wc-custom-popup-file-input input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.wc-custom-popup-file-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 15px;
    border: 2px dashed var(--wc-popup-border-color);
    border-radius: 6px;
    /* Background handled by @supports rules above */
    color: var(--wc-popup-text-light);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.wc-custom-popup-file-label:hover {
    border-color: var(--wc-popup-primary-color);
    /* Background handled by @supports rules above */
    color: var(--wc-popup-primary-color);
}

.wc-custom-popup-file-icon {
    font-size: 18px;
}

/* Image Preview */
.wc-custom-popup-image-preview {
    display: none;
    margin-top: 10px;
    text-align: center;
}

.wc-custom-popup-image-preview img {
    max-width: 150px;
    max-height: 150px;
    border-radius: 6px;
    border: 2px solid var(--wc-popup-border-color);
    object-fit: cover;
}

/* Error States */
.wc-custom-popup-error {
    border-color: var(--wc-popup-error-color) !important;
    /* Box-shadow handled by @supports rules above */
}

.wc-custom-popup-field-error {
    color: var(--wc-popup-error-color);
    font-size: 12px;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
    animation: error-shake 0.5s ease-in-out;
}

.wc-custom-popup-field-error::before {
    content: "⚠";
    font-size: 14px;
}

@keyframes error-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Submit Button */
.wc-custom-popup-submit {
    background: linear-gradient(135deg, var(--wc-popup-primary-color) 0%, var(--wc-popup-secondary-color) 100%);
    color: #fff;
    border: none;
    padding: 15px 30px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 10px;
}

.wc-custom-popup-submit:hover:not(:disabled) {
    transform: translateY(-2px);
    /* Box-shadow handled by @supports rules above */
}

.wc-custom-popup-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Enhanced processing state for better UX */
.wc-popup-processing {
    pointer-events: none !important;
    opacity: 0.7 !important;
    cursor: not-allowed !important;
    position: relative;
}

.wc-popup-processing::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.3);
    z-index: 1;
    pointer-events: none;
}

.wc-popup-processing::before {
    content: 'Processing...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 12px;
    z-index: 2;
    pointer-events: none;
}

/* Prevent multiple rapid clicks on add to cart buttons */
.wc-popup-processing {
    pointer-events: none !important;
    opacity: 0.7 !important;
    cursor: not-allowed !important;
}

.wc-popup-processing::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.3);
    z-index: 1;
}

/* Body modifications when popup is open */
body.wc-custom-popup-open {
    overflow: hidden;
}

/* Messages */
.wc-custom-popup-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 6px;
    color: #fff;
    font-weight: 500;
    z-index: 1000000;
    max-width: 300px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.wc-custom-popup-message.show {
    transform: translateX(0);
}

.wc-custom-popup-success {
    background: var(--wc-popup-success-color);
}

.wc-custom-popup-error-msg {
    background: var(--wc-popup-error-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .wc-custom-popup-container {
        margin: 20px;
        max-width: none;
        width: calc(100% - 40px);
    }

    .wc-custom-popup-header {
        padding: 15px 20px;
    }

    .wc-custom-popup-title {
        font-size: 20px;
    }

    .wc-custom-popup-content {
        padding: 20px;
    }

    .wc-custom-popup-message {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .wc-custom-popup-container {
        margin: 10px;
        width: calc(100% - 20px);
    }

    .wc-custom-popup-content {
        padding: 15px;
    }

    .wc-custom-popup-form {
        gap: 15px;
    }

    .wc-custom-popup-submit {
        padding: 12px 25px;
        font-size: 14px;
    }
}

/* High DPI / Retina Display Support */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    .wc-custom-popup-container {
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    }
}

/* Dark mode support (if theme supports it) */
@media (prefers-color-scheme: dark) {
    .wc-custom-popup-container {
        background: #2c3e50;
        color: #ecf0f1;
    }

    .wc-custom-popup-input,
    .wc-custom-popup-textarea {
        background: #34495e;
        border-color: #4a5f7a;
        color: #ecf0f1;
    }

    .wc-custom-popup-input:focus,
    .wc-custom-popup-textarea:focus {
        border-color: #667eea;
        background: #3c566e;
    }

    .wc-custom-popup-file-label {
        background: #34495e;
        border-color: #4a5f7a;
        color: #bdc3c7;
    }

    .wc-custom-popup-file-label:hover {
        background: #3c566e;
        border-color: #667eea;
        color: #667eea;
    }
}

/* Print styles */
@media print {
    #wc-custom-popup {
        display: none !important;
    }
}

/* Accessibility improvements */
.wc-custom-popup-close:focus,
.wc-custom-popup-submit:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Animation for better UX */
.wc-custom-popup-field {
    opacity: 0;
    animation: wc-field-fade-in 0.3s ease forwards;
}

.wc-custom-popup-field:nth-child(1) {
    animation-delay: 0.1s;
}

.wc-custom-popup-field:nth-child(2) {
    animation-delay: 0.2s;
}

.wc-custom-popup-field:nth-child(3) {
    animation-delay: 0.3s;
}

.wc-custom-popup-field:nth-child(4) {
    animation-delay: 0.4s;
}

@keyframes wc-field-fade-in {
    to {
        opacity: 1;
    }
}

/* Popular Theme Compatibility */

/* Astra Theme */
.theme-astra:root {
    --wc-popup-primary-color: var(--ast-global-color-0, var(--wc-popup-primary-color));
    --wc-popup-text-color: var(--ast-global-color-3, var(--wc-popup-text-color));
    --wc-popup-bg-color: var(--ast-global-color-5, var(--wc-popup-bg-color));
}

/* GeneratePress Theme */
body[class*="generate"]:root {
    --wc-popup-primary-color: var(--generate-button-background, var(--wc-popup-primary-color));
    --wc-popup-text-color: var(--generate-text-color, var(--wc-popup-text-color));
    --wc-popup-bg-color: var(--generate-background-color, var(--wc-popup-bg-color));
}

/* OceanWP Theme */
body[class*="oceanwp"]:root {
    --wc-popup-primary-color: var(--oe-primary-color, var(--wc-popup-primary-color));
    --wc-popup-text-color: var(--oe-text-color, var(--wc-popup-text-color));
    --wc-popup-bg-color: var(--oe-background-color, var(--wc-popup-bg-color));
}

/* Storefront Theme (WooCommerce default) */
.storefront:root {
    --wc-popup-primary-color: var(--storefront-primary, #96588a);
    --wc-popup-text-color: var(--storefront-text, #43454b);
    --wc-popup-bg-color: var(--storefront-background, #ffffff);
}

/* Kadence Theme */
body[class*="kadence"]:root {
    --wc-popup-primary-color: var(--global-palette1, var(--wc-popup-primary-color));
    --wc-popup-text-color: var(--global-palette3, var(--wc-popup-text-color));
    --wc-popup-bg-color: var(--global-palette9, var(--wc-popup-bg-color));
}

/* Twenty Twenty-One/Two/Three */
body[class*="twenty-twenty"]:root {
    --wc-popup-primary-color: var(--wp--preset--color--primary, var(--wc-popup-primary-color));
    --wc-popup-text-color: var(--wp--preset--color--foreground, var(--wc-popup-text-color));
    --wc-popup-bg-color: var(--wp--preset--color--background, var(--wc-popup-bg-color));
}

/* Neve Theme */
body[class*="neve"]:root {
    --wc-popup-primary-color: var(--nv-primary-accent, var(--wc-popup-primary-color));
    --wc-popup-text-color: var(--nv-text-color, var(--wc-popup-text-color));
    --wc-popup-bg-color: var(--nv-site-bg, var(--wc-popup-bg-color));
}

/* Hello Elementor Theme */
body[class*="hello-elementor"]:root {
    --wc-popup-primary-color: var(--e-global-color-primary, var(--wc-popup-primary-color));
    --wc-popup-text-color: var(--e-global-color-text, var(--wc-popup-text-color));
    --wc-popup-bg-color: var(--e-global-color-background, var(--wc-popup-bg-color));
}

/* Divi Theme */
body[class*="et_"]:root {
    --wc-popup-primary-color: var(--et_primary_nav_text_color_new, var(--wc-popup-primary-color));
    --wc-popup-text-color: var(--et_body_font_color, var(--wc-popup-text-color));
    --wc-popup-bg-color: var(--et_body_background_color, var(--wc-popup-bg-color));
}