/* Editor Wrapper */
.editor-wrapper {
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    position: relative;
}

.editor-top-toolbar {
    min-height: 54px;
    overflow: visible;
}

.editor-global-toolbar-wrapper {
    min-height: 40px;
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    padding: 0;
    overflow: hidden; /* Evitar scroll en el wrapper */
    max-width: 100vw; /* No exceder viewport */
    box-sizing: border-box;
    position: relative; /* Para posicionamiento del dropdown */
}

/* Permitir overflow cuando hay dropdown activo */
.editor-global-toolbar-wrapper.dropdown-active {
    overflow: visible !important;
    z-index: 1050;
}

/* Asegurar que los dropdowns del toolbar tengan z-index apropiado */
.text-toolbar .dropdown-menu {
    z-index: 1060;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.15);
}

/* Estilos para dropdowns movidos al body */
body > .dropdown-menu {
    z-index: 1060 !important;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.15);
    max-height: 300px;
    overflow-y: auto;
}

/* Mejorar posicionamiento para dropdowns en toolbars con scroll */
.text-toolbar .btn-group.show .dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: max-content;
}

.editor-global-toolbar-wrapper .text-toolbar {
    width: 100%;
    max-width: 100%; /* No exceder contenedor */
    margin-bottom: 0;
    box-shadow: none;
    border: none;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 1;
    /* Asegurar que el scrollbar sea del toolbar */
    scrollbar-width: thin;
    scrollbar-color: #dee2e6 transparent;
    box-sizing: border-box;
}


.editor-wrapper-fullscreen {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh !important;
    z-index: 1040;
    background: #f8f9fa;
}

body.block-editor-fullscreen-active .modal-backdrop {
    z-index: 1080;
}

body.block-editor-fullscreen-active .modal {
    z-index: 1090;
}

.editor-sidebar{
    height: 100% !important;
}

.editor-wrapper-fullscreen > .d-flex {
    height: 100% !important;
}

.editor-wrapper-fullscreen .editor-sidebar{
    max-height: 100%;
}
.editor-wrapper-fullscreen .editor-main{
    max-height: 100%;
}
/* Editor Canvas */
#editor-canvas {
    min-height: 80vh;
    outline: none;
    transition: all 0.3s ease;
}

#preview-container {
    width: 100%;
    height: calc(100vh - 100px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
}

#preview-iframe {
    background: white;
}

/* Block Styles */
.editor-block {
    position: relative;
    border: 2px solid transparent; /* Highlight border */
    transition: border-color 0.2s;
}

.editor-block:hover {
    border-color: rgba(13, 110, 253, 0.25);
}

.editor-block.selected {
    border-color: #0d6efd;
}

.editor-wrapper-single-block .editor-block:hover,
.editor-wrapper-single-block .editor-block.selected {
    border-color: transparent !important;
}

.editor-wrapper-single-block .editor-block .block-actions {
    display: none !important;
}

.editor-wrapper-single-text-locked .editor-block:hover,
.editor-wrapper-single-text-locked .editor-block.selected {
    border-color: transparent !important;
}

.editor-wrapper-single-text-locked .editor-block.selected .block-actions {
    display: none !important;
}

.editor-block.dragging {
    opacity: 0.5;
    border-color: #0d6efd;
    border-style: dashed;
}

.editor-block .block-actions {
    position: absolute;
    top: -24px;
    right: 0;
    display: none;
    z-index: 10;
    background: #0d6efd;
    border-radius: 4px 4px 0 0;
    padding: 2px 5px;
}

.editor-block.selected .block-actions {
    display: flex;
    gap: 5px;
}

.block-action-btn {
    color: white;
    cursor: pointer;
    font-size: 0.8rem;
    background: none;
    border: none;
    padding: 0 4px;
}

.block-action-btn:hover {
    color: #e9ecef;
}

.block-action-btn.drag-handle {
    cursor: grab;
    font-size: 0.9rem;
}

.block-action-btn.drag-handle:active {
    cursor: grabbing;
}

/* Text Block specific */
.text-block-content {
    outline: none;
    min-height: 1.5em;
    white-space: pre-wrap; /* Preserve tabs and spaces */
}

.block-editor-code-wrapper {
    display: flex;
    flex-direction: column;
    margin: 1rem 0;
    padding: 0.75rem;
    border: 1px solid #d0d7de;
    border-radius: 0.75rem;
    background: #f8fafc;
    position: relative;
    padding-right: 3.25rem;
}

.block-editor-code-copy-btn {
    align-self: flex-end;
    position: absolute;
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
    right: 0.5rem;
    top: 0.4rem;
}

.block-editor-code-pre {
    margin: 0;
    white-space: pre-wrap;
    overflow-x: auto;
    
}

.block-editor-code-content {
    display: block;
    font-family: SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, monospace;
}

