/* SPDX-License-Identifier: AGPL-3.0-or-later
 * Copyright (C) 2026 Chris de Vries. Part of Al Dente Code; see LICENSE. */

:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --hl: #f97316;
  --err-bg: #fef2f2;
  --err: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --grid: #e2e8f0;
  --code-hl: rgba(249, 115, 22, .16);
  --code-err: rgba(220, 38, 38, .14);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1120;
  --panel: #111827;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --hl: #fb923c;
  --err-bg: #2a1215;
  --err: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;
  --grid: #1e293b;
  --code-hl: rgba(251, 146, 60, .18);
  --code-err: rgba(248, 113, 113, .16);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.brand svg { color: var(--accent); }
.spacer { flex: 1; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.check { display: flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; user-select: none; }
select, .btn, .menu-list button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
select { max-width: 220px; }
.btn { cursor: pointer; min-width: 30px; }
.btn:hover, .menu-list button:hover { border-color: var(--accent); }

.menu { position: relative; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  min-width: 170px;
}
.menu-list button { text-align: left; border-color: transparent; background: none; cursor: pointer; }
.limits { min-width: 270px; gap: 6px; padding: 10px; }
.limits label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.limits input {
  width: 96px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px;
}
.limits input:invalid { border-color: var(--err); }
.limits-note { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------ about */
.about {
  max-width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .25);
  font-size: 13px;
  line-height: 1.5;
}
.about::backdrop { background: rgba(0, 0, 0, .4); }
.about form { padding: 18px 22px; }
.about h2 { margin: 0 0 4px; font-size: 17px; }
.about h3 { margin: 18px 0 6px; font-size: 14px; }
.about p { margin: 8px 0; }
.about a { color: var(--accent); }
.about .muted { color: var(--muted); }
.about code { font-size: 12px; }
.about ol { margin: 8px 0; padding-left: 22px; }
.about li { margin: 6px 0; }
.about kbd { font: 11px ui-monospace, monospace; padding: 1px 4px; border: 1px solid var(--border); border-radius: 4px; }
.about a.btn { display: inline-block; text-decoration: none; color: var(--text); }
.about .credits { margin: 0; padding-left: 18px; }
.about .credits li { margin: 4px 0; }
.about details { margin-top: 10px; }
.about summary { cursor: pointer; color: var(--muted); }
.about pre {
  white-space: pre-wrap; font-size: 11px; padding: 10px; margin: 8px 0 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
.about-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

/* ------------------------------------------------------------------ split */
.split { flex: 1; display: flex; min-height: 0; }
.pane { position: relative; min-width: 0; min-height: 0; }
.editor-pane { width: 42%; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.diagram-pane { flex: 1; display: flex; flex-direction: column; }
.divider { width: 6px; cursor: col-resize; background: transparent; margin-left: -3px; margin-right: -3px; z-index: 5; }
.divider:hover, .divider.dragging { background: var(--accent); opacity: .5; }

.CodeMirror {
  flex: 1;
  height: auto;
  font: 13.5px/1.55 ui-monospace, "JetBrains Mono", "Fira Code", "Cascadia Code", Menlo, Consolas, monospace;
}
.cm-hl-line { background: var(--code-hl) !important; }
.cm-err-line { background: var(--code-err) !important; }

/* --------------------------------------------------------------- diagram */
.viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: grab;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1px, transparent 1px);
  background-size: 20px 20px;
  touch-action: none;
}
.viewport.panning { cursor: grabbing; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; transition: opacity .15s; }
.stage.stale { opacity: .45; }
.stage svg { display: block; }
.stage .node { cursor: pointer; }
.stage .node.hl { filter: drop-shadow(0 0 5px var(--hl)) drop-shadow(0 0 2px var(--hl)); }
.stage .node.hl :is(rect, polygon, path, circle, ellipse) { stroke: var(--hl) !important; stroke-width: 3px !important; }

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  padding: 16px;
}

.zoom { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 4px; }
.zoom .btn { background: var(--panel); font-size: 16px; line-height: 1; padding: 6px 0; }

.legend {
  position: absolute;
  left: 12px;
  bottom: 44px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  max-width: calc(100% - 24px);
  padding: 6px 10px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg { display: inline-block; width: 14px; height: 10px; border: 1.5px solid; }
.lg.term { border-radius: 6px; background: #dcfce7; border-color: #15803d; }
.lg.process { background: #e0f2fe; border-color: #0369a1; }
.lg.decision { width: 10px; transform: rotate(45deg) scale(.85); background: #fef3c7; border-color: #b45309; }
.lg.io { transform: skewX(-20deg); background: #f3e8ff; border-color: #7e22ce; }
.lg.call { background: #ccfbf1; border-color: #0f766e; box-shadow: inset 3px 0 0 -1.5px #0f766e, inset -3px 0 0 -1.5px #0f766e; }
.lg.ret { background: #ffe4e6; border-color: #be123c; }
.lg.exc { background: #fee2e2; border-color: #b91c1c; border-style: dashed; }
.lg-loop polygon { fill: #ffedd5; stroke: #c2410c; stroke-width: 1.5; }
.lg.note { background: #fefce8; border-color: #a8a29e; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 25% 50%); }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  min-height: 32px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  font-size: 13px;
  color: var(--muted);
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.status.warn .dot { background: var(--warn); }
.status.error { background: var(--err-bg); color: var(--err); cursor: pointer; }
.status.error .dot { background: var(--err); }

/* ---------------------------------------------------------------- narrow */
@media (max-width: 760px) {
  .split { flex-direction: column; }
  .editor-pane { width: auto !important; height: 45%; border-right: 0; border-bottom: 1px solid var(--border); }
  .divider { display: none; }
  .legend { display: none; }
}

/* multi-statement boxes read like code */
.stage g.node:is(.fc_process, .fc_io, .fc_ret, .fc_exc) .nodeLabel { text-align: left; display: inline-block; }
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { background: var(--panel); }
#examples { width: 8rem; }
#methodSelect { max-width: 200px; }

/* editing a box's text in place (app/node-edit.js) */
.node-edit { position: fixed; z-index: 50; box-sizing: border-box; padding: 4px 6px; font: 13px/1.35 ui-monospace, monospace;
  color: var(--text); background: var(--panel); border: 2px solid var(--hl); border-radius: 4px; resize: both; }

/* ------------------------------------------------- VS Code panel (js/host/vscode.js)
 * The code lives in VS Code's own editor: only the chart is shown, in VS Code's colours. */
:root[data-host="vscode"] {
  --bg: var(--vscode-editor-background);
  --panel: var(--vscode-sideBar-background, var(--vscode-editor-background));
  --border: var(--vscode-panel-border, var(--vscode-widget-border, transparent));
  --text: var(--vscode-foreground);
  --muted: var(--vscode-descriptionForeground);
  --accent: var(--vscode-focusBorder);
  --grid: var(--vscode-editorIndentGuide-background1, var(--vscode-editorIndentGuide-background, transparent));
}
:root[data-host="vscode"] body { font-family: var(--vscode-font-family); }
:root[data-host="vscode"] :is(#editorPane, #divider, #indentBtn, #examples, #themeBtn, #sourceBtn, #vscodeBtn, #vscodeSection, .brand span) { display: none !important; }
:root[data-host="vscode"] .toolbar { padding: 6px 10px; }
