/**
 * Kadence Block Builder & Gutenberg Compatibility Styles
 * 
 * This file ensures NBN plugin styles are properly scoped and don't
 * interfere with Kadence blocks or the Gutenberg editor.
 */

/* Ensure NBN plugin styles don't affect Kadence blocks */
.nbn-plugin-wrapper {
    /* Create a new stacking context to contain z-index values */
    position: relative;
    z-index: 1;
}

/* Scope all NBN elements within the plugin wrapper */
.nbn-plugin-wrapper * {
    /* Reset box-sizing to prevent inheritance issues */
    box-sizing: border-box;
}

/* Prevent NBN styles from affecting Kadence blocks */
.kt-blocks-wrap .nbn-plugin-wrapper,
.kadence-blocks-wrap .nbn-plugin-wrapper,
.wp-block .nbn-plugin-wrapper {
    /* Isolate NBN content from block editor styles */
    isolation: isolate;
}

/* Fix for editor context - hide NBN overlays in editor */
.block-editor-page .nbn-progress-overlay,
.edit-post-layout .nbn-progress-overlay,
.editor-styles-wrapper .nbn-progress-overlay,
.block-editor-page .nbn-loading-overlay,
.edit-post-layout .nbn-loading-overlay,
.editor-styles-wrapper .nbn-loading-overlay {
    display: none !important;
}

/* Ensure NBN modals don't interfere with Kadence/Gutenberg UI */
.nbn-modal-overlay {
    /* Keep z-index reasonable for frontend but not blocking editor */
    z-index: 999;
}

/* In editor context, reduce modal z-index further */
.block-editor-page .nbn-modal-overlay,
.edit-post-layout .nbn-modal-overlay {
    z-index: 99;
}

/* Prevent NBN fixed elements from overlaying editor UI */
.block-editor-page .nbn-fixed-element,
.edit-post-layout .nbn-fixed-element,
.editor-styles-wrapper .nbn-fixed-element {
    position: relative !important;
}

/* Scope form elements to prevent conflicts */
.nbn-plugin-wrapper input[type='text'],
.nbn-plugin-wrapper input[type='email'],
.nbn-plugin-wrapper input[type='tel'],
.nbn-plugin-wrapper select,
.nbn-plugin-wrapper textarea {
    /* Use inherit to respect parent styles when in Kadence blocks */
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

/* Prevent NBN button styles from affecting Kadence buttons */
.kt-blocks-btn .nbn-plugin-wrapper button,
.wp-block-kadence-advancedbtn .nbn-plugin-wrapper button {
    /* Reset to initial to prevent style inheritance */
    all: initial;

    /* Then apply minimal required styles */
    cursor: pointer;
    display: inline-block;
}

/* Ensure NBN grids don't break Kadence layouts */
.kt-blocks-wrap .nbn-plans-grid,
.kadence-row-layout-wrap .nbn-plans-grid {
    /* Use auto-fit instead of fixed columns in Kadence context */
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

/* Fix potential flexbox conflicts */
.kt-blocks-wrap .nbn-plugin-wrapper .flex-container,
.kadence-blocks-wrap .nbn-plugin-wrapper .flex-container {
    /* Reset flex properties that might conflict */
    flex: initial;
}

/* Ensure NBN tooltips appear above Kadence elements */
.nbn-tooltip {
    z-index: 999;

    /* But not in editor */
}

.block-editor-page .nbn-tooltip,
.edit-post-layout .nbn-tooltip {
    z-index: 1;
}

/* Compatibility for responsive styles */
@media (max-width: 768px) {
    /* Ensure NBN mobile styles don't affect Kadence mobile layouts */
    .kt-blocks-wrap .nbn-plugin-wrapper,
    .kadence-blocks-wrap .nbn-plugin-wrapper {
        /* Prevent width overflow on mobile */
        max-width: 100%;
        overflow-x: hidden;
    }
}

/* Special handling for NBN shortcodes within Kadence columns */
.wp-block-kadence-column .nbn-plugin-wrapper {
    /* Ensure proper width inheritance */
    width: 100%;
    max-width: 100%;
}

/* Fix for potential JavaScript-added styles */
.nbn-plugin-wrapper [style*='z-index'] {
    /* Cap inline z-index values */
    z-index: 999 !important;
}

/* Editor-specific fixes */
.editor-styles-wrapper .nbn-plugin-wrapper {
    /* Prevent style bleed in editor preview */
    contain: layout style;
}
