/**
 * AI Page Builder Editor - Modern Design
 */

/* AI Page Builder Editor uses design system variables from design-system.css */

/* Editor Mode */
body.aipb-editing-mode {
    position: relative;
}

/* Modern Toolbar */
.aipb-toolbar {
    position: fixed;
    top: 50%;
    right: 30px;
    transform: translateY(-50%);
    background: var(--aipb-bg-primary);
    backdrop-filter: blur(20px);
    border: 1px solid var(--aipb-border);
    border-radius: var(--aipb-radius-xl);
    padding: var(--aipb-space-5);
    box-shadow: var(--aipb-shadow-2xl);
    z-index: var(--aipb-z-tooltip);
    display: none;
    min-width: 200px;
    animation: slideInRight 0.4s ease;
}

@keyframes slideInRight {
    from {
        transform: translateY(-50%) translateX(100px);
        opacity: 0;
    }
    to {
        transform: translateY(-50%) translateX(0);
        opacity: 1;
    }
}

body.admin-bar .aipb-toolbar {
    top: calc(50% + 16px);
}

.aipb-toolbar h3 {
    margin: 0 0 var(--aipb-space-5) 0;
    font-size: var(--aipb-text-base);
    font-weight: var(--aipb-font-semibold);
    color: var(--aipb-text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.aipb-toolbar-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--aipb-space-3);
}

/* Modern Buttons */
.aipb-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--aipb-transition);
    position: relative;
    overflow: hidden;
    text-align: center;
}

.aipb-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.aipb-btn:hover::before {
    width: 300px;
    height: 300px;
}

.aipb-btn-primary {
    /* Inherits all styles from .aipb-button-primary in design-system.css */
    background: var(--aipb-primary);
}

.aipb-btn-secondary {
    /* Inherits all styles from .aipb-button-secondary in design-system.css */
    background: var(--aipb-bg-secondary);
    color: var(--aipb-text-primary);
    border: 1px solid var(--aipb-border);
}

.aipb-btn-secondary:hover {
    background: var(--aipb-bg-tertiary);
    border-color: var(--aipb-primary);
    color: var(--aipb-primary);
}

/* Toggle AI button */
#aipb-toggle-prompt {
    background: var(--aipb-primary);
    color: white;
    box-shadow: var(--aipb-shadow-lg);
}

/* Modern Prompt Container - Always Visible at Bottom */
.aipb-prompt-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--aipb-bg-primary);
    backdrop-filter: blur(30px);
    border-top: 1px solid var(--aipb-border);
    box-shadow: var(--aipb-shadow-2xl);
    z-index: var(--aipb-z-dropdown);
    display: none;
    transform: translateY(0);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

body.aipb-editing-mode .aipb-prompt-container {
    display: block;
    transform: translateY(0);
    animation: slideUpPrompt 0.4s ease;
}

@keyframes slideUpPrompt {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.aipb-prompt-box {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px;
}

.aipb-prompt-box h3 {
    margin: 0 0 var(--aipb-space-5) 0;
    font-size: var(--aipb-text-2xl);
    font-weight: var(--aipb-font-semibold);
    color: var(--aipb-primary);
}

/* Modern Textarea */
#aipb-prompt {
    width: 100%;
    padding: var(--aipb-space-5);
    border: 2px solid var(--aipb-border);
    border-radius: var(--aipb-radius-lg);
    font-size: var(--aipb-text-base);
    line-height: 1.6;
    resize: vertical;
    min-height: 100px;
    font-family: var(--aipb-font-primary);
    background: var(--aipb-bg-secondary);
    color: var(--aipb-text-primary);
    transition: var(--aipb-transition);
}

#aipb-prompt:focus {
    border-color: var(--aipb-primary);
    outline: none;
    box-shadow: 0 0 0 4px var(--aipb-ring-primary);
    background: var(--aipb-bg-tertiary);
}

/* Image References Section */
.aipb-image-references {
    margin-top: 25px;
    padding-top: 25px;
    border-top: 1px solid rgba(226, 232, 240, 0.3);
}

.aipb-image-references h4 {
    margin: 0 0 var(--aipb-space-4) 0;
    font-size: var(--aipb-text-base);
    font-weight: var(--aipb-font-semibold);
    color: var(--aipb-text-primary);
}

.aipb-image-preview-container {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.aipb-image-preview {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.1);
    transition: var(--aipb-transition);
}

.aipb-image-preview:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.2);
}

.aipb-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.aipb-remove-image {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--aipb-transition);
}

.aipb-image-preview:hover .aipb-remove-image {
    opacity: 1;
}

.aipb-remove-image:hover {
    background: var(--aipb-error);
    transform: scale(1.1);
}

/* Add Image Button */
#aipb-add-image {
    display: inline-flex;
    align-items: center;
    gap: var(--aipb-space-2);
    padding: var(--aipb-space-3) var(--aipb-space-5);
    background: var(--aipb-bg-secondary);
    border: 2px dashed var(--aipb-border);
    border-radius: var(--aipb-radius-lg);
    color: var(--aipb-text-secondary);
    font-weight: var(--aipb-font-medium);
    transition: var(--aipb-transition);
}

#aipb-add-image:hover {
    border-color: var(--aipb-primary);
    color: var(--aipb-primary);
    background: var(--aipb-bg-primary-subtle);
}

.aipb-prompt-actions {
    margin-top: 25px;
    display: flex;
    gap: 15px;
}

#aipb-generate {
    background: var(--aipb-primary);
    color: white;
    padding: var(--aipb-space-4) var(--aipb-space-10);
    font-size: var(--aipb-text-base);
    font-weight: var(--aipb-font-semibold);
    box-shadow: var(--aipb-shadow-lg);
}

#aipb-generate:hover {
    transform: translateY(-2px);
    box-shadow: var(--aipb-shadow-xl);
    background: var(--aipb-primary-hover);
}

#aipb-cancel-prompt {
    padding: var(--aipb-space-4) var(--aipb-space-8);
    background: var(--aipb-bg-secondary);
    color: var(--aipb-text-secondary);
    font-weight: var(--aipb-font-medium);
}

/* Editable Elements - Specific to text and structural elements */
.aipb-text-element[data-aipb-id],
.aipb-structural-element[data-aipb-id],
img[data-aipb-id] {
    position: relative;
    transition: var(--aipb-transition);
}

body.aipb-editing-mode .aipb-text-element[data-aipb-id],
body.aipb-editing-mode .aipb-structural-element[data-aipb-id] {
    cursor: text;
}

/* Remove generic hover - now specific to element types */
/* Structural elements hover */
body.aipb-editing-mode .aipb-structural-element:hover {
    outline: 2px dashed var(--aipb-primary-hover);
    outline-offset: 8px;
    border-radius: var(--aipb-radius-md);
}

/* Images hover - keep original */
body.aipb-editing-mode img[data-aipb-id]:hover {
    outline: 2px dashed var(--aipb-primary-hover);
    outline-offset: 8px;
    border-radius: var(--aipb-radius-md);
}

body.aipb-editing-mode .aipb-text-element[data-aipb-id].aipb-editing,
body.aipb-editing-mode .aipb-structural-element[data-aipb-id].aipb-editing,
body.aipb-editing-mode img[data-aipb-id].aipb-editing {
    outline: 2px solid var(--aipb-primary);
    outline-offset: 8px;
    background: var(--aipb-bg-primary-subtle);
    border-radius: var(--aipb-radius-md);
    box-shadow: 0 0 0 8px var(--aipb-ring-primary);
}

/* Image Wrappers */
.aipb-image-wrapper {
    position: relative;
    display: inline-block;
    transition: var(--aipb-transition);
}

body.aipb-editing-mode .aipb-image-wrapper {
    cursor: pointer;
}

body.aipb-editing-mode .aipb-image-wrapper::after {
    content: '🖼️ Clicca per cambiare';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--aipb-primary);
    color: white;
    padding: var(--aipb-space-3) var(--aipb-space-6);
    border-radius: var(--aipb-radius-lg);
    font-size: var(--aipb-text-sm);
    font-weight: var(--aipb-font-medium);
    opacity: 0;
    transition: var(--aipb-transition);
    pointer-events: none;
    white-space: nowrap;
}

body.aipb-editing-mode .aipb-image-wrapper:hover::after {
    opacity: 1;
}

body.aipb-editing-mode .aipb-image-wrapper:hover img {
    filter: brightness(0.7);
}

/* Loading State */
.aipb-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--aipb-bg-primary);
    padding: var(--aipb-space-10);
    border-radius: var(--aipb-radius-xl);
    z-index: var(--aipb-z-modal);
    display: none;
    backdrop-filter: blur(20px);
    box-shadow: var(--aipb-shadow-2xl);
}

