*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-hover: #f5f7fa;
  --bg-active: #e8ecf1;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-blue: #4f6df5;
  --accent-blue-light: #eef2ff;
  --accent-blue-bg: #e0e7ff;
  --accent-green: #22c55e;
  --accent-green-light: #f0fdf4;
  --accent-red: #ef4444;
  --accent-red-light: #fef2f2;
  --accent-orange: #f97316;
  --accent-purple: #8b5cf6;
  --accent-yellow: #eab308;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --radius: 6px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --font-mono: 'Courier New', Consolas, monospace;
  --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --req-color: #ef4444;
  --opt-color: #22c55e;
  --ui-font-size: 14px;
  --code-font-size: 12.5px;
  --tree-font-size: 13px;
  --panel-header-font-size: 13px;
  --code-text-color: var(--text-primary);
  --code-bg: var(--bg-primary);
  --panel-code-bg: var(--bg-secondary);
  --tree-text-color: var(--text-primary);
  --code-highlight-bg: #fef08a;
  --accent-blue-hover: #4361ee;
}

body { font-family: var(--font-sans); font-size: var(--ui-font-size); background: var(--bg-primary); color: var(--text-primary); height: 100vh; overflow: hidden; }
#app { display: flex; flex-direction: column; height: 100vh; }

/* ─── Header ─── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px; background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm); z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 20px; }
.header-left h1 { font-size: 1.15rem; font-weight: 700; color: var(--text-primary); }
.header-left .subtitle { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; }

/* ─── Mode Switcher ─── */
.mode-switcher {
  display: flex; background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-md); overflow: hidden;
}
/* Shared header control typography / height */
.mode-btn,
.file-label,
.btn-clear,
.btn-help,
.btn-settings,
.btn-gen-example {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  height: 32px;
  box-sizing: border-box;
  vertical-align: middle;
}

.mode-btn {
  padding: 0 14px; border: none; background: none; cursor: pointer;
  color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.2s; white-space: nowrap;
}
.mode-btn.active { background: var(--accent-blue); color: #fff; font-weight: 600; }
.mode-btn:hover:not(.active) { background: var(--bg-hover); color: var(--text-primary); }

.header-right { display: flex; align-items: center; gap: 10px; }


/* ─── File Label ─── */
.file-label {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 16px; background: var(--accent-blue); color: #fff;
  border-radius: var(--radius-md); cursor: pointer;
  transition: background 0.2s;
  border: 2px solid transparent; white-space: nowrap;
}
.file-label:hover { filter: brightness(0.92); }
.file-label input { display: none; }

.btn-clear {
  width: 32px; min-width: 32px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted); transition: all 0.2s; padding: 0;
}
.btn-clear:hover { background: var(--accent-red-light); color: var(--accent-red); border-color: var(--accent-red); }

