/**
 * Custom HTML Block Editor Modal Styles
 * 
 * High-priority z-index overrides to ensure our modals are always on top
 */

/* Force our modal overlays above everything including theme headers/navbars */
.xi-html-editor-overlay,
.xi-styling-modal-overlay {
    z-index: 150000 !important; /* Below WordPress Media Modal (159900) */
}

.xi-html-editor-modal,
.xi-styling-modal {
    z-index: 150001 !important; /* Below WordPress Media Modal */
}

/* Force any loading overlays above modal content */
.xi-save-overlay,
.xi-modal-loading-overlay {
    z-index: 150002 !important; /* Still below WordPress Media Modal */
}

/* Modal Overlay */
.xi-html-editor-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999999;
    display: none;
}

/* Modal Container */
.xi-html-editor-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    height: 80vh;
    max-height: 800px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 999998;
    display: flex;
    flex-direction: column;
}

/* Modal Header */
.xi-html-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px;
    border-bottom: 1px solid #ddd;
    background: #f8f9fa;
}

.xi-header-content {
    flex: 1;
}

.xi-save-workflow-info {
    color: #0073aa;
    font-size: 12px;
    margin-top: 5px;
    font-weight: 500;
}

.xi-save-workflow-info .dashicons {
    font-size: 14px;
    vertical-align: middle;
}

.xi-html-editor-header h3 {
    margin: 0;
    color: #333;
    font-size: 18px;
}

.xi-html-editor-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.xi-html-editor-close:hover {
    background: #e9ecef;
    color: #333;
}

/* Modal Body */
.xi-html-editor-body {
    padding: 15px 20px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    box-sizing: border-box;
}

/* Content Type Tabs */
.xi-content-type-tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin-bottom: 20px;
}

.xi-content-type-tab {
    padding: 12px 20px;
    border: none;
    background: none;
    cursor: pointer;
    color: #666;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.3s;
}

.xi-content-type-tab:hover {
    color: #333;
    background: #f8f9fa;
}

.xi-content-type-tab.active {
    color: #0073aa;
    border-bottom-color: #0073aa;
}

/* Content Panels */
.xi-content-panel {
    display: none;
}

.xi-content-panel.active {
    display: block;
}

/* Form Fields */
.xi-field-group {
    margin-bottom: 15px;
}

.xi-field-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.xi-field-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    min-width: 0;
}

.xi-field-textarea {
    width: 100%;
    min-height: 200px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    resize: vertical;
}

.xi-field-help {
    margin-top: 5px;
    font-size: 12px;
    color: #666;
    font-style: italic;
}

/* WordPress Editor Container */
.xi-wp-editor-container {
    border: 1px solid #ddd;
    border-radius: 4px;
}

.xi-wp-editor-container .wp-editor-wrap {
    margin: 0;
}

/* Link Fields */
.xi-link-fields {
    display: grid;
    grid-template-columns: 1fr 150px 120px;
    gap: 10px;
    align-items: end;
}

.xi-link-target-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.xi-link-target-group input[type="checkbox"] {
    margin: 0;
}

/* Media Button */
.xi-media-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #0073aa;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 13px;
    margin-top: 10px;
    cursor: pointer;
    border: none;
}

.xi-media-button:hover {
    background: #005a87;
    color: white;
}

.xi-media-button .dashicons {
    font-size: 16px;
}

/* Modal Footer */
.xi-html-editor-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 15px 20px;
    border-top: 1px solid #ddd;
    background: #f8f9fa;
    flex-shrink: 0;
}

.xi-element-info {
    flex: 1;
    color: #666;
    font-size: 12px;
}

.xi-save-info {
    margin-top: 5px;
    color: #0073aa;
    font-size: 11px;
}

.xi-save-info .dashicons {
    font-size: 14px;
    vertical-align: middle;
}

.xi-html-editor-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.xi-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Button classes removed - now inherited from admin.css */

/* Remaining button classes removed - now inherited from admin.css */

.xi-btn-danger {
    background: #dc3545;
    color: white;
}

.xi-btn-danger:hover {
    background: #c82333;
}

/* Zone Element Layout Updates */
.xi-zone-element {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 8px !important;
    position: relative !important;
}

.xi-element-name {
    flex: 1 !important;
}

