* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #1e1e1e;
    color: #d4d4d4;
    height: 100vh;
    overflow: hidden;
}

#loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    font-size: 1.2em;
    flex-direction: column;
    gap: 12px;
}

#loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #333;
    border-top-color: #007acc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#app {
    display: none;
    flex-direction: column;
    height: 100vh;
}

.toolbar {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    background: #2d2d2d;
    border-bottom: 1px solid #404040;
    gap: 12px;
    flex-shrink: 0;
}

.toolbar h1 {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.toolbar select, .toolbar button {
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.toolbar select:hover, .toolbar button:hover {
    background: #4c4c4c;
}

.toolbar .spacer { flex: 1; }

#project-select {
    max-width: 220px;
}

#btn-new-project,
#btn-delete-project,
#btn-reset-example {
    padding: 4px 8px;
    font-size: 12px;
}

#btn-delete-project {
    color: #d4d4d4;
}

#btn-delete-project:hover {
    background: #c72e2e;
    border-color: #c72e2e;
}

#btn-reset-example:hover {
    background: #4c4c4c;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.editor-panel {
    display: flex;
    flex-direction: column;
    flex: 0 0 50%;
    min-width: 200px;
    border-right: none;
}

.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-section + .editor-section {
    border-top: 1px solid #404040;
}

.editor-label {
    padding: 4px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    background: #252526;
    flex-shrink: 0;
}

.editor-container {
    flex: 1;
    overflow: hidden;
}

.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-tabs {
    display: flex;
    align-items: center;
    background: #252526;
    border-bottom: 1px solid #404040;
    flex-shrink: 0;
}

.preview-tabs .spacer { flex: 1; }

#zoom-select {
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    margin-right: 8px;
}

.preview-tabs button {
    background: none;
    color: #888;
    border: none;
    padding: 6px 16px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.preview-tabs button.active {
    color: #d4d4d4;
    border-bottom-color: #007acc;
}

.preview-tabs button:hover {
    color: #d4d4d4;
}

.preview-content {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
    position: relative;
    min-height: 0;
}

.tab-pane { display: none; width: 100%; height: 100%; }
.tab-pane.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* preview-pane image styles moved to #preview-image-wrap img */

#errors-pane {
    align-items: flex-start;
    justify-content: flex-start;
    padding: 12px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 13px;
    color: #f48771;
    white-space: pre-wrap;
    overflow: auto;
}

#errors-pane:empty::after {
    content: 'No errors';
    color: #4ec9b0;
}

/* --- Layout inspector section (below preview) --- */
#layout-section {
    display: flex;
    flex-direction: column;
    border-top: 1px solid #404040;
    flex-shrink: 0;
    max-height: 40%;
    transition: max-height 0.2s;
}

#layout-section.collapsed {
    max-height: 28px;
}

#layout-section.collapsed #layout-pane {
    display: none;
}

#layout-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
    background: #252526;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

#layout-header:hover {
    color: #bbb;
}

#layout-toggle {
    background: none;
    border: none;
    color: #888;
    font-size: 10px;
    cursor: pointer;
    padding: 0 4px;
    transition: transform 0.2s;
}

#layout-section.collapsed #layout-toggle {
    transform: rotate(-90deg);
}

#layout-pane {
    padding: 8px 12px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 12px;
    overflow: auto;
    color: #9cdcfe;
    flex: 1;
    min-height: 60px;
}

#layout-pane:empty::after {
    content: 'No layout data — render a template first';
    color: #666;
}

/* --- Preview image wrapper with highlight overlay --- */
#preview-image-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 100%;
}

#preview-image-wrap img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#highlight-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.layout-tree {
    width: 100%;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
}

.layout-tree details {
    margin-left: 16px;
}

.layout-tree > details {
    margin-left: 0;
}

.layout-tree summary {
    cursor: pointer;
    list-style: none;
    padding: 1px 4px;
    border-radius: 3px;
}

.layout-tree summary:hover,
.layout-tree .layout-leaf:hover {
    background: rgba(0, 122, 204, 0.15);
}

.layout-tree summary::before {
    content: '\25B6';
    display: inline-block;
    width: 14px;
    font-size: 9px;
    transition: transform 0.15s;
}

.layout-tree details[open] > summary::before {
    transform: rotate(90deg);
}

.layout-leaf {
    margin-left: 16px;
    padding: 1px 4px 1px 18px;
}

.node-type {
    font-weight: 600;
    border-radius: 3px;
    padding: 0 4px;
}