.btn-help {
  width: 32px; min-width: 32px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--accent-blue); transition: all 0.2s; padding: 0;
}
.btn-help:hover { background: var(--accent-blue-light, #e8eeff); color: var(--accent-blue); border-color: var(--accent-blue); }

.btn-settings {
  width: 32px; min-width: 32px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--accent-blue); transition: all 0.2s; padding: 0;
}
.btn-settings:hover { background: var(--accent-blue-light, #e8eeff); color: var(--accent-blue); border-color: var(--accent-blue); }

.help-legend { display: flex; flex-direction: column; gap: 12px; font-size: 0.86rem; line-height: 1.45; color: var(--text-primary); }
.help-legend dt { font-weight: 700; margin: 0 0 2px 0; color: var(--text-primary); }
.help-legend dd { margin: 0 0 0 0; color: var(--text-secondary); padding-left: 0; }
.help-legend .swatch {
  display: inline-block; width: 18px; height: 12px; border-radius: 2px; margin-right: 6px;
  vertical-align: middle; box-sizing: border-box;
}
.help-legend .swatch-req { border: 2px solid var(--accent-red); background: transparent; }
.help-legend .swatch-opt { border: 2px dashed var(--accent-green); background: transparent; }
.help-legend .swatch-struct { border: 2px solid #94a3b8; background: transparent; }
.help-legend .swatch-attr { color: #38bdf8; font-weight: 700; font-family: var(--font-mono); margin-right: 4px; }
.help-legend .swatch-type { color: var(--accent-purple); font-family: var(--font-mono); font-size: 0.8rem; }
.help-legend .swatch-doc { color: var(--text-muted); font-style: italic; }
.help-legend .swatch-match { color: var(--accent-green); font-weight: 600; }
.help-legend .swatch-miss { color: var(--accent-red); font-weight: 600; }
.help-legend .swatch-extra { color: var(--text-muted); font-weight: 600; }
.help-legend .swatch-hl { background: #fef08a; padding: 0 4px; border-radius: 2px; }

/* ─── Main Content ─── */
#mainContent { display: flex; flex: 1; overflow: hidden; position: relative; }

/* ─── Resizer ─── */
.resizer {
  width: 5px; background: transparent; cursor: col-resize;
  position: relative; flex-shrink: 0; z-index: 2;
}
.resizer::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 2px; background: transparent; transition: background 0.12s; pointer-events: none;
}
.resizer:hover::before,
.resizer.dragging::before {
  background: var(--accent-blue);
}
/* no mid grip — keeps a continuous divider line while dragging */
.resizer::after { content: none; display: none; }

/* ─── Code Panel (Left) ─── */
.panel-code { width: 48%; min-width: 300px; background: var(--panel-code-bg, var(--bg-secondary)); border-right: none; display: flex; flex-direction: column; overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; border-bottom: 1px solid var(--border-light); flex-shrink: 0; }
.panel-header h2 { font-size: var(--panel-header-font-size); font-weight: 600; color: var(--text-secondary); }

/* Find bar (code panel only) */
.code-find-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-bottom: 1px solid var(--border-light);
  background: var(--bg-secondary); flex-shrink: 0;
}
.code-find-bar.hidden { display: none; }
.code-find-bar input[type="search"] {
  flex: 1; min-width: 0; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-primary); color: var(--text-primary);
  font-size: 0.82rem; font-family: var(--font-sans);
}
.code-find-bar input[type="search"]:focus { outline: none; border-color: var(--accent-blue); }
.code-find-count { font-size: 0.72rem; color: var(--text-muted); font-family: var(--font-mono); white-space: nowrap; min-width: 3.5em; text-align: right; }
.code-find-btn {
  width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-primary); color: var(--text-secondary); cursor: pointer; font-size: 0.85rem; line-height: 1;
}
.code-find-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent-blue); }

