/* Interactive demo page (demo.md + javascripts/ain-dt-demo.js). Shared tokens only, so it follows
   light and dark mode. Severity colours are the site's ramp (--st-*). */

.md-typeset .demo-band { padding: 56px 0 80px; background: var(--bg); }
.md-typeset .demo { --demo-r: 16px; font-size: 15px; }
.md-typeset .demo ul, .md-typeset .demo ol { list-style: none; margin: 0; padding: 0; }
.md-typeset .demo li { margin: 0; }
.md-typeset .demo h3 { margin: 0 0 8px; font-size: 20px; font-weight: 700; }
.md-typeset .demo h4 { margin: 22px 0 8px; font-size: 15px; font-weight: 700; }
.md-typeset .demo code { font: 500 12.5px/1.4 var(--mono); padding: 2px 6px; border-radius: 6px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); white-space: nowrap; }
.md-typeset .demo button { font: inherit; color: inherit; cursor: pointer; }
.md-typeset .demo .ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.md-typeset .demo-noscript, .md-typeset .demo-note { color: var(--muted); font-size: 14px; max-width: 80ch; margin: 28px 0 0; }

/* steps */
.md-typeset .demo .demo-steps { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 22px; }
.md-typeset .demo .demo-steps li { display: flex; align-items: center; gap: 9px; padding: 7px 14px 7px 8px; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-weight: 600; font-size: 14px; transition: color .2s, border-color .2s; }
.md-typeset .demo .demo-steps li b { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); font-size: 12.5px; }
.md-typeset .demo .demo-steps li.now { color: var(--text); border-color: var(--text); }
.md-typeset .demo .demo-steps li.now b { background: var(--accent); color: var(--accent-ink); }
.md-typeset .demo .demo-steps li.done b { background: var(--st-low); color: #0E2A22; }

/* layout */
.md-typeset .demo-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 22px; align-items: start; }
.md-typeset .demo-side, .md-typeset .demo-stage, .md-typeset .demo-pipe, .md-typeset .demo-result { background: var(--surface); border: 1px solid var(--line); border-radius: var(--demo-r); box-shadow: var(--shadow); }
.md-typeset .demo-side { padding: 16px; position: sticky; top: 76px; max-height: calc(100vh - 96px); display: flex; flex-direction: column; }
.md-typeset .demo-main { display: grid; gap: 22px; min-width: 0; }

/* network switch */
.md-typeset .demo-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.md-typeset .demo-seg button { border: 0; background: transparent; border-radius: 9px; padding: 9px 8px; font-weight: 700; font-size: 14px; text-align: left; line-height: 1.25; }
.md-typeset .demo-seg button small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 2px; }
.md-typeset .demo-seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(var(--ink), .14); }
.md-typeset .demo-blurb { margin: 12px 2px 12px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }

/* kind filter */
.md-typeset .demo-kinds { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.md-typeset .chipbtn { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); font-size: 12.5px; font-weight: 600; }
.md-typeset .chipbtn .ico { width: 14px; height: 14px; }
.md-typeset .chipbtn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* change list */
.md-typeset .demo .demo-list { overflow-y: auto; display: grid; gap: 6px; padding-right: 2px; min-height: 0; }
.md-typeset .demo-item { width: 100%; text-align: left; display: grid; gap: 2px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); transition: border-color .15s, background .15s; }
.md-typeset .demo-item:hover { border-color: var(--muted); }
.md-typeset .demo-item.sel { border-color: var(--link); background: color-mix(in srgb, var(--link) 8%, var(--surface)); box-shadow: inset 3px 0 0 var(--link); }
.md-typeset .demo-item b { font-size: 14.5px; }
.md-typeset .demo-item small { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.md-typeset .demo .k { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--link); }
.md-typeset .demo .k .ico { width: 14px; height: 14px; }
.md-typeset .demo-listnote { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 13px; color: var(--muted); padding: 2px 2px 6px; }
.md-typeset .linkbtn { border: 0; background: none; padding: 0; color: var(--link) !important; font-weight: 600; font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }

/* stage */
.md-typeset .demo-stage { overflow: hidden; }
.md-typeset .demo-stage-head { display: flex; gap: 18px; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); min-height: 86px; }
.md-typeset .demo-hint { margin: 0; color: var(--muted); }
.md-typeset .demo-hint .hl { color: var(--link); font-weight: 600; }
.md-typeset .demo-sel h3 { margin: 4px 0 6px; }
.md-typeset .demo .demo-ops li { color: var(--muted); font-size: 14px; }
.md-typeset .demo .demo-ops li + li { margin-top: 2px; }
.md-typeset .demo-run, .md-typeset .demo-actions .primary, .md-typeset .demo-actions button { display: inline-flex; align-items: center; gap: 8px; padding: 12px 22px; border-radius: var(--r-pill); border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink) !important; font-weight: 700; font-size: 15px; white-space: nowrap; text-decoration: none; flex: none; transition: transform .12s, opacity .2s; }
.md-typeset .demo-run .ico { fill: currentColor; stroke: none; }
.md-typeset .demo-run:hover:not(:disabled) { transform: translateY(-1px); }
.md-typeset .demo-run:disabled { opacity: .45; cursor: progress; }

