/* ── Editor root: full-viewport app layout ─────────────── */
.editor-root {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ────────────────────────────────────────────── */
.editor-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px 12px;
    flex-shrink: 0;
}

.editor-header__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.editor-header__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.editor-header__breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 13px;
}

.editor-header__breadcrumb a { color: var(--text-muted); }
.editor-header__breadcrumb a:hover { color: var(--text); }
.editor-header__breadcrumb .sep { color: #555; }
.editor-header__breadcrumb .current { color: var(--text); font-weight: 600; }

/* ── Export dropdown ───────────────────────────────────── */
.dropdown { position: relative; }

.dropdown__menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 150px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    z-index: 100;
    padding: 4px;
}

.dropdown__item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    color: var(--text);
    font-size: 13px;
    text-align: left;
    border-radius: 4px;
    cursor: pointer;
}

.dropdown__item:hover { background: #222244; color: var(--accent); }

/* ── Body: sidebar + content ───────────────────────────── */
.editor-body {
    flex: 1;
    display: grid;
    grid-template-columns: 220px 1fr;
    overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────── */
.editor-sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.editor-components {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.editor-elements {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.palette-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.palette-btn {
    padding: 7px 4px;
    border: 1px solid #333;
    border-radius: 4px;
    background: #1a1a2e;
    color: #ccc;
    font-size: 11px;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-btn:hover {
    background: #16213e;
    border-color: #0f3460;
    color: var(--accent);
}

.palette-btn[draggable="true"] { cursor: grab; }
.palette-btn[draggable="true"]:active { cursor: grabbing; }

/* ── Element list ──────────────────────────────────────── */
.element-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.block-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    font-size: 11px;
    color: #aaa;
    border-radius: 4px;
    border: 1px solid transparent;
}

.block-item:hover {
    background: #16213e;
    border-color: var(--border);
}

.block-item--selected {
    background: rgba(233, 69, 96, 0.12);
    border-color: rgba(233, 69, 96, 0.6);
    color: var(--text);
}

.block-item__info {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.block-item__pos { color: #666; }
.block-order { color: #666; font-size: 10px; }

.block-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    flex-shrink: 0;
}

.order-btn {
    color: #888;
    cursor: pointer;
    background: none;
    border: 1px solid #333;
    border-radius: 2px;
    font-size: 10px;
    padding: 1px 4px;
    line-height: 1;
    transition: all 0.15s;
}

.order-btn:hover:not(:disabled) {
    color: var(--accent);
    border-color: var(--accent);
}

.order-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.style-select {
    background: #1a1a2e;
    color: #aaa;
    border: 1px solid #333;
    border-radius: 3px;
    font-size: 10px;
    padding: 1px 2px;
    cursor: pointer;
    max-width: 72px;
}

.style-select:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.delete-block {
    color: var(--accent);
    cursor: pointer;
    background: none;
    border: none;
    font-size: 14px;
    padding: 0 4px;
}

/* ── Content (canvas) ──────────────────────────────────── */
/* The canvas fills all the free space; the container is the only
   scroller (the art scrolls inside it, the dark background extends
   over the whole visible area). */
.editor-content {
    overflow: hidden;
}

.canvas-container {
    background: #1a1a2e;
    overflow: auto;
    position: relative;
    width: 100%;
    height: 100%;
}

.canvas-drag-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* ── Render wrapper: shared coordinate system with .ascii-art ─
   The 16px padding is the ONLY offset between the wrapper's border box
   and the art/overlay origin — overlays use the same 16px padding_offset. */
.render-wrapper {
    position: relative;
    display: block;
    font-size: 12px;
    padding: 16px;
}

.drag-preview {
    position: absolute;
    border: 2px dashed #e94560;
    border-radius: 4px;
    background: rgba(233, 69, 96, 0.15);
    pointer-events: none;
    transition: left 0.05s, top 0.05s;
    z-index: 30;
}

.drag-preview.dragging {
    opacity: 0.7;
    border-color: #ff6b81;
    background: rgba(233, 69, 96, 0.25);
}

.canvas-container[draggable] { cursor: default; }

.canvas-container.drag-over {
    border: 2px dashed #e94560;
    border-radius: 8px;
}

/* ASCII art layer. A <div>, not a <pre>: the HTML parser strips the first
   newline right after a <pre> start tag, which would drop the first row of
   the art when it starts with an empty row (topmost block not at y=0). */
.canvas-container .ascii-art {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.3;
    color: #e0e0e0;
    white-space: pre;
}

/* ── Layout bounds (set width/height — visual guide only) ──
   A set layout width draws a vertical line at x=width, a set height a
   horizontal line at y=height. The lines do not constrain block
   placement or the canvas size and are not part of the ASCII art. */
.layout-bounds {
    position: absolute;
    pointer-events: none;
    z-index: 5;
}

.layout-bounds--v { border-left: 1px dashed rgba(233, 69, 96, 0.45); }
.layout-bounds--h { border-top: 1px dashed rgba(233, 69, 96, 0.45); }

/* ── Render overlay (block previews + resize handles) ──── */
.block-preview {
    position: absolute;
    pointer-events: auto;
    z-index: 10;
}

.block-inner {
    width: 100%;
    height: 100%;
    position: relative;
}

.block-border {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.block-border--solid { outline: 1px solid rgba(136, 136, 170, 0.5); }
.block-border--dashed { outline: 1px dashed rgba(136, 136, 170, 0.5); }
.block-border--dotted { outline: 1px dotted rgba(136, 136, 170, 0.5); }
.block-border--double { outline: 2px double rgba(136, 136, 170, 0.5); }
.block-border--none { outline: 1px dashed rgba(136, 136, 170, 0.3); }

/* Line blocks (hline / vline) */
.block-line {
    position: absolute;
    pointer-events: none;
}

.block-line--h { left: 0; right: 0; top: 50%; }
.block-line--v { top: 0; bottom: 0; left: 50%; }

.block-line--h.block-line--solid { border-top: 1px solid rgba(136, 136, 170, 0.5); }
.block-line--h.block-line--dashed { border-top: 1px dashed rgba(136, 136, 170, 0.5); }
.block-line--h.block-line--dotted { border-top: 1px dotted rgba(136, 136, 170, 0.5); }
.block-line--h.block-line--double { border-top: 3px double rgba(136, 136, 170, 0.5); }
.block-line--h.block-line--none { border-top: 1px dashed rgba(136, 136, 170, 0.3); }
.block-line--v.block-line--solid { border-left: 1px solid rgba(136, 136, 170, 0.5); }
.block-line--v.block-line--dashed { border-left: 1px dashed rgba(136, 136, 170, 0.5); }
.block-line--v.block-line--dotted { border-left: 1px dotted rgba(136, 136, 170, 0.5); }
.block-line--v.block-line--double { border-left: 3px double rgba(136, 136, 170, 0.5); }
.block-line--v.block-line--none { border-left: 1px dashed rgba(136, 136, 170, 0.3); }

/* Resize handle — bottom-right corner */
.resize-handle {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Cpath d='M8 1L4 5M8 3L3 8M6 1L8 1L8 3' stroke='%23888' stroke-width='1.2' fill='none'/%3E%3C/svg%3E");
    background-size: 10px 10px;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 20;
}

.resize-handle.visible { opacity: 1; }

.resize-handle:hover {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Cpath d='M8 1L4 5M8 3L3 8M6 1L8 1L8 3' stroke='%23e94560' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
}

/* ── Selection frame (single-click selection) ───────────── */
.block-selection {
    position: absolute;
    z-index: 100;
    pointer-events: none;
}

.block-selection__frame {
    position: absolute;
    inset: 0;
    background: rgba(233, 69, 96, 0.10);
    border: 1px solid rgba(233, 69, 96, 0.85);
    border-radius: 2px;
    pointer-events: none;
}

.sel-icon {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    font-size: 11px;
    line-height: 1;
    color: #fff;
    background: rgba(233, 69, 96, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 3px;
    pointer-events: auto;
    transition: background 0.15s;
}

.sel-icon--dup,
.sel-icon--del { cursor: pointer; }
.sel-icon--dup:hover,
.sel-icon--del:hover { background: #ff6b81; }

.sel-icon--dup { top: -9px; left: -9px; }
.sel-icon--del { top: -9px; right: -9px; }

/* Resize handle on the selection frame (bottom-right corner) */
.sel-resize {
    position: absolute;
    right: -9px;
    bottom: -9px;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    background-color: rgba(233, 69, 96, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 3px;
    pointer-events: auto;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Cpath d='M8 1L4 5M8 3L3 8M6 1L8 1L8 3' stroke='%23fff' stroke-width='1.2' fill='none'/%3E%3C/svg%3E");
    background-size: 10px 10px;
    background-repeat: no-repeat;
    background-position: center;
    transition: background-color 0.15s;
}

.sel-resize:hover { background-color: #ff6b81; }

/* ── Block properties panel (floats next to selected block) ─ */
.block-props {
    position: absolute;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    font-size: 12px;
}

.block-props__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.block-props__type {
    font-weight: 600;
    color: var(--accent);
    text-transform: capitalize;
}

.block-props__close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
}

.block-props__close:hover { color: var(--accent); }

.block-props__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
}

.prop {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.prop > span {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.prop input,
.prop select {
    background: #0f0f23;
    border: 1px solid #333;
    border-radius: 4px;
    color: var(--text);
    font-size: 12px;
    padding: 4px 6px;
    width: 100%;
}

.prop input:focus,
.prop select:focus {
    outline: none;
    border-color: var(--accent);
}

.prop--wide { grid-column: 1 / -1; }

/* ── Inline content editor (double-click a block) ───────── */
.block-edit-overlay {
    position: absolute;
    z-index: 40;
}

.block-edit-overlay textarea {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.3;
    color: #e0e0e0;
    background: #16213e;
    border: 1px solid var(--accent);
    border-radius: 2px;
    padding: 1px 3px;
    resize: none;
    outline: none;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 800px) {
    .editor-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        overflow-y: auto;
    }
    .editor-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 45vh;
    }
}
