:root {
  --bg: #1e1e2e; --surface: #313244; --surface2: #45475a;
  --text: #cdd6f4; --text-dim: #a6adc8; --accent: #89b4fa;
  --red: #f38ba8; --yellow: #f9e2af; --green: #a6e3a1;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; }

header { padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--surface2); display: flex; gap: 14px;
  align-items: center; position: sticky; top: 0; z-index: 5; }
header h1 { font-size: 1.05em; margin: 0; }
header .spacer { flex: 1; }
header .version-meta { color: var(--text-dim); font-size: .78em; opacity: .75; margin-right: 4px; white-space: nowrap; }
header label { color: var(--text-dim); font-size: .9em; }

nav#viewtabs { display: flex; gap: 4px; }
nav#viewtabs button { background: transparent; color: var(--text-dim);
  border: none; border-bottom: 2px solid transparent; padding: 6px 12px;
  cursor: pointer; font: inherit; }
nav#viewtabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
nav#viewtabs button:hover { color: var(--text); }

select, input, button, a.btn { background: var(--surface2); color: var(--text);
  border: 1px solid var(--surface2); border-radius: 4px; padding: 4px 8px;
  font: inherit; text-decoration: none; }

main { padding: 12px 16px; max-width: 1100px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
#err { color: var(--red); padding: 12px 16px; }

/* ---- engine: groups / dataitems (shared by config + runtime) ---- */
.group { border: 1px solid var(--surface2); border-radius: 6px;
  margin-bottom: 10px; overflow: hidden; }
.group.inactive { opacity: 0.5; }
.group.role-hidden { display: none; }
.group.collapsed .group-body { display: none; }
.group-header { display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--surface); cursor: pointer; }
.group-header h2 { font-size: 0.95em; margin: 0; }
.group.collapsed .chevron { transform: rotate(-90deg); }
.chevron { transition: transform .15s; display: inline-block; }
.badge.inactive { font-size: .75em; color: var(--yellow);
  border: 1px solid var(--yellow); border-radius: 4px; padding: 1px 6px; }
.group-body { padding: 6px 12px; }