/* map */
.md-typeset .demo-map-wrap { padding: 8px 10px 0; background: radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 0) 0 0 / 22px 22px; }
.md-typeset .demo-map { display: block; width: 100%; height: auto; max-height: 520px; }
.demo-map .edge .vis { stroke: color-mix(in srgb, var(--muted) 55%, transparent); stroke-width: 2.2; vector-effect: non-scaling-stroke; transition: stroke .3s, stroke-width .3s; }
.demo-map .edge.k-access .vis { stroke-width: 1.4; }
.demo-map .edge.k-trunk .vis { stroke-dasharray: 6 3; }
.demo-map .edge .hitline { stroke: transparent; stroke-width: 16; vector-effect: non-scaling-stroke; }
.demo-map .edge.pick { cursor: pointer; }
.demo-map .edge.pick .vis { stroke: color-mix(in srgb, var(--link) 55%, transparent); stroke-width: 3; }
.demo-map .edge.pick:hover .vis, .demo-map .edge.pick:focus .vis { stroke: var(--link); stroke-width: 4.5; }
.demo-map .edge:focus { outline: none; }
.demo-map .edge.target .vis { stroke: var(--link); stroke-width: 5; animation: demo-pulse 1.4s ease-in-out infinite; }
.demo-map .edge.changed .vis { stroke: var(--st-medium); stroke-width: 5; stroke-dasharray: 2 6; stroke-linecap: round; animation: none; }
.demo-map .edge.down .vis { stroke: var(--st-critical); stroke-width: 5; stroke-dasharray: 10 7; animation: none; }
.demo-map .node circle:not(.halo), .demo-map .node rect { fill: var(--surface); stroke: var(--text); stroke-width: 1.8; transition: fill .3s, stroke .3s; }
.demo-map .node.r-router circle:not(.halo) { fill: var(--hero); stroke: var(--hero); }
.demo-map .node.r-router .glyph { stroke: #EAF1F8; stroke-width: 1.5; fill: none; }
.demo-map .node.r-switch rect { fill: var(--surface-2); }
.demo-map .node .glyph { stroke: var(--text); stroke-width: 1.4; fill: none; }
.demo-map .node.r-server rect { fill: color-mix(in srgb, var(--link) 14%, var(--surface)); stroke: var(--link); }
.demo-map .node.r-host circle:not(.halo) { fill: var(--surface); stroke: var(--muted); }
.demo-map .node text { font: 500 10.5px var(--mono); fill: var(--muted); text-anchor: middle; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.demo-map .node .halo { fill: transparent; stroke: none; transition: fill .3s; }
.demo-map .node.pick { cursor: pointer; }
.demo-map .node.pick.r-host circle:not(.halo) { stroke: var(--link); stroke-width: 2.4; }
.demo-map .node.pick:hover .halo, .demo-map .node.pick:focus .halo { fill: color-mix(in srgb, var(--link) 16%, transparent); }
.demo-map .node:focus { outline: none; }
.demo-map .node.target .halo { fill: color-mix(in srgb, var(--link) 22%, transparent); animation: demo-pulse 1.4s ease-in-out infinite; }
.demo-map .node.hit .halo { fill: color-mix(in srgb, var(--st-medium) 30%, transparent); }
.demo-map .node.hit.b-low .halo { fill: color-mix(in srgb, var(--st-low) 35%, transparent); }
.demo-map .node.hit.b-high .halo { fill: color-mix(in srgb, var(--st-high) 32%, transparent); }
.demo-map .node.hit.b-critical .halo { fill: color-mix(in srgb, var(--st-critical) 30%, transparent); }
.demo-map .node.cut circle:not(.halo), .demo-map .node.cut rect { stroke: var(--st-critical); stroke-width: 2.6; }
.demo-map .node.cut text { fill: var(--st-critical-ink); font-weight: 600; }
@keyframes demo-pulse { 50% { opacity: .45; } }

.md-typeset .demo .demo-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 10px 20px 14px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); }
.md-typeset .demo .demo-legend li { display: inline-flex; align-items: center; gap: 6px; }
.md-typeset .demo .demo-legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1.6px solid var(--text); background: var(--surface); }
.md-typeset .demo .demo-legend .lg.router { background: var(--hero); border-color: var(--hero); }
.md-typeset .demo .demo-legend .lg.switch { border-radius: 3px; background: var(--surface-2); }
.md-typeset .demo .demo-legend .lg.host { width: 9px; height: 9px; border-color: var(--muted); }
.md-typeset .demo .demo-legend .lg.server { width: 9px; border-radius: 2px; border-color: var(--link); }
.md-typeset .demo .demo-legend .lg.pick, .md-typeset .demo .demo-legend .lg.down { width: 18px; height: 0; border-radius: 0; border: 0; border-top: 3px solid var(--link); }
.md-typeset .demo .demo-legend .lg.down { border-top: 3px dashed var(--st-critical); }
.md-typeset .demo .demo-legend .lg.hit { border: 0; background: color-mix(in srgb, var(--st-high) 40%, transparent); width: 14px; height: 14px; }

