:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1d2530; --muted: #6b7684; --line: #e3e7ec;
  --pri: #2f6fed; --pri-d: #1f56c4; --ok: #1a8f4e; --bad: #c8352b; --warn: #b7791f;
  --radius: 10px;
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="dark"] { --bg: #12161c; --card: #1b2129; --ink: #e6eaef; --muted: #9aa5b1; --line: #2c343e; --pri: #5b8ef5; --pri-d: #4677e0; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #12161c; --card: #1b2129; --ink: #e6eaef; --muted: #9aa5b1; --line: #2c343e; --pri: #5b8ef5; --pri-d: #4677e0; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--pri); }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; }
h2 { font-size: 1.15rem; margin: 1.2em 0 .5em; }
.card > h2:first-child, .card > :first-child h2 { margin-top: 0; }
h3 { font-size: 1rem; margin: 1.2em 0 .4em; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
code { background: color-mix(in srgb, var(--line) 60%, transparent); padding: .1em .35em; border-radius: 4px; }
pre { background: #0f1720; color: #dfe7ef; padding: 12px 14px; border-radius: 8px; overflow-x: auto; line-height: 1.45; }
.break { word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }

/* Top bar */
.top { background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 0 16px; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); padding: 14px 0; white-space: nowrap; }
.top nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.top nav a, .linkbtn { text-decoration: none; color: var(--ink); padding: 8px 10px; border-radius: 6px; }
.top nav a.active { background: color-mix(in srgb, var(--pri) 14%, transparent); color: var(--pri); }
.top nav a:hover, .linkbtn:hover { background: color-mix(in srgb, var(--line) 70%, transparent); }
.linkbtn { background: none; border: 0; font: inherit; cursor: pointer; color: var(--muted); }
.navbtn { display: none; margin-left: auto; font-size: 1.4rem; cursor: pointer; padding: 8px; }
@media (max-width: 860px) {
  .navbtn { display: block; }
  .top { flex-wrap: wrap; }
  .top nav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: 10px; }
  #navtoggle:checked ~ nav { display: flex; }
}

.container { max-width: 980px; margin: 0 auto; padding: 18px 16px 40px; }
.foot { text-align: center; font-size: .8rem; padding: 20px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head-row h1 { margin: .2em 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 16px; display: block; }
.cards { display: grid; gap: 12px; }
.card.rec { text-decoration: none; color: inherit; margin: 0; transition: border-color .15s; }
.card.rec:hover { border-color: var(--pri); }
.rec-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.fname { word-break: break-word; }
.snippet { margin: 8px 0 0; color: var(--ink); opacity: .9; }
.snippet.err { color: var(--bad); }
.inactive { opacity: .55; }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 30px; text-align: center; color: var(--muted); }

.badge { font-size: .75rem; padding: 2px 9px; border-radius: 99px; font-weight: 600; white-space: nowrap; background: var(--line); color: var(--ink); }
.s-done { background: #dff5e8; color: #126b3a; }
.s-error { background: #fde3e1; color: #a1271e; }
.s-processing { background: #e2ebfd; color: #1f56c4; }
.s-queued { background: #f1ecdf; color: #7d5a12; }
:root[data-theme="dark"] .s-done { background: #173a27; color: #7fe0a8; }
:root[data-theme="dark"] .s-error { background: #47201d; color: #ff9b93; }
:root[data-theme="dark"] .s-processing { background: #1c2c4d; color: #9dbbff; }
:root[data-theme="dark"] .s-queued { background: #3a321f; color: #e9c879; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .s-done { background: #173a27; color: #7fe0a8; }
  :root:not([data-theme="light"]) .s-error { background: #47201d; color: #ff9b93; }
  :root:not([data-theme="light"]) .s-processing { background: #1c2c4d; color: #9dbbff; }
  :root:not([data-theme="light"]) .s-queued { background: #3a321f; color: #e9c879; }
}

/* Forms */
label { display: block; margin: 0 0 12px; font-weight: 500; }
label small { display: block; font-weight: 400; margin-top: 3px; }
input:not([type=checkbox]):not([type=file]):not([type=hidden]), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 11px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--pri) 40%, transparent); border-color: var(--pri); }
label.check { font-weight: 400; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
label.check input { transform: translateY(1px); }
label.check small { display: inline; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }
.code-input { font-size: 1.4rem !important; letter-spacing: .25em; text-align: center; }

.btn { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { border-color: var(--pri); }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.primary:hover { background: var(--pri-d); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.block { width: 100%; padding: 11px; }
.btn:disabled { opacity: .6; cursor: wait; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
form.inline { display: inline; margin: 0; }
.inline-test { display: flex; gap: 8px; margin-top: 12px; }
.inline-test input { margin: 0 !important; }
.copyrow { display: flex; gap: 8px; }
.copyrow input { margin: 0 !important; font-family: ui-monospace, monospace; }
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1 1 220px; margin: 0; }
.filters select { width: auto; margin: 0; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px; text-align: center; cursor: pointer; }
.drop:hover { border-color: var(--pri); }
.drop input { display: block; margin: 0 auto 10px; max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; border: 1px solid; }
.flash.ok { background: #e7f7ee; border-color: #b6e5c8; color: #135c34; }
.flash.error { background: #fdeceb; border-color: #f3c1bc; color: #8f2219; }
.flash.warn { background: #fdf5e3; border-color: #f0dba8; color: #6d4d0c; }
.flash.info { background: #e9f0fe; border-color: #c4d6fb; color: #1d3f86; }
:root[data-theme="dark"] .flash.ok { background: #14301f; border-color: #1f5a37; color: #a8ecc2; }
:root[data-theme="dark"] .flash.error { background: #3a1816; border-color: #6d2a25; color: #ffb4ad; }
:root[data-theme="dark"] .flash.warn { background: #33290f; border-color: #6a5520; color: #f3d58d; }
:root[data-theme="dark"] .flash.info { background: #172642; border-color: #2b4677; color: #b8cdfb; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .flash.ok { background: #14301f; border-color: #1f5a37; color: #a8ecc2; }
  :root:not([data-theme="light"]) .flash.error { background: #3a1816; border-color: #6d2a25; color: #ffb4ad; }
  :root:not([data-theme="light"]) .flash.warn { background: #33290f; border-color: #6a5520; color: #f3d58d; }
  :root:not([data-theme="light"]) .flash.info { background: #172642; border-color: #2b4677; color: #b8cdfb; }
}
.flash form { margin-left: 8px; }

/* Tables */
.tbl-wrap { overflow-x: auto; padding: 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.tbl-wrap .tbl th:first-child, .tbl-wrap .tbl td:first-child { padding-left: 16px; }
.lvl-error { color: var(--bad); font-weight: 600; } .lvl-warn { color: var(--warn); font-weight: 600; } .lvl-info { color: var(--muted); }

.player { width: 100%; margin-bottom: 10px; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 6px 0 0; font-size: .92rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.pager { display: flex; gap: 4px; justify-content: center; margin-top: 16px; }
.pager a { padding: 6px 11px; border-radius: 6px; text-decoration: none; border: 1px solid var(--line); background: var(--card); }
.pager a.active { background: var(--pri); color: #fff; border-color: var(--pri); }
.subnav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.subnav a { padding: 5px 11px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); text-decoration: none; font-size: .88rem; }
.doc ol, .doc ul { padding-left: 1.3em; } .doc li { margin-bottom: 6px; }
.qr { background: #fff; padding: 12px; display: inline-block; border-radius: 8px; margin: 6px 0 10px; }
.codes { font-size: 1.1rem; letter-spacing: .08em; columns: 2; }
details summary { cursor: pointer; font-weight: 500; margin: 10px 0; }
.checks { list-style: none; padding: 0; } .checks li { padding: 2px 0; }

/* Auth pages */
body.auth { display: flex; min-height: 100vh; align-items: flex-start; justify-content: center; padding: 8vh 16px 30px; }
.auth-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px; width: 100%; max-width: 400px; }
.auth-box.wide { max-width: 620px; }
.auth-box h1 { text-align: center; }

/* AI */
.ai-block { border-top: 1px solid var(--line); padding: 12px 0; }
.ai-block:first-of-type { border-top: 0; padding-top: 0; }
.ai-out { background: color-mix(in srgb, #7a5af5 8%, var(--bg)); border-left: 4px solid #7a5af5; padding: 10px 14px; border-radius: 6px; white-space: pre-wrap; line-height: 1.5; margin: 8px 0; color: var(--ink); font-family: inherit; font-size: .95rem; }
pre.ai-out { overflow-x: auto; }
td.pre { white-space: pre-wrap; }

/* Prevent long values (emails, URLs, file names) from widening the page on phones */
.tbl td { overflow-wrap: anywhere; }
.card { min-width: 0; overflow-x: auto; }
@media (max-width: 600px) {
  .tbl th, .tbl td { padding: 7px 6px; }
  .container { padding: 14px 10px 30px; }
}

.themebtn { background: none; border: 0; font-size: 1.1rem; cursor: pointer; padding: 6px 8px; border-radius: 6px; line-height: 1; }
.themebtn:hover { background: color-mix(in srgb, var(--line) 70%, transparent); }
.subnav a.active { background: var(--pri); color: #fff; border-color: var(--pri); }
.pick-row { border-top: 1px solid var(--line); padding: 8px 0; margin: 0; align-items: flex-start; flex-wrap: nowrap; }
.pick-row > span { flex: 1; min-width: 0; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--pri); margin-right: 4px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* Comparison */
.cmp-pick { margin-bottom: 14px; }
.cmp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.cmp-col { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cmp-col.current { background: color-mix(in srgb, var(--pri) 5%, transparent); }
.cmp-col.chosen { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok) inset; }
.cmp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.cmp-text { white-space: pre-wrap; line-height: 1.55; font-size: .93rem; flex: 1; overflow-wrap: anywhere; }
.cmp-text mark { background: #ffe58a; color: #3b2f00; border-radius: 3px; padding: 0 2px; }
:root[data-theme="dark"] .cmp-text mark { background: #5c4a00; color: #ffe9a6; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cmp-text mark { background: #5c4a00; color: #ffe9a6; } }
.linkbtn.small { font-size: .85rem; }

[hidden] { display: none !important; }

/* {{variable}} autocomplete */
.varac { position: fixed; z-index: 1000; max-height: 260px; overflow-y: auto; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 4px; }
.varac-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.varac-item code { font-size: .9em; background: none; padding: 0; color: var(--pri); }
.varac-item small { color: var(--muted); font-size: .8em; line-height: 1.25; }
.varac-item.on, .varac-item:hover { background: color-mix(in srgb, var(--pri) 14%, transparent); }
code.varchip { cursor: pointer; }
code.varchip:hover { outline: 1px solid var(--pri); }
.varhint { display: block; font-size: .8em; color: var(--muted); margin-top: 2px; }

/* Soft info box (rule test etc.) */
.card.soft { background: color-mix(in srgb, var(--pri) 6%, var(--card)); box-shadow: none; border: 1px solid var(--line); padding: 12px 14px; margin: 10px 0; }
div.pre { white-space: pre-wrap; margin: 6px 0; line-height: 1.45; }
.linkout { white-space: nowrap; }

/* ---------- Flow overview ---------- */
.fwarn { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fwarn li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; background: color-mix(in srgb, var(--line) 35%, transparent); font-size: .92em; line-height: 1.4; }
.fwarn li.lvl-error { background: color-mix(in srgb, #e5484d 13%, transparent); }
.fwarn li.lvl-warn { background: color-mix(in srgb, #f5a524 16%, transparent); }
.fwarn .ico { flex: none; }
.flow-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 18px 2px 10px; color: var(--muted); align-items: center; }
.flow-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 26px; height: 0; border-top: 2px solid; }
.lg-cond { border-color: var(--pri); }
.lg-var { border-top-style: dashed; border-color: #9b6bd6; }
.lg-feed { border-color: var(--line); border-top-width: 2px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot.st-on { background: #2f9e5b; } .dot.st-off { background: var(--line); } .dot.st-stopped { background: #e5484d; } .dot.st-unknown { background: #f5a524; }

.flow { position: relative; display: grid; grid-template-columns: minmax(200px, .8fr) minmax(220px, 1fr) minmax(320px, 1.6fr); gap: 56px; align-items: start; padding: 4px 4px 24px; }
.flow-lines { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; z-index: 0; }
.fcol { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.fcol h3 { margin: 0 0 2px; font-size: .95em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.farrow { text-align: center; color: var(--muted); line-height: 1; margin: -4px 0; }
.fnode { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); cursor: pointer; transition: opacity .15s, box-shadow .15s, border-color .15s; font-size: .92em; }
.fnode:hover { border-color: color-mix(in srgb, var(--pri) 50%, var(--line)); }
.fnode.inactive { opacity: .5; border-style: dashed; }
.fhead { display: flex; align-items: center; gap: 6px; }
.fhead strong { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.fedit { font-size: .82em; opacity: .7; }
.fnum { flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: color-mix(in srgb, var(--pri) 15%, transparent); color: var(--pri); font-size: .78em; font-weight: 700; }
.fico { flex: none; }
.fcond { margin-top: 4px; line-height: 1.35; }
.fsub { margin-top: 4px; font-size: .88em; color: var(--muted); }
.fsrc { margin: 6px 0 2px; padding-left: 18px; }
.fstat { display: block; margin-top: 6px; font-size: .8em; color: var(--muted); }
.fstat .bad, .fnode .bad { color: #d93036; }
.chip { display: inline-block; padding: 0 7px; border-radius: 999px; background: color-mix(in srgb, var(--line) 60%, transparent); font-size: .85em; }
.frow { display: flex; gap: 10px; align-items: stretch; }
.fmain { flex: 1; min-width: 0; }
.fact { flex: 0 0 132px; display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--pri) 7%, transparent); border: 1px solid color-mix(in srgb, var(--pri) 20%, var(--line)); font-size: .88em; overflow-wrap: anywhere; }
.fact .muted { font-size: .9em; line-height: 1.3; }
.fnode.stopper { border-bottom: 3px solid #e5484d; }
.fstop { margin-top: 8px; font-size: .85em; color: #d93036; font-weight: 600; }
.fsim { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: .86em; line-height: 1.35; }

.edge { fill: none; stroke-width: 2; transition: opacity .15s, stroke-width .15s; }
.edge-cond { stroke: var(--pri); opacity: .75; }
.edge-var { stroke: #9b6bd6; stroke-dasharray: 5 4; opacity: .75; }
.edge-feed { stroke: var(--line); stroke-width: 1.5; }
.edge.dead { opacity: .2; }
.arrowhead.ah-cond { fill: var(--pri); } .arrowhead.ah-var { fill: #9b6bd6; } .arrowhead.ah-feed { fill: var(--line); }

/* Focus on one node */
.flow.focusing .fnode:not(.hl) { opacity: .25; }
.flow.focusing .edge:not(.hl) { opacity: .06; }
.flow.focusing .fnode.hl { box-shadow: 0 0 0 2px color-mix(in srgb, var(--pri) 45%, transparent); }
.flow.focusing .edge.hl { opacity: 1; stroke-width: 2.6; }

/* Simulation */
.flow.simulating .fnode.st-on { border-color: #2f9e5b; box-shadow: 0 0 0 2px color-mix(in srgb, #2f9e5b 30%, transparent); }
.flow.simulating .fnode.st-on .fsim { color: #1f7a45; }
.flow.simulating .fnode.st-off, .flow.simulating .fnode.st-inactive, .flow.simulating .fnode.st-scope { opacity: .45; }
.flow.simulating .fnode.st-stopped { opacity: .5; border-color: #e5484d; border-style: dashed; }
.flow.simulating .fnode.st-stopped .fsim, .flow.simulating .fnode.st-error .fsim { color: #d93036; }
.flow.simulating .fnode.st-unknown { border-color: #f5a524; }
.flow.simulating .fnode.st-unknown .fsim { color: #9a6a0a; }
.flow.simulating .edge:not(.on) { opacity: .12; }
.flow.simulating .edge.on { opacity: 1; stroke-width: 2.6; stroke: #2f9e5b; }
.sim-summary { margin-top: 10px; }
:root[data-theme="dark"] .flow.simulating .fnode.st-on .fsim { color: #8be0ad; }

@media (max-width: 980px) {
  .flow { grid-template-columns: 1fr; gap: 18px; }
  .flow-lines { display: none; }
  .fact { flex-basis: 112px; }
}
@media (max-width: 480px) {
  .frow { flex-direction: column; }
  .fact { flex-basis: auto; flex-direction: row; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
}
.fnode.dead { border-color: #e5484d; border-style: dashed; }
@media (max-width: 980px) { .flow-legend .lg-line { display: none; } }