.block-editor-code-copy-tooltip {
    position: absolute;
    right: 0;
    bottom: calc(100% + 6px);
    padding: 0.2rem 0.45rem;
    border-radius: 0.35rem;
    font-size: 0.75rem;
    line-height: 1;
    color: #fff;
    background: rgba(33, 37, 41, 0.95);
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    white-space: nowrap;
}

.block-editor-code-copy-btn.is-copied .block-editor-code-copy-tooltip,
.block-editor-code-copy-btn.is-copy-failed .block-editor-code-copy-tooltip {
    opacity: 1;
    transform: translateY(0);
}

/* Placeholder for image drop */
.image-drop-zone {
    border: 2px dashed #dee2e6;
    border-radius: 4px;
    background-color: #f8f9fa;
    transition: all 0.2s;
}

.image-drop-zone.drag-over {
    border-color: #0d6efd;
    background-color: #e7f1ff;
}

/* Nesting visual aid for Rows */
.row-block-container {
    padding: 1rem;
    border: 1px dashed #ced4da; /* To visualize row boundaries while editing */
}

.row-column-dropzone {
    min-height: 60px;
    transition: background-color 0.2s;
}

.row-column-dropzone.drag-over {
    background-color: rgba(13, 110, 253, 0.1);
}

/* Floating Toolbar for Text */
/* Toolbar for Text */
.text-toolbar {
    /* position: relative; Default is fine, pushes content down */
    z-index: 100;
    /*background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.1);
    padding: 5px;
    margin-bottom: 5px;*/
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: #dee2e6 transparent;
    gap: 0;
    min-height: 40px;
    align-items: center;
    max-width: 100%; /* No exceder contenedor */
    width: 100%;
    /* Forzar que el scroll sea del toolbar */
    contain: layout style;
    box-sizing: border-box;
}

/* Mejorar el scrollbar en WebKit browsers */
.text-toolbar::-webkit-scrollbar {
    height: 6px;
}

.text-toolbar::-webkit-scrollbar-track {
    background: transparent;
}

.text-toolbar::-webkit-scrollbar-thumb {
    background-color: #dee2e6;
    border-radius: 3px;
}

.text-toolbar::-webkit-scrollbar-thumb:hover {
    background-color: #adb5bd;
}

/* Asegurar que los botones no se contraigan */
.text-toolbar .btn {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Clase específica para toolbars con overflow handling */
.toolbar-with-overflow-handling {
    /* Forzar contenedor de scroll */
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: thin;
    scrollbar-color: #dee2e6 transparent;
    /* Prevenir que el scroll se propague */
    overscroll-behavior-x: contain;
}

/* Estilos para el botón "más opciones" */
.toolbar-more-btn {
    background: #f8f9fa !important;
    border: 1px solid #dee2e6 !important;
    color: #495057 !important;
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-more-btn:hover {
    background: #e9ecef !important;
    border-color: #adb5bd !important;
}

.toolbar-more-btn:focus {
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25) !important;
}

.text-toolbar.keep-visible {
    display: flex !important;
}

/* Sistema de dropdown para toolbars con overflow */
.toolbar-overflow-container {
    position: relative;
    display: inline-block;
}

.toolbar-dropdown {
    position: fixed;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    z-index: 1060;
    padding: 8px 0;
    display: none;
    max-height: 400px;
    overflow-y: auto;
}

.toolbar-dropdown.show {
    display: block;
}

.toolbar-dropdown .btn {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    border-radius: 0;
    padding: 8px 16px;
    background: white;
    color: #212529;
}

.toolbar-dropdown .btn:hover {
    background: #f8f9fa;
}

/* Estilos para dropdowns anidados dentro del overflow */
.dropdown-in-overflow {
    width: 100%;
}

.dropdown-in-overflow .dropdown-toggle {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 100% !important;
    text-align: left !important;
    padding: 8px 16px;
    background: white;
    color: #212529;
    border: none;
    border-radius: 0;
}

.dropdown-in-overflow .dropdown-toggle:hover {
    background: #f8f9fa;
}

.dropdown-in-overflow .dropdown-toggle::after {
    margin-left: auto;
}

.dropdown-in-overflow .dropdown-menu {
    position: static !important;
    display: none !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #f8f9fa;
    width: 100% !important;
}

.dropdown-in-overflow .dropdown-menu .dropdown-item {
    padding: 6px 24px;
    border: none;
    border-radius: 0;
    background: #f8f9fa;
    color: #495057;
}

.dropdown-in-overflow .dropdown-menu .dropdown-item:hover {
    background: #e9ecef;
    color: #212529;
}

.toolbar-dropdown-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 1059;
    display: none;
}

.toolbar-dropdown-backdrop.show {
    display: block;
}
    display: flex;
    align-items: center;
}