/* pipeline */
.md-typeset .demo-pipe { padding: 18px 20px; }
.md-typeset .demo-pipe-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.md-typeset .demo .demo-stages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 8px !important; }
.md-typeset .demo .demo-stages li { display: grid; grid-template-columns: 18px 1fr; column-gap: 10px; align-items: start; padding: 12px; border-radius: 12px; background: var(--surface-2); opacity: .5; transition: opacity .25s, background .25s; }
.md-typeset .demo .demo-stages li b { font-size: 14px; }
.md-typeset .demo .demo-stages li .d { grid-column: 2; color: var(--muted); font-size: 13px; line-height: 1.4; min-height: 1.4em; }
.md-typeset .demo .demo-stages .dot { width: 14px; height: 14px; margin-top: 3px; border-radius: 50%; border: 2px solid var(--muted); grid-row: span 2; }
.md-typeset .demo .demo-stages li.now { opacity: 1; background: color-mix(in srgb, var(--link) 10%, var(--surface-2)); }
.md-typeset .demo .demo-stages li.now .dot { border-color: var(--link); border-top-color: transparent; animation: demo-spin .8s linear infinite; }
.md-typeset .demo .demo-stages li.done { opacity: 1; }
.md-typeset .demo .demo-stages li.done .dot { border-color: var(--st-low); background: var(--st-low); box-shadow: inset 0 0 0 2px var(--surface-2); }
@keyframes demo-spin { to { transform: rotate(360deg); } }

/* result */
.md-typeset .demo-result { padding: 22px; }
.md-typeset .demo-verdict { display: grid; grid-template-columns: 220px 1fr; gap: 26px; align-items: center; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.md-typeset .demo-gauge { width: 100%; height: auto; }
.demo-gauge .seg { fill: none; stroke-width: 16; }
.demo-gauge .s-low { stroke: var(--st-low); } .demo-gauge .s-medium { stroke: var(--st-medium); }
.demo-gauge .s-high { stroke: var(--st-high); } .demo-gauge .s-critical { stroke: var(--st-critical); }
.demo-gauge .mark { fill: var(--surface); stroke: var(--text); stroke-width: 4; }

.demo-gauge .val { font: 700 30px var(--font); fill: var(--text); text-anchor: middle; }
.demo-gauge .of { font: 400 11px var(--font); fill: var(--muted); text-anchor: middle; }
.md-typeset .demo-badge { display: inline-flex; align-items: center; gap: 8px; padding: 5px 14px; border-radius: var(--r-pill); font-weight: 700; font-size: 14px; background: color-mix(in srgb, var(--st-invalid) 20%, var(--surface)); color: var(--st-invalid-ink); }
.md-typeset .demo-badge::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.md-typeset .demo-badge.low { background: color-mix(in srgb, var(--st-low) 22%, var(--surface)); color: var(--st-low-ink); }
.md-typeset .demo-badge.medium { background: color-mix(in srgb, var(--st-medium) 22%, var(--surface)); color: var(--st-medium-ink); }
.md-typeset .demo-badge.high { background: color-mix(in srgb, var(--st-high) 20%, var(--surface)); color: var(--st-high-ink); }
.md-typeset .demo-badge.critical { background: color-mix(in srgb, var(--st-critical) 18%, var(--surface)); color: var(--st-critical-ink); }
.md-typeset .demo-vtext h3 { margin: 10px 0 6px; font-size: 22px; line-height: 1.25; }
.md-typeset .demo-raise { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.md-typeset .demo-raise b { color: var(--text); }
.md-typeset .demo .demo-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin-top: 14px !important; }
.md-typeset .demo .demo-kpis li { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.md-typeset .demo .demo-kpis b { display: block; font-size: 22px; line-height: 1.1; color: var(--muted); }
.md-typeset .demo .demo-kpis li.on b { color: var(--text); }
.md-typeset .demo .demo-kpis span { font-size: 12.5px; color: var(--muted); }

.md-typeset .demo-tabs { display: flex; gap: 4px; margin: 18px 0 4px; border-bottom: 1px solid var(--line); }
.md-typeset .demo-tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 2.5px solid transparent; margin-bottom: -1px; }
.md-typeset .demo-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }
.md-typeset .demo-panel { padding: 4px 2px 0; }
.md-typeset .demo-sub { color: var(--muted); font-size: 14px; margin: 14px 0 6px; }
.md-typeset .demo-ok { margin: 16px 0 0; padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--st-low) 14%, var(--surface)); color: var(--text); }
.md-typeset .demo .demo-lost li { padding: 8px 0; border-bottom: 1px solid var(--line); line-height: 2; }
.md-typeset .demo .demo-lost li > code:first-child { background: color-mix(in srgb, var(--st-critical) 14%, var(--surface)); border-color: color-mix(in srgb, var(--st-critical) 35%, var(--line)); }
.md-typeset .demo .demo-plain li { padding: 5px 0 5px 16px; position: relative; font-size: 14px; }
.md-typeset .demo .demo-plain li::before { content: ""; position: absolute; left: 2px; top: 13px; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.md-typeset .demo-table { width: 100%; border-collapse: collapse; font-size: 14px; display: table; }
.md-typeset .demo-table th, .md-typeset .demo-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; background: none; }
.md-typeset .demo-table .num { text-align: right; font-family: var(--mono); }

