/* -- Strategy Builder -- */
/* Visual node-based strategy configuration interface.
 * Uses CSS variables from theme-base.css exclusively. */

/* -- Page Layout -- */
.sb-layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  grid-template-rows: 1fr auto;
  height: calc(100vh - 60px);
  overflow: hidden;
  position: relative;
}

/* -- Center area (canvas + code) -- */
.sb-center {
  display: flex;
  overflow: hidden;
  position: relative;
}

.sb-center .sb-canvas { flex: 1; min-width: 0; }
.sb-center .sb-code-panel { display: none; }

/* View modes */
.sb-layout.view-code .sb-center .sb-canvas { display: none; }
.sb-layout.view-code .sb-center .sb-code-panel { display: flex; flex: 1; }
.sb-layout.view-split .sb-center .sb-code-panel { display: flex; flex: 1; border-left: 1px solid var(--border); }
.sb-layout.view-split .sb-center .sb-canvas { flex: 1; }

/* Hide empty state in code mode */
.sb-layout.view-code .sb-canvas-empty { display: none; }

/* -- Block Palette (left sidebar) -- */
.sb-palette {
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.sb-palette-header {
  padding: 12px 16px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-palette-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-palette-search input {
  width: 100%;
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.sb-palette-search input:focus {
  border-color: var(--accent);
}

.sb-palette-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sb-palette-group {
  margin-bottom: 8px;
}

.sb-palette-group-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  padding: 6px 8px 4px;
}

.sb-palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s;
  user-select: none;
  position: relative;
}

.sb-palette-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--border);
  transition: background 0.15s;
}

.sb-palette-item[data-color="green"]::before { background: var(--accent); }
.sb-palette-item[data-color="blue"]::before { background: var(--blue); }
.sb-palette-item[data-color="orange"]::before { background: var(--orange); }
.sb-palette-item[data-color="purple"]::before { background: var(--purple); }
.sb-palette-item[data-color="red"]::before { background: var(--red); }
.sb-palette-item[data-color="yellow"]::before { background: var(--warning); }

.sb-palette-item:hover {
  border-color: var(--accent);
  box-shadow: var(--card-shadow);
}

.sb-palette-item:active {
  cursor: grabbing;
  opacity: 0.8;
}

.sb-palette-item-icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.sb-palette-item-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-palette-item-type {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* -- Canvas (center) -- */
.sb-canvas {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: default;
  min-width: 0;
}

.sb-canvas.panning {
  cursor: move;
}

.sb-canvas-inner {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
  width: 100%;
  height: 100%;
}

.sb-canvas-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

.sb-canvas-empty i {
  font-size: 32px;
  opacity: 0.3;
}

.sb-canvas-empty span {
  font-size: 12px;
}

/* -- Nodes -- */
.sb-node {
  position: absolute;
  width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
  user-select: none;
  z-index: 2;
}

.sb-node:hover {
  border-color: var(--muted);
}

.sb-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.sb-node.dragging {
  opacity: 0.8;
  cursor: grabbing;
  z-index: 10;
}

.sb-node-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  border-top: 4px solid var(--border);
  border-radius: 8px 8px 0 0;
  cursor: grab;
}

.sb-node.dragging .sb-node-header {
  cursor: grabbing;
}

