:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1a1f29;
  --muted: #677084;
  --line: #e2e5eb;
  --hover: #f0f2f6;
  --accent: #2f5fd0;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --warn: #9a6200;
  --radius: 8px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --ink: #e6e9ef;
    --muted: #98a1b3;
    --line: #2c323c;
    --hover: #242a33;
    --accent: #7ea2f5;
    --accent-ink: #10141a;
    --danger: #f08a82;
    --warn: #e0b060;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }

.topbar { --bar: 48px; position: sticky; top: 0; z-index: 10; height: 48px; display: flex; align-items: center; gap: 18px; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .spacer { flex: 1; }
.topbar .brand { font-weight: 700; font-size: 16px; color: var(--ink); }
.topbar .brand:hover { text-decoration: none; }
.top-nav { display: flex; gap: 2px; align-self: stretch; }
.top-nav a { display: flex; align-items: center; padding: 0 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.top-nav a:hover { color: var(--ink); text-decoration: none; }
.top-nav a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.topbar .me { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 13px; }
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 48px); }
.shell.wide { grid-template-columns: 1fr; }
.shell.wide .main { max-width: 1200px; width: 100%; margin: 0 auto; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 12px 10px; position: sticky; top: 48px; height: calc(100vh - 48px); overflow-y: auto; }
td.wrap { white-space: normal; max-width: 420px; }
.ok { color: #2e9e5b; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }

/* workflow canvas */
.shell.wide .main.canvas { max-width: none; padding: 0; display: flex; flex-direction: column; height: calc(100vh - 48px); }
.wf-top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.wf-top .spacer { flex: 1; }
.wf-editor { flex: 1; display: grid; grid-template-columns: 1fr 400px; min-height: 0; }
.wf-canvas { overflow: auto; background-color: var(--bg); background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 20px 20px; }
.wf-surface { position: relative; min-width: 100%; min-height: 100%; }
.wf-edges { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.wf-edge { fill: none; stroke: var(--muted); stroke-width: 2; pointer-events: stroke; cursor: pointer; }
.wf-edge:hover, .wf-edge.selected { stroke: var(--accent); stroke-width: 3; }
.wf-edge.temp { stroke: var(--accent); stroke-dasharray: 5 4; pointer-events: none; }
.wf-node { position: absolute; width: 230px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 8px; padding: 9px 12px 10px; cursor: grab; user-select: none; touch-action: none; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.wf-node:active { cursor: grabbing; }
.wf-node.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.wf-node.start { border-left-color: #2e9e5b; }
.wf-node.resource { border-left-color: #2a78d6; }
.wf-node.code { border-left-color: #8a5cd6; }
.wf-node.response { border-left-color: #c98500; }
.wf-node-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.wf-kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-node-name { font-weight: 600; font-family: ui-monospace, Consolas, monospace; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.wf-node-sum { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-status { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.wf-status.ok { background: #2e9e5b; }
.wf-status.failed { background: #c0392b; }
.wf-status.skipped { background: #8a93a5; }
.wf-port { position: absolute; top: 24px; width: 20px; height: 20px; border-radius: 50%; background: var(--panel); border: 2px solid var(--muted); display: grid; place-items: center; font-size: 13px; line-height: 1; color: var(--muted); }
.wf-port.in { left: -13px; width: 12px; height: 12px; top: 28px; }
.wf-port.out { right: -11px; cursor: crosshair; }
.wf-port.out:hover { border-color: var(--accent); color: var(--accent); }
.wf-menu { position: fixed; z-index: 30; display: grid; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }
.wf-menu button { border: 0; text-align: left; }
.wf-inspector { border-left: 1px solid var(--line); background: var(--panel); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.wf-inspector .field label { margin-bottom: 4px; }
.wf-inspector .hint { font-size: 12px; margin-top: 4px; }
.wf-more summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.wf-more .field, .wf-more .check-row { margin-bottom: 10px; }
.wf-suggest-box { position: relative; }
.wf-suggest { position: absolute; z-index: 6; left: 0; right: 0; top: 100%; margin-top: 2px; max-height: 240px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }
.wf-suggest div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 9px; cursor: pointer; font-size: 12px; }
.wf-suggest div span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.wf-suggest div.active, .wf-suggest div:hover { background: var(--hover); }
.wf-output { max-height: 320px; overflow: auto; margin: 6px 0 0; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
label.check-row { display: flex; gap: 8px; align-items: center; }
@media (max-width: 900px) {
  .wf-editor { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .wf-inspector { border-left: 0; border-top: 1px solid var(--line); }
}
.choices button { display: grid; gap: 6px; text-align: left; padding: 14px; white-space: normal; }
.nav-group { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.nav a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--ink); }
.nav a:hover { background: var(--hover); text-decoration: none; }
.nav a.active { background: var(--hover); font-weight: 600; color: var(--accent); }
.main { padding: 22px 28px 60px; min-width: 0; }

.head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head .spacer { flex: 1; }
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.count { color: var(--muted); font-size: 13px; }

button, .btn { font: inherit; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }

input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%; min-width: 0; }
input[type="checkbox"] { width: auto; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar { display: flex; gap: 8px; padding: 10px; flex-wrap: wrap; border-bottom: 1px solid var(--line); align-items: center; }
.toolbar input[type="search"] { width: 220px; }
.toolbar select { width: auto; max-width: 180px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
th { font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; }
th.check, td.check { width: 30px; cursor: default; }
tbody tr:hover { background: var(--hover); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 10px; color: var(--muted); font-size: 13px; }
.bulkbar { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: var(--hover); border-bottom: 1px solid var(--line); }

.badge { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 18px; padding: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field.wide { grid-column: 1 / -1; }
.field .check-row { display: flex; align-items: center; gap: 8px; height: 34px; }
.step { border: 1px solid var(--line); border-radius: 6px; padding: 12px; background: var(--bg); }
.step-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.step-head button { padding: 3px 10px; }
.pair-row { display: grid; grid-template-columns: 1fr 1.4fr auto auto; gap: 8px; align-items: center; }
.pair-row label { display: flex; gap: 4px; align-items: center; margin: 0; white-space: nowrap; }
.pair-row button { padding: 3px 9px; }
.field .req { color: var(--danger); }
details.group { border-top: 1px solid var(--line); }
details.group > summary { padding: 12px 16px; cursor: pointer; font-weight: 600; font-size: 13px; }
details.group > summary:hover { background: var(--hover); }
details.group[open] > summary { border-bottom: 1px solid var(--line); }
.kv-list { border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; }
.kv-list .kv { gap: 16px; }
.kv-list .kv span:last-child { text-align: right; word-break: break-word; }
a.btn { display: inline-block; }
a.btn:hover { background: var(--hover); text-decoration: none; }
.meta-line { padding: 0 16px 14px; color: var(--muted); font-size: 12px; }
.lookup { position: relative; }
.lookup-menu { position: absolute; z-index: 5; left: 0; right: 0; top: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; max-height: 220px; overflow-y: auto; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15); }
.lookup-menu div { padding: 6px 9px; cursor: pointer; }
.lookup-menu div:hover { background: var(--hover); }

.tabs { display: flex; gap: 4px; margin: 22px 0 10px; flex-wrap: wrap; }
.tabs button.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { padding: 14px 16px; }
.tile .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 12px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.box { padding: 16px; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border: 0; }

/* report tables */
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { border-top: 2px solid var(--line); border-bottom: 0; font-weight: 600; }
.foot-label { font-weight: 400; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-right: 6px; }
.range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.record-pager { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.record-pager button { padding: 2px 9px; }

/* stored HTML shown in a cell or under its field */
td .html { max-height: 3em; overflow: hidden; white-space: normal; }
td .html img { max-height: 40px; width: auto; }
.html-preview { margin-top: 6px; padding: 10px; border: 1px dashed var(--line); border-radius: 6px; max-height: 260px; overflow: auto; }
.html img { max-width: 100%; }

/* charts — series colors are a validated pair, stepped separately for dark */
.viz { --series-1: #2a78d6; --series-2: #eb6834; }
@media (prefers-color-scheme: dark) {
  .viz { --series-1: #3987e5; --series-2: #d95926; }
}
.viz-plot { position: relative; }
.viz svg { display: block; width: 100%; height: auto; max-height: 300px; }
.viz .grid { stroke: var(--line); stroke-width: 1; }
.viz .tick, .viz .value { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz .value, .viz .end-label { fill: var(--ink); font-size: 11px; }
.viz .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz .line.series-1, .viz .mark.series-1 { stroke: var(--series-1); }
.viz .line.series-2, .viz .mark.series-2 { stroke: var(--series-2); }
.viz .col.series-1, .viz .mark.series-1 { fill: var(--series-1); }
.viz .mark.series-2 { fill: var(--series-2); }
.viz .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.swatch.series-1 { background: var(--series-1); }
.swatch.series-2 { background: var(--series-2); }
.viz-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.viz-tip { position: absolute; top: 8px; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); white-space: nowrap; z-index: 2; }
.tip-title { color: var(--muted); margin-bottom: 3px; }
.tip-row { display: flex; align-items: center; gap: 2px; }
.tip-row strong { margin-left: auto; padding-left: 14px; font-variant-numeric: tabular-nums; }
.viz.bars { display: grid; gap: 8px; max-width: 760px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 200px) 1fr 56px; gap: 10px; align-items: center; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; }
.bar-fill { height: 100%; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.viz-data { margin-top: 12px; }
.viz-data summary { cursor: pointer; color: var(--muted); font-size: 12px; }

.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); display: flex; justify-content: flex-end; z-index: 20; }
.overlay.center { justify-content: center; align-items: center; }
.drawer { width: min(520px, 100vw); height: 100%; background: var(--panel); padding: 20px; overflow-y: auto; }
.modal { width: min(460px, 94vw); background: var(--panel); border-radius: var(--radius); padding: 20px; max-height: 90vh; overflow-y: auto; }
.modal .row, .drawer .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.audit { padding: 10px 0; border-bottom: 1px solid var(--line); }
.audit .what { font-size: 12px; color: var(--muted); word-break: break-word; }
pre { background: var(--bg); padding: 10px; border-radius: 6px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; }

.login { min-height: 100vh; display: grid; place-items: center; }
.login .panel { padding: 28px; width: min(360px, 92vw); display: grid; gap: 14px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 6px; z-index: 40; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 16px; }
  .topbar { height: auto; min-height: 48px; flex-wrap: wrap; padding: 6px 12px; gap: 8px 14px; position: static; }
  .top-nav a { padding: 8px 10px; }
  .choices { grid-template-columns: 1fr; }
}
