/* ========== CSS Variables ========== */
:root {
  --bg-primary: #0a0a0b;
  --bg-secondary: #111113;
  --bg-tertiary: #18181b;
  --bg-elevated: #1f1f23;
  --bg-hover: #27272a;
  --border-subtle: #27272a;
  --border-default: #3f3f46;
  --border-active: #52525b;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent-primary: #6366f1;
  --accent-hover: #818cf8;
  --accent-subtle: rgba(99, 102, 241, 0.15);
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  --font-sans: 'Manrope', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app { height: 100%; overflow: hidden; }
body { font-family: var(--font-sans); background: var(--bg-primary); color: var(--text-primary); font-size: 13px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 3px; }

/* Layout */
.app-layout { display: grid; grid-template-columns: 240px 1fr 280px; grid-template-rows: 48px 1fr 28px; height: 100%; gap: 1px; background: var(--border-subtle); }

/* Header */
.app-header { grid-column: 1 / -1; background: var(--bg-secondary); display: flex; align-items: center; padding: 0 16px; gap: 16px; border-bottom: 1px solid var(--border-subtle); }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; }
.logo-icon { width: 28px; height: 28px; background: linear-gradient(135deg, var(--accent-primary), #8b5cf6); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 14px; color: white; }
.header-tabs { display: flex; gap: 4px; margin-left: 24px; }
.header-tab { padding: 6px 12px; background: transparent; border: none; color: var(--text-secondary); font-family: inherit; font-size: 12px; font-weight: 500; border-radius: var(--radius-md); cursor: pointer; transition: all 0.15s; }
.header-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.header-tab.active { background: var(--accent-subtle); color: var(--accent-hover); }
.header-actions { margin-left: auto; display: flex; gap: 8px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--bg-tertiary); border: 1px solid var(--border-default); color: var(--text-primary); font-family: inherit; font-size: 12px; font-weight: 500; border-radius: var(--radius-md); cursor: pointer; transition: all 0.15s; }
.btn:hover { background: var(--bg-hover); border-color: var(--border-active); }
.btn-primary { background: var(--accent-primary); border-color: var(--accent-primary); color: white; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* Sidebars */
.sidebar-left, .sidebar-right { background: var(--bg-secondary); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-section { border-bottom: 1px solid var(--border-subtle); }
.sidebar-section:last-child { border-bottom: none; flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.section-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.section-header button { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: var(--text-muted); border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; }
.section-header button:hover { background: var(--bg-hover); color: var(--text-primary); }
.section-content { padding: 0 8px 8px; }

/* Pages & Layers */
.pages-list { display: flex; flex-direction: column; gap: 2px; }
.page-item, .layer-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: transparent; border: none; border-radius: var(--radius-md); color: var(--text-secondary); font-family: inherit; font-size: 12px; cursor: pointer; text-align: left; width: 100%; transition: all 0.15s; }
.page-item:hover, .layer-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.page-item.active, .layer-item.selected { background: var(--accent-subtle); color: var(--accent-hover); }
.layers-container { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.layer-item { padding: 6px 8px; font-size: 11px; border-radius: var(--radius-sm); }

/* Components Grid */
.components-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.component-item { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-secondary); font-size: 10px; cursor: grab; transition: all 0.15s; }
.component-item:hover { background: var(--bg-hover); border-color: var(--border-default); color: var(--text-primary); }
.component-item:active { cursor: grabbing; }
.component-item .comp-icon { font-size: 18px; }

/* Main Area */
.main-area { background: var(--bg-primary); display: flex; flex-direction: column; overflow: hidden; }

/* Canvas Toolbar */
.canvas-toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--bg-secondary); border-bottom: 1px solid var(--border-subtle); }
.toolbar-group { display: flex; gap: 2px; padding: 2px; background: var(--bg-tertiary); border-radius: var(--radius-md); }
.toolbar-btn { width: 28px; height: 24px; display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: var(--text-secondary); border-radius: var(--radius-sm); cursor: pointer; font-size: 12px; transition: all 0.15s; }
.toolbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.toolbar-btn.active { background: var(--accent-subtle); color: var(--accent-hover); }
.toolbar-separator { width: 1px; height: 20px; background: var(--border-subtle); margin: 0 4px; }
.zoom-control { display: flex; align-items: center; gap: 6px; margin-left: auto; font-size: 11px; color: var(--text-muted); }
.zoom-value { min-width: 40px; text-align: center; font-family: var(--font-mono); }

/* Canvas */
.canvas-container { flex: 1; position: relative; overflow: hidden; background: radial-gradient(circle at center, var(--bg-tertiary) 0%, var(--bg-primary) 100%), repeating-linear-gradient(0deg, transparent, transparent 19px, var(--border-subtle) 19px, var(--border-subtle) 20px), repeating-linear-gradient(90deg, transparent, transparent 19px, var(--border-subtle) 19px, var(--border-subtle) 20px); background-size: 100% 100%, 20px 20px, 20px 20px; }
.canvas-viewport { position: absolute; top: 50%; left: 50%; transform-origin: center; }
.canvas-artboard { background: #141416; border: 1px solid var(--border-default); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.artboard-label { position: absolute; top: -22px; left: 0; font-size: 10px; color: var(--text-muted); }

/* Canvas Elements */
.canvas-element { position: absolute; cursor: move; user-select: none; }
.canvas-element.selected { outline: 2px solid var(--accent-primary); outline-offset: 2px; }
.canvas-element.text { padding: 4px 8px; font-size: 14px; color: var(--text-primary); white-space: nowrap; }
.canvas-element .el-button { padding: 8px 16px; background: var(--accent-primary); border: none; border-radius: var(--radius-md); color: white; font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.canvas-element .el-progress { background: rgba(255,255,255,0.1); border-radius: 100px; height: 8px; width: 100%; overflow: hidden; }
.canvas-element .el-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent-primary), var(--success)); border-radius: 100px; transition: width 0.3s; }
.canvas-element .el-input { padding: 8px 12px; background: var(--bg-tertiary); border: 1px solid var(--border-default); border-radius: var(--radius-md); color: var(--text-primary); font-family: inherit; font-size: 13px; width: 100%; }
.canvas-element .el-image { background: var(--bg-tertiary); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 24px; width: 100%; height: 100%; min-height: 60px; }
.canvas-element .el-container { background: rgba(255,255,255,0.02); border: 1px dashed var(--border-default); border-radius: var(--radius-md); width: 100%; height: 100%; min-height: 60px; }