.aipb-loading.active {
    display: block;
}

.aipb-loading-content {
    position: relative;
    width: 80px;
    height: 80px;
}

/* AI Icon */
.aipb-ai-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    color: var(--aipb-primary);
    z-index: 2;
    filter: drop-shadow(0 0 15px var(--aipb-ring-primary));
}

/* Spinner */
.aipb-loading-spinner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.aipb-spinner-ring {
    width: 100%;
    height: 100%;
    border: 3px solid var(--aipb-ring-primary);
    border-top: 3px solid var(--aipb-primary);
    border-radius: 50%;
    animation: aipb-spin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
    box-shadow: 0 0 25px var(--aipb-ring-primary);
}

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

/* Pulse effect for AI icon */
.aipb-loading.active .aipb-ai-icon {
    animation: aipb-pulse 2s ease-in-out infinite;
}

@keyframes aipb-pulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    50% {
        transform: translate(-50%, -50%) scale(0.95);
        opacity: 0.8;
    }
}

/* Legacy message styles - commented out to prevent conflicts with toast system */
/*
.aipb-message {
    position: fixed;
    top: 100px;
    right: 30px;
    padding: 20px 30px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    z-index: 100002;
    animation: slideInMessage 0.4s ease;
    box-shadow: var(--aipb-shadow);
}

@keyframes slideInMessage {
    from {
        transform: translateX(100px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.aipb-message.success {
    background: var(--aipb-success);
    color: white;
}

.aipb-message.error {
    background: var(--aipb-error);
    color: white;
}
*/

/* Empty Page Notice */
.aipb-empty-page-notice {
    text-align: center;
    padding: var(--aipb-space-20) var(--aipb-space-5);
    color: var(--aipb-text-secondary);
    font-size: var(--aipb-text-xl);
    font-weight: var(--aipb-font-light);
    line-height: 1.6;
}

/* Admin Bar Button Style */
.aipb-admin-bar-button .ab-item {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
}

.aipb-admin-bar-button:hover {
    background: var(--aipb-bg-primary-subtle) !important;
}

/* Admin Bar Header/Footer Edit Links */
#wpadminbar .aipb-admin-bar-header .ab-item,
#wpadminbar .aipb-admin-bar-footer .ab-item {
    display: flex !important;
    align-items: center !important;
}

#wpadminbar .aipb-admin-bar-header:hover,
#wpadminbar .aipb-admin-bar-footer:hover {
    background: var(--aipb-bg-primary-subtle) !important;
}

/* Green glow effect on hover */
#wpadminbar .aipb-admin-bar-header:hover .dashicons,
#wpadminbar .aipb-admin-bar-footer:hover .dashicons {
    text-shadow: 0 0 8px var(--aipb-primary) !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .aipb-toolbar {
        top: auto;
        bottom: 100px;
        right: 20px;
        left: 20px;
        transform: none;
        max-width: 400px;
        margin: 0 auto;
    }
    
    .aipb-prompt-box {
        padding: 20px;
    }
    
    .aipb-prompt-box h3 {
        font-size: 20px;
    }
    
    #aipb-prompt {
        font-size: 14px;
        padding: 15px;
    }
    
    .aipb-prompt-actions {
        flex-direction: column;
    }
    
    .aipb-prompt-actions button {
        width: 100%;
    }
}

/* Fix for display:contents elements - Specific to editor elements */
.aipb-text-element[data-aipb-id][style*="display: contents"],
.aipb-structural-element[data-aipb-id][style*="display: contents"] {
    display: inline-block !important;
}

/* Remove overlay - we want to see live changes */

/* Code Editor Panel - IDE Style */
.aipb-code-editor-panel {
    position: fixed;
    top: 0;
    right: -50vw;
    width: 50vw;
    height: 100vh;
    background: var(--aipb-bg-primary);
    z-index: var(--aipb-z-modal);
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--aipb-shadow-2xl);
    border-left: 1px solid var(--aipb-border);
}

/* Admin bar spacing */
body.admin-bar .aipb-code-editor-panel {
    top: 32px;
    height: calc(100vh - 32px);
}

@media screen and (max-width: 782px) {
    body.admin-bar .aipb-code-editor-panel {
        top: 46px;
        height: calc(100vh - 46px);
    }
}

.aipb-code-editor-panel.active {
    right: 0;
}

/* Page content when editor is open - NO WRAPPING */
body.aipb-code-editor-open {
    overflow-x: hidden;
}

/* Editor Header */
.aipb-code-editor-header {
    background: var(--aipb-bg-secondary);
    padding: var(--aipb-space-4) var(--aipb-space-5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--aipb-border);
    flex-shrink: 0;
}

.aipb-code-editor-title {
    color: var(--aipb-text-primary);
    font-size: var(--aipb-text-base);
    font-weight: var(--aipb-font-medium);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-3);
}

.aipb-code-editor-title .dashicons,
.aipb-code-editor-title .uil {
    font-size: 20px;
    color: var(--aipb-primary);
}

.aipb-code-editor-actions {
    display: flex;
    gap: 8px;
}

.aipb-code-editor-btn {
    background: transparent;
    border: 1px solid var(--aipb-border);
    color: var(--aipb-text-primary);
    padding: var(--aipb-space-2) var(--aipb-space-4);
    border-radius: var(--aipb-radius-md);
    font-size: var(--aipb-text-sm);
    cursor: pointer;
    transition: var(--aipb-transition);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-2);
    font-weight: var(--aipb-font-medium);
}

.aipb-code-editor-btn:hover {
    background: var(--aipb-bg-tertiary);
    border-color: var(--aipb-border-hover);
    transform: translateY(-1px);
}

.aipb-code-editor-btn.primary {
    background: var(--aipb-primary);
    border-color: var(--aipb-primary);
    color: white;
}

.aipb-code-editor-btn.primary:hover {
    background: var(--aipb-primary-hover);
    border-color: var(--aipb-primary-hover);
    box-shadow: 0 4px 12px var(--aipb-ring-primary);
}

.aipb-code-editor-close {
    background: transparent;
    border: none;
    color: var(--aipb-text-tertiary);
    font-size: 20px;
    cursor: pointer;
    padding: var(--aipb-space-1);
    line-height: 1;
    transition: var(--aipb-transition);
}

.aipb-code-editor-close:hover {
    color: var(--aipb-danger);
    transform: rotate(90deg);
}

/* Editor Container */
.aipb-code-editor-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.aipb-code-editor-container .CodeMirror {
    height: 100%;
    font-family: var(--aipb-font-mono);
    font-size: var(--aipb-text-sm);
    line-height: 1.6;
    background: var(--aipb-bg-primary);
}

/* Status Bar */
.aipb-code-editor-status {
    background: var(--aipb-bg-secondary);
    border-top: 1px solid var(--aipb-border);
    padding: var(--aipb-space-2) var(--aipb-space-5);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--aipb-text-xs);
    color: var(--aipb-text-secondary);
    flex-shrink: 0;
}

.aipb-code-editor-status span {
    color: var(--aipb-text-secondary);
}

.aipb-code-editor-status-left {
    display: flex;
    gap: 20px;
}

.aipb-code-editor-status-right {
    display: flex;
    gap: 10px;
}

/* Live preview overlay */
.aipb-live-preview-updating {
    position: relative;
}

.aipb-live-preview-updating::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--aipb-bg-overlay);
    pointer-events: none;
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* Ensure wrapper doesn't create nested structures */
.aipb-page-content-wrapper {
    width: 100% !important;
    max-width: 100% !important;
}

/* Remove aipb-content-wrapper from saved content */
.aipb-content-wrapper {
    display: contents;
}

/* Responsive adjustments */
@media (max-width: 1400px) {
    .aipb-code-editor-panel {
        width: 60vw;
        right: -60vw;
    }
    
    body.aipb-code-editor-open .aipb-page-content-wrapper {
        margin-right: 60vw;
    }
}

@media (max-width: 1024px) {
    .aipb-code-editor-panel {
        width: 70vw;
        right: -70vw;
    }
    
    body.aipb-code-editor-open .aipb-page-content-wrapper {
        margin-right: 70vw;
    }
}

@media (max-width: 768px) {
    .aipb-code-editor-panel {
        width: 100vw;
        right: -100vw;
    }
    
    body.aipb-code-editor-open .aipb-page-content-wrapper {
        margin-right: 100vw;
        opacity: 0.3;
        pointer-events: none;
    }
}