.node-type[data-type="flex"] { color: #4caf50; }
.node-type[data-type="text"] { color: #2196f3; }
.node-type[data-type="image"] { color: #ff9800; }
.node-type[data-type="qr"] { color: #9c27b0; }
.node-type[data-type="barcode"] { color: #795548; }
.node-type[data-type="separator"] { color: #9e9e9e; }
.node-type[data-type="each"] { color: #00bcd4; }
.node-type[data-type="if"] { color: #ffeb3b; }
.node-type[data-type="table"] { color: #e91e63; }
.node-type[data-type="svg"] { color: #3f51b5; }
.node-type[data-type="content"] { color: #ff5722; }

.node-dims {
    color: #666;
    font-weight: 400;
}

.node-props {
    color: #888;
    font-weight: 400;
    font-size: 11px;
}

.layout-error {
    color: #f48771;
    padding: 8px;
}

/* Debug overlay toggle */
#overlay-toggle,
#bounds-toggle {
    font-size: 11px;
    color: #aaa;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
    cursor: pointer;
    user-select: none;
}

#overlay-toggle:hover,
#bounds-toggle:hover {
    color: #ddd;
}

#overlay-toggle input,
#bounds-toggle input {
    cursor: pointer;
}

.status-bar {
    display: flex;
    align-items: center;
    padding: 2px 12px;
    background: #007acc;
    color: #fff;
    font-size: 12px;
    flex-shrink: 0;
    gap: 16px;
}

.status-bar.error { background: #c72e2e; }

.drop-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 122, 204, 0.15);
    border: 3px dashed #007acc;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    pointer-events: none;
}

.drop-overlay.visible { display: flex; }

/* --- Draggable splitters --- */
.splitter-v {
    width: 5px;
    cursor: col-resize;
    background: #404040;
    flex-shrink: 0;
    transition: background 0.15s;
}

.splitter-h {
    height: 5px;
    cursor: row-resize;
    background: #404040;
    flex-shrink: 0;
    transition: background 0.15s;
}

.splitter-v:hover, .splitter-h:hover,
.splitter-v.active, .splitter-h.active {
    background: #007acc;
}

/* --- Collapsible editor sections --- */
.editor-label.collapsible {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.editor-label.collapsible:hover {
    color: #bbb;
}

.collapse-icon {
    font-size: 10px;
    transition: transform 0.2s;
}

.editor-section.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.editor-section.collapsed .editor-container,
.editor-section.collapsed .files-container {
    display: none;
}

.editor-section.collapsed {
    flex: 0 0 auto !important;
}

/* --- Files panel --- */
.files-container {
    flex: 1;
    overflow: auto;
    padding: 4px 0;
}

.files-toolbar {
    margin-left: auto;
}

.files-toolbar button {
    background: none;
    border: none;
    color: #888;
    font-size: 12px;
    cursor: pointer;
    padding: 0 4px;
}

.files-toolbar button:hover {
    color: #ddd;
}

/* --- File tree --- */
.files-tree {
    font-size: 12px;
    line-height: 1.6;
    padding: 0 8px;
}

.files-tree:empty::after {
    content: 'Drop files here or click + to add a folder';
    color: #666;
    padding: 8px;
    display: block;
}

.ft-node {
    cursor: default;
    padding: 1px 4px;
    border-radius: 3px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ft-node:hover {
    background: rgba(0, 122, 204, 0.15);
}

.ft-node.selected {
    background: rgba(0, 122, 204, 0.3);
}

.ft-node.drag-over {
    outline: 1px dashed #007acc;
}

.ft-icon {
    font-size: 14px;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.ft-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ft-name-input {
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #007acc;
    font-size: 12px;
    padding: 0 4px;
    outline: none;
    width: 100%;
}

.ft-children {
    margin-left: 16px;
}

.ft-dir > .ft-node .ft-arrow {
    display: inline-block;
    width: 10px;
    font-size: 8px;
    transition: transform 0.15s;
    text-align: center;
    flex-shrink: 0;
}

.ft-dir.open > .ft-node .ft-arrow {
    transform: rotate(90deg);
}

.ft-dir:not(.open) > .ft-children {
    display: none;
}

.ft-size {
    color: #666;
    font-size: 10px;
    margin-left: auto;
    flex-shrink: 0;
}

/* --- Context menu --- */
.ctx-menu {
    position: fixed;
    background: #2d2d2d;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 4px 0;
    min-width: 160px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    font-size: 12px;
}

.ctx-menu-item {
    padding: 4px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ctx-menu-item:hover {
    background: #094771;
}

.ctx-menu-sep {
    height: 1px;
    background: #404040;
    margin: 4px 0;
}

.ctx-menu-shortcut {
    color: #666;
    margin-left: auto;
    font-size: 11px;
}