.code-tabs {
  display: flex; gap: 0; padding: 0 8px;
  border-bottom: 1px solid var(--border-light); flex-shrink: 0;
  background: var(--panel-code-bg, var(--bg-secondary));
}
.code-tab {
  padding: 8px 14px; background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; font-size: var(--panel-header-font-size); font-weight: 500; color: var(--text-muted); transition: all 0.2s;
}
.code-tab:hover { color: var(--text-secondary); }
.code-tab.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); font-weight: 600; }
/* Types file checkbox (header) */
.types-file-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  font-family: var(--font-sans); font-size: 0.82rem; font-weight: 600;
  color: var(--text-muted); background: var(--bg-primary);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  cursor: pointer; user-select: none; white-space: nowrap;
  box-sizing: border-box; transition: all 0.2s;
}
.types-file-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.types-file-toggle:has(input:checked) {
  background: var(--accent-blue-light, #e8eeff); color: var(--accent-blue);
  border-color: var(--accent-blue);
}
.types-file-toggle input { margin: 0; cursor: pointer; accent-color: var(--accent-blue); }
.types-file-hint {
  font-size: 0.75rem; color: var(--accent-red); max-width: 220px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.types-file-hint.hidden { display: none; }
.code-tab.hidden { display: none; }


.code-body { flex: 1; overflow: auto; background: var(--code-bg, var(--bg-primary)); position: relative; }
.code-block { padding: 14px; font-family: var(--font-mono); font-size: var(--code-font-size); line-height: 1.55; white-space: normal; word-break: break-all; color: var(--code-text-color, var(--text-primary)); tab-size: 2; margin: 0; }
.code-block.active { display: block; }
.code-block:not(.active) { display: none; }
.code-line { white-space: pre-wrap; word-break: break-all; padding: 0 4px; border-radius: 2px; min-height: 1.55em; color: inherit; cursor: pointer; }
.code-line.highlighted {
  background: var(--code-highlight-bg, #fef08a);
  color: #0f172a !important;
}
.code-line.find-hit { background: rgba(96, 165, 250, 0.35); outline: 1px solid var(--accent-blue); }
.code-line.find-hit.find-current { background: rgba(250, 204, 21, 0.55); outline: 2px solid var(--accent-orange, #fb923c); }
.code-line.find-hit.highlighted,
.code-line.find-hit.find-current.highlighted {
  background: var(--code-highlight-bg, #fef08a);
  color: #0f172a !important;
}


/* === XML syntax tokens (Oxygen-like) === */
.tok-punct { color: var(--tok-punct, #64748b); }
.tok-name { color: var(--tok-name, #1d4ed8); font-weight: 600; }
.tok-prefix { color: var(--tok-prefix, #7c3aed); }
.tok-attr { color: var(--tok-attr, #b91c1c); }
.tok-value { color: var(--tok-value, #0369a1); }
.tok-text { color: var(--tok-text, var(--code-text-color, var(--text-primary))); }
.tok-comment { color: var(--tok-comment, #15803d); font-style: italic; }

.code-line.highlighted .tok-punct,
.code-line.highlighted .tok-name,
.code-line.highlighted .tok-prefix,
.code-line.highlighted .tok-attr,
.code-line.highlighted .tok-value,
.code-line.highlighted .tok-text,
.code-line.highlighted .tok-comment {
  color: inherit;
  font-style: normal;
}

[data-theme="dark"] {
  --tok-punct: #94a3b8;
  --tok-name: #7dd3fc;
  --tok-prefix: #c4b5fd;
  --tok-attr: #f9a8d4;
  --tok-value: #86efac;
  --tok-text: var(--code-text-color, var(--text-primary));
  --tok-comment: #4ade80;
}

[data-theme="contrast"] {
  --tok-punct: #ffff00;
  --tok-name: #00ffff;
  --tok-prefix: #ff00ff;
  --tok-attr: #ff8080;
  --tok-value: #80ff80;
  --tok-text: #ffffff;
  --tok-comment: #00ff00;
}
/* ─── Tree Panel (Right) ─── */
.panel-tree { flex: 1; background: var(--bg-secondary); display: flex; flex-direction: column; overflow: hidden; }
.tree-controls { display: flex; gap: 3px; }
.tree-btn {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.72rem; color: var(--text-muted); transition: all 0.15s;
}
.tree-btn:hover { background: var(--accent-blue-bg); color: var(--accent-blue); border-color: var(--accent-blue); }

.tree-container { flex: 1; overflow-y: auto; padding: 8px 0; }

/* ─── Tree Styles - Altoro-inspired ─── */
.tree-item { user-select: none; }

.tree-node {
  display: flex; align-items: center;
  padding: 3px 4px; cursor: pointer;
  margin: 0 6px; position: relative;
  border-radius: var(--radius-sm);
}
.tree-node:hover { background: transparent; }

.tree-toggle {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 0.9rem; font-weight: 700; color: var(--accent-blue);
  line-height: 1; cursor: pointer; user-select: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
}
.tree-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.tree-toggle.open { color: var(--text-secondary); }
.tree-toggle.hidden { visibility: hidden; }

/* Soft rectangle nodes - Altoro style */
.tree-rect {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px 10px;
  font-size: var(--tree-font-size);
  font-family: var(--font-mono);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  line-height: 1.4;
  font-weight: 500;
  letter-spacing: 0.2px;
}
.tree-rect.required {
  border: 1.5px solid var(--req-color);
  color: var(--tree-text-color, var(--req-color));
  background: linear-gradient(135deg, #fff5f5 0%, #fff 100%);
}
.tree-rect.optional {
  border: 1.5px dashed var(--opt-color);
  color: var(--tree-text-color, var(--opt-color));
  background: linear-gradient(135deg, #f0fdf4 0%, #fff 100%);
}
.tree-rect.default-req {
  border: 1.5px solid #cbd5e1;
  color: var(--tree-text-color, #475569);
  background: linear-gradient(135deg, #f8fafc 0%, #fff 100%);
}
.tree-rect:hover {
  /* no darkening / no lift/shadow */
}
.tree-rect.required:hover { background: linear-gradient(135deg, #fff5f5 0%, #fff 100%); }
.tree-rect.optional:hover { background: linear-gradient(135deg, #f0fdf4 0%, #fff 100%); }
.tree-rect.default-req:hover { background: linear-gradient(135deg, #f8fafc 0%, #fff 100%); }
.tree-rect.tree-pulse {
  animation: tree-pulse-flash 1s ease;
}
@keyframes tree-pulse-flash {
  0%, 100% { box-shadow: none; }
  20%, 60% { box-shadow: 0 0 0 3px var(--accent-blue); }
  40%, 80% { box-shadow: 0 0 0 1px var(--accent-blue); }
}

.tree-label-inline { font-family: var(--font-mono); font-size: var(--tree-font-size); margin-left: 4px; }

.tree-children {
  margin-left: 14px; padding-left: 12px;
  border-left: 1px solid var(--border-light);
  overflow: hidden;
}
.tree-children.collapsed { display: none; }

.tree-annotation {
  font-style: italic; color: var(--text-muted); font-size: var(--tree-font-size);
  padding: 3px 8px 3px 14px; margin: 2px 6px;
  border-left: 2px solid var(--border); margin-left: 14px;
  background: var(--bg-primary); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.tree-empty, .tree-error { padding: 30px 16px; text-align: center; color: var(--text-muted); font-size: 0.85rem; }
.tree-error { color: var(--accent-red); }
.tree-empty .empty-icon { font-size: 2rem; margin-bottom: 8px; display: block; color: var(--text-muted); }

/* ─── Details Panel ─── */
.tree-details-panel { border-top: 1px solid var(--border-light); max-height: 220px; overflow-y: auto; flex-shrink: 0; }
.tree-details-panel.hidden { display: none; }
.tree-details { padding: 12px 14px; font-size: var(--tree-font-size); line-height: 1.6; }
.tree-details h3 { font-size: 0.88rem; color: var(--accent-blue); margin-bottom: 6px; border-bottom: 1px solid var(--border-light); padding-bottom: 4px; font-weight: 600; }
.tree-details .detail-row { display: flex; padding: 1px 0; }
.tree-details .detail-key { color: var(--text-muted); min-width: 120px; flex-shrink: 0; }
.tree-details .detail-val { color: var(--text-primary); font-weight: 500; }
.tree-details .detail-val.required { color: var(--req-color); }
.tree-details .detail-val.optional { color: var(--opt-color); }

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--bg-secondary); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 85%; max-width: 800px; max-height: 80vh;
  display: flex; flex-direction: column; overflow: hidden;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.modal-close {
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 1rem; color: var(--text-muted); transition: all 0.2s;
}
.modal-close:hover { background: var(--accent-red-light); color: var(--accent-red); border-color: var(--accent-red); }

.modal-body { flex: 1; overflow: auto; padding: 16px 20px; }

.modal-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.modal-table th { background: var(--bg-primary); padding: 8px 12px; text-align: left; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-secondary); }
.modal-table td { padding: 6px 12px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
.modal-table tr:hover td { background: var(--bg-hover); }
.comp-xsd { color: var(--accent-purple); font-family: var(--font-mono); }
.comp-xml { color: var(--accent-blue); font-family: var(--font-mono); }
.comp-match { color: var(--accent-green); font-weight: 600; }
.comp-mismatch { color: var(--accent-red); font-weight: 600; }
.comp-missing { color: var(--text-muted); font-style: italic; }

/* ─── Drop Overlay ─── */
#dropOverlay {
  position: fixed; inset: 0; background: rgba(79, 109, 245, 0.1);
  border: 3px dashed var(--accent-blue); display: flex; align-items: center; justify-content: center; z-index: 100;
}
.drop-overlay-content { text-align: center; color: var(--accent-blue); }
.drop-overlay-content p { font-size: 1.1rem; margin-top: 10px; font-weight: 500; }

.hidden { display: none !important; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  #mainContent { flex-direction: column; }
  .panel-code { width: 100%; min-width: unset; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .resizer { display: none; }
}

/* ─── Empty State ─── */
.empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 32px 20px; background: var(--bg-primary);
}
.empty-state-card {
  max-width: 460px; width: 100%; text-align: center;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 36px 28px;
  box-shadow: var(--shadow-md);
}
.empty-state-icon { font-size: 2.4rem; margin-bottom: 10px; }
.empty-state-card h2 { font-size: var(--panel-header-font-size); margin-bottom: 8px; color: var(--text-primary); }
.empty-state-card p { color: var(--text-secondary); font-size: 0.88rem; line-height: 1.5; margin-bottom: 14px; }
.empty-hints {
  text-align: left; margin: 0 auto 20px; padding-left: 18px;
  color: var(--text-muted); font-size: 0.8rem; line-height: 1.7; max-width: 340px;
}
.btn-demo {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 22px; border: none; border-radius: var(--radius-md);
  background: var(--accent-blue); color: #fff; font-size: 0.9rem;
  font-weight: 600; cursor: pointer; transition: background 0.2s;
}
.btn-demo:hover { background: #4361ee; }
.btn-demo:disabled { opacity: 0.65; cursor: wait; }

.tree-attr-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-right: 4px; border-radius: 3px;
  background: var(--accent-blue-light); color: var(--accent-blue);
  font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
}
.tree-type { color: var(--accent-purple); font-family: var(--font-mono); font-size: var(--tree-font-size); }

/* === Theme presets === */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-hover: #334155;
  --bg-active: #475569;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent-blue: #60a5fa;
  --accent-blue-light: #1e3a5f;
  --accent-blue-bg: #1e3a5f;
  --accent-blue-hover: #3b82f6;
  --accent-green: #4ade80;
  --accent-green-light: #14532d;
  --accent-red: #f87171;
  --accent-red-light: #7f1d1d;
  --accent-orange: #fb923c;
  --accent-purple: #a78bfa;
  --accent-yellow: #facc15;
  --border: #334155;
  --border-light: #1e293b;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
  --req-color: #f87171;
  --opt-color: #4ade80;
  --tree-text-color: #e2e8f0;
}
[data-theme="dark"] .tree-rect.required {
  border-color: #fca5a5;
  color: #fecaca;
  background: linear-gradient(135deg, rgba(248,113,113,0.22) 0%, rgba(30,41,59,0.95) 100%);
}
[data-theme="dark"] .tree-rect.optional {
  border-color: #86efac;
  color: #bbf7d0;
  background: linear-gradient(135deg, rgba(74,222,128,0.18) 0%, rgba(30,41,59,0.95) 100%);
}
[data-theme="dark"] .tree-rect.default-req {
  border-color: #94a3b8;
  color: #e2e8f0;
  background: linear-gradient(135deg, rgba(148,163,184,0.16) 0%, rgba(30,41,59,0.95) 100%);
}
[data-theme="dark"] .tree-rect.required:hover,
[data-theme="dark"] .tree-rect.optional:hover,
[data-theme="dark"] .tree-rect.default-req:hover {
  background: linear-gradient(135deg, rgba(51,65,85,0.95) 0%, rgba(30,41,59,1) 100%);
}
[data-theme="dark"] .tree-details,
[data-theme="dark"] .tree-details .detail-val { color: var(--text-primary); }
[data-theme="dark"] .tree-details .detail-key { color: var(--text-muted); }
[data-theme="dark"] .tree-annotation { background: var(--bg-primary); color: var(--text-muted); }
[data-theme="dark"] .code-tab { color: var(--text-muted); }
[data-theme="dark"] .code-tab.active { color: var(--accent-blue); }

[data-theme="contrast"] {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-hover: #1a1a1a;
  --bg-active: #262626;
  --text-primary: #ffffff;
  --text-secondary: #f5f5f5;
  --text-muted: #e5e5e5;
  --accent-blue: #ffff00;
  --accent-blue-light: #333300;
  --accent-blue-bg: #333300;
  --accent-blue-hover: #cccc00;
  --accent-green: #00ff00;
  --accent-green-light: #003300;
  --accent-red: #ff0000;
  --accent-red-light: #330000;
  --accent-orange: #ff8800;
  --accent-purple: #ff00ff;
  --accent-yellow: #ffff00;
  --border: #ffffff;
  --border-light: #666666;
  --shadow-sm: 0 0 0 1px #fff;
  --shadow-md: 0 0 0 2px #fff;
  --shadow-lg: 0 0 0 3px #fff;
  --req-color: #ff0000;
  --opt-color: #00ff00;
  --tree-text-color: #ffffff;
}
[data-theme="contrast"] .tree-rect.required {
  border: 2px solid #ff5555; color: #ffffff;
  background: #330000;
}
[data-theme="contrast"] .tree-rect.optional {
  border: 2px dashed #55ff55; color: #ffffff;
  background: #003300;
}
[data-theme="contrast"] .tree-rect.default-req {
  border: 2px solid #ffffff; color: #ffffff;
  background: #111111;
}
[data-theme="contrast"] .tree-rect.required:hover,
[data-theme="contrast"] .tree-rect.optional:hover,
[data-theme="contrast"] .tree-rect.default-req:hover {
  background: #1a1a1a;
}

[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-hover: #f5f7fa;
  --bg-active: #e8ecf1;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-blue: #4f6df5;
  --accent-blue-light: #eef2ff;
  --accent-blue-bg: #e0e7ff;
  --accent-blue-hover: #4361ee;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
}

/* === Settings modal === */
.settings-modal-card { max-width: 560px; width: min(560px, 94vw); }
.settings-section { margin-bottom: 16px; }
.settings-section:last-of-type { margin-bottom: 8px; }
.settings-section h3 {
  font-size: 0.78rem; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 0 0 8px 0; padding-bottom: 6px; border-bottom: 1px solid var(--border-light);
}
.settings-rows { display: flex; flex-direction: column; gap: 2px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 7px 4px; min-height: 34px; border-radius: var(--radius-sm);
}
.settings-row:hover { background: var(--bg-hover); }
.settings-row label { font-size: 0.86rem; color: var(--text-primary); flex: 1; }
.settings-row .settings-control { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.settings-row input[type="range"] { width: 140px; accent-color: var(--accent-blue); }
.settings-row input[type="color"] {
  width: 42px; height: 28px; padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-primary); cursor: pointer;
}
.settings-colors-grid {
  display: grid; grid-template-columns: 1fr; gap: 2px;
}
@media (min-width: 520px) {
  .settings-colors-grid { grid-template-columns: 1fr 1fr; gap: 4px 16px; }
  .settings-colors-grid .settings-row { padding: 6px 4px; }
}
.settings-value {
  font-size: 0.78rem; font-family: var(--font-mono); color: var(--text-muted);
  min-width: 42px; text-align: right;
}
.settings-theme-group {
  display: flex; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden;
}
.settings-theme-btn {
  padding: 6px 12px; border: none; background: var(--bg-primary); cursor: pointer;
  font-size: 0.78rem; font-weight: 500; color: var(--text-muted); transition: all 0.15s;
}
.settings-theme-btn + .settings-theme-btn { border-left: 1px solid var(--border); }
.settings-theme-btn.active { background: var(--accent-blue); color: #fff; font-weight: 600; }
.settings-theme-btn:hover:not(.active) { background: var(--bg-hover); color: var(--text-primary); }
.settings-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--border-light);
}
.settings-hint { font-size: 0.75rem; color: var(--text-muted); flex: 1; }
.btn-settings-reset {
  padding: 6px 14px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-primary); color: var(--text-primary); cursor: pointer;
  font-size: 0.82rem; font-weight: 600; transition: all 0.15s;
}
.btn-settings-reset:hover { background: var(--accent-red-light); color: var(--accent-red); border-color: var(--accent-red); }
/* === Generate example button / modal === */
.btn-gen-example {
  display: none; align-items: center; justify-content: center;
  padding: 0 12px; margin-right: 6px;
  background: var(--accent-blue); color: #fff; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s;
}
.btn-gen-example:hover { filter: brightness(0.92); }
.btn-gen-example.visible { display: inline-flex; }
.example-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.example-tab {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-primary); cursor: pointer; font-size: 0.78rem; color: var(--text-secondary);
}
.example-tab.active { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); font-weight: 600; }
.example-preview {
  font-family: var(--font-mono); font-size: 0.78rem; line-height: 1.45;
  white-space: pre-wrap; word-break: break-all;
  background: var(--code-bg, var(--bg-primary)); color: var(--code-text-color, var(--text-primary));
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; max-height: 42vh; overflow: auto; margin: 0 0 12px 0;
}
.example-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-example-save, .btn-example-save-all {
  padding: 7px 14px; border: none; border-radius: var(--radius-md);
  background: var(--accent-blue); color: #fff; font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.btn-example-save-all { background: var(--text-secondary); }
.btn-example-save:hover, .btn-example-save-all:hover { filter: brightness(0.92); }