/* Prevent selection issues */
[contenteditable="true"] {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

/* WordPress Admin Bar Compatibility */
body.admin-bar .aipb-prompt-container {
    bottom: 0;
}

/* Dark mode support - Inherits from design system dark theme */

/* Edit Elements Buttons - Modern Icon Wrapper */
.aipb-element-buttons {
    position: absolute;
    top: 0px;
    right: 5px;
    display: flex;
    align-items: center;
    gap: 2px;
    z-index: var(--aipb-z-dropdown);
    background: var(--aipb-bg-primary);
    backdrop-filter: blur(10px);
    border: 1px solid var(--aipb-border);
    border-radius: 5px !important;
    padding: 2px;
    box-shadow: var(--aipb-shadow-sm);
    transition: opacity 0.2s ease-in-out;
    opacity: 0;
}

/* Show on direct parent hover only - not nested */
body.aipb-editing-mode .aipb-structural-element:hover > .aipb-element-buttons,
body.aipb-editing-mode .aipb-element-selected > .aipb-element-buttons,
body.aipb-editing-mode .aipb-text-element:hover > .aipb-element-buttons {
    opacity: 1;
}

/* Show buttons on wrapper hover when button is inside wrapper */
body.aipb-editing-mode .aipb-text-element-wrapper:hover > .aipb-element-buttons {
    opacity: 1 !important;
}

/* Keep buttons visible when hovering on them */
body.aipb-editing-mode .aipb-element-buttons:hover {
    opacity: 1;
}

.aipb-element-edit-btn,
.aipb-element-delete-btn,
.aipb-template-config-btn,
.aipb-form-settings-btn,
.aipb-search-settings-btn,
.aipb-bg-image-btn,
.aipb-element-link-btn,
.aipb-drag-handle,
.aipb-hide-wrapper-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    color: var(--aipb-text-secondary);
    border: none;
    border-radius: var(--aipb-radius-sm);
    cursor: pointer;
    font-size: var(--aipb-text-sm);
    transition: var(--aipb-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Hover states with colors */
.aipb-element-edit-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

.aipb-element-delete-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-text-secondary);
}

.aipb-add-section-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

.aipb-template-config-btn:hover {
    background: rgba(16, 185, 129, 0.1);
    color: #10B981;
}

.aipb-form-settings-btn:hover {
    background: rgba(16, 185, 129, 0.1);
    color: #10B981;
}

.aipb-search-settings-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

.aipb-element-link-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-text-secondary);
}

.aipb-drag-handle:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-text-secondary);
}

.aipb-hide-wrapper-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-text-secondary);
}

/* Icon styling for Uicons */
.aipb-element-buttons button .uil {
    font-size: 16px;
    line-height: 1;
    width: 16px;
    height: 16px;
    display: inline-block;
}

/* Add specific icon styling if needed */
.aipb-add-section-btn .uil {
    font-size: 20px;
    width: 20px;
    height: 20px;
}

/* Code editor icons */
.aipb-code-editor-title .uil,
.aipb-code-editor-btn .uil {
    font-size: 16px;
    margin-right: 5px;
    vertical-align: middle;
}

/* Modern Toast Notifications */
.aipb-toast-container {
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 2147483646 !important;
    pointer-events: none !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Adjust for admin bar */
body.admin-bar .aipb-toast-container {
    top: 52px !important; /* Account for admin bar height */
}

.aipb-toast {
    background: var(--aipb-bg-secondary) !important;
    color: var(--aipb-text-primary) !important;
    padding: var(--aipb-space-4) var(--aipb-space-5) !important;
    border-radius: var(--aipb-radius-lg) !important;
    margin-bottom: var(--aipb-space-3) !important;
    display: flex !important;
    align-items: center !important;
    gap: var(--aipb-space-3) !important;
    min-width: 320px !important;
    max-width: 420px !important;
    box-shadow: var(--aipb-shadow-lg) !important;
    position: relative !important;
    overflow: hidden !important;
    pointer-events: all !important;
    animation: slideInRight 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55) !important;
    visibility: visible !important;
    opacity: 1 !important;
}

@keyframes slideInRight {
    from {
        transform: translateX(110%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(110%);
        opacity: 0;
    }
}

.aipb-toast.hiding {
    animation: slideOutRight 0.3s ease-in forwards;
}

/* Toast icon */
.aipb-toast-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aipb-toast-icon .uil {
    font-size: 24px;
    line-height: 1;
}

/* Toast types */
.aipb-toast.success {
    border-left: 4px solid var(--aipb-success);
}

.aipb-toast.success .aipb-toast-icon {
    color: var(--aipb-success);
}

.aipb-toast.error {
    border-left: 4px solid var(--aipb-error);
}

.aipb-toast.error .aipb-toast-icon {
    color: var(--aipb-error);
}

.aipb-toast.info {
    border-left: 4px solid var(--aipb-primary);
}

.aipb-toast.info .aipb-toast-icon {
    color: var(--aipb-primary);
}

.aipb-toast.warning {
    border-left: 4px solid var(--aipb-warning);
}

.aipb-toast.warning .aipb-toast-icon {
    color: var(--aipb-warning);
}

/* Toast content */
.aipb-toast-content {
    flex: 1;
    font-size: 14px;
    line-height: 1.5;
}

/* Progress bar */
.aipb-toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    animation: shrinkWidth 3s linear forwards;
}

@keyframes shrinkWidth {
    from {
        width: 100%;
    }
    to {
        width: 0;
    }
}

/* Close button */
.aipb-toast-close {
    background: transparent;
    border: none;
    color: var(--aipb-text-tertiary);
    cursor: pointer;
    padding: var(--aipb-space-1);
    margin-left: var(--aipb-space-2);
    border-radius: var(--aipb-radius-sm);
    transition: var(--aipb-transition);
    line-height: 1;
}

.aipb-toast-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.aipb-toast-close .uil {
    font-size: 16px;
}

.aipb-drag-handle {
    cursor: move !important;
}

/* Hide text spans if they exist */
.aipb-element-buttons button span {
    display: none;
}

/* Modern AI Loading Animation */
.aipb-theme-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--aipb-bg-overlay);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--aipb-z-modal);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.aipb-theme-loading.active {
    opacity: 1;
    visibility: visible;
}

.aipb-theme-loading-wrapper {
    text-align: center;
}

.aipb-theme-loading-content {
    position: relative;
    display: inline-block;
    margin-bottom: 2rem;
}

/* AI Icon with glow effect */
.aipb-theme-ai-icon {
    color: var(--aipb-primary);
    filter: drop-shadow(0 0 20px var(--aipb-ring-primary));
    animation: ai-pulse 2s ease-in-out infinite;
}

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

/* Modern spinner animation */
.aipb-theme-loading-spinner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.aipb-theme-spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 2px solid transparent;
    border-radius: 50%;
    animation: ai-spinner-rotate 1.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
}

.aipb-theme-spinner-ring::before,
.aipb-theme-spinner-ring::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    border: 2px solid transparent;
}

.aipb-theme-spinner-ring::before {
    border-top-color: var(--aipb-primary);
    border-right-color: var(--aipb-primary);
    animation: ai-spinner-rotate 2s linear infinite;
}

.aipb-theme-spinner-ring::after {
    border-bottom-color: var(--aipb-primary-hover);
    border-left-color: var(--aipb-primary-hover);
    animation: ai-spinner-rotate 1.5s linear infinite reverse;
    opacity: 0.6;
}

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

/* Additional decorative rings */
.aipb-theme-loading-spinner::before,
.aipb-theme-loading-spinner::after {
    content: '';
    position: absolute;
    border: 1px solid var(--aipb-ring-primary);
    border-radius: 50%;
    animation: ai-ripple 2s ease-out infinite;
}

.aipb-theme-loading-spinner::before {
    width: 100px;
    height: 100px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.aipb-theme-loading-spinner::after {
    width: 120px;
    height: 120px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: 0.5s;
}

@keyframes ai-ripple {
    0% {
        opacity: 0.6;
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.5);
    }
}

/* Loading text */
.aipb-theme-loading-text {
    color: var(--aipb-text-primary);
    font-size: var(--aipb-text-2xl);
    font-weight: var(--aipb-font-semibold);
    margin-bottom: var(--aipb-space-2);
    letter-spacing: -0.025em;
    animation: ai-text-fade 2s ease-in-out infinite;
}

.aipb-theme-loading-subtext {
    color: var(--aipb-text-tertiary);
    font-size: var(--aipb-text-sm);
    animation: ai-text-fade 2s ease-in-out infinite;
    animation-delay: 0.2s;
}

@keyframes ai-text-fade {
    0%, 100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}

/* Dots animation for loading text */
.aipb-theme-loading-dots {
    display: inline-block;
    width: 20px;
    text-align: left;
}

.aipb-theme-loading-dots::after {
    content: '...';
    animation: ai-dots 1.5s steps(4, end) infinite;
}

@keyframes ai-dots {
    0%, 20% {
        content: '';
    }
    40% {
        content: '.';
    }
    60% {
        content: '..';
    }
    80%, 100% {
        content: '...';
    }
}

