/* Styles spécifiques à l'éditeur (non exportés) */

html, body { height: 100%; }

body.editor-mode {
    margin: 0;
    background: var(--color-bg-alt);
    overflow: hidden;
}

/* Topbar */
.editor-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    height: 60px;
    flex-shrink: 0;
    gap: var(--space-sm);
}

.topbar-title {
    font-size: 1.05rem;
    margin: 0;
    flex-shrink: 0;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.topbar-actions input[type="text"],
.topbar-actions select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}

.topbar-actions input[type="text"] {
    min-width: 180px;
}

.topbar-actions button {
    padding: 8px 14px;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
}

.topbar-actions button:hover {
    background: var(--color-border);
}

#btn-save {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

#btn-save:hover {
    background: var(--color-primary-dark);
}

/* Layout 2 colonnes */
.editor-layout {
    display: flex;
    height: calc(100vh - 60px);
}

/* Sidebar */
.editor-sidebar {
    width: 280px;
    background: #fff;
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

/* Onglets de la sidebar */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    background: var(--color-bg-alt);
}

.sidebar-tab {
    flex: 1;
    padding: 12px 8px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    color: var(--color-muted);
    font-weight: 500;
}

.sidebar-tab:hover {
    background: #fff;
    color: var(--color-text);
}

.sidebar-tab.active {
    background: #fff;
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: 600;
}

.sidebar-panel {
    padding: var(--space-sm);
    flex: 1;
    overflow-y: auto;
}

.sidebar-panel[hidden] { display: none; }

#block-search,
#library-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: var(--space-sm);
    font-size: 14px;
    font-family: inherit;
}

.block-list,
.library-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.block-card,
.library-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding: 12px;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: grab;
    font-family: inherit;
    width: 100%;
    position: relative;
}

.block-card:hover,
.library-card:hover {
    border-color: var(--color-primary);
    background: #fff;
}

.block-card:active,
.library-card:active {
    cursor: grabbing;
}

.block-card-name,
.library-card-name {
    font-weight: 600;
    font-size: 14px;
}

.block-card-desc,
.library-card-desc {
    font-size: 12px;
    color: var(--color-muted);
    margin-top: 4px;
}

.library-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.library-tag {
    font-size: 11px;
    padding: 2px 6px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 3px;
    color: var(--color-muted);
}

.library-card-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--color-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    border-radius: 3px;
    padding: 0;
    font-family: inherit;
    display: none;
}

.library-card:hover .library-card-delete {
    display: flex;
    align-items: center;
    justify-content: center;
}

.library-card-delete:hover {
    background: #fee;
    color: var(--color-error);
}

.block-card[hidden],
.library-card[hidden] {
    display: none;
}

.sidebar-hint {
    font-size: 12px;
    color: var(--color-muted);
    margin-top: var(--space-sm);
    line-height: 1.4;
}

.library-empty {
    text-align: center;
    color: var(--color-muted);
    font-size: 13px;
    padding: var(--space-md) var(--space-sm);
}

/* Onglet Options (thème) */
.options-section {
    margin-bottom: var(--space-md);
}

.options-section h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-muted);
    margin: 0 0 var(--space-xs);
    font-weight: 600;
}

.options-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.options-row label {
    flex: 1;
    font-size: 13px;
    color: var(--color-text);
}

.options-row input[type="color"] {
    width: 40px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: pointer;
    background: #fff;
}

.options-row input[type="text"] {
    width: 90px;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    text-align: right;
}

.options-row select {
    flex: 0 0 140px;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
}

.options-actions {
    display: flex;
    gap: 8px;
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border);
}

.options-actions button {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
}

.options-actions .btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.options-actions .btn-primary:hover {
    background: var(--color-primary-dark);
}

/* Canvas */
.editor-canvas {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    background: var(--color-bg-alt);
}

.canvas-page {
    background: #fff;
    min-height: calc(100% - 4px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border-radius: var(--radius);
    overflow: hidden;
}

.canvas-page.drag-over {
    background: #f0f7ff;
    outline: 2px dashed var(--color-primary);
    outline-offset: -8px;
}

.canvas-empty {
    padding: 80px var(--space-md);
    text-align: center;
    color: var(--color-muted);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    margin: var(--space-md);
}

/* Wrapper de bloc dans le canvas */
.canvas-block {
    position: relative;
}

.canvas-block.dragging {
    opacity: 0.4;
}

.canvas-block.drop-before {
    border-top: 3px solid var(--color-primary);
}

.canvas-block.drop-after {
    border-bottom: 3px solid var(--color-primary);
}

.canvas-block:hover .canvas-block-controls {
    opacity: 1;
}

.canvas-block-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
}

