/* ===================================================================
   DESIGNER-2 & FPD INTEGRATION - REFACTORED & OPTIMIZED (v2.0)
   =================================================================== */

/* --- Main Wrapper & Layout --- */
.d2-modules-wrapper {
    display: flex;
    flex-direction: column;
    gap: 30px; /* Provides consistent spacing between D2 and FPD */
}

/* --- Loading Overlay --- */
.d2-design-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000; /* High z-index to cover designer and sit above FPD arrows */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: d2-overlay-enter 0.5s ease-out forwards;
    pointer-events: none; /* Default to no interaction */
    color: #2c3e50; /* Base text color for all overlays */
}

.d2-design-overlay.d2-active {
    pointer-events: all; /* Allow interaction when active */
}

.d2-design-overlay.d2-fade-out {
    animation: d2-overlay-exit 0.6s ease-in forwards;
}

@keyframes d2-overlay-enter {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes d2-overlay-exit {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.95); }
}

.d2-overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 12px; /* Match parent container */
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
}

.d2-overlay-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 28px 32px; /* reduce vertical padding to lower overall height */
    max-width: 320px;
}

/* New: two-row layout for overlay */
.d2-overlay-layout {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-rows: 34vh 1fr; /* lowered header area so content sits slightly lower */
    align-items: center;
    justify-items: center;
    padding: 0;
}

.d2-overlay-header { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding-top: 8px; /* nudge content downward slightly */ }
.d2-header-stack { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 10px; }
/* Ensure consistent spacing for the very first status as well as updates */
.d2-overlay-header .d2-status-message { margin: 4px 0 0 0 !important; gap: 6px; }
.d2-overlay-footer { width: 100%; height: 100%; pointer-events: none; display: flex; align-items: stretch; }

/* --- Progress Indicator --- */
.d2-progress-ring {
    position: relative;
    margin-bottom: 4px; /* reduced bottom spacing under the ring */
    width: 140px;
    height: 140px;
}

.d2-progress-circle {
    transform: rotate(-90deg);
}

.d2-progress-fill {
    transition: stroke-dashoffset 0.4s ease-out;
}

.d2-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: 700;
}

/* Status below ring, consistently centered */
.d2-status-message { text-align: center; }
.d2-status-message .d2-status-icon { font-size: 20px; display: block; margin-bottom: 2px; }
.d2-status-message .d2-status-text { font-size: 16px; line-height: 1.2; margin: 0 auto; max-width: 320px; }

/* --- Status Messages & Icons --- */
.d2-status-message-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px; /* reduce extra bottom spacing */
}

.d2-status-icon {
    font-size: 44px;
}

.d2-status-text {
    font-size: 22px;
    font-weight: 600;
    line-height: 1.3;
}

/* --- Confetti Animation --- */
.d2-confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.d2-confetti-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    top: -10px;
    animation: d2-confetti-fall linear forwards;
}