/* Modern AI Generation Loading */
.aipb-ai-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    background: var(--aipb-bg-secondary);
    border: 1px solid var(--aipb-border);
    border-radius: var(--aipb-radius-xl);
    padding: var(--aipb-space-5) var(--aipb-space-6);
    box-shadow: var(--aipb-shadow-2xl);
    z-index: var(--aipb-z-modal);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    overflow: hidden;
}

.aipb-ai-loading.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.aipb-ai-loading-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* AI Sparkles Icon */
.aipb-ai-sparkles {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--aipb-bg-primary-subtle);
    border-radius: var(--aipb-radius-md);
    animation: ai-sparkle-glow 2s ease-in-out infinite;
}

.aipb-ai-sparkles svg {
    color: var(--aipb-primary);
    animation: ai-sparkle-rotate 3s linear infinite;
}

@keyframes ai-sparkle-glow {
    0%, 100% {
        box-shadow: 0 0 0 transparent;
    }
    50% {
        box-shadow: 0 0 20px var(--aipb-ring-primary);
    }
}

@keyframes ai-sparkle-rotate {
    0% {
        transform: rotate(0deg) scale(1);
    }
    50% {
        transform: rotate(180deg) scale(1.1);
    }
    100% {
        transform: rotate(360deg) scale(1);
    }
}

/* Loading Text */
.aipb-ai-loading-text {
    color: var(--aipb-text-primary);
    font-size: var(--aipb-text-sm);
    font-weight: var(--aipb-font-medium);
    min-width: 200px;
}

.aipb-loading-dots {
    display: inline-block;
    width: 20px;
    text-align: left;
}

.aipb-loading-dots::after {
    content: '';
    animation: loading-dots 1.5s steps(4, end) infinite;
}

@keyframes loading-dots {
    0%, 20% {
        content: '';
    }
    40% {
        content: '.';
    }
    60% {
        content: '..';
    }
    80%, 100% {
        content: '...';
    }
}

/* Progress Bar */
.aipb-ai-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--aipb-bg-primary-subtle);
    overflow: hidden;
}

.aipb-ai-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--aipb-primary) 0%, var(--aipb-primary-hover) 100%);
    width: 0%;
    animation: ai-progress 10s ease-out forwards;
}

@keyframes ai-progress {
    0% {
        width: 0%;
    }
    20% {
        width: 30%;
    }
    40% {
        width: 50%;
    }
    60% {
        width: 70%;
    }
    80% {
        width: 85%;
    }
    100% {
        width: 95%;
    }
}

/* Animazione veloce per il salvataggio */
.aipb-ai-progress-fill-fast {
    animation: ai-progress-fast 1s ease-out forwards !important;
}

@keyframes ai-progress-fast {
    0% {
        width: 0%;
    }
    50% {
        width: 70%;
    }
    100% {
        width: 100%;
    }
}

/* Adjust for admin bar - not needed when centered */

/* Tooltip on hover */
.aipb-element-edit-btn::after,
.aipb-element-delete-btn::after,
.aipb-add-section-btn::after,
.aipb-template-config-btn::after,
.aipb-form-settings-btn::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: var(--aipb-space-2);
    padding: var(--aipb-space-2) var(--aipb-space-3);
    background: var(--aipb-bg-primary);
    color: var(--aipb-text-primary);
    font-size: var(--aipb-text-xs);
    font-weight: var(--aipb-font-medium);
    font-family: var(--aipb-font-primary);
    border-radius: var(--aipb-radius-md);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.aipb-element-edit-btn:hover::after,
.aipb-element-delete-btn:hover::after,
.aipb-add-section-btn:hover::after,
.aipb-template-config-btn:hover::after,
.aipb-form-settings-btn:hover::after {
    opacity: 1;
}

/* Template inline icons - hide them as they're now in the wrapper */
.aipb-template-icon {
    display: none;
}

/* Ensure buttons maintain color in editing mode */
body.aipb-editing-mode .aipb-element-edit-btn {
    color: var(--aipb-primary);
}

body.aipb-editing-mode .aipb-add-section-btn {
    color: #fff;
}

body.aipb-editing-mode .aipb-template-config-btn {
    color: #10B981;
}

body.aipb-editing-mode .aipb-form-settings-btn {
    color: #10B981;
}

/* Add section button - separate from wrapper */
.aipb-add-section-btn {
    position: absolute !important;
    bottom: -15px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 25px !important;
    height: 25px !important;
    background: #4A63EC !important;
    color: white !important;
    border: none;
    border-radius: 50%;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    line-height: 1;
    padding: 0;
}

.aipb-add-section-btn:hover {
    background: var(--aipb-primary-hover);
    transform: translateX(-50%) scale(1.1);
}

/* Show + button on direct element hover only */
body.aipb-editing-mode .aipb-structural-element:hover > .aipb-add-section-btn {
    opacity: 1;
}

/* Keep + button visible when hovering on it */
body.aipb-editing-mode .aipb-add-section-btn:hover {
    opacity: 1;
}

/* Code Editor Button */
.aipb-code-btn {
    background: transparent;
    border: none;
    color: var(--aipb-text-secondary);
    cursor: pointer;
    padding: var(--aipb-space-2);
    font-size: var(--aipb-text-xl);
    transition: var(--aipb-transition);
    border-radius: var(--aipb-radius-md);
    position: relative;
    margin-right: var(--aipb-space-3);
}

.aipb-code-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

.aipb-code-btn.active {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

/* Extra Code Button */
.aipb-extra-code-btn {
    background: transparent;
    border: none;
    color: var(--aipb-text-secondary);
    cursor: pointer;
    padding: var(--aipb-space-2) var(--aipb-space-3);
    font-size: var(--aipb-text-base);
    border-radius: var(--aipb-radius-md);
    transition: var(--aipb-transition);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-1);
    margin-right: var(--aipb-space-3);
}

.aipb-extra-code-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

.aipb-extra-code-btn.active {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

/* Theme Builder Button */
.aipb-theme-builder-btn {
    background: transparent;
    border: none;
    color: var(--aipb-text-secondary);
    cursor: pointer;
    padding: var(--aipb-space-2) var(--aipb-space-3);
    font-size: var(--aipb-text-base);
    border-radius: var(--aipb-radius-md);
    transition: var(--aipb-transition);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-1);
    margin-right: var(--aipb-space-3);
}

.aipb-theme-builder-btn:hover {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

.aipb-theme-builder-btn.active {
    background: var(--aipb-bg-primary-subtle);
    color: var(--aipb-primary);
}

/* Extra Code Panel - Dark Theme */
.aipb-extra-code-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 500px;
    height: 100vh;
    background: var(--aipb-bg-primary);
    box-shadow: var(--aipb-shadow-2xl);
    z-index: var(--aipb-z-modal);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    color: var(--aipb-text-primary);
}

.aipb-extra-code-panel.active {
    transform: translateX(0);
}

.aipb-extra-code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--aipb-space-5);
    border-bottom: 1px solid var(--aipb-border);
    background: var(--aipb-bg-secondary);
}

.aipb-extra-code-title {
    display: flex;
    align-items: center;
    gap: var(--aipb-space-3);
    font-size: var(--aipb-text-lg);
    font-weight: var(--aipb-font-semibold);
    color: var(--aipb-text-primary);
}

.aipb-extra-code-title .dashicons {
    color: var(--aipb-primary);
}

.aipb-extra-code-close {
    background: transparent;
    border: none;
    font-size: var(--aipb-text-2xl);
    cursor: pointer;
    color: var(--aipb-text-tertiary);
    padding: var(--aipb-space-1);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--aipb-radius-sm);
    transition: var(--aipb-transition);
}

.aipb-extra-code-close:hover {
    background: var(--aipb-bg-tertiary);
    color: var(--aipb-text-primary);
}

.aipb-extra-code-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--aipb-space-5);
    background: var(--aipb-bg-primary);
}

.aipb-extra-code-section {
    margin-bottom: 30px;
}

.aipb-extra-code-section h4 {
    margin: 0 0 var(--aipb-space-4) 0;
    font-size: var(--aipb-text-base);
    font-weight: var(--aipb-font-semibold);
    color: var(--aipb-text-primary);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-2);
}

.aipb-extra-code-section h4:before {
    content: '';
    width: 4px;
    height: 16px;
    background: var(--aipb-primary);
    border-radius: 2px;
}

.aipb-extra-code-textarea {
    width: 100%;
    min-height: 250px;
    font-family: var(--aipb-font-mono);
    font-size: var(--aipb-text-sm);
    line-height: 1.5;
    padding: var(--aipb-space-4);
    border: 1px solid var(--aipb-border);
    border-radius: var(--aipb-radius-md);
    background: var(--aipb-bg-secondary);
    color: var(--aipb-text-primary);
    resize: vertical;
}