.xi-element-actions {
    display: flex !important;
    align-items: center !important;
    gap: 15px !important;
    margin-left: auto !important;
    padding-left: 10px !important;
}

/* Element Edit Button - Always Visible */
.xi-element-edit-btn {
    background: transparent !important;
    color: #0073aa !important;
    border: 1px solid #ddd !important;
    border-radius: 3px !important;
    width: 26px !important;
    height: 26px !important;
    cursor: pointer !important;
    font-size: 14px !important;
    line-height: 1 !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: static !important;
    margin: 0 !important;
    transition: all 0.2s ease !important;
}

.xi-element-edit-btn:hover {
    background: #f0f8ff !important;
    border-color: #0073aa !important;
    color: #005a87 !important;
}

/* Element Style Button - Always Visible */
.xi-element-style-btn {
    background: transparent !important;
    color: #666 !important;
    border: 1px solid #ddd !important;
    border-radius: 3px !important;
    width: 26px !important;
    height: 26px !important;
    cursor: pointer !important;
    font-size: 14px !important;
    line-height: 1 !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: static !important;
    margin: 0 !important;
    transition: all 0.2s ease !important;
}

.xi-element-style-btn:hover {
    background: #f5f5f5 !important;
    border-color: #666 !important;
    color: #333 !important;
}

/* Remove Button */
.xi-remove-element {
    background: #dc3545 !important;
    color: white !important;
    border: none !important;
    border-radius: 3px !important;
    width: 22px !important;
    height: 22px !important;
    cursor: pointer !important;
    font-size: 14px !important;
    line-height: 1 !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.xi-remove-element:hover {
    background: #c82333 !important;
}

/* Content Preview */
.xi-content-preview {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    margin-top: 10px;
    max-height: 100px;
    overflow-y: auto;
}

.xi-content-preview h4 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 14px;
}

.xi-content-preview-content {
    color: #666;
    font-size: 13px;
    line-height: 1.4;
}

/* Spinning Animation */
@keyframes xi-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.xi-spinning {
    animation: xi-spin 1s linear infinite;
    display: inline-block;
}

/* Save Button States */
.xi-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.xi-btn-success {
    background: #28a745 !important;
    color: white !important;
    border-color: #28a745 !important;
}

/* Loading Overlay */
.xi-save-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999997;
}

/* Modal Loading Overlay */
.xi-modal-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999997;
    border-radius: 4px;
}

.xi-modal-loading-spinner {
    background: white;
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: #333;
    border: 1px solid #e1e1e1;
}

.xi-save-spinner {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: #333;
}

.xi-save-spinner .dashicons {
    font-size: 20px;
}

/* Ensure WordPress media modals stay below our modals */
.media-modal {
    z-index: 999000 !important;
}

.media-modal-backdrop {
    z-index: 998999 !important;
}

/* Message System */
.xi-message {
    margin: 0 0 20px 0;
    padding: 12px 16px;
    border-left: 4px solid;
    border-radius: 4px;
    font-weight: 500;
}

.xi-message-success {
    background: #d4edda;
    color: #155724;
    border-left-color: #28a745;
}

.xi-message-error {
    background: #f8d7da;
    color: #721c24;
    border-left-color: #dc3545;
}

/* Rich Text Editor Container */
#xi-html-editor-container {
    border: 1px solid #ccd0d4;
    border-radius: 4px;
    overflow: hidden;
}

#xi-html-editor-container .wp-editor-wrap {
    border: none;
    background: white;
}

#xi-html-editor-container .wp-editor-tools {
    background: #f1f1f1;
    border-bottom: 1px solid #e1e1e1;
    padding: 0;
}

#xi-html-editor-container .wp-media-buttons {
    float: left;
    padding: 8px 8px 0 8px;
}

#xi-html-editor-container .wp-editor-tabs {
    float: right;
    padding: 0;
}

#xi-html-editor-container .wp-switch-editor {
    background: #f1f1f1;
    border: 1px solid #c3c4c7;
    border-bottom: none;
    color: #50575e;
    cursor: pointer;
    font: 13px/19px "Open Sans", sans-serif;
    margin: 5px 0 0 5px;
    padding: 3px 8px 4px;
    position: relative;
    top: 1px;
    text-decoration: none;
}

#xi-html-editor-container .wp-switch-editor:hover {
    background: #fafafa;
    color: #135e96;
}