.md-typeset .demo .demo-factors { display: grid; gap: 10px; margin-top: 10px !important; }
.md-typeset .demo .demo-factors li { display: grid; grid-template-columns: minmax(180px, 1.1fr) 2fr 92px; gap: 14px; align-items: center; }
.md-typeset .demo .demo-factors .fl b { display: block; font-size: 14px; }
.md-typeset .demo .demo-factors .fl small { color: var(--muted); font-size: 12.5px; line-height: 1.35; display: block; }
.md-typeset .demo .demo-factors .fb { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.md-typeset .demo .demo-factors .fb i { display: block; height: 100%; border-radius: 6px; background: var(--text); }
.md-typeset .demo .demo-factors .fv { font: 500 13px var(--mono); text-align: right; color: var(--muted); }
.md-typeset .demo .demo-rules li { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); margin-top: 8px; display: grid; gap: 2px; }
.md-typeset .demo .demo-rules span { color: var(--muted); font-size: 14px; }

.md-typeset .demo-ai p { line-height: 1.65; max-width: 80ch; }
.md-typeset .demo-ai ol { list-style: decimal; padding-left: 22px; }
.md-typeset .demo-ai ol li { margin: 4px 0; }
.md-typeset .demo-ai details { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: none; box-shadow: none; font-size: inherit; color: var(--text); }
.md-typeset .demo-ai summary { font-weight: 600; cursor: pointer; background: none; padding: 0; margin: 0; color: var(--text); }
.md-typeset .demo-ai details p { color: var(--text); }
.md-typeset .demo-ai summary::before, .md-typeset .demo-ai summary::after { display: none; }
.md-typeset .demo .cite { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 4px; margin: 0 1px; border-radius: 6px; border: 1px solid color-mix(in srgb, var(--link) 40%, var(--line)); background: color-mix(in srgb, var(--link) 10%, var(--surface)); color: var(--link); font: 600 11px var(--mono); vertical-align: 2px; }
.md-typeset .demo .cite.on { background: var(--link); color: var(--surface); }
.md-typeset .demo-cite-box { margin: 0 0 8px; padding: 10px 14px; border-radius: 12px; border-left: 3px solid var(--link); background: var(--surface-2); font-size: 14px; }

.md-typeset .demo-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.md-typeset .demo-actions button { background: transparent; color: var(--text) !important; border-color: var(--line); }

@media (max-width: 980px) {
  .md-typeset .demo-grid { grid-template-columns: 1fr; }
  .md-typeset .demo-side { position: static; max-height: none; }
  .md-typeset .demo .demo-list { max-height: 360px; }
  .md-typeset .demo .demo-stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md-typeset .demo-verdict { grid-template-columns: 1fr; }
  .md-typeset .demo-gauge { max-width: 240px; }
}
@media (max-width: 600px) {
  .md-typeset .demo-stage-head { flex-direction: column; align-items: stretch; }
  .md-typeset .demo .demo-stages { grid-template-columns: 1fr; }
  .md-typeset .demo .demo-factors li { grid-template-columns: 1fr 64px; }
  .md-typeset .demo .demo-factors .fb { grid-column: 1 / -1; grid-row: 2; }
}
@media (prefers-reduced-motion: reduce) {
  .demo-map .edge.target .vis, .demo-map .node.target .halo, .md-typeset .demo .demo-stages li.now .dot { animation: none; }
}
.demo-map .node text.slant { text-anchor: start; }