.aipb-extra-code-textarea:focus {
    outline: none;
    border-color: var(--aipb-primary);
    box-shadow: 0 0 0 3px var(--aipb-ring-primary);
    background: var(--aipb-bg-tertiary);
}

.aipb-extra-code-textarea::placeholder {
    color: var(--aipb-text-tertiary);
    opacity: 1;
}

.aipb-extra-code-footer {
    padding: var(--aipb-space-5);
    border-top: 1px solid var(--aipb-border);
    background: var(--aipb-bg-secondary);
    display: flex;
    gap: var(--aipb-space-3);
    justify-content: flex-end;
}

.aipb-extra-code-footer .aipb-btn {
    padding: var(--aipb-space-3) var(--aipb-space-5);
    border-radius: var(--aipb-radius-md);
    font-size: var(--aipb-text-sm);
    font-weight: var(--aipb-font-medium);
    cursor: pointer;
    transition: var(--aipb-transition);
    border: none;
}

.aipb-extra-code-footer .aipb-btn-primary {
    background: var(--aipb-primary);
    color: white;
}

.aipb-extra-code-footer .aipb-btn-primary:hover {
    background: var(--aipb-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--aipb-shadow-lg);
}

.aipb-extra-code-footer .aipb-btn:not(.aipb-btn-primary) {
    background: var(--aipb-bg-tertiary);
    color: var(--aipb-text-primary);
}

.aipb-extra-code-footer .aipb-btn:not(.aipb-btn-primary):hover {
    background: var(--aipb-bg-secondary);
}

body.admin-bar .aipb-extra-code-panel {
    top: 32px;
    height: calc(100vh - 32px);
}

/* Code Editor Modal */
.aipb-code-editor-content {
    max-width: 90vw;
    width: 1200px;
    height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    background: var(--aipb-bg-primary);
    color: var(--aipb-text-primary);
}

.aipb-code-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: #2d2d2d;
    border-bottom: 1px solid #3e3e3e;
}

.aipb-code-editor-header h3 {
    margin: 0;
    color: var(--aipb-text-primary);
    font-size: var(--aipb-text-lg);
    font-weight: var(--aipb-font-semibold);
}

.aipb-code-editor-close {
    background: transparent;
    border: none;
    color: #999;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.aipb-code-editor-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.aipb-code-editor-body {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.aipb-code-editor-container {
    height: 100%;
}

.aipb-code-editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #2d2d2d;
    border-top: 1px solid #3e3e3e;
}

.aipb-code-editor-info {
    color: #999;
    font-size: 14px;
}

.aipb-code-editor-status {
    display: inline-block;
}

/* CodeMirror Dark Theme Overrides */
.aipb-code-editor-container .CodeMirror {
    height: 100%;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 14px;
}

.aipb-code-editor-container .CodeMirror-gutters {
    background: #2d2d2d;
    border-right: 1px solid #3e3e3e;
}

.aipb-code-editor-container .CodeMirror-linenumber {
    color: #666;
}

.aipb-code-editor-container .CodeMirror-scroll {
    background: #1e1e1e;
}

/* Code Editor Popup Active State */
#aipb-code-editor-popup.active {
    display: flex !important;
}

/* Format Button */
#aipb-code-format {
    background: var(--aipb-bg-tertiary);
    color: var(--aipb-text-primary);
    border: 1px solid var(--aipb-border);
}

#aipb-code-format:hover {
    background: var(--aipb-bg-secondary);
    border-color: var(--aipb-border-hover);
}

/* Save Button in Dark Theme */
.aipb-code-editor-footer .aipb-btn-primary {
    background: linear-gradient(135deg, var(--aipb-primary) 0%, var(--aipb-secondary) 100%);
    border: none;
}

.aipb-code-editor-footer .aipb-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* Cancel Button in Dark Theme */
.aipb-code-editor-footer .aipb-btn {
    background: #3e3e3e;
    color: #e0e0e0;
    border: 1px solid #4e4e4e;
}

.aipb-code-editor-footer .aipb-btn:hover {
    background: var(--aipb-bg-tertiary);
    border-color: var(--aipb-border-hover);
}

/* Header and Footer Templates */
.aipb-header-template,
.aipb-footer-template {
    width: 100%;
    position: relative;
}

/* Template Type Indicator Icon */
.aipb-template-type-indicator {
    background: var(--aipb-bg-primary) !important;
    border: 1px solid var(--aipb-primary) !important;
    color: var(--aipb-primary) !important;
    width: 32px !important;
    height: 32px !important;
    border-radius: var(--aipb-radius-md) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-right: var(--aipb-space-1) !important;
    cursor: default !important;
    flex-shrink: 0 !important;
    box-shadow: 0 0 8px var(--aipb-ring-primary) !important;
    transition: var(--aipb-transition) !important;
}

.aipb-template-type-indicator:hover {
    box-shadow: 0 0 12px var(--aipb-ring-primary) !important;
    border-color: var(--aipb-primary) !important;
}

.aipb-template-type-indicator .dashicons {
    font-size: var(--aipb-text-base) !important;
    width: 16px !important;
    height: 16px !important;
    line-height: 1 !important;
    color: var(--aipb-primary) !important;
}

/* Remove white background from template editor */
body.single-aipb_template {
    background: transparent !important;
}

body.single-aipb_template .aipb-full-width-wrapper {
    background: transparent !important;
}

/* Ensure header appears at the very top */
.aipb-header-template {
    order: -9999;
}

/* Ensure footer appears at the very bottom */
.aipb-footer-template {
    order: 9999;
}

/* When editing header/footer templates */
body.single-aipb_template .aipb-header-template,
body.single-aipb_template .aipb-footer-template {
    min-height: 100px;
    border: 2px dashed var(--aipb-border);
    position: relative;
}

body.single-aipb_template .aipb-header-template::before,
body.single-aipb_template .aipb-footer-template::before {
    content: attr(data-template-type);
    position: absolute;
    top: var(--aipb-space-3);
    left: var(--aipb-space-3);
    background: var(--aipb-bg-secondary);
    color: var(--aipb-text-primary);
    padding: var(--aipb-space-1) var(--aipb-space-3);
    font-size: var(--aipb-text-xs);
    border-radius: var(--aipb-radius-sm);
    text-transform: uppercase;
    z-index: 1;
}

/* Form Settings Popup */
.aipb-form-settings-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--aipb-bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--aipb-z-modal);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.aipb-form-settings-popup.active {
    opacity: 1;
}

.aipb-form-settings-popup .aipb-popup-content {
    background: var(--aipb-bg-primary);
    border-radius: var(--aipb-radius-lg);
    box-shadow: var(--aipb-shadow-2xl);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.aipb-form-settings-popup.active .aipb-popup-content {
    transform: scale(1);
}

.aipb-form-settings-popup .aipb-popup-header {
    background: var(--aipb-bg-secondary);
    padding: var(--aipb-space-5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--aipb-border);
}

.aipb-form-settings-popup .aipb-popup-header h3 {
    margin: 0;
    font-size: var(--aipb-text-lg);
    font-weight: var(--aipb-font-semibold);
    color: var(--aipb-text-primary);
}

.aipb-form-settings-popup .aipb-popup-close {
    background: transparent;
    border: none;
    color: var(--aipb-text-tertiary);
    font-size: var(--aipb-text-2xl);
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--aipb-radius-sm);
    transition: var(--aipb-transition);
}

.aipb-form-settings-popup .aipb-popup-close:hover {
    background: var(--aipb-bg-tertiary);
    color: var(--aipb-text-primary);
}

.aipb-form-settings-popup .aipb-popup-body {
    padding: var(--aipb-space-8);
    overflow-y: auto;
    flex: 1;
}

.aipb-form-settings-popup .aipb-form-field {
    margin-bottom: 25px;
}

.aipb-form-settings-popup .aipb-form-field:last-child {
    margin-bottom: 0;
}

.aipb-form-settings-popup .aipb-form-field label {
    display: block;
    margin-bottom: var(--aipb-space-2);
    font-size: var(--aipb-text-sm);
    font-weight: var(--aipb-font-medium);
    color: var(--aipb-text-primary);
}

.aipb-form-settings-popup .aipb-form-field input {
    width: 100%;
    padding: var(--aipb-space-3) var(--aipb-space-4);
    background: var(--aipb-bg-secondary);
    border: 1px solid var(--aipb-border);
    border-radius: var(--aipb-radius-md);
    color: var(--aipb-text-primary);
    font-size: var(--aipb-text-sm);
    transition: var(--aipb-transition);
}

.aipb-form-settings-popup .aipb-form-field input:focus {
    outline: none;
    border-color: var(--aipb-primary);
    background: var(--aipb-bg-tertiary);
}