.toolbar-more-btn {
    flex-shrink: 0;
    margin-left: 4px;
    position: relative;
}

.toolbar-dropdown {
    position: fixed; /* Cambiar a fixed para evitar overflow del contenedor */
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    padding: 8px;
    z-index: 9999; /* Z-index muy alto para estar por encima del editor */
    min-width: 200px;
    display: none;
    flex-direction: column;
    gap: 4px;
    margin-top: 2px;
}

.toolbar-dropdown.show {
    display: flex;
    animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toolbar-dropdown .btn {
    justify-content: flex-start;
    text-align: left;
    width: 100%;
    margin: 0;
    border: none;
    border-radius: 4px;
    padding: 8px 12px;
}

.toolbar-dropdown .btn:hover {
    background-color: #f8f9fa;
}

.toolbar-dropdown .btn i {
    margin-right: 8px;
    width: 16px;
    text-align: center;
}

/* Backdrop para cerrar el dropdown */
.toolbar-dropdown-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9998; /* Justo por debajo del dropdown */
    display: none;
    background: transparent;
}

.toolbar-dropdown-backdrop.show {
    display: block;
}

/* Insert Indicators */
.insert-indicator {
    position: relative;
    height: 2px;
    margin: 1px 0;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.insert-indicator:hover {
    opacity: 1;
}

.insert-line {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: #0d6efd;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.insert-btn {
    position: relative;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #0d6efd;
    color: white;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0;
}

.insert-btn:hover {
    background: #0b5ed7;
    transform: scale(1.15);
    transition: all 0.2s ease;
}

.insert-btn i {
    pointer-events: none;
}

/* Context Menu */
.text-block-context-menu {
    position: fixed;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 4px 0;
    z-index: 10000;
    min-width: 220px;
    animation: contextMenuFadeIn 0.15s ease-out;
}

@keyframes contextMenuFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.context-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    font-size: 14px;
    gap: 12px;
}

.context-menu-item:hover {
    background-color: #f8f9fa;
}

.context-menu-item:active {
    background-color: #e9ecef;
}

.context-menu-item i {
    width: 18px;
    font-size: 16px;
    color: #495057;
    flex-shrink: 0;
}

.context-menu-shortcut {
    font-size: 12px;
    color: #6c757d;
    margin-left: auto;
    white-space: nowrap;
}

.context-menu-separator {
    height: 1px;
    background-color: #dee2e6;
    margin: 4px 0;
}

/* Undo/Redo Button Enhancements */
.undo-redo-counter {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #0d6efd;
    color: white;
    font-size: 10px;
    font-weight: bold;    
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.undo-redo-counter.visible {
    opacity: 1;
}

.btn-group .btn {
    position: relative;
}

.btn:disabled .undo-redo-counter {
    background: #6c757d;
}

/* Workspace layout */
.editor-workspace {
    display: flex;
    position: relative;
    height: calc(100% - 78px);
}
.editor-main {
    height: 100% !important;
    overflow: auto;
}

.editor-sidebar {
    width: 200px;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow: auto;    
}

@media (max-width: 991.98px) {
    .editor-workspace {
        flex-direction: column !important;
        overflow: auto !important;
    }

    .editor-main {
        order: 1;
        min-height: 320px;
    }

    .editor-sidebar {
        order: 2;
        width: 100% !important;
        min-width: 0 !important;
        border-left: 0 !important;
        border-top: 1px solid #dee2e6;
    }
}

/* Overflow dropdown styling */
.dropdown-in-overflow {
    position: relative !important;
    width: 100% !important;
    margin-bottom: 2px;
}

.dropdown-in-overflow .btn {
    width: 100% !important;
    text-align: left !important;
    border-radius: 0.25rem !important;
    transition: background-color 0.15s ease-in-out;
}

.dropdown-in-overflow .btn:hover {
    background-color: #e9ecef !important;
}

.overflow-submenu {
    position: static !important;
    display: none !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
    border: 1px solid #dee2e6 !important;
    border-radius: 0.375rem !important;
    margin-top: 4px !important;
    width: 100% !important;
    background-color: #ffffff !important;
    z-index: 1000 !important;
    max-height: 200px !important;
    overflow-y: auto !important;
}

.overflow-submenu.show {
    display: block !important;
}

.overflow-submenu .dropdown-item {
    padding: 8px 16px !important;
    display: block !important;
    width: 100% !important;
    color: #212529 !important;
    text-decoration: none !important;
    border: none !important;
    background: transparent !important;
    text-align: left !important;
    white-space: nowrap !important;
    transition: background-color 0.15s ease-in-out;
}

.overflow-submenu .dropdown-item:hover {
    background-color: #e9ecef !important;
    color: #1e2125 !important;
}

.overflow-submenu .dropdown-item:focus {
    background-color: #0d6efd !important;
    color: #ffffff !important;
}