#xi-html-editor-container .wp-editor-wrap.tmce-active .switch-tmce,
#xi-html-editor-container .wp-editor-wrap.html-active .switch-html {
    background: white;
    border-bottom-color: white;
    color: #333;
}

#xi-html-editor-container .wp-editor-container {
    border: none;
    background: white;
}

#xi-html-editor-container .wp-editor-area {
    border: none;
    font-family: Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.4;
    outline: none;
    resize: none;
    width: 100%;
    box-shadow: none;
}

#xi-html-editor-container .mce-toolbar-grp {
    border-bottom: 1px solid #e1e1e1;
}

#xi-html-content_ifr {
    border: none !important;
}

/* TinyMCE specific styling */
#xi-html-editor-container .mce-tinymce {
    border: none !important;
}

#xi-html-editor-container .mce-container {
    border: none !important;
}

#xi-html-editor-container .mce-top-part {
    border: none !important;
}

/* Frontend Custom HTML Block */
.xi-custom-html-block {
    margin: 15px 0;
}

.xi-custom-html-title {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 16px;
    font-weight: 600;
}

.xi-custom-html-block img {
    max-width: 100%;
    height: auto;
    margin: 10px 0;
}

.xi-custom-html-block p {
    margin: 0 0 15px 0;
    line-height: 1.6;
}

/* Element Styling Section */
.xi-element-styling-section {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

.xi-element-styling-section h4 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 15px;
    font-weight: 600;
}

.xi-styling-help {
    color: #666;
    font-size: 12px;
    margin: 0 0 15px 0;
    font-style: italic;
}

.xi-styling-grid {
    display: grid;
    gap: 15px;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    box-sizing: border-box;
}

.xi-styling-group {
    background: white;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    padding: 12px;
    box-sizing: border-box;
    min-width: 0;
    width: 100%;
}

.xi-styling-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 13px;
}

/* Spacing Inputs (Margin & Padding) */
.xi-spacing-inputs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 6px;
}

.xi-spacing-input {
    padding: 6px 4px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
    text-align: center;
    min-width: 0;
}

.xi-spacing-input::placeholder {
    color: #999;
    font-size: 10px;
}

/* Color Input Group */
.xi-color-input-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

.xi-color-picker {
    width: 40px;
    height: 32px;
    border: 1px solid #ddd;
    border-radius: 3px;
    cursor: pointer;
    padding: 1px;
    flex-shrink: 0;
}

.xi-color-text {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
    min-width: 0;
}

/* Border Inputs */
.xi-border-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 6px;
}

.xi-border-inputs .xi-border-color-row {
    display: flex;
    gap: 6px;
    align-items: center;
    grid-column: 1 / -1;
}

.xi-border-input {
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
    min-width: 0;
}

.xi-border-input[type="color"] {
    width: 40px;
    height: 32px;
    cursor: pointer;
    padding: 1px;
    flex-shrink: 0;
}

/* Styled Preview */
.xi-styled-preview {
    border: 2px dashed #0073aa;
    position: relative;
}

.xi-styled-preview::before {
    content: "Styled Preview";
    position: absolute;
    top: -2px;
    left: -2px;
    background: #0073aa;
    color: white;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 600;
    border-radius: 0 0 4px 0;
    z-index: 10;
}


/* Responsive */
@media (max-width: 768px) {
    .xi-html-editor-modal {
        width: 95%;
        max-height: 85vh;
    }
    
    .xi-link-fields {
        grid-template-columns: 1fr;
    }
    
    .xi-content-type-tabs {
        flex-wrap: wrap;
    }
    
    .xi-content-type-tab {
        flex: 1;
        min-width: 80px;
    }
    
    .xi-styling-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .xi-spacing-inputs {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }
    
    .xi-spacing-input {
        padding: 4px 2px;
        font-size: 11px;
    }
    
    .xi-border-inputs {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .xi-color-input-group {
        flex-direction: row;
        gap: 4px;
    }
    
    .xi-color-picker {
        width: 35px;
        height: 28px;
    }
    
    .xi-border-input[type="color"] {
        width: 35px;
        height: 28px;
    }
}

/* Store Selector Section */
.xi-store-selector-section {
    background: #f8f9fa;
    border: 1px solid #e2e4e7;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0;
}

.xi-store-selector-section h4 {
    margin: 0 0 8px 0;
    color: #1e1e1e;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.xi-store-selector-section h4::before {
    content: "🏪";
    font-size: 16px;
}

.xi-store-help {
    margin: 0 0 12px 0;
    font-size: 13px;
    color: #646970;
    line-height: 1.4;
}

#xi-store-selector {
    width: 100%;
    max-width: 400px;
}