.aipb-form-settings-popup .aipb-form-field .description {
    margin-top: var(--aipb-space-2);
    font-size: var(--aipb-text-xs);
    color: var(--aipb-text-tertiary);
    font-style: italic;
}

.aipb-form-settings-popup .aipb-popup-footer {
    background: var(--aipb-bg-secondary);
    padding: var(--aipb-space-5);
    border-top: 1px solid var(--aipb-border);
    display: flex;
    gap: var(--aipb-space-3);
    justify-content: flex-end;
}

.aipb-form-settings-popup .aipb-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.aipb-form-settings-popup .aipb-btn-primary {
    background: var(--aipb-primary);
    color: white;
}

.aipb-form-settings-popup .aipb-btn-primary:hover {
    background: var(--aipb-primary-hover);
}

.aipb-form-settings-popup .aipb-btn-secondary {
    background: var(--aipb-bg-tertiary);
    color: var(--aipb-text-primary);
}

.aipb-form-settings-popup .aipb-btn-secondary:hover {
    background: var(--aipb-bg-secondary);
}

/* Form section styles */
.aipb-form-settings-popup .aipb-form-section {
    margin-top: var(--aipb-space-8);
    padding-top: var(--aipb-space-6);
    border-top: 1px solid var(--aipb-border);
}

.aipb-form-settings-popup .aipb-form-section h4 {
    margin: 0 0 var(--aipb-space-5) 0;
    font-size: var(--aipb-text-base);
    font-weight: var(--aipb-font-semibold);
    color: var(--aipb-text-primary);
}

.aipb-form-settings-popup .aipb-checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: var(--aipb-text-sm);
    color: var(--aipb-text-primary);
}

/* Link Manager Popup - Modern Style */
.aipb-link-manager-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--aipb-bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--aipb-z-modal);
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
}

.aipb-link-manager-popup.active {
    opacity: 1;
}

.aipb-link-manager-popup .aipb-popup-content {
    background: var(--aipb-bg-primary);
    border-radius: var(--aipb-radius-xl);
    border: 1px solid var(--aipb-border);
    box-shadow: var(--aipb-shadow-2xl);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.aipb-link-manager-popup.active .aipb-popup-content {
    transform: scale(1);
}

.aipb-link-manager-popup .aipb-popup-header {
    background: var(--aipb-bg-secondary);
    padding: var(--aipb-space-6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--aipb-border);
}

.aipb-link-manager-popup .aipb-popup-header h3 {
    margin: 0;
    font-size: var(--aipb-text-xl);
    font-weight: var(--aipb-font-semibold);
    color: var(--aipb-text-primary);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-3);
}

.aipb-link-manager-popup .aipb-popup-header h3 i {
    font-size: 24px;
    color: var(--aipb-primary);
}

.aipb-link-manager-popup .aipb-popup-close {
    background: transparent;
    border: none;
    color: var(--aipb-text-tertiary);
    font-size: var(--aipb-text-2xl);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--aipb-radius-md);
    transition: var(--aipb-transition);
}

.aipb-link-manager-popup .aipb-popup-close:hover {
    background: var(--aipb-bg-tertiary);
    color: var(--aipb-text-primary);
}

.aipb-link-manager-popup .aipb-popup-body {
    padding: var(--aipb-space-6);
    overflow-y: auto;
    flex: 1;
}

/* Modern Tabs */
.aipb-tabs {
    display: flex;
    gap: var(--aipb-space-2);
    margin-bottom: var(--aipb-space-6);
    background: var(--aipb-bg-secondary);
    padding: var(--aipb-space-2);
    border-radius: var(--aipb-radius-lg);
}

.aipb-tab {
    flex: 1;
    padding: var(--aipb-space-3) var(--aipb-space-4);
    background: transparent;
    border: none;
    border-radius: var(--aipb-radius-md);
    color: var(--aipb-text-secondary);
    font-size: var(--aipb-text-sm);
    font-weight: var(--aipb-font-medium);
    cursor: pointer;
    transition: var(--aipb-transition);
    position: relative;
}

.aipb-tab:hover {
    color: var(--aipb-text-primary);
}

.aipb-tab.active {
    background: var(--aipb-bg-primary);
    color: var(--aipb-primary);
    box-shadow: var(--aipb-shadow-sm);
}

.aipb-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 3px;
    background: var(--aipb-primary);
    border-radius: 3px;
}

/* Tab Content */
.aipb-tab-content {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Form Fields */
.aipb-link-manager-popup .aipb-form-field {
    margin-bottom: var(--aipb-space-5);
}

.aipb-link-manager-popup .aipb-form-field:last-child {
    margin-bottom: 0;
}

.aipb-link-manager-popup .aipb-form-field label {
    display: block;
    margin-bottom: var(--aipb-space-2);
    font-size: var(--aipb-text-sm);
    font-weight: var(--aipb-font-medium);
    color: var(--aipb-text-primary);
}

.aipb-link-manager-popup .aipb-form-field input,
.aipb-link-manager-popup .aipb-form-field select {
    width: 100%;
    padding: var(--aipb-space-3) var(--aipb-space-4);
    background: var(--aipb-bg-secondary);
    border: 1px solid var(--aipb-border);
    border-radius: var(--aipb-radius-md);
    color: var(--aipb-text-primary);
    font-size: var(--aipb-text-sm);
    transition: var(--aipb-transition);
}

.aipb-link-manager-popup .aipb-form-field input:focus,
.aipb-link-manager-popup .aipb-form-field select:focus {
    outline: none;
    border-color: var(--aipb-primary);
    background: var(--aipb-bg-tertiary);
    box-shadow: 0 0 0 3px var(--aipb-ring-primary);
}

/* Search Results */
.aipb-search-results {
    margin-top: var(--aipb-space-3);
    background: var(--aipb-bg-secondary);
    border: 1px solid var(--aipb-border);
    border-radius: var(--aipb-radius-md);
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.aipb-search-results.active {
    display: block;
}

.aipb-search-result {
    padding: var(--aipb-space-3) var(--aipb-space-4);
    cursor: pointer;
    transition: var(--aipb-transition);
    border-bottom: 1px solid var(--aipb-border);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-3);
}

.aipb-search-result:last-child {
    border-bottom: none;
}

.aipb-search-result:hover {
    background: var(--aipb-bg-tertiary);
}

.aipb-search-result-thumb {
    width: 40px;
    height: 40px;
    border-radius: var(--aipb-radius-sm);
    object-fit: cover;
    flex-shrink: 0;
}

.aipb-search-result-info {
    flex: 1;
}

.aipb-search-result-title {
    font-size: var(--aipb-text-sm);
    font-weight: var(--aipb-font-medium);
    color: var(--aipb-text-primary);
    margin-bottom: 2px;
}

.aipb-search-result-type {
    font-size: var(--aipb-text-xs);
    color: var(--aipb-text-tertiary);
    text-transform: capitalize;
}

/* Selected Content Display */
.aipb-selected-content-info {
    background: var(--aipb-bg-secondary);
    border: 1px solid var(--aipb-border);
    border-radius: var(--aipb-radius-md);
    padding: var(--aipb-space-4);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-3);
}

.aipb-selected-content-info .aipb-selected-thumb {
    width: 50px;
    height: 50px;
    border-radius: var(--aipb-radius-sm);
    object-fit: cover;
    flex-shrink: 0;
}

.aipb-selected-content-info .aipb-selected-details {
    flex: 1;
}

.aipb-selected-content-info .aipb-selected-title {
    font-size: var(--aipb-text-base);
    font-weight: var(--aipb-font-medium);
    color: var(--aipb-text-primary);
    margin-bottom: 2px;
}

.aipb-selected-content-info .aipb-selected-type {
    font-size: var(--aipb-text-sm);
    color: var(--aipb-text-tertiary);
}

/* Remove Link Button */
.aipb-btn-danger {
    background: var(--aipb-danger);
    color: white;
}