.sub-group { margin: 4px 0; }
.sub-group-header { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.sub-group-header h3 { font-size: .85em; margin: 6px 0; color: var(--text-dim); }
.aspect-badge { font-size: .68em; font-weight: 400; color: var(--accent);
  background: rgba(137,180,250,.12); border: 1px solid rgba(137,180,250,.35);
  border-radius: 4px; padding: 0 5px; margin-left: 6px; vertical-align: middle; }
.sub-group-body { margin-left: 7px; padding-left: 12px;
  border-left: 2px solid var(--surface2); }
.sub-group.collapsed .sub-group-body { display: none; }
.sub-group.collapsed .chevron { transform: rotate(-90deg); }

.dp-row { display: flex; align-items: center; gap: 12px;
  padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.dp-row.hidden { display: none; }
.dp-row.role-hidden { display: none; }
.dp-info { flex: 1; min-width: 0; }
.dp-name { font-weight: 600; }
.cat-icon { display: inline-block; margin-right: 5px; font-weight: 400;
  font-size: .9em; opacity: .8; cursor: help; }
.dp-desc { color: var(--text-dim); font-size: .85em; }
.dp-calc { color: var(--text-dim); opacity: .7; font-size: .78em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.dp-constraint { color: var(--yellow); font-size: .8em; }
.dp-warn { color: var(--red); font-size: .8em; font-weight: 600; }
.dp-row.out-of-range { background: rgba(243, 139, 168, .08);
  border-left: 2px solid var(--red); padding-left: 8px; }
.dp-row.out-of-range .dp-name { color: var(--red); }
.dp-control { flex: 0 0 auto; }

.toggle { cursor: pointer; padding: 4px 12px; border-radius: 4px;
  background: var(--surface2); user-select: none; }
.toggle.on { background: var(--accent); color: #11111b; }
.toggle.locked { opacity: .5; cursor: not-allowed; }

.derived { margin-top: 8px; padding: 6px 8px; background: var(--surface); border-radius: 4px; }
.derived-title { font-size: .8em; color: var(--text-dim); margin-bottom: 4px; }
.derived-item { display: flex; justify-content: space-between; font-size: .9em; }
.derived-item.exceeded { color: var(--red); }

/* ---- system view ---- */
.sys-section { border: 1px solid var(--surface2); border-radius: 6px;
  margin-bottom: 12px; padding: 10px 14px; }
.sys-section h2 { font-size: .95em; margin: 0 0 8px; display: flex; align-items: center; gap: 10px; }
.sys-row { display: flex; align-items: center; gap: 12px; padding: 5px 0; }
.sys-label { flex: 1; display: flex; align-items: center; gap: 8px; }
.sys-badge { font-size: .7em; color: var(--text-dim);
  border: 1px solid var(--surface2); border-radius: 4px; padding: 1px 6px; }
.sys-hint { color: var(--text-dim); font-size: .85em; font-style: italic; }

/* ---- variant picker (cards, grouped by deliverable) ---- */
.mono { font-family: 'Cascadia Code', 'Consolas', monospace; }
.sys-clear { margin-left: auto; font-size: .72em; font-weight: normal;
  color: var(--text-dim); border: 1px solid var(--surface2); border-radius: 4px;
  padding: 2px 8px; cursor: pointer; }
.sys-clear:hover { color: var(--text); border-color: var(--accent); }
.sys-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sys-selected { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: .85em; margin: 0 0 12px; padding: 6px 10px; border-radius: 5px;
  background: var(--surface); border: 1px solid var(--surface2); }
.sys-selected.none { color: var(--text-dim); font-style: italic; }
.sys-selected-lbl { font-size: .7em; text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent); }
.sys-selected .mono { font-weight: 600; }
.sys-selected-desc { color: var(--text-dim); }

.variant-group { margin-bottom: 14px; }
.variant-group h3 { font-size: .82em; margin: 0 0 8px; color: var(--text-dim);
  display: flex; align-items: baseline; gap: 8px; text-transform: uppercase;
  letter-spacing: .04em; }
.variant-group-count { font-size: .82em; text-transform: none; letter-spacing: 0;
  color: var(--text-dim); opacity: .7; }
.variant-grid { display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.variant-card { position: relative; display: flex; flex-direction: column;
  align-items: stretch; gap: 4px; text-align: left; padding: 9px 11px;
  background: var(--surface); border: 1px solid var(--surface2); border-radius: 6px;
  cursor: pointer; color: var(--text); font: inherit; transition: border-color .12s, background .12s; }
.variant-card:hover { border-color: var(--accent); background: var(--surface2); }
.variant-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.variant-card.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--accent); }
.vc-check { position: absolute; top: 6px; right: 8px; color: var(--accent);
  font-weight: 700; font-size: .9em; }
.vc-name { font-size: .92em; font-weight: 600; padding-right: 14px; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.vc-mlfb { font-size: .78em; color: var(--text-dim); word-break: break-all; }
.vc-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.vc-chip { font-size: .68em; border-radius: 3px; padding: 1px 5px; white-space: nowrap;
  border: 1px solid transparent; }
.vc-chip.on { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, transparent);
  background: color-mix(in srgb, var(--green) 12%, transparent); }
.vc-chip.off { color: var(--text-dim); border-color: var(--surface2); opacity: .8; }
.vc-slots { font-size: .68em; color: var(--text-dim); margin-top: 2px; }

/* ---- events & logs view ---- */
.el-section { margin-bottom: 14px; }
.el-section h2 { font-size: .95em; }
.el-card { border: 1px solid var(--surface2); border-radius: 6px;
  padding: 8px 12px; margin-bottom: 6px; }
.el-card.inactive { opacity: .45; }
.el-head { display: flex; align-items: center; gap: 8px; }
.el-key { color: var(--text-dim); font-size: .85em; font-family: monospace; }
.el-off { color: var(--yellow); font-size: .75em; margin-left: auto; }
.el-sub { color: var(--text-dim); font-size: .8em; margin-top: 4px; }
.sev, .kind { font-size: .7em; padding: 1px 6px; border-radius: 4px; background: var(--surface2); }
.sev.error { background: var(--red); color: #11111b; }
.sev.warning { background: var(--yellow); color: #11111b; }
.sev.info { background: var(--accent); color: #11111b; }

/* ---- app layout: side panels + content ---- */
header .group-sep { color: var(--text-dim); font-size: .8em; margin-left: 8px; }
header .panel-toggle { color: var(--text-dim); font-size: .9em; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; }

#layout { display: flex; align-items: stretch; gap: 0;
  height: calc(100vh - 45px); max-width: none; margin: 0; padding: 0; }
.side-panel { flex: 0 0 260px; border-right: 1px solid var(--surface2);
  background: var(--surface); display: flex; flex-direction: column; overflow: hidden; }
.side-panel[hidden] { display: none; }
.side-panel .panel-head { padding: 6px 10px; font-size: .8em; color: var(--text-dim);
  border-bottom: 1px solid var(--surface2); text-transform: uppercase; letter-spacing: .05em; }
.side-panel .panel-body { flex: 1; overflow: auto; padding: 8px 10px; }

#content { flex: 1; overflow: auto; padding: 12px 16px; }

.files-hint { color: var(--text-dim); font-size: .8em; font-style: italic; margin-bottom: 8px; }
.file-item { padding: 3px 4px; font-size: .9em; cursor: pointer; border-radius: 4px; }
.file-item:hover { background: var(--surface2); }

/* ---- in-app project switcher ---- */
.project-picker { position: relative; }
#home-btn { background: transparent; border: 1px solid var(--surface2);
  color: var(--text); cursor: pointer; padding: 4px 10px; border-radius: 4px;
  text-decoration: none; font-size: .9em; white-space: nowrap; }
#home-btn:hover { background: var(--surface2); }
#project-btn { background: transparent; border: 1px solid var(--surface2);
  color: var(--text); cursor: pointer; padding: 4px 10px; border-radius: 4px; }
#project-btn:hover { background: var(--surface2); }
.project-menu { position: absolute; top: 100%; left: 0; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--surface2); border-radius: 6px;
  min-width: 280px; max-height: 60vh; overflow: auto; z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.project-menu[hidden] { display: none; }
.project-item { padding: 8px 12px; cursor: pointer; display: flex;
  flex-direction: column; gap: 2px; border-bottom: 1px solid rgba(255,255,255,.04); }
.project-item:hover { background: var(--surface2); }
.project-item.active { border-left: 3px solid var(--accent); }
.project-item b { font-size: .95em; }
.project-item span { color: var(--text-dim); font-size: .8em; }

/* ---- files panel: tree + outline ---- */
.tree-row { display: flex; align-items: center; gap: 5px; padding: 2px 4px;
  cursor: pointer; border-radius: 4px; font-size: .85em; white-space: nowrap; }
.tree-row:hover { background: var(--surface2); }
.tw-chevron { display: inline-block; width: 12px; transition: transform .12s; }
.tw-chevron.collapsed { transform: rotate(-90deg); }
.tw-indent { display: inline-block; width: 12px; }
.tw-indent2 { display: inline-block; width: 24px; }
.tw-label { overflow: hidden; text-overflow: ellipsis; }
.tw-count { margin-left: auto; color: var(--text-dim); font-size: .85em; }
.tw-type { margin-left: auto; color: var(--accent); font-size: .8em;
  font-family: monospace; }
.tree-children { margin-left: 10px; }
.tree-children.hidden { display: none; }
.tree-file-head { font-weight: 600; }
.tree-dp .tw-label { color: var(--text-dim); }
.tree-section { font-size: .7em; color: var(--text-dim); text-transform: uppercase;
  margin: 4px 0 2px 12px; letter-spacing: .05em; }
.tree-enum .tw-label { color: var(--text-dim); }

/* ---- text panel: monaco editor ---- */
#panel-text { flex: 0 0 480px; }
#panel-text .panel-body { padding: 0; display: flex; flex-direction: column; }
.text-toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-bottom: 1px solid var(--surface2); }
.text-toolbar .spacer { flex: 1; }
.text-editor { flex: 1; min-height: 0; }
.text-status { padding: 4px 8px; font-size: .8em; color: var(--text-dim);
  border-top: 1px solid var(--surface2); }
.text-status.ok { color: var(--green); }
.text-status.error { color: var(--red); }
.text-status.loading { color: var(--yellow); }

/* ---- clickable source links (jump to definition) ---- */
.src-link { cursor: pointer; }
.src-link:hover { color: var(--accent); text-decoration: underline; }
.aspect-badge.src-link:hover { text-decoration: none; }

/* Type column: the data item's type; a custom type (enum/selection) links to
   its definition. */
.dp-type { flex: 0 0 auto; font-family: ui-monospace, monospace; font-size: .78em;
  color: var(--text-dim); background: var(--surface2); padding: 1px 7px;
  border-radius: 4px; white-space: nowrap; max-width: 170px; overflow: hidden;
  text-overflow: ellipsis; }
.dp-type.custom { color: var(--accent); }

/* Template badge — a compact ⧉ icon after the item name; popover on hover for
   chained templates. Always visible (it's a first-class navigation affordance). */
.tmpl-badge-wrap { position: relative; display: inline-flex; margin-left: 6px;
  vertical-align: baseline; }
.tmpl-badge { font-size: .82em; line-height: 1; color: var(--text-dim);
  cursor: pointer; user-select: none; }
.tmpl-badge:hover { color: var(--accent); }
.tmpl-badge:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px;
  border-radius: 3px; color: var(--accent); }