@keyframes d2-confetti-fall {
    from {
        transform: translateY(0vh) rotate(0deg);
        opacity: 1;
    }
    to {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* ===================================================
   STYLE-SPECIFIC OVERLAY THEMES 
   =================================================== */

/* Base styles for all themes */
.d2-overlay-theme-area .d2-status-text {
    font-size: 22px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.d2-overlay-theme-area .d2-progress-text {
    font-weight: 700;
}

/* Modern */
.d2-style-modern .d2-overlay-backdrop {
    background: linear-gradient(135deg, rgba(79, 172, 254, 0.1), rgba(0, 242, 254, 0.1)), rgba(248, 252, 255, 0.96);
}
.d2-style-modern .d2-status-text { color: #2563eb; }
.d2-style-modern .d2-progress-text { color: #1e40af; }

/* Minimalist */
.d2-style-minimalist .d2-overlay-backdrop {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(4px);
}
.d2-style-minimalist .d2-status-text { color: #2c3e50; font-family: 'SF Pro Display', -apple-system, sans-serif; }
.d2-style-minimalist .d2-progress-text { color: #34495e; font-weight: 300; }
.d2-style-minimalist .d2-status-icon { opacity: 0.8; }

/* Vintage */
.d2-style-vintage .d2-overlay-backdrop {
    background: radial-gradient(circle, rgba(212, 165, 116, 0.2), rgba(139, 69, 19, 0.3)), rgba(244, 228, 188, 0.96);
    backdrop-filter: sepia(0.4) blur(5px);
}
.d2-style-vintage .d2-status-text { color: #8b4513; font-family: Georgia, serif; }
.d2-style-vintage .d2-progress-text { color: #a0522d; }
.d2-style-vintage .d2-status-icon { filter: sepia(0.3); }

/* Abstract */
.d2-style-abstract .d2-overlay-backdrop {
    background: linear-gradient(45deg, rgba(255, 107, 107, 0.85), rgba(78, 205, 196, 0.85));
    backdrop-filter: blur(8px) saturate(1.2);
}
.d2-style-abstract .d2-status-text { color: #e74c3c; }
.d2-style-abstract .d2-progress-text { color: #c0392b; }
.d2-style-abstract .d2-status-icon { animation: d2-abstract-pulse 2s ease-in-out infinite; }

@keyframes d2-abstract-pulse {
    50% { transform: scale(1.05); }
}

/* Geometric */
.d2-style-geometric .d2-overlay-backdrop {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.12), rgba(118, 75, 162, 0.12)), rgba(248, 244, 253, 0.96);
}
.d2-style-geometric .d2-status-text { color: #667eea; font-family: 'SF Mono', Consolas, monospace; letter-spacing: 0.5px; }
.d2-style-geometric .d2-progress-text { color: #5a6fd8; font-family: 'SF Mono', Consolas, monospace; }
.d2-style-geometric .d2-status-icon { animation: d2-geometric-rotate 4s linear infinite; }

@keyframes d2-geometric-rotate {
    to { transform: rotate(360deg); }
}

/* Nature */
.d2-style-nature .d2-overlay-backdrop {
    background: linear-gradient(135deg, rgba(163, 230, 150, 0.2), rgba(67, 138, 77, 0.2)), rgba(240, 250, 238, 0.96);
}
.d2-style-nature .d2-status-text { color: #276749; }
.d2-style-nature .d2-progress-text { color: #2f855a; }
.d2-style-nature .d2-status-icon { animation: d2-nature-sway 3s ease-in-out infinite; }

@keyframes d2-nature-sway {
    50% { transform: rotate(8deg); }
}

/* Urban */
.d2-style-urban .d2-overlay-backdrop {
    background: linear-gradient(rgba(50, 50, 50, 0.1), rgba(10, 10, 10, 0.1)), rgba(235, 237, 240, 0.96);
    backdrop-filter: contrast(1.1);
}
.d2-style-urban .d2-status-text { color: #2d3748; text-shadow: none; }
.d2-style-urban .d2-progress-text { color: #1a202c; }
.d2-style-urban .d2-status-icon { filter: grayscale(0.5); }

/* Photorealistic */
.d2-style-photorealistic .d2-overlay-backdrop {
    background: rgba(245, 245, 245, 0.96);
    backdrop-filter: blur(4px);
}
.d2-style-photorealistic .d2-status-text { color: #4a5568; }
.d2-style-photorealistic .d2-progress-text { color: #2d3748; }
.d2-style-photorealistic .d2-status-icon { animation: d2-camera-focus 3s ease-in-out infinite; }

@keyframes d2-camera-focus {
    50% { transform: scale(1.05) rotate(-2deg); }
}

/* ===================================================
   FANCY PRODUCT DESIGNER - STYLE OVERRIDES
   =================================================== */

/* Additive styling: Apply our theme on top of FPD */

/* Main UI Bar */
body .fpd-main-bar {
    background: #ffffff;
    border-bottom: 2px solid #e1e4e8;
}

/* Legacy styles - replaced by more specific rules below */
/*
body .fpd-main-bar .fpd-navigation > .fpd-nav-item {
    color: #4a5568;
    transition: all 0.2s ease-in-out;
}

body .fpd-main-bar .fpd-navigation > .fpd-nav-item:hover {
    color: #2d3748;
    background-color: #f7f8fa;
}

body .fpd-main-bar .fpd-navigation > .fpd-nav-item.fpd-active {
    color: #ffffff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
}
*/

/* Buttons */
body .fpd-container .fpd-btn:not(.fpd-color-btn, .fpd-swatch, .fpd-color-picker, .fpd-color-palette) {
    background-color: #f8f9fa;
    color: #2c3e50;
    border: 1px solid #e1e4e8;
    transition: all 0.2s ease-in-out;
}

body .fpd-container .fpd-btn:not(.fpd-color-btn, .fpd-swatch, .fpd-color-picker, .fpd-color-palette):hover {
    border-color: #c8ced5;
    background-color: #ffffff;
    transform: translateY(-1px);
}

/* Inputs */
body .fpd-container input:not([type="range"], .fpd-color-input),
body .fpd-container textarea,
body .fpd-container select {
    border: 1px solid #d2d6dc;
    background-color: #ffffff;
    transition: all 0.2s ease-in-out;
}

body .fpd-container input:focus:not([type="range"], .fpd-color-input),
body .fpd-container textarea:focus,
body .fpd-container select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

/* Dropdown Menus */
body .fpd-dropdown-menu,
body .fpd-actions-menu .fpd-dropdown-menu {
    background-color: #ffffff;
    border: 1px solid #e1e4e8;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

body .fpd-dropdown-menu .fpd-btn {
    color: #4a5568;
}

body .fpd-dropdown-menu .fpd-btn:hover {
    color: #2d3748;
    background-color: #f7f8fa;
}

/* Contextual Layout Adjustments */
.single-product .d2-enhanced-container + .fpd-product-designer-wrapper,
.single-product .fpd-product-designer-wrapper + .d2-enhanced-container {
    margin-top: 30px;
}

/* MINIMALISTIC OVERLAY ANIMATION STYLES */
.d2-design-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000; /* Ensure overlay is above the front/back arrows (9999) */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: d2-overlay-enter 0.6s ease forwards;
    pointer-events: none;
}

.d2-design-overlay:not(.d2-fade-out) {
    pointer-events: all;
}

.d2-design-overlay.d2-fullscreen-overlay {
    position: fixed;
    background: rgba(0, 0, 0, 0.8);
}

.d2-design-overlay.d2-fade-out {
    animation: d2-overlay-exit 0.8s ease forwards;
}

@keyframes d2-overlay-enter {
    0% { opacity: 0; transform: scale(0.9); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes d2-overlay-exit {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.95); }
}

.d2-overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-radius: 12px;
}

.d2-overlay-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    max-width: 300px;
}

.d2-progress-ring {
    position: relative;
    margin-bottom: 30px;
}

.d2-progress-circle {
    transform: rotate(-90deg);
    width: 140px;
    height: 140px;
}

.d2-progress-fill {
    transition: stroke-dashoffset 0.5s ease;
}

.d2-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: 700;
    color: #2c3e50;
}

.d2-status-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.d2-status-icon {
    font-size: 44px;
}

.d2-status-text {
    font-size: 24px;
    font-weight: 700;
    color: #2c3e50;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
    text-align: center;
    line-height: 1.3;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.d2-confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    overflow: hidden;
}

.d2-confetti-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    top: -10px;
    animation: d2-confetti-fall linear forwards;
}

@keyframes d2-confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* DESIGNER-2 ENHANCED STYLE-SPECIFIC OVERLAY THEMES */

/* Modern Default Theme - Designer-2 */
.d2-style-modern .d2-overlay-backdrop {
    background: linear-gradient(135deg, rgba(79, 172, 254, 0.1) 0%, rgba(0, 242, 254, 0.1) 100%), 
                rgba(248, 252, 255, 0.96);
    backdrop-filter: blur(6px) saturate(1.1);
}
.d2-style-modern .d2-status-text {
    color: #2563eb;
    font-size: 24px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(37, 99, 235, 0.1);
}
.d2-style-modern .d2-progress-text {
    color: #1e40af;
    font-weight: 700;
}

/* Minimalist Theme - Enhanced for Designer-2 */
.d2-style-minimalist .d2-overlay-backdrop {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(2px) brightness(1.02);
}
.d2-style-minimalist .d2-status-text {
    color: #2c3e50;
    font-size: 24px;
    font-weight: 700;
    font-family: 'SF Pro Display', -apple-system, sans-serif;
}
.d2-style-minimalist .d2-progress-text {
    color: #34495e;
    font-weight: 300;
    font-size: 22px;
}
.d2-style-minimalist .d2-status-icon {
    opacity: 0.8;
    filter: grayscale(0.2);
}

/* Vintage Theme - Enhanced with richer tones */
.d2-style-vintage .d2-overlay-backdrop {
    background: radial-gradient(circle, rgba(212, 165, 116, 0.2) 0%, rgba(139, 69, 19, 0.3) 100%), 
                rgba(244, 228, 188, 0.96);
    backdrop-filter: sepia(0.4) blur(5px) brightness(1.05);
}
.d2-style-vintage .d2-status-text {
    color: #8b4513;
    font-size: 24px;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(212, 175, 55, 0.3);
    font-family: Georgia, serif;
}
.d2-style-vintage .d2-progress-text {
    color: #a0522d;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(139, 69, 19, 0.2);
}
.d2-style-vintage .d2-status-icon {
    filter: sepia(0.3) brightness(1.1);
}

/* Abstract Theme - Enhanced with vibrant Designer-2 colors */
.d2-style-abstract .d2-overlay-backdrop {
    background: linear-gradient(45deg, rgba(255, 107, 107, 0.85) 0%, rgba(78, 205, 196, 0.85) 30%, 
                rgba(255, 154, 158, 0.85) 70%, rgba(254, 207, 239, 0.85) 100%);
    backdrop-filter: blur(8px) saturate(1.3) hue-rotate(5deg);
}
.d2-style-abstract .d2-status-text {
    color: #e74c3c;
    font-size: 24px;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(255, 107, 107, 0.2);
}
.d2-style-abstract .d2-progress-text {
    color: #c0392b;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(231, 76, 60, 0.2);
}
.d2-style-abstract .d2-status-icon {
    filter: saturate(1.2) brightness(1.1);
    animation: d2-abstract-pulse 2s ease-in-out infinite;
}

@keyframes d2-abstract-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.9; }
}

/* Geometric Theme - Enhanced with Designer-2 precision */
.d2-style-geometric .d2-overlay-backdrop {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.12) 0%, rgba(118, 75, 162, 0.12) 100%), 
                rgba(248, 244, 253, 0.96);
    backdrop-filter: blur(6px) contrast(1.05);
}
.d2-style-geometric .d2-status-text {
    color: #667eea;
    font-size: 24px;
    font-weight: 700;
    font-family: 'SF Mono', Consolas, monospace;
    letter-spacing: 0.5px;
}
.d2-style-geometric .d2-progress-text {
    color: #5a6fd8;
    font-weight: 600;
    font-family: 'SF Mono', Consolas, monospace;
}
.d2-style-geometric .d2-status-icon {
    filter: brightness(1.1);
    transform-origin: center;
    animation: d2-geometric-rotate 4s linear infinite;
}

@keyframes d2-geometric-rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Nature Theme - Enhanced with organic Designer-2 colors */
.d2-style-nature .d2-overlay-backdrop {
    background: radial-gradient(circle, rgba(86, 204, 157, 0.15) 0%, rgba(106, 183, 214, 0.15) 100%), 
                rgba(232, 245, 232, 0.96);
    backdrop-filter: blur(4px) hue-rotate(10deg) saturate(1.15);
}
.d2-style-nature .d2-status-text {
    color: #22c55e;
    font-size: 24px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(34, 197, 94, 0.1);
}
.d2-style-nature .d2-progress-text {
    color: #16a34a;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(22, 163, 74, 0.1);
}
.d2-style-nature .d2-status-icon {
    filter: hue-rotate(10deg) saturate(1.2);
    animation: d2-nature-sway 3s ease-in-out infinite;
}

@keyframes d2-nature-sway {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
}

/* Urban Theme - Enhanced with industrial Designer-2 aesthetic */
.d2-style-urban .d2-overlay-backdrop {
    background: linear-gradient(135deg, rgba(72, 85, 99, 0.92) 0%, rgba(41, 50, 60, 0.94) 100%);
    backdrop-filter: blur(6px) contrast(1.15) brightness(0.95);
}
.d2-style-urban .d2-status-text {
    color: #e2e8f0;
    font-size: 24px;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    font-family: 'Inter', sans-serif;
}
.d2-style-urban .d2-progress-text {
    color: #f1f5f9;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.d2-style-urban .d2-status-icon {
    filter: brightness(1.2) contrast(1.1);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Photorealistic Theme - Enhanced with camera precision */
.d2-style-photorealistic .d2-overlay-backdrop {
    background: linear-gradient(135deg, rgba(67, 67, 67, 0.88) 0%, rgba(0, 0, 0, 0.92) 100%);
    backdrop-filter: blur(8px) brightness(0.92) contrast(1.1);
}
.d2-style-photorealistic .d2-status-text {
    color: #f8fafc;
    font-size: 24px;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    font-family: 'Camera', serif;
}
.d2-style-photorealistic .d2-progress-text {
    color: #ffffff;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.d2-style-photorealistic .d2-status-icon {
    filter: brightness(1.3) contrast(1.2);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    animation: d2-camera-focus 1.5s ease-in-out infinite;
}

@keyframes d2-camera-focus {
    0%, 100% { transform: scale(1); filter: brightness(1.3) contrast(1.2); }
    50% { transform: scale(0.95); filter: brightness(1.5) contrast(1.3); }
}

/* Enhanced progress ring animations for each theme */
.d2-style-vintage .d2-progress-fill {
    filter: sepia(0.2);
}

.d2-style-abstract .d2-progress-fill {
    filter: saturate(1.3);
    animation: d2-abstract-gradient 3s ease-in-out infinite;
}

@keyframes d2-abstract-gradient {
    0%, 100% { filter: saturate(1.3) hue-rotate(0deg); }
    50% { filter: saturate(1.5) hue-rotate(10deg); }
}

.d2-style-nature .d2-progress-fill {
    filter: hue-rotate(5deg) saturate(1.1);
}

.d2-style-urban .d2-progress-fill {
    filter: brightness(1.1) contrast(1.1);
}

.d2-style-photorealistic .d2-progress-fill {
    filter: contrast(1.2) brightness(1.1);
}

/* Selection counter styling updates for different limits */
.d2-selection-counter {
    font-size: 12px;
    font-weight: 500;
    color: #4facfe;
    background: rgba(79, 172, 254, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 8px;
    display: inline-block;
    transition: all 0.3s ease;
}

.d2-selection-counter.at-limit {
    background: rgba(79, 172, 254, 0.2);
    color: #0ea5e9;
    font-weight: 600;
}

.d2-selection-counter.over-limit {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    animation: d2-counter-pulse 0.5s ease-in-out;
}

@keyframes d2-counter-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* FPD GENERAL STYLES */
.fpd-product-designer-wrapper {
    transform: none !important;
    -webkit-transform: none !important;
    will-change: auto !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border-radius: 16px !important;
    overflow: hidden !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
    border: 2px solid #e1e4e8 !important;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%) !important;
    margin: 20px 0 30px 0 !important;
    min-height: 600px !important;
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
}

/* STICKY BEHAVIOR FOR FPD WRAPPER - REDESIGNED APPROACH */
@media screen and (min-width: 769px) {
    /* CRITICAL: Override the grid layout behavior for smaller screens */
    .single-product .qodef-woo-single-inner {
        position: relative !important;
        /* On smaller laptops/tablets, switch to stacked layout for better scroll behavior */
        display: block !important;
        gap: 30px !important;
        min-height: auto !important;
        height: auto !important;
    }
    
    /* Stack image and summary vertically on smaller screens for better scroll */
    .single-product .qodef-woo-single-image,
    .single-product .summary {
        position: relative !important;
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        margin-bottom: 30px !important;
    }
    
    /* Apply sticky behavior to FPD wrapper - SMART CALCULATION APPROACH */
    .single-product .fpd-product-designer-wrapper,
    .single-product.post-type-product .fpd-product-designer-wrapper,
    body.single-product .fpd-product-designer-wrapper,
    .woocommerce.single-product .fpd-product-designer-wrapper {
        position: sticky !important;
        /* CSS fallback - JavaScript will override with calculated value */
        top: 0 !important; /* avoid initial offset to prevent flicker */
        z-index: 10 !important;
        /* Allow natural content expansion without constraints */
        min-height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        overflow-y: visible !important;
        margin-top: 0 !important;
        margin-bottom: 30px !important;
        /* Remove align-self to prevent grid conflicts */
        align-self: unset !important;
        /* Ensure proper rendering */
        transform: translateZ(0) !important;
        -webkit-transform: translateZ(0) !important;
        /* Full width in stacked layout */
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Target FPD wrapper when placed in summary (fpd-under-title) */
    .single-product .summary .fpd-product-designer-wrapper {
        position: sticky !important;
        top: 0 !important; /* avoid initial offset to prevent flicker */
        z-index: 10 !important;
        max-height: none !important;
        overflow-y: visible !important;
    }
    
    /* Target FPD wrapper when placed after summary (fpd-after-summary) */
    .single-product .woocommerce-tabs.wc-tabs-wrapper ~ .fpd-product-designer-wrapper,
    .single-product .woocommerce-tabs ~ .fpd-product-designer-wrapper {
        position: sticky !important;
        top: 0 !important; /* avoid initial offset to prevent flicker */
        z-index: 10 !important;
        max-height: none !important;
        overflow-y: visible !important;
    }
    
    /* Target FPD wrapper when replacing image (fpd-replace-image) */
    .single-product .qodef-woo-single-image .fpd-product-designer-wrapper {
        position: sticky !important;
        top: 0 !important; /* avoid initial offset to prevent flicker */
        z-index: 10 !important;
        max-height: none !important;
        overflow-y: visible !important;
    }
    
    /* Ensure FPD canvas container handles sticky properly */
    .single-product .fpd-product-designer-wrapper .fpd-container {
        position: relative !important;
        height: auto !important; /* JS will set parent min-height after scale */
        max-height: none !important;
        overflow: visible !important;
    }
    
    /* Make sure the main FPD container doesn't interfere */
    .single-product .fpd-product-designer-wrapper #fancy-product-designer,
    .single-product .fpd-product-designer-wrapper .fpd-main-wrapper {
        position: relative !important;
        height: auto !important;
    }
    
    /* Maintain proper spacing with other elements */
    .single-product .fpd-product-designer-wrapper + * {
        margin-top: 30px !important;
    }
    
    /* Ensure the wrapper doesn't break out of its container */
    .single-product .fpd-product-designer-wrapper {
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Force sticky behavior with higher specificity - LAST RESORT */
    body.single-product.woocommerce div.product .fpd-product-designer-wrapper,
    body.single-product.woocommerce div#qodef-woo-page .fpd-product-designer-wrapper,
    body.single-product div[class*="product"] .fpd-product-designer-wrapper {
        position: sticky !important;
        top: 0 !important; /* avoid initial offset to prevent flicker */
        z-index: 10 !important;
        max-height: none !important;
        overflow-y: visible !important;
        transform: translateZ(0) !important;
        -webkit-transform: translateZ(0) !important;
    }
}

.fpd-product-designer-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 5px;
    right: 5px;
    height: 4px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px 16px 0 0;
}

fpd-main-bar,
fpd-main-bar .fpd-navigation,
fpd-main-bar .fpd-navigation *,
fpd-actions-bar,
fpd-actions-bar * {
    position: relative !important;
    transform: none !important;
    -webkit-transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
}
fpd-element-toolbar {
    transform: none !important;
    -webkit-transform: none !important;
}

/* FPD MAIN BAR */
/* Restore soft Fabcrush theme for main bar */
fpd-main-bar {
    background: rgba(102, 126, 234, 0.10) !important;
    border-bottom: none !important;
    box-shadow: none !important;
    padding: 0 10px !important;
    height: auto !important;
    display: block !important;
}
fpd-main-bar .fpd-navigation {
    background: transparent !important;
    display: flex !important;
    justify-content: center !important;
    gap: 8px !important;
}
fpd-main-bar .fpd-navigation > .fpd-nav-item {
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    align-content: center !important;
    place-items: center !important;
    place-content: center !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    background: #ffffff !important;
    color: #2c3e50 !important;
    border: 1px solid #e1e4e8 !important;
    border-radius: 8px !important;
    margin: 0 !important;
    padding: 5px 0px 5px 0px !important;
    font-weight: 500 !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08) !important;
    min-width: 70px !important;
    height: auto !important;
    max-height: none !important;
    min-height: auto !important;
    text-align: center !important;
    vertical-align: middle !important;
    letter-spacing: 0.025em !important;
    box-sizing: border-box !important;
}
fpd-main-bar .fpd-navigation > .fpd-nav-item:hover {
    background: #f8fafc !important;
    border-color: #667eea !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.12) !important;
    color: #1a202c !important;
}
fpd-main-bar .fpd-navigation > .fpd-nav-item.fpd-active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #ffffff !important;  
    border-color: #667eea !important;
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.25) !important;
    transform: translateY(-1px) !important;
}

/* Icon adjustments for vertical nav items */
fpd-main-bar .fpd-navigation > .fpd-nav-item .fpd-nav-icon {
    font-size: 20px !important;
    margin-right: 0 !important;
    margin-bottom: 0px !important;
}

fpd-main-bar .fpd-navigation > .fpd-nav-item [class*="fpd-icon-"] {
    font-size: 20px !important;
    margin-right: 0 !important;
    margin-bottom: 0px !important;
}

fpd-main-bar .fpd-navigation > .fpd-nav-item .fpd-label {
    line-height: 1.2 !important;
}

/* Override FPD core styles with higher specificity */
.fpd-container fpd-main-bar .fpd-navigation > .fpd-nav-item {
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    align-content: center !important;
    place-items: center !important;
    place-content: center !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    padding: 5px 0px 5px 0px !important;
    margin: 0px !important;
    height: auto !important;
    max-height: none !important;
    min-height: auto !important;
    text-align: center !important;
    vertical-align: middle !important;
    box-sizing: border-box !important;
}

/* Reset all child elements to ensure proper centering */
.fpd-container fpd-main-bar .fpd-navigation > .fpd-nav-item > * {
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    text-align: center !important;
    line-height: 1.2 !important;
}

/* Specific overrides for icons and labels */
.fpd-container fpd-main-bar .fpd-navigation > .fpd-nav-item > span:first-child {
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    line-height: 1.2 !important;
}

.fpd-container fpd-main-bar .fpd-navigation > .fpd-nav-item > .fpd-label,
.fpd-container fpd-main-bar .fpd-navigation > .fpd-nav-item > span:last-child {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1.2 !important;
    font-size: 12px !important;
}

.fpd-container fpd-main-bar .fpd-navigation > .fpd-nav-item [class*="fpd-icon-"],
.fpd-container fpd-main-bar .fpd-navigation > .fpd-nav-item .fpd-nav-icon {
    margin-right: 0 !important;
    margin-bottom: 0px !important;
    font-size: 20px !important;
}

.fpd-container fpd-main-bar .fpd-navigation > .fpd-nav-item .fpd-label {
    line-height: 1px !important;
    margin-top: 0 !important;
}

/* FPD BUTTONS & CONTROLS */
.fpd-container .fpd-btn:not(.fpd-color-btn):not(.fpd-swatch):not(.fpd-color-picker):not(.fpd-color-palette) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #ffffff !important;
    border: none !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2) !important;
}
.fpd-container .fpd-btn:not(.fpd-color-btn):not(.fpd-swatch):not(.fpd-color-picker):not(.fpd-color-palette):hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6b4d94 100%) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
}
/* Hide actions bar per Fabcrush layout (Front/Back switcher replaces it) */
fpd-actions-bar { display: none !important; }
fpd-actions-bar .fpd-btn {
    background: #000000 !important;
    color: #2c3e50 !important;
    border: 2px solid #e1e4e8 !important;
    border-radius: 8px !important;
    padding: 8px 16px !important;
    font-weight: 600 !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05) !important;
}
fpd-actions-bar .fpd-btn:hover {
    background: rgba(102, 126, 234, 0.1) !important;
    border-color: #667eea !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.15) !important;
}
.fpd-container input:not([type="range"]):not(.fpd-color-input),
.fpd-container textarea,
.fpd-container select {
    border: 2px solid #e1e4e8 !important;
    border-radius: 8px !important;
    padding: 10px 14px !important;
    background: #ffffff !important;
    color: #2c3e50 !important;
    font-weight: 500 !important;
    transition: all 0.3s ease !important;
}
.fpd-container input:focus:not([type="range"]):not(.fpd-color-input),
.fpd-container textarea:focus,
.fpd-container select:focus {
    border-color: #667eea !important;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
    background: #fafbff !important;
    outline: none !important;
}

/* FPD Dropdown Menu Integration - Minimalist Style */

/* Create a positioning context for the dropdown trigger */
.fpd-actions-menu {
    position: relative !important;
}

/* Make the dropdown container itself invisible AND position it */
.fpd-dropdown-menu,
fpd-dropdown .fpd-dropdown-list {
    position: absolute !important;
    top: 100% !important; /* Position it directly below the menu container */
    z-index: 100 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin-top: 8px !important; /* Add some space from the trigger button */
}

/* Position left-aligned dropdowns */
.fpd-actions-menu[data-pos="left"] .fpd-dropdown-menu,
.fpd-actions-menu[data-pos="left"] fpd-dropdown .fpd-dropdown-list {
    left: 0 !important;
    right: auto !important;
}

/* Position right-aligned dropdowns */
.fpd-actions-menu[data-pos="right"] .fpd-dropdown-menu,
.fpd-actions-menu[data-pos="right"] fpd-dropdown .fpd-dropdown-list {
    right: 0 !important;
    left: auto !important;
}

/* Style the individual buttons within the invisible dropdown */
.fpd-dropdown-menu .fpd-btn,
.fpd-dropdown-list .fpd-item {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #ffffff !important;
    border: none !important;
    border-radius: 10px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    padding: 12px 20px !important;
    margin-bottom: 6px !important; /* Space between buttons */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
    transition: all 0.3s ease !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    min-width: 160px !important;
}

.fpd-dropdown-menu .fpd-btn:hover,
.fpd-dropdown-list .fpd-item:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3) !important;
}

/* Ensure icons are visible and styled correctly */
.fpd-dropdown-menu .fpd-btn [class*='fpd-icon-'],
.fpd-dropdown-list .fpd-item [class*='fpd-icon-'] {
    display: inline-block !important;
    color: #ffffff !important;
    font-size: 16px !important;
}

/* Hide any extra wrappers that might have their own backgrounds */
.fpd-actions-menu .fpd-collapsed-menu {
    background: none !important;
    padding: 0 !important;
}

/* ===================================
   IMPROVED LAYOUT ALIGNMENT - FIXED VERSION
   =================================== */

/* Force both components to align at top - Critical Fix */
.single-product .summary .d2-enhanced-container {
    margin-top: 0 !important;
    margin-bottom: 10px !important;
    align-self: flex-start !important;
}

.single-product .summary .fpd-product-designer-wrapper,
.single-product .fpd-product-designer-wrapper {
    margin-top: 0 !important;
    margin-bottom: 30px !important;
    align-self: flex-start !important;
}
/* Create a flex container for proper alignment */
.single-product .summary {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
}

/* Ensure components start at same level regardless of order */
.single-product .d2-enhanced-container,
.single-product .fpd-product-designer-wrapper {
    margin-top: 0 !important;
    position: relative !important;
    top: 0 !important;
}

/* Reset any inherited spacing that might cause misalignment */
.single-product .d2-enhanced-container:first-child,
.single-product .fpd-product-designer-wrapper:first-child {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Specific fixes for common theme compatibility */
.single-product div.product .summary .d2-enhanced-container,
.single-product div.product .summary .fpd-product-designer-wrapper {
    margin-top: 0 !important;
    transform: none !important;
    position: relative !important;
    vertical-align: top !important;
}

/* Override any theme-specific margins that might interfere */
.woocommerce div.product .summary .d2-enhanced-container,
.woocommerce div.product .summary .fpd-product-designer-wrapper {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Single Product Page Layout Improvements */
.single-product .woocommerce-tabs.wc-tabs-wrapper,
.single-product .woocommerce-tabs {
    margin-top: 30px !important;
}

/* Create better visual hierarchy */
.single-product .woocommerce-product-details__short-description {
    margin-bottom: 25px !important;
}

/* Better alignment for the AI generator when positioned after FPD */
.fpd-product-designer-wrapper + .d2-enhanced-container {
    margin-top: 0 !important;
    border-top: 1px solid #e1e4e8;
    padding-top: 30px;
}

/* Ensure consistent spacing */
.single-product .d2-enhanced-container + .fpd-product-designer-wrapper {
    margin-top: 0 !important;
}

/* Module Container Wrapper - Force alignment */
.d2-modules-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0px;
    margin: 0px 0;
    align-items: stretch;
}

.d2-modules-wrapper > * {
    margin-top: 0 !important;
    margin-bottom: 30px !important;
}

/* Create visual connection between modules */
.d2-enhanced-container {
    position: relative;
    z-index: 1;
}

.fpd-product-designer-wrapper {
    position: relative;
    z-index: 2;
}

/* Restore grid layout for large screens where it works properly */
@media screen and (min-width: 1200px) {
    .single-product .qodef-woo-single-inner {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 40px !important;
    }
    
    .single-product .qodef-woo-single-image,
    .single-product .summary {
        margin-bottom: 0 !important;
    }
}

/* Additional responsive adjustments for different screen sizes */
@media screen and (min-width: 1200px) {
    /* On larger screens, keep consistent header spacing */
    .single-product .fpd-product-designer-wrapper {
        top: 90px !important;
    }
}

@media screen and (min-width: 1400px) {
    /* On very large screens, keep consistent header spacing */
    .single-product .fpd-product-designer-wrapper {
        top: 100px !important;
    }
}

@media screen and (max-width: 1024px) and (min-width: 769px) {
    /* Tablet-specific adjustments - smaller header */
    .single-product .fpd-product-designer-wrapper {
        top: 70px !important;
    }
}

/* Responsive layout improvements */
@media (max-width: 768px) {
    /* Reset sticky behavior on mobile for better touch experience */
    .single-product .fpd-product-designer-wrapper {
        position: relative !important;
        top: auto !important;
        max-height: none !important;
        overflow-y: visible !important;
        margin: 20px 0 30px 0 !important;
        align-self: auto !important;
    }
    
    .single-product .qodef-woo-single-image {
        min-height: auto !important;
    }
    
    .single-product .d2-enhanced-container {
        margin-bottom: 30px !important;
        margin-top: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    .single-product .fpd-product-designer-wrapper {
        margin-bottom: 20px !important;
        margin-top: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    .fpd-product-designer-wrapper + .d2-enhanced-container {
        margin-top: 0 !important;
        padding-top: 20px;
    }
    
    /* Ensure FPD mobile navigation is touch-friendly */
    fpd-main-bar .fpd-navigation > .fpd-nav-item {
        touch-action: manipulation !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Better mobile canvas interaction */
    .fpd-container .fpd-canvas-wrapper {
        touch-action: pan-x pan-y !important;
    }
    
    /* Mobile-optimized FPD modal/popup */
    .fpd-modal-wrapper {
        padding: 10px !important;
        box-sizing: border-box !important;
    }
    
    .fpd-modal {
        max-width: calc(100vw - 20px) !important;
        max-height: calc(100vh - 40px) !important;
        margin: 10px !important;
    }
}

/* Ensure title doesn't interfere with layout */
.single-product .product_title.entry-title {
    display: none !important;
}

/* Better alignment for WooCommerce elements */
.single-product .woocommerce div.product div.summary {
    width: 100% !important;
}

/* Align price and other elements better */
.single-product .price {
    margin-bottom: 20px !important;
}

.single-product .single_add_to_cart_button {
    margin-top: 20px !important;
} 