/* ===== Super Advanced HTML Block Editor Styles ===== */

/* Force Gutenberg to allow full-width for this block */
.wp-block[data-type="sahb/advanced-html"] {
    max-width: none !important;
    width: 100% !important;
}

/* Wrapper div (gets block props) */
.sahb-editor-wrapper {
    border: 1px dashed #ccc;
    padding: 16px;
    min-height: 500px;
    width: 100% !important;
    max-width: none !important;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
    box-sizing: border-box;
    overflow: auto;
    resize: both;
}

.sahb-editor-wrapper:focus-within {
    border-color: #007cba;
    background: #fff;
    box-shadow: 0 0 0 1px #007cba;
}

/* The shadow host element */
.sahb-shadow-host {
    display: block;
    width: 100%;
    min-height: 450px;
    max-width: none;
    box-sizing: border-box;
    overflow: auto;
}

/* Contain pasted full-page layouts inside the editor preview only */
.editor-styles-wrapper .sahb-editor-wrapper,
.block-editor-block-list__layout .sahb-editor-wrapper {
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box;
    contain: layout style;
}

.editor-styles-wrapper .sahb-editor-wrapper #bernese-standalone-page,
.editor-styles-wrapper .sahb-editor-wrapper .bh-wrap,
.editor-styles-wrapper .sahb-editor-wrapper [style*="100vw"],
.block-editor-block-list__layout .sahb-editor-wrapper #bernese-standalone-page,
.block-editor-block-list__layout .sahb-editor-wrapper .bh-wrap,
.block-editor-block-list__layout .sahb-editor-wrapper [style*="100vw"] {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    left: auto !important;
    right: auto !important;
    box-sizing: border-box;
}

.editor-styles-wrapper .sahb-editor-wrapper img,
.editor-styles-wrapper .sahb-editor-wrapper svg,
.editor-styles-wrapper .sahb-editor-wrapper video,
.editor-styles-wrapper .sahb-editor-wrapper iframe,
.block-editor-block-list__layout .sahb-editor-wrapper img,
.block-editor-block-list__layout .sahb-editor-wrapper svg,
.block-editor-block-list__layout .sahb-editor-wrapper video,
.block-editor-block-list__layout .sahb-editor-wrapper iframe {
    max-width: 100vw !important;
}

/* Legacy: contentEditable styles (now handled inside Shadow DOM) */
.sahb-contenteditable {
    min-height: 60px;
    outline: none;
    cursor: text;
}

.sahb-contenteditable:empty::before {
    content: 'Click here to start editing...';
    color: #aaa;
    pointer-events: none;
}

/* Images inside the editor */
.sahb-contenteditable img {
    max-width: 100vw;
    height: auto;
    display: inline-block;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 3px;
    transition: border-color 0.2s, box-shadow 0.2s;
    vertical-align: middle;
    /* Ensure even broken images have a minimum clickable area */
    min-width: 100px;
    min-height: 60px;
}

.sahb-contenteditable img:hover {
    border-color: #007cba;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.25);
}

.sahb-contenteditable img.sahb-img-selected {
    border-color: #007cba;
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.35);
}

/* Broken / missing images — make them visible and clickable */
.sahb-contenteditable img.sahb-img-broken {
    min-width: 200px;
    min-height: 100px;
    background: #f5f5f5;
    border: 2px dashed #bbb;
    border-radius: 4px;
    position: relative;
    display: inline-block;
    color: #999;
    font-size: 13px;
    padding: 12px;
    box-sizing: border-box;
    cursor: pointer !important;
    pointer-events: auto !important;
    -webkit-user-select: none;
    user-select: none;
}

.sahb-contenteditable img.sahb-img-broken:hover {
    border-color: #007cba;
    background: #eef6fc;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.25);
}

.sahb-contenteditable img.sahb-img-broken.sahb-img-selected {
    border-color: #007cba;
    background: #e3f0fa;
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.35);
}

/* Wrapper span for broken images — makes entire area clickable */
.sahb-contenteditable .sahb-img-wrap {
    display: inline-block;
    position: relative;
    cursor: pointer !important;
    min-width: 200px;
    min-height: 100px;
    vertical-align: middle;
    -webkit-user-select: none;
    user-select: none;
}

.sahb-contenteditable .sahb-img-wrap::after {
    content: '🖼 Click to replace image: ' attr(data-alt);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #888;
    font-size: 13px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 1;
}

.sahb-contenteditable .sahb-img-wrap:hover {
    background: #eef6fc;
    border-radius: 4px;
}

/* Links inside the editor */
.sahb-contenteditable a {
    color: #0073aa;
    text-decoration: underline;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: border-color 0.2s;
}

.sahb-contenteditable a:hover {
    color: #005a87;
    border-bottom-color: #007cba;
}

/* Code editor (textarea) */
.sahb-code-editor {
    width: 100%;
    min-height: 250px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
    line-height: 1.5;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #1e1e1e;
    color: #d4d4d4;
    resize: vertical;
    tab-size: 2;
    box-sizing: border-box;
}

.sahb-code-editor:focus {
    outline: none;
    border-color: #007cba;
    box-shadow: 0 0 0 1px #007cba;
}

/* Link modal */
.sahb-link-modal .components-base-control {
    margin-bottom: 12px;
}

.sahb-link-modal .components-button.is-primary {
    margin-top: 8px;
}

/* Image replace modal */
.sahb-img-modal .sahb-img-modal-preview {
    margin-bottom: 16px;
    text-align: center;
}

/* Shared modal action buttons */
.sahb-modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

/* Sidebar buttons */
.sahb-sidebar-btn {
    width: 100%;
    justify-content: center;
}

.sahb-sidebar-help {
    font-size: 12px;
    color: #757575;
    margin-bottom: 12px;
}

/* Frontend styles for rendered block */
.sahb-frontend-content img {
    max-width: 100vw;
    height: auto;
}

.sahb-frontend-content a {
    color: #0073aa;
    text-decoration: underline;
}