/* Mobile responsive for store selector */
@media (max-width: 768px) {
    .xi-store-selector-section {
        padding: 12px;
    }

    .xi-store-selector-section h4 {
        font-size: 13px;
    }

    .xi-store-help {
        font-size: 12px;
    }
}

/* Store Selector Improvements */
.xi-store-selector-wide {
    min-width: 280px !important;
    max-width: none !important;
}

/* Title Input Field Improvements */
#xi-text-title,
#xi-shortcode-title,
#xi-link-title,
#xi-divider-title,
#xi-html-title {
    min-width: 250px !important;
    flex-grow: 1;
    text-align: left !important;
}

/* Store visibility section styling when inline */
.xi-store-selector-section {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    margin: 15px 0;
}

.xi-store-selector-section .xi-field-label {
    color: #0073aa;
    font-weight: 600;
}

/* Ensure store selector is visible in all panels */
.xi-content-panel .xi-store-selector-section {
    display: block;
}

/* Store visibility radio/checkbox styling */
.xi-store-options {
    margin-top: 8px;
}

.xi-store-option {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.xi-store-option input[type="radio"],
.xi-store-option input[type="checkbox"] {
    margin: 0;
    width: auto;
}

.xi-store-option label {
    margin: 0;
    font-weight: normal;
    cursor: pointer;
    flex-grow: 1;
}

.xi-store-individual-options {
    margin-left: 20px;
    margin-top: 8px;
    padding-left: 12px;
    border-left: 2px solid #ddd;
}

/* Highlight All Stores option */
.xi-store-option:first-child {
    font-weight: 600;
    color: #0073aa;
}

.xi-store-option:first-child label {
    font-weight: 600;
    color: #0073aa;
}

/* Enhanced TinyMCE Editor Styles */
.mce-toolbar-grp {
    background: #f9f9f9 !important;
    border-bottom: 1px solid #ddd !important;
}

.mce-btn {
    border-radius: 3px !important;
    margin: 1px !important;
}

.mce-btn:hover {
    background: #e1e1e1 !important;
    border-color: #ccc !important;
}

.mce-btn.mce-active {
    background: #007cba !important;
    border-color: #005a87 !important;
    color: white !important;
}

.mce-statusbar {
    background: #f9f9f9 !important;
    border-top: 1px solid #ddd !important;
    color: #666 !important;
}

/* TinyMCE Content Area */
.mce-content-body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    line-height: 1.6 !important;
}

.mce-content-body h1,
.mce-content-body h2,
.mce-content-body h3,
.mce-content-body h4,
.mce-content-body h5,
.mce-content-body h6 {
    color: #333 !important;
    margin: 15px 0 10px 0 !important;
}

.mce-content-body blockquote {
    border-left: 4px solid #007cba !important;
    padding: 15px 20px !important;
    background: #f8f9fa !important;
    margin: 15px 0 !important;
}

.mce-content-body table {
    border-collapse: collapse !important;
    width: 100% !important;
}

.mce-content-body table td,
.mce-content-body table th {
    border: 1px solid #ddd !important;
    padding: 10px !important;
}

.mce-content-body table th {
    background: #f1f1f1 !important;
    font-weight: 600 !important;
}

/* TinyMCE Modal Improvements */
.mce-window {
    border-radius: 5px !important;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3) !important;
}

.mce-window-head {
    background: #007cba !important;
    color: white !important;
    border-bottom: none !important;
}

.mce-close {
    color: white !important;
}

.mce-close:hover {
    color: #ccc !important;
}

/* Color Picker Improvements */
.mce-colorbutton .mce-preview {
    border-radius: 2px !important;
}

/* Improve mobile toolbar */
@media (max-width: 768px) {
    .mce-toolbar {
        flex-wrap: wrap !important;
    }

    .mce-btn-group {
        margin-bottom: 2px !important;
    }
}