.aipb-btn-danger:hover {
    background: var(--aipb-danger-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Popup Footer */
.aipb-link-manager-popup .aipb-popup-footer {
    background: var(--aipb-bg-secondary);
    padding: var(--aipb-space-5);
    border-top: 1px solid var(--aipb-border);
    display: flex;
    gap: var(--aipb-space-3);
    justify-content: flex-end;
}

/* Link indicator for elements with links */
.aipb-element-link-btn.aipb-has-link {
    color: var(--aipb-primary) !important;
}

.aipb-element-link-btn.aipb-has-link::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 6px;
    height: 6px;
    background: var(--aipb-success);
    border-radius: 50%;
    box-shadow: 0 0 0 2px var(--aipb-bg-primary);
}

.aipb-form-settings-popup .aipb-checkbox-label input[type="checkbox"] {
    width: auto;
    margin-right: 10px;
    cursor: pointer;
}

.aipb-form-settings-popup textarea {
    width: 100%;
    padding: var(--aipb-space-3) var(--aipb-space-4);
    background: var(--aipb-bg-secondary);
    border: 1px solid var(--aipb-border);
    border-radius: var(--aipb-radius-md);
    color: var(--aipb-text-primary);
    font-size: var(--aipb-text-sm);
    resize: vertical;
    min-height: 80px;
    transition: var(--aipb-transition);
}

.aipb-form-settings-popup textarea:focus {
    outline: none;
    border-color: var(--aipb-primary);
    background: var(--aipb-bg-tertiary);
}

.aipb-thanks-fields {
    margin-top: 15px;
}

/* Search Settings Popup - Reuse form popup styles */
.aipb-search-settings-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.aipb-search-settings-popup.active {
    opacity: 1;
}

.aipb-search-settings-popup .aipb-popup-content {
    background: #1e1e1e;
    border-radius: var(--aipb-radius);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.aipb-search-settings-popup.active .aipb-popup-content {
    transform: scale(1);
}

/* Reuse all form popup styles for consistency */
.aipb-search-settings-popup .aipb-popup-header,
.aipb-search-settings-popup .aipb-popup-body,
.aipb-search-settings-popup .aipb-popup-footer,
.aipb-search-settings-popup .aipb-form-field,
.aipb-search-settings-popup .aipb-btn {
    /* Inherit styles from form popup */
}

/* Checkbox group for search types */
.aipb-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.aipb-checkbox-group .aipb-checkbox-label {
    margin: 0;
}

/* Template Config Popup */
#aipb-template-config-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#aipb-template-config-popup.active {
    display: flex !important;
    opacity: 1;
}

#aipb-template-config-popup .aipb-popup-content {
    background: #1e1e1e;
    border-radius: var(--aipb-radius);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: auto;
    padding: 30px;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

#aipb-template-config-popup.active .aipb-popup-content {
    transform: scale(1);
}

#aipb-template-config-popup h3 {
    margin: 0 0 25px 0;
    font-size: 20px;
    font-weight: 600;
    color: #fff;
}

#aipb-template-config-popup .aipb-popup-field {
    margin-bottom: 20px;
}

#aipb-template-config-popup .aipb-popup-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #e0e0e0;
}

#aipb-template-config-popup .aipb-popup-field select,
#aipb-template-config-popup .aipb-popup-field input {
    width: 100%;
    padding: 10px 15px;
    background: #2e2e2e;
    border: 1px solid #3e3e3e;
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    transition: all 0.2s;
}

#aipb-template-config-popup .aipb-popup-field select:focus,
#aipb-template-config-popup .aipb-popup-field input:focus {
    outline: none;
    border-color: #6366f1;
    background: #363636;
}

#aipb-template-config-popup .aipb-popup-field select[multiple] {
    min-height: 120px;
}

#aipb-template-config-popup .aipb-popup-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #3e3e3e;
}

#aipb-template-config-popup .aipb-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

#aipb-template-config-popup .aipb-btn-primary {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

#aipb-template-config-popup .aipb-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

#aipb-template-config-popup .aipb-btn-secondary {
    background: #3e3e3e;
    color: #e0e0e0;
}

#aipb-template-config-popup .aipb-btn-secondary:hover {
    background: #4e4e4e;
}

/* Link Manager Popup */
.aipb-link-manager-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.aipb-link-manager-popup.active {
    opacity: 1;
}

.aipb-link-manager-popup .aipb-popup-content {
    background: #1e1e1e;
    border-radius: var(--aipb-radius);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow: visible;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.aipb-link-manager-popup.active .aipb-popup-content {
    transform: scale(1);
}

.aipb-link-manager-popup .aipb-popup-header {
    background: #2d2d2d;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #3e3e3e;
}

.aipb-link-manager-popup .aipb-popup-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #cccccc;
}

.aipb-link-manager-popup .aipb-popup-close {
    background: transparent;
    border: none;
    color: #999;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.aipb-link-manager-popup .aipb-popup-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.aipb-link-manager-popup .aipb-popup-body {
    padding: 30px;
    overflow-y: auto;
    overflow-x: visible;
    flex: 1;
}

.aipb-link-manager-popup .aipb-form-field {
    margin-bottom: 25px;
    position: relative;
}

.aipb-link-manager-popup .aipb-form-field:last-child {
    margin-bottom: 0;
}

.aipb-link-manager-popup .aipb-form-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #cccccc;
}

.aipb-link-manager-popup .aipb-form-field input,
.aipb-link-manager-popup .aipb-form-field select {
    width: 100%;
    padding: 10px 15px;
    background: #2d2d2d;
    border: 1px solid #3e3e3e;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 14px;
    transition: all 0.2s;
}

.aipb-link-manager-popup .aipb-form-field input:focus,
.aipb-link-manager-popup .aipb-form-field select:focus {
    outline: none;
    border-color: var(--aipb-primary);
    background: #252525;
}

/* Tabs */
.aipb-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #3e3e3e;
}

.aipb-tab {
    background: transparent;
    border: 1px solid #3e3e3e;
    color: #999;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.aipb-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
}

.aipb-tab.active {
    background: var(--aipb-primary);
    border-color: var(--aipb-primary);
    color: white;
}

/* Search Results */
.aipb-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 5px;
    max-height: 200px;
    overflow-y: auto;
    background: #2d2d2d;
    border: none;
    border-radius: 6px;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.aipb-search-results:not(:empty) {
    padding: 5px 0;
}

/* Form field containing search results needs extra margin */
.aipb-form-field.has-search-results {
    margin-bottom: 20px;
}

/* Search Settings Popup */
.aipb-search-settings-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 200000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.aipb-search-settings-popup.active {
    display: flex;
}

.aipb-search-settings-popup .aipb-popup-content {
    background: #1a1a1a;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform 0.2s;
}

.aipb-search-settings-popup.active .aipb-popup-content {
    transform: scale(1);
}

.aipb-search-settings-popup .aipb-popup-header {
    background: #2d2d2d;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #3e3e3e;
}

.aipb-search-settings-popup .aipb-popup-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #e0e0e0;
}

.aipb-search-settings-popup .aipb-popup-close {
    background: transparent;
    border: none;
    color: #999;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.aipb-search-settings-popup .aipb-popup-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.aipb-search-settings-popup .aipb-popup-body {
    padding: 30px;
    overflow-y: auto;
    flex: 1;
}

.aipb-search-settings-popup .aipb-form-field {
    margin-bottom: 25px;
}

.aipb-search-settings-popup .aipb-form-field:last-child {
    margin-bottom: 0;
}

.aipb-search-settings-popup .aipb-form-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #cccccc;
}

.aipb-search-settings-popup .aipb-form-field input[type="text"],
.aipb-search-settings-popup .aipb-form-field input[type="number"] {
    width: 100%;
    padding: 10px 15px;
    background: #2d2d2d;
    border: 1px solid #3e3e3e;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 14px;
    transition: all 0.2s;
}

.aipb-search-settings-popup .aipb-form-field input:focus {
    outline: none;
    border-color: var(--aipb-primary);
    background: #252525;
}

/* Checkbox styling for search settings */
.aipb-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.aipb-checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.aipb-checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    background: #2d2d2d;
    border: 1px solid #3e3e3e;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    appearance: none;
    -webkit-appearance: none;
}

.aipb-checkbox-item input[type="checkbox"]:checked {
    background: var(--aipb-primary);
    border-color: var(--aipb-primary);
}

.aipb-checkbox-item input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 6px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.aipb-checkbox-item label {
    margin: 0 !important;
    font-size: 14px;
    color: #e0e0e0;
    cursor: pointer;
    font-weight: normal !important;
}

/* Description text in popups */
p.description {
    color: white;
    font-size: 13px;
    margin-top: 5px;
}

/* Popup footer */
.aipb-popup-footer {
    padding: 20px 30px;
    background: #2d2d2d;
    border-top: 1px solid #3e3e3e;
    display: flex;
    gap: 15px;
    justify-content: flex-end;
}