/* Resize Handles */
.resize-handle { position: absolute; width: 8px; height: 8px; background: var(--accent-primary); border: 1px solid white; border-radius: 2px; }
.resize-handle.nw { top: -4px; left: -4px; cursor: nw-resize; }
.resize-handle.ne { top: -4px; right: -4px; cursor: ne-resize; }
.resize-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }

/* Logic Editor */
.logic-editor { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.logic-toolbar { display: flex; gap: 6px; padding: 8px 12px; background: var(--bg-secondary); border-bottom: 1px solid var(--border-subtle); }
.logic-canvas { flex: 1; position: relative; overflow: auto; background: var(--bg-primary); min-height: 400px; }
.logic-connections { position: absolute; top: 0; left: 0; width: 2000px; height: 2000px; pointer-events: none; }
.logic-node { position: absolute; background: var(--bg-elevated); border: 1px solid var(--border-default); border-radius: var(--radius-md); min-width: 200px; box-shadow: var(--shadow-md); cursor: move; }
.logic-node.selected { border-color: var(--accent-primary); }
.logic-node-header { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border-subtle); font-weight: 600; font-size: 11px; }
.logic-node-body { padding: 10px 12px; }
.node-field { margin-bottom: 8px; }
.node-field:last-child { margin-bottom: 0; }
.node-field label { display: block; font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.node-field input, .node-field select { width: 100%; padding: 6px 8px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); color: var(--text-primary); font-family: inherit; font-size: 11px; }
.node-field input.mono { font-family: var(--font-mono); }
.node-trigger .logic-node-header { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.node-condition .logic-node-header { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.node-action .logic-node-header { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.node-output, .node-input { position: absolute; width: 12px; height: 12px; border-radius: 50%; top: 50%; transform: translateY(-50%); cursor: crosshair; }
.node-output { right: -6px; background: var(--accent-primary); }
.node-input { left: -6px; background: var(--bg-tertiary); border: 2px solid var(--accent-primary); }
.node-delete { margin-left: auto; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; border-radius: var(--radius-sm); }
.node-delete:hover { background: var(--error); color: white; }

/* Props Editor */
.props-editor-container { flex: 1; overflow-y: auto; padding: 20px; }
.props-editor-inner { max-width: 600px; margin: 0 auto; }
.props-editor-inner h2 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.props-description { color: var(--text-secondary); font-size: 13px; margin-bottom: 20px; }
.props-description code { background: var(--bg-tertiary); padding: 2px 6px; border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 12px; }
.schema-list { margin-bottom: 24px; }
.schema-item { background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); margin-bottom: 8px; overflow: hidden; }
.schema-item-header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--bg-elevated); cursor: pointer; }
.schema-item-header:hover { background: var(--bg-hover); }
.schema-toggle { font-size: 10px; color: var(--text-muted); width: 12px; }
.schema-name { flex: 1; font-family: var(--font-mono); font-size: 13px; color: var(--accent-hover); }
.schema-type { font-size: 11px; color: var(--text-muted); padding: 2px 6px; background: var(--bg-tertiary); border-radius: var(--radius-sm); }
.schema-delete { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm); }
.schema-delete:hover { background: var(--error); color: white; }
.schema-item-body { padding: 12px; }
.nested-props-header { margin-top: 12px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }
.nested-props { margin-left: 12px; padding-left: 12px; border-left: 1px solid var(--border-subtle); }
.nested-prop { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.nested-name { width: 100px; font-size: 11px; }
.nested-type { width: 80px; font-size: 11px; }
.nested-delete { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; }
.add-nested-btn { margin-top: 8px; padding: 6px 10px; background: transparent; border: 1px dashed var(--border-default); border-radius: var(--radius-sm); color: var(--text-muted); font-family: inherit; font-size: 11px; cursor: pointer; }
.add-nested-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.add-prop-btn { display: flex; align-items: center; justify-content: center; width: 100%; padding: 12px; background: transparent; border: 1px dashed var(--border-default); border-radius: var(--radius-md); color: var(--text-muted); font-family: inherit; font-size: 13px; cursor: pointer; }
.add-prop-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); background: var(--accent-subtle); }
.schema-preview h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.schema-json { background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 16px; font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); overflow-x: auto; white-space: pre; }