.tmpl-badge.has-chain { text-decoration: underline dotted; text-underline-offset: 3px; }
.tmpl-pop { position: absolute; top: 100%; left: 0; margin-top: 4px; z-index: 20;
  display: none; white-space: nowrap; background: var(--surface);
  border: 1px solid var(--surface2); border-radius: 5px; padding: 4px 8px;
  font-size: .8em; box-shadow: 0 4px 12px rgba(0, 0, 0, .35); }
.tmpl-badge-wrap:hover .tmpl-pop, .tmpl-badge-wrap:focus-within .tmpl-pop { display: block; }
.tmpl-pop-hop { color: var(--text-dim); cursor: pointer; }
.tmpl-pop-hop:hover, .tmpl-pop-hop:focus-visible { color: var(--accent);
  text-decoration: underline; outline: none; }
.tmpl-pop-sep { color: var(--text-dim); opacity: .5; margin: 0 5px; }

/* Editor: template references (Ctrl/Cmd+Click to jump to the template def). */
.tmpl-ref { text-decoration: underline dotted; text-underline-offset: 3px;
  cursor: pointer; }

/* ---- project panel: file tree + editor together ---- */
.project-panel { flex: 0 0 var(--project-w, 900px); display: flex;
  background: var(--surface); overflow: hidden; position: relative; min-width: 360px; }
.project-panel[hidden] { display: none; }
.project-files { flex: 0 0 240px; overflow: auto; padding: 8px 10px;
  border-right: 1px solid var(--surface2); }
.project-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.project-text .text-toolbar { display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-bottom: 1px solid var(--surface2); }
.project-text .text-editor { flex: 1; min-height: 0; }

/* drag handle on the panel's right edge to resize it (editor grows with it) */
.project-resizer { flex: 0 0 6px; cursor: col-resize; background: var(--surface2);
  border-left: 1px solid var(--bg); border-right: 1px solid var(--bg); }
.project-resizer[hidden] { display: none; }
.project-resizer:hover, .project-resizer.dragging { background: var(--accent); }
body.col-resizing { cursor: col-resize; user-select: none; }
body.col-resizing iframe, body.col-resizing .text-editor { pointer-events: none; }