.aipb-popup-footer button {
    padding: 10px 25px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.aipb-popup-footer .aipb-btn-primary {
    background: var(--aipb-primary);
    color: white;
}

.aipb-popup-footer .aipb-btn-primary:hover {
    background: var(--aipb-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.aipb-popup-footer .aipb-btn-secondary {
    background: #3e3e3e;
    color: #e0e0e0;
}

.aipb-popup-footer .aipb-btn-secondary:hover {
    background: #4a4a4a;
}

.aipb-search-result {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #3e3e3e;
    transition: background 0.2s;
    background: #1a1a1a;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.aipb-search-result:last-child {
    border-bottom: none;
}

.aipb-search-result:hover {
    background: rgba(99, 102, 241, 0.1);
}

.aipb-result-title {
    font-size: 14px;
    font-weight: 500;
    color: #e0e0e0;
    margin-bottom: 4px;
}

.aipb-result-excerpt {
    font-size: 12px;
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.aipb-loading-small {
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 14px;
}

.aipb-loading-small .spinner {
    display: inline-block;
    float: none;
    margin: 0 5px 0 0;
    visibility: visible;
}

.aipb-no-results,
.aipb-error {
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 14px;
}

.aipb-selected-content-info {
    padding: 10px 15px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 6px;
    color: #e0e0e0;
}

/* Visual indicator for elements with links */
.aipb-has-link {
    position: relative;
}

/* Show link icon only in editor mode */
body.aipb-editing-mode .aipb-has-link::after {
    content: '\f103';
    font-family: dashicons;
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--aipb-primary);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    opacity: 0.8;
    pointer-events: none;
    z-index: 999;
}

/* Fix for duplicate link icons in text elements */
/* Let Unicons handle the icon naturally - no forced content */

/* Remove any duplicate ::before on parent button */
.aipb-text-link-btn::before {
    content: none !important;
    display: none !important;
}

/* Ensure text element buttons have proper colors */
.aipb-text-edit-btn,
.aipb-text-link-btn,
.aipb-text-delete-btn {
    color: var(--aipb-text-primary) !important;
}

.aipb-text-edit-btn:hover,
.aipb-text-link-btn:hover,
.aipb-text-delete-btn:hover {
    color: white !important;
}

/* Dynamic link styles for frontend */
.aipb-has-dynamic-link {
    cursor: pointer;
    transition: opacity 0.2s ease;
}

/* Link icon for images - using ::before to avoid conflict with ::after */
body.aipb-editing-mode .aipb-image-wrapper.aipb-has-image-link {
    position: relative;
}

body.aipb-editing-mode .aipb-image-wrapper.aipb-has-image-link::before {
    content: '\f103';
    font-family: dashicons;
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--aipb-primary);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    opacity: 0.8;
    pointer-events: none;
    z-index: 2; /* Higher than overlay (1) but lower than buttons (3) */
    transform: none; /* Override any inherited transform */
    padding: 0; /* Override any inherited padding */
    left: auto; /* Override any inherited left position */
    white-space: normal; /* Override white-space */
}

.aipb-has-dynamic-link:hover {
    opacity: 0.8;
}

/* Popup Footer */
.aipb-link-manager-popup .aipb-popup-footer {
    background: #2d2d2d;
    padding: 20px;
    border-top: 1px solid #3e3e3e;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Button styles in popup */
.aipb-link-manager-popup .aipb-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.aipb-link-manager-popup .aipb-btn-primary {
    background: var(--aipb-primary);
    color: white;
}

.aipb-link-manager-popup .aipb-btn-primary:hover {
    background: var(--aipb-primary-dark);
}

.aipb-link-manager-popup .aipb-btn-secondary {
    background: #3e3e3e;
    color: #e0e0e0;
}

.aipb-link-manager-popup .aipb-btn-secondary:hover {
    background: #4a4a4a;
}

.aipb-link-manager-popup .aipb-btn-danger {
    background: var(--aipb-error);
    color: white;
}

.aipb-link-manager-popup .aipb-btn-danger:hover {
    background: #dc2626;
}

/* Drag and Drop Styles */
.aipb-drag-placeholder {
    background: rgba(99, 102, 241, 0.05);
    border: 2px dashed rgba(99, 102, 241, 0.3);
    border-radius: 8px;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

/* Clone element for dragging - more stable */
.aipb-drag-clone {
    cursor: move !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

/* Original element while dragging - more specific */
.aipb-structural-element.aipb-dragging,
.aipb-text-element.aipb-dragging {
    opacity: 0.1 !important;
    transition: opacity 0.2s;
}

/* Ensure drag handle cursor is always move */
.aipb-drag-handle {
    cursor: move !important;
}

/* Ensure no overlay during drag */
body.aipb-dragging {
    background: transparent !important;
}

body.aipb-dragging::before,
body.aipb-dragging::after {
    display: none !important;
}

/* Remove any potential overlays from wrapper elements */
body.aipb-dragging .aipb-content-wrapper,
body.aipb-dragging .aipb-page-content-wrapper,
body.aipb-dragging .entry-content,
body.aipb-dragging .page-content,
body.aipb-dragging .post-content,
body.aipb-dragging main {
    background: transparent !important;
}

body.aipb-dragging .aipb-content-wrapper::before,
body.aipb-dragging .aipb-content-wrapper::after,
body.aipb-dragging .aipb-page-content-wrapper::before,
body.aipb-dragging .aipb-page-content-wrapper::after {
    display: none !important;
}

/* Highlight drop zones on drag - only outline, no opacity changes */
body.aipb-dragging .aipb-structural-element:not(.aipb-dragging):hover,
body.aipb-dragging .aipb-text-element:not(.aipb-dragging):hover {
    outline: 2px solid var(--aipb-primary);
    outline-offset: 2px;
}

/* Hidden wrapper state */
.aipb-wrapper-hidden {
    display: none !important;
}

/* Show wrapper button */
.aipb-show-wrapper-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    background: rgba(147, 51, 234, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    transition: all 0.2s;
    opacity: 0.7;
}

.aipb-show-wrapper-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.aipb-show-wrapper-btn::before {
    content: "\e8f4"; /* uil-eye-slash */
    font-family: 'unicons-line';
    font-size: 14px;
    line-height: 1;
}

/* Header/Footer template overlay styles */
.aipb-header-template,
.aipb-footer-template {
    position: relative !important;
}

/* Interactive overlay for header/footer */
.aipb-template-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--aipb-bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999; /* Ridotto per non coprire la barra dei prompt che ha z-index 2147483647 */
    opacity: 0;
    transition: opacity 0.3s ease;
    cursor: pointer;
}

body.aipb-editing-mode .aipb-header-template:hover .aipb-template-overlay,
body.aipb-editing-mode .aipb-footer-template:hover .aipb-template-overlay {
    opacity: 1;
}

.aipb-template-overlay-content {
    background: var(--aipb-bg-primary);
    color: var(--aipb-text-primary);
    padding: var(--aipb-space-4) var(--aipb-space-8);
    border-radius: var(--aipb-radius-lg);
    font-size: var(--aipb-text-lg);
    font-weight: var(--aipb-font-semibold);
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: var(--aipb-shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--aipb-space-3);
    transition: transform 0.2s ease;
}

.aipb-template-overlay:hover .aipb-template-overlay-content {
    transform: scale(1.05);
}

.aipb-template-overlay-content::before {
    content: "\e905"; /* uil-edit */
    font-family: 'unicons-line';
    font-size: 24px;
    line-height: 1;
}

/* Ensure elements inside header/footer are not editable in edit mode */
body.aipb-editing-mode .aipb-header-template [data-aipb-id],
body.aipb-editing-mode .aipb-footer-template [data-aipb-id],
body.aipb-editing-mode .aipb-header-template .aipb-text-element,
body.aipb-editing-mode .aipb-footer-template .aipb-text-element,
body.aipb-editing-mode .aipb-header-template .aipb-structural-element,
body.aipb-editing-mode .aipb-footer-template .aipb-structural-element {
    pointer-events: none !important;
    cursor: default !important;
}

/* Remove any edit buttons that might appear */
body.aipb-editing-mode .aipb-header-template .aipb-element-buttons,
body.aipb-editing-mode .aipb-footer-template .aipb-element-buttons,
body.aipb-editing-mode .aipb-header-template .aipb-reset-btn,
body.aipb-editing-mode .aipb-footer-template .aipb-reset-btn,
body.aipb-editing-mode .aipb-header-template .aipb-element-edit-btn,
body.aipb-editing-mode .aipb-footer-template .aipb-element-edit-btn,
body.aipb-editing-mode .aipb-header-template .aipb-element-delete-btn,
body.aipb-editing-mode .aipb-footer-template .aipb-element-delete-btn {
    display: none !important;
}

/* Fix for AI loading popup background in mobile */
@media (max-width: 768px) {
    .aipb-ai-loading {
        background: #252525 !important;
        background: var(--aipb-bg-secondary, #252525) !important;
    }
    
    .aipb-ai-loading-content {
        color: #ffffff;
    }
    
    .aipb-ai-loading-text {
        color: var(--aipb-text-secondary, #e0e0e0);
    }
}

/* Purple highlight animation for control buttons */
@keyframes aipb-control-pulse {
    0% {
        opacity: 0;
        transform: scale(0.95);
    }
    50% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(1.05);
    }
}