.canvas-block-controls button {
    width: 32px;
    height: 32px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-family: inherit;
}

.canvas-block-controls button:hover {
    background: var(--color-bg-alt);
}

.canvas-block-controls button[data-action="delete"]:hover {
    background: #fee;
    color: var(--color-error);
    border-color: var(--color-error);
}

.canvas-block-controls button[data-action="ai"],
.canvas-block-controls button[data-action="save-lib"] {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    width: auto;
    padding: 0 10px;
    font-weight: 600;
    font-size: 12px;
}

.canvas-block-controls button[data-action="ai"]:hover,
.canvas-block-controls button[data-action="save-lib"]:hover {
    background: var(--color-primary-dark);
}

.canvas-block-controls button[data-action="save-lib"] {
    background: var(--color-success);
    border-color: var(--color-success);
}

.canvas-block-controls button[data-action="save-lib"]:hover {
    background: #15803d;
    border-color: #15803d;
}

/* Édition inline */
[data-editable] {
    outline: 1px dashed transparent;
    outline-offset: 2px;
    cursor: text;
    transition: outline-color 0.15s;
    min-height: 1em;
}

[data-editable]:empty::before {
    content: attr(data-placeholder);
    color: var(--color-muted);
    opacity: 0.6;
}

[data-editable]:hover {
    outline-color: var(--color-border);
}

[data-editable]:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

[data-editable-href] {
    position: relative;
}

[data-editable-href]::after {
    content: "🔗";
    position: absolute;
    top: 50%;
    right: -28px;
    transform: translateY(-50%);
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.15s;
    cursor: pointer;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-block:hover [data-editable-href]::after {
    opacity: 1;
}

/* Modales */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-md);
}

.modal[hidden] { display: none; }

.modal-content {
    background: #fff;
    padding: var(--space-md);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin: 0 0 var(--space-sm);
    font-size: 1.2rem;
}

.modal-content h3 {
    font-size: 1rem;
    margin: 0 0 var(--space-xs);
}

.modal-help {
    font-size: 14px;
    color: var(--color-muted);
    margin: 0 0 var(--space-sm);
}

.modal textarea,
.modal input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
}

.modal textarea {
    min-height: 80px;
    resize: vertical;
}

.modal-field {
    margin-bottom: var(--space-sm);
}

.modal-field label {
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
    font-weight: 600;
}

.modal-field-hint {
    font-size: 12px;
    color: var(--color-muted);
    margin-top: 4px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: var(--space-sm);
}

.modal-actions button {
    padding: 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    background: #fff;
    font-family: inherit;
}

.modal-actions .btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.modal-actions .btn-primary:hover {
    background: var(--color-primary-dark);
}

.modal-actions button:disabled {
    opacity: 0.5;
    cursor: wait;
}

.ai-result {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border);
}

.ai-preview {
    background: var(--color-bg-alt);
    padding: 12px;
    border-radius: var(--radius);
    font-size: 14px;
    max-height: 240px;
    overflow-y: auto;
}

/* Toasts */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: #1a1a1a;
    color: #fff;
    border-radius: var(--radius);
    z-index: 2000;
    font-size: 14px;
    animation: toast-in 0.2s;
    max-width: 90vw;
    text-align: center;
}

.toast.error { background: var(--color-error); }
.toast.success { background: var(--color-success); }

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Mobile */
@media (max-width: 999px) {
    .editor-topbar {
        flex-wrap: wrap;
        height: auto;
        gap: var(--space-xs);
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .topbar-actions input[type="text"] {
        flex: 1 1 100%;
        min-width: 0;
    }

    .editor-layout {
        flex-direction: column;
        height: auto;
    }

    .editor-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        max-height: 280px;
    }

    .block-list,
    .library-list {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .block-card,
    .library-card {
        flex: 1 1 calc(50% - 4px);
        min-width: 130px;
        width: auto;
    }

    .canvas-block-controls {
        opacity: 1;
    }
}

.block-card-preview {
    width: 100%;
    height: 80px;
    margin-bottom: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--color-border);
    pointer-events: none; /* éviter les interactions, c'est juste un aperçu */
}

.block-card-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Aperçu HTML : on miniaturise via transform pour garder la structure visible */
.block-card-preview-html {
    position: relative;
}

.block-card-preview-html::after {
    /* zone tappable au-dessus de l'aperçu sans bloquer le drag */
    content: "";
    position: absolute;
    inset: 0;
}

.block-card-info {
    width: 100%;
}