/* -- Node type color variants (top border) -- */
/* Colors match backend BLOCK_CATEGORIES in protocol.py */
.sb-node[data-type="data"] .sb-node-header { border-top-color: #3b82f6; }
.sb-node[data-type="config"] .sb-node-header { border-top-color: #6b7280; }
.sb-node[data-type="indicator"] .sb-node-header { border-top-color: #06b6d4; }
.sb-node[data-type="condition"] .sb-node-header { border-top-color: #eab308; }
.sb-node[data-type="signal"] .sb-node-header { border-top-color: #22c55e; }
.sb-node[data-type="risk"] .sb-node-header { border-top-color: #f97316; }
.sb-node[data-type="event_processor"] .sb-node-header { border-top-color: #a855f7; }
.sb-node[data-type="exit"] .sb-node-header { border-top-color: #dc2626; }
.sb-node[data-type="position"] .sb-node-header { border-top-color: #ef4444; }
.sb-node[data-type="metrics"] .sb-node-header { border-top-color: #10b981; }
.sb-node[data-type="output"] .sb-node-header { border-top-color: #475569; }

.sb-node-header-icon {
  font-size: 12px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.sb-node[data-type="data"] .sb-node-header-icon { color: #3b82f6; }
.sb-node[data-type="config"] .sb-node-header-icon { color: #6b7280; }
.sb-node[data-type="indicator"] .sb-node-header-icon { color: #06b6d4; }
.sb-node[data-type="condition"] .sb-node-header-icon { color: #eab308; }
.sb-node[data-type="signal"] .sb-node-header-icon { color: #22c55e; }
.sb-node[data-type="risk"] .sb-node-header-icon { color: #f97316; }
.sb-node[data-type="event_processor"] .sb-node-header-icon { color: #a855f7; }
.sb-node[data-type="exit"] .sb-node-header-icon { color: #dc2626; }
.sb-node[data-type="position"] .sb-node-header-icon { color: #ef4444; }
.sb-node[data-type="metrics"] .sb-node-header-icon { color: #10b981; }
.sb-node[data-type="output"] .sb-node-header-icon { color: #475569; }

.sb-node-header-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-node-body {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.5;
}

.sb-node-body:empty {
  display: none;
}

/* -- Ports -- */
.sb-port {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  transform: translateY(-50%);
  cursor: crosshair;
  z-index: 3;
  transition: transform 0.15s, border-color 0.15s;
}

.sb-port-input {
  left: -5px;
}

.sb-port-output {
  right: -5px;
}

.sb-port:hover {
  transform: translateY(-50%) scale(1.3);
}

.sb-port.connected {
  background: var(--accent);
  border-color: var(--accent);
}

.sb-port.compatible {
  border-color: var(--accent);
  animation: sb-port-pulse 1s ease-in-out infinite;
}

@keyframes sb-port-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 4px var(--accent-glow); }
}

/* -- Port data type colors -- */
.sb-port[data-dtype="signal"] { border-color: var(--accent); }
.sb-port[data-dtype="signal"].connected { background: var(--accent); }

.sb-port[data-dtype="number"] { border-color: var(--blue); }
.sb-port[data-dtype="number"].connected { background: var(--blue); }

.sb-port[data-dtype="boolean"] { border-color: var(--orange); }
.sb-port[data-dtype="boolean"].connected { background: var(--orange); }

.sb-port[data-dtype="series"] { border-color: var(--purple); }
.sb-port[data-dtype="series"].connected { background: var(--purple); }

.sb-port[data-dtype="config"] { border-color: var(--muted); }
.sb-port[data-dtype="config"].connected { background: var(--muted); }

/* -- Connections (SVG overlay) -- */
.sb-connections {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

.sb-connection {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
  pointer-events: stroke;
  transition: stroke 0.15s, stroke-width 0.15s;
}

.sb-connection:hover {
  stroke-width: 3;
  stroke: var(--text-secondary);
}

.sb-connection.active {
  stroke: var(--accent);
}

.sb-connection-temp {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

/* -- Property Panel (right sidebar) -- */
.sb-properties {
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.sb-properties-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-top: 4px solid var(--border);
  flex-shrink: 0;
}

.sb-properties-header[data-type="data"] { border-top-color: #3b82f6; }
.sb-properties-header[data-type="config"] { border-top-color: #6b7280; }
.sb-properties-header[data-type="indicator"] { border-top-color: #06b6d4; }
.sb-properties-header[data-type="condition"] { border-top-color: #eab308; }
.sb-properties-header[data-type="signal"] { border-top-color: #22c55e; }
.sb-properties-header[data-type="risk"] { border-top-color: #f97316; }
.sb-properties-header[data-type="event_processor"] { border-top-color: #a855f7; }
.sb-properties-header[data-type="exit"] { border-top-color: #dc2626; }
.sb-properties-header[data-type="position"] { border-top-color: #ef4444; }
.sb-properties-header[data-type="metrics"] { border-top-color: #10b981; }
.sb-properties-header[data-type="output"] { border-top-color: #475569; }

.sb-properties-header-icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sb-properties-header-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-properties-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sb-properties-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 24px;
}

/* -- Property Fields -- */
.sb-prop-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sb-prop-field label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.sb-prop-field input,
.sb-prop-field select,
.sb-prop-field textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sb-prop-field input:focus,
.sb-prop-field select:focus,
.sb-prop-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.sb-prop-field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2371717a' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: 32px;
}

.sb-prop-field input[type="number"] {
  font-family: 'JetBrains Mono', monospace;
}

.sb-prop-field textarea {
  resize: vertical;
  min-height: 60px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.5;
}

.sb-prop-hint {
  font-size: 11px;
  color: var(--muted);
}

.sb-prop-separator {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* -- Toolbar (bottom bar) -- */
.sb-toolbar {
  grid-column: 2 / 3;
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.sb-toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sb-toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.sb-toolbar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  margin-right: 4px;
}

.sb-toolbar .chip {
  padding: 4px 10px;
  font-size: 11px;
}

.sb-toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.sb-toolbar-btn:hover {
  border-color: var(--muted);
  color: var(--text);
}

.sb-toolbar-btn:active {
  transform: scale(0.95);
  opacity: 0.85;
  transition: none;
}

.sb-toolbar-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

.sb-toolbar-zoom {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  min-width: 36px;
  text-align: center;
}

.sb-toolbar-spacer {
  flex: 1;
}

.sb-toolbar .btn-primary {
  padding: 6px 16px;
  font-size: 12px;
}

/* -- JSON Preview Panel -- */
.sb-json-preview {
  position: absolute;
  bottom: 48px;
  left: 280px;
  right: 300px;
  max-height: 0;
  overflow: hidden;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 15;
  transition: max-height 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sb-json-preview.open {
  max-height: 300px;
  overflow: auto;
}

.sb-json-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

.sb-json-preview-header span {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.sb-json-preview pre {
  padding: 12px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre;
  tab-size: 2;
  margin: 0;
}

.sb-json-preview pre .json-key { color: var(--blue); }
.sb-json-preview pre .json-str { color: var(--accent); }
.sb-json-preview pre .json-num { color: var(--orange); }
.sb-json-preview pre .json-bool { color: var(--purple); }
.sb-json-preview pre .json-null { color: var(--muted); }

/* -- Drawflow Theme Override -- */
.sb-drawflow-theme .drawflow {
  background:
    radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
}

.sb-drawflow-theme .drawflow .drawflow-node {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  color: var(--text);
  min-width: 200px;
  padding: 0;
}

.sb-drawflow-theme .drawflow .drawflow-node:hover {
  border-color: var(--muted);
}

.sb-drawflow-theme .drawflow .drawflow-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.sb-drawflow-theme .drawflow .drawflow-node .title-box {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.sb-drawflow-theme .drawflow .drawflow-node .box {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.sb-drawflow-theme .drawflow .drawflow-node .input,
.sb-drawflow-theme .drawflow .drawflow-node .output {
  width: 10px;
  height: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
}

.sb-drawflow-theme .drawflow .drawflow-node .input:hover,
.sb-drawflow-theme .drawflow .drawflow-node .output:hover {
  transform: scale(1.3);
}

.sb-drawflow-theme .drawflow .connection .main-path {
  stroke: var(--accent);
  stroke-width: 2;
}

.sb-drawflow-theme .drawflow .connection .main-path:hover {
  stroke-width: 3;
}

.sb-drawflow-theme .drawflow .drawflow-delete {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* -- Code Panel -- */
.sb-code-panel {
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.sb-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.sb-code-header-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.sb-code-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.sb-code-gutter {
  width: 40px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
  text-align: right;
  user-select: none;
  overflow: hidden;
  flex-shrink: 0;
}

.sb-code-editor {
  flex: 1;
  padding: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.sb-code-status {
  padding: 4px 12px;
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 22px;
}

.sb-code-status.error { color: var(--red); }
.sb-code-status.valid { color: var(--green); }

/* -- Version Panel (right drawer) -- */
.sb-version-panel {
  position: absolute;
  top: 0;
  right: 300px;
  width: 280px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 25;
  transform: translateX(100%);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -4px 0 12px rgba(0,0,0,0.15);
}

.sb-version-panel.open {
  transform: translateX(0);
}

.sb-version-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
}

.sb-version-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sb-version-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 24px;
}

.sb-version-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.sb-version-item:hover { border-color: var(--accent); }
.sb-version-item.active { border-color: var(--accent); background: var(--accent-bg); }

.sb-version-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.sb-version-item-num {
  font-size: 12px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
}

.sb-version-item-date {
  font-size: 10px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.sb-version-item-changelog {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-version-item-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.sb-version-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* -- Quick Preview Overlay -- */
.sb-preview-overlay {
  position: absolute;
  bottom: 48px;
  left: 280px;
  right: 300px;
  max-height: 0;
  overflow: hidden;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 18;
  transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.sb-preview-overlay.open {
  max-height: 320px;
  overflow: auto;
}

.sb-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-preview-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.sb-preview-status {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
}

.sb-preview-status.running { color: var(--accent); }
.sb-preview-status.done { color: var(--green); }
.sb-preview-status.error { color: var(--red); }

.sb-preview-stats {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.sb-preview-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sb-preview-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.sb-preview-stat-value {
  font-size: 14px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
}

.sb-preview-stat-value.positive { color: var(--green); }
.sb-preview-stat-value.negative { color: var(--red); }

.sb-preview-chart {
  flex: 1;
  min-height: 120px;
  padding: 8px 16px;
  overflow-x: auto;
}

.sb-preview-trades {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  max-height: 220px;
  overflow-y: auto;
}

.sb-preview-mode-btn.active {
  background: var(--accent);
  color: var(--bg);
}

/* -- Responsive -- */
@media (max-width: 768px) {
  .sb-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
    min-height: calc(100vh - 60px);
  }

  .sb-palette {
    grid-row: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
  }

  .sb-palette-list {
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .sb-center { flex-direction: column; }
  .sb-canvas { min-height: 400px; }
  .sb-layout.view-split .sb-center .sb-code-panel { border-left: none; border-top: 1px solid var(--border); }

  .sb-properties {
    grid-row: auto;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 300px;
  }

  .sb-toolbar {
    grid-column: 1 / -1;
    flex-wrap: wrap;
  }

  .sb-json-preview { left: 0; right: 0; }
  .sb-preview-overlay { left: 0; right: 0; }
  .sb-version-panel { right: 0; width: 100%; }
}
