/* ══════════════════════════════════════════════════
   html-editor.css — reusable HTML WYSIWYG editor control
   Scoped under .he- prefix to avoid collisions.
   ══════════════════════════════════════════════════ */

/* ── Root container ─────────────────────────────── */
.he-root {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
    --he-toolbar-h: 36px;
    --he-accent: var(--accent, #7c3aed);
}

/* ── Toolbar ────────────────────────────────────── */
.he-toolbar {
    height: var(--he-toolbar-h);
    min-height: var(--he-toolbar-h);
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 8px;
    background: var(--bg-panel, #1a1a1a);
    border-bottom: 1px solid var(--border, #333);
    font-size: 12px;
    user-select: none;
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 5;
}
.he-toolbar::-webkit-scrollbar { height: 0; }

.he-tb-group {
    display: flex;
    align-items: center;
    gap: 1px;
}
.he-tb-sep {
    width: 1px;
    height: 20px;
    background: var(--border, #333);
    margin: 0 6px;
    flex-shrink: 0;
}
.he-tb-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: var(--text-secondary, #aaa);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.12s, color 0.12s;
    padding: 0;
    flex-shrink: 0;
}
.he-tb-btn:hover { background: var(--bg-hover, #2a2a2a); color: var(--text-primary, #eee); }
.he-tb-btn.active { background: var(--bg-surface, #252525); color: var(--he-accent); }
.he-tb-btn[disabled] { opacity: 0.3; pointer-events: none; }
.he-tb-btn svg { width: 16px; height: 16px; }

.he-tb-select {
    height: 26px;
    padding: 0 6px;
    background: var(--bg-surface, #252525);
    border: 1px solid var(--border, #333);
    border-radius: 4px;
    color: var(--text-primary, #eee);
    font-size: 11px;
    cursor: pointer;
    max-width: 110px;
}
.he-tb-input {
    width: 42px;
    height: 26px;
    padding: 0 4px;
    background: var(--bg-surface, #252525);
    border: 1px solid var(--border, #333);
    border-radius: 4px;
    color: var(--text-primary, #eee);
    font-size: 11px;
    text-align: center;
}
.he-tb-label {
    font-size: 10px;
    color: var(--text-muted, #777);
    margin-right: 4px;
    white-space: nowrap;
}
.he-tb-spacer { flex: 1; }

/* ── Canvas area (slide + overlay) ──────────────── */
.he-canvas-area {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
    position: relative;
}
.he-canvas {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-width: 0;
}

/* ── Selection overlay ──────────────────────────── */
.he-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 10;
}
.he-overlay.interactive {
    pointer-events: auto;
    cursor: crosshair;
}
.he-select-box {
    position: absolute;
    border: 2px solid var(--he-accent);
    background: rgba(124, 58, 237, 0.08);
    pointer-events: auto;
    cursor: move;
    z-index: 11;
}
.he-select-box .he-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #fff;
    border: 2px solid var(--he-accent);
    border-radius: 2px;
    pointer-events: auto;
    z-index: 12;
}
.he-select-box .he-handle-tl { top: -5px; left: -5px; cursor: nwse-resize; }
.he-select-box .he-handle-tr { top: -5px; right: -5px; cursor: nesw-resize; }
.he-select-box .he-handle-bl { bottom: -5px; left: -5px; cursor: nesw-resize; }
.he-select-box .he-handle-br { bottom: -5px; right: -5px; cursor: nwse-resize; }
.he-select-box .he-handle-t { top: -5px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.he-select-box .he-handle-b { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.he-select-box .he-handle-l { left: -5px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.he-select-box .he-handle-r { right: -5px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

/* Element hover highlight (before click) */
.he-hover-highlight {
    position: absolute;
    border: 1px dashed rgba(124, 58, 237, 0.5);
    background: rgba(124, 58, 237, 0.04);
    pointer-events: none;
    z-index: 9;
    transition: all 0.08s ease-out;
}

/* ── Right panel (properties / HTML / prompt) ───── */
.he-panel {
    width: 280px;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel, #1a1a1a);
    border-left: 1px solid var(--border, #333);
    overflow: hidden;
    transition: width 0.2s, min-width 0.2s;
}
.he-panel.collapsed {
    width: 0;
    min-width: 0;
    border-left: none;
}
.he-panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border, #333);
    background: var(--bg-primary, #111);
    flex-shrink: 0;
}
.he-panel-tab {
    flex: 1;
    padding: 8px 4px;
    font-size: 11px;
    text-align: center;
    color: var(--text-muted, #777);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}
.he-panel-tab:hover { color: var(--text-secondary, #aaa); }
.he-panel-tab.active { color: var(--he-accent); border-bottom-color: var(--he-accent); }
.he-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}
.he-panel-content::-webkit-scrollbar { width: 4px; }
.he-panel-content::-webkit-scrollbar-track { background: transparent; }
.he-panel-content::-webkit-scrollbar-thumb { background: var(--border, #333); border-radius: 2px; }

/* ── Panel sections ─────────────────────────────── */
.he-prop-section {
    margin-bottom: 16px;
}
.he-prop-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted, #777);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.he-prop-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.he-prop-row label {
    font-size: 11px;
    color: var(--text-secondary, #aaa);
    width: 55px;
    flex-shrink: 0;
}
.he-prop-row input, .he-prop-row select {
    flex: 1;
    height: 26px;
    padding: 0 6px;
    background: var(--bg-surface, #252525);
    border: 1px solid var(--border, #333);
    border-radius: 4px;
    color: var(--text-primary, #eee);
    font-size: 11px;
}
.he-prop-row input[type="color"] {
    width: 26px;
    flex: 0 0 26px;
    padding: 2px;
    cursor: pointer;
}

/* ── Raw HTML editor ────────────────────────────── */
.he-code-editor {
    width: 100%;
    height: 100%;
    min-height: 200px;
    background: var(--bg-surface, #1a1a1a);
    color: var(--text-primary, #e0e0e0);
    border: none;
    padding: 8px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    line-height: 1.5;
    resize: none;
    tab-size: 2;
    white-space: pre;
    overflow: auto;
}
.he-code-editor:focus { outline: none; }

/* ── Inline text editing ────────────────────────── */
.he-inline-edit {
    outline: 2px solid var(--he-accent);
    outline-offset: 2px;
    min-width: 20px;
    min-height: 1em;
    cursor: text;
}

/* ── Prompt section in panel ────────────────────── */
.he-prompt-area textarea {
    width: 100%;
    min-height: 60px;
    resize: vertical;
    background: var(--bg-surface, #252525);
    border: 1px solid var(--border, #333);
    border-radius: 4px;
    color: var(--text-primary, #eee);
    font-size: 12px;
    padding: 8px;
    font-family: inherit;
    line-height: 1.4;
    box-sizing: border-box;
}
.he-prompt-area textarea:focus { outline: none; border-color: var(--he-accent); }
.he-prompt-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.he-prompt-actions button {
    padding: 5px 12px;
    font-size: 11px;
    background: var(--bg-surface, #252525);
    border: 1px solid var(--border, #333);
    border-radius: 4px;
    color: var(--text-secondary, #aaa);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.he-prompt-actions button:hover { border-color: var(--text-muted); color: var(--text-primary); }
.he-prompt-actions button.primary {
    background: var(--he-accent);
    border-color: var(--he-accent);
    color: #fff;
}

/* ── Settings section (radio groups etc) ────────── */
.he-settings-section { margin-bottom: 14px; }
.he-settings-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary, #eee);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.he-settings-radio {
    display: block;
    padding: 4px 0;
    font-size: 12px;
    color: var(--text-secondary, #aaa);
    cursor: pointer;
}
.he-settings-radio input { margin-right: 6px; accent-color: var(--he-accent); }
.he-settings-hint {
    font-size: 11px;
    color: var(--text-muted, #666);
    font-style: italic;
    margin-top: 4px;
}

/* ── Layers list ────────────────────────────────── */
.he-layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary, #aaa);
    transition: background 0.12s;
}
.he-layer-item:hover { background: var(--bg-hover, #2a2a2a); }
.he-layer-item.selected { background: var(--bg-surface, #252525); color: var(--he-accent); }
.he-layer-tag {
    font-size: 10px;
    color: var(--text-muted, #666);
    font-family: monospace;
    background: var(--bg-primary, #111);
    padding: 1px 5px;
    border-radius: 3px;
}
.he-layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.he-layer-actions { display: flex; gap: 2px; }
.he-layer-actions button {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    padding: 2px 4px; font-size: 11px; border-radius: 3px;
}
.he-layer-actions button:hover { color: var(--text-primary); background: var(--bg-hover); }
.he-layer-eye {
    background: none; border: none; cursor: pointer; font-size: 13px;
    padding: 2px 4px; border-radius: 3px; flex-shrink: 0;
    opacity: 0.7; transition: opacity 0.12s;
    position: relative;
}
.he-layer-eye:hover { opacity: 1; }
.he-layer-eye.off { opacity: 0.3; }
.he-layer-eye.off::after {
    content: '';
    position: absolute;
    left: 2px; right: 2px;
    top: 50%;
    height: 2px;
    background: var(--text-muted, #777);
    transform: rotate(-20deg);
}
.he-layer-bg { border-bottom: 1px solid var(--border, #333); padding-bottom: 8px; margin-bottom: 4px; }