/* Right Sidebar Props */
.props-tabs { display: flex; border-bottom: 1px solid var(--border-subtle); }
.props-tab { flex: 1; padding: 10px; background: transparent; border: none; color: var(--text-muted); font-family: inherit; font-size: 11px; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; }
.props-tab:hover { color: var(--text-secondary); }
.props-tab.active { color: var(--accent-hover); border-bottom-color: var(--accent-primary); }
.props-content { flex: 1; overflow-y: auto; padding: 12px; }
.props-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 12px; }
.props-section { margin-bottom: 16px; }
.section-title { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }
.prop-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.prop-row label { width: 60px; font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }
.prop-row input, .prop-row select { flex: 1; padding: 6px 8px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); color: var(--text-primary); font-family: inherit; font-size: 11px; }
.prop-row input:focus, .prop-row select:focus { outline: none; border-color: var(--accent-primary); }
.prop-row input.mono { font-family: var(--font-mono); }
.prop-row-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.prop-input-group { display: flex; }
.prop-input-group input { flex: 1; border-radius: var(--radius-sm) 0 0 var(--radius-sm); padding: 6px 8px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); color: var(--text-primary); font-family: var(--font-mono); font-size: 11px; width: 100%; }
.prop-input-group .suffix { padding: 6px 8px; background: var(--bg-hover); border: 1px solid var(--border-subtle); border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-muted); font-size: 10px; }
.color-input { display: flex; gap: 8px; flex: 1; }
.color-input input[type="color"] { width: 28px; height: 28px; padding: 0; border: 1px solid var(--border-default); border-radius: var(--radius-sm); cursor: pointer; }
.color-input input[type="text"] { flex: 1; }
.bindings-hint { font-size: 11px; color: var(--text-muted); margin-bottom: 12px; }
.bindings-hint code { background: var(--bg-tertiary); padding: 1px 4px; border-radius: 2px; font-family: var(--font-mono); }
.available-paths { background: var(--bg-tertiary); border-radius: var(--radius-md); padding: 8px; }
.path-item { padding: 6px 8px; cursor: pointer; border-radius: var(--radius-sm); display: flex; justify-content: space-between; align-items: center; }
.path-item:hover { background: var(--bg-hover); }
.path-item code { color: var(--accent-hover); font-size: 11px; }
.path-item .copy-hint { font-size: 9px; color: var(--text-muted); opacity: 0; }
.path-item:hover .copy-hint { opacity: 1; }
.no-paths { color: var(--text-muted); font-size: 11px; padding: 8px; text-align: center; }

/* Footer */
.app-footer { grid-column: 1 / -1; background: var(--bg-secondary); display: flex; align-items: center; padding: 0 12px; font-size: 10px; color: var(--text-muted); gap: 16px; }
.footer-item { display: flex; align-items: center; gap: 6px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.footer-version { margin-left: auto; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(4px); }
.modal { background: var(--bg-elevated); border: 1px solid var(--border-default); border-radius: var(--radius-lg); width: 90%; max-width: 600px; max-height: 80vh; overflow: hidden; box-shadow: var(--shadow-lg); }
.modal-small { max-width: 400px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border-subtle); }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: var(--text-muted); border-radius: var(--radius-sm); cursor: pointer; font-size: 18px; }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body { padding: 20px; overflow-y: auto; max-height: 60vh; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border-subtle); }
.export-platform { margin-bottom: 16px; }
.export-platform label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.export-platform select { width: 100%; padding: 8px 12px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-primary); font-family: inherit; font-size: 13px; }
.export-preview { background: var(--bg-primary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); overflow: hidden; }
.export-tabs { display: flex; border-bottom: 1px solid var(--border-subtle); }
.export-tab { padding: 8px 16px; background: transparent; border: none; color: var(--text-muted); font-family: inherit; font-size: 12px; cursor: pointer; }
.export-tab.active { background: var(--bg-secondary); color: var(--text-primary); }
.export-code { padding: 16px; font-family: var(--font-mono); font-size: 11px; line-height: 1.6; color: var(--text-secondary); white-space: pre-wrap; overflow-x: auto; max-height: 300px; margin: 0; }
.prop-row-vertical { margin-bottom: 12px; }
.prop-row-vertical label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.prop-row-vertical input, .prop-row-vertical select { width: 100%; padding: 8px 12px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-primary); font-family: inherit; font-size: 13px; }
