:root {
  color-scheme: dark;
  --bg: #07101d;
  --panel: #0d1828;
  --panel-2: #111f33;
  --line: #25344a;
  --text: #edf5ff;
  --muted: #93a6bd;
  --cyan: #66e4ff;
  --green: #78f2b0;
  --amber: #ffca66;
  --red: #ff6f79;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; color: var(--text); background: radial-gradient(circle at 75% -20%, #143251 0, transparent 42%), var(--bg); }
button, input { font: inherit; }
button { border: 0; border-radius: 9px; padding: .72rem 1rem; font-weight: 750; color: #03131d; background: var(--cyan); cursor: pointer; transition: transform .18s ease, opacity .18s ease, border-color .18s ease; }
button:hover:not(:disabled) { transform: translateY(-1px); }
button:focus-visible, a:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
button:disabled { opacity: .38; cursor: not-allowed; }
button.secondary, button.ghost { color: var(--text); border: 1px solid var(--line); background: #132236; }
button.ghost { background: transparent; }
h1, h2, p { margin-top: 0; }
h1, h2 { margin-bottom: .2rem; letter-spacing: -.035em; }
h1 { font-size: clamp(1.45rem, 2vw, 2rem); }
h2 { font-size: 1.2rem; }
p { color: var(--muted); line-height: 1.55; }
.skip-link { position: fixed; z-index: 20; top: 10px; left: 10px; transform: translateY(-160%); padding: .7rem 1rem; color: #00131d; background: var(--cyan); border-radius: 8px; }
.skip-link:focus { transform: translateY(0); }
.topbar { position: sticky; z-index: 10; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .85rem clamp(1rem, 3vw, 2.5rem); border-bottom: 1px solid rgba(127, 159, 192, .18); background: rgba(7, 16, 29, .88); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: .65rem; letter-spacing: .12em; }
.brand-mark { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid #34819a; border-radius: 10px; color: var(--cyan); font-size: 1.8rem; }
.brand div { display: flex; flex-direction: column; }
.brand span:last-child { color: var(--muted); font-size: .67rem; letter-spacing: .04em; text-transform: uppercase; }
.header-actions, .tool-status { display: flex; align-items: center; gap: .65rem; }
.tool-status { min-height: 38px; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: .78rem; }
.tool-status span:last-child:not(.status-dot) { max-width: 180px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 14px var(--amber); }
.tool-status[data-status="ready"] .status-dot { background: var(--green); box-shadow: 0 0 14px var(--green); }
main { padding: clamp(1rem, 3vw, 2.5rem); }
.incident-strip { display: flex; align-items: center; gap: 2rem; max-width: 1480px; margin: 0 auto 1rem; padding: .9rem 1rem; border: 1px solid #59363c; border-radius: 14px; background: linear-gradient(90deg, rgba(91, 26, 35, .28), rgba(13, 24, 40, .85)); }
.incident-strip > div:first-child { display: flex; align-items: center; gap: .7rem; min-width: 220px; }
.incident-strip > div:first-child div { display: flex; flex-direction: column; }
.pulse { width: 11px; height: 11px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 6px rgba(255,111,121,.11), 0 0 18px var(--red); }
.incident-strip dl { display: flex; flex: 1; gap: clamp(1rem, 4vw, 4rem); margin: 0; }
.incident-strip dl div { display: flex; flex-direction: column; }
dt, .eyebrow { color: var(--muted); font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; }
dd { margin: .2rem 0 0; font-weight: 750; }
.training-badge { padding: .35rem .55rem; border: 1px solid #765e30; border-radius: 999px; color: var(--amber); font-size: .7rem; font-weight: 800; text-transform: uppercase; }
.workspace { display: grid; grid-template-columns: minmax(0, 2fr) minmax(290px, .8fr); gap: 1rem; max-width: 1480px; margin: 0 auto; }
.panel { min-width: 0; padding: 1.15rem; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(145deg, rgba(17,31,51,.95), rgba(10,20,34,.95)); box-shadow: 0 18px 45px rgba(0,0,0,.16); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.topology { display: block; width: 100%; height: auto; border: 1px solid rgba(107,137,166,.17); border-radius: 18px; }
.grid-lines path { fill: none; stroke: #3e526c; stroke-width: 5; stroke-linecap: round; }
.fault-line path { stroke: var(--red); stroke-width: 5; stroke-dasharray: 10 10; }
.fault-line circle { fill: var(--red); filter: drop-shadow(0 0 7px var(--red)); }
.source-node circle, .source-node rect, .load-node rect, .switch circle { fill: #13233a; stroke: #4e627d; stroke-width: 2; }
.source-node path, .load-node path, .switch path { fill: none; stroke: #a8bdd4; stroke-width: 3; stroke-linejoin: round; }
.source-node text, .load-node text, .switch text { fill: #a7bad0; font-size: 12px; font-weight: 700; text-anchor: middle; letter-spacing: .05em; }
.source-node .symbol { fill: var(--cyan); font-size: 20px; }
.source-node .node-status { fill: var(--red); font-size: 10px; }
.load-node { transition: filter .35s ease; }
.load-node.preview rect { stroke: var(--amber); stroke-width: 3; stroke-dasharray: 7 4; }
.load-node.preview path { stroke: var(--amber); }
.load-node.energized { filter: drop-shadow(0 0 12px rgba(120,242,176,.55)); }
.load-node.energized rect { fill: #103529; stroke: var(--green); stroke-width: 3; }
.load-node.energized path { stroke: var(--green); }
.constraint-callout { display: flex; gap: .7rem; margin-top: .8rem; padding: .8rem; border-left: 3px solid var(--red); background: rgba(255,111,121,.07); }
.constraint-callout span { color: var(--muted); font-size: .85rem; }
.legend { display: flex; flex-wrap: wrap; gap: .6rem; color: var(--muted); font-size: .72rem; }
.legend span { display: flex; align-items: center; gap: .3rem; }
.legend i { width: 8px; height: 8px; border-radius: 50%; background: #53677f; }
.legend i.preview { background: var(--amber); }
.legend i.live { background: var(--green); }
.priority-list { margin: 0; padding: 0; list-style: none; }
.priority-list li { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding: .75rem 0; border-top: 1px solid var(--line); }
.priority-list li div { display: flex; flex-direction: column; }
.priority-list small { color: var(--muted); }
.priority-list button { min-width: 78px; padding: .48rem .65rem; color: var(--muted); border: 1px solid var(--line); background: transparent; }
.priority-list button[data-active="true"] { color: #032719; border-color: var(--green); background: var(--green); }
.reserve-target { display: flex; justify-content: space-between; margin: .7rem 0; padding: .8rem; border: 1px solid var(--line); border-radius: 10px; }
.human-demo { display: grid; gap: .5rem; margin-top: 1.1rem; }
.human-demo button { width: 100%; text-align: left; }
.candidates-panel, .approval-panel { grid-column: 1; }
.draft-panel, .evidence-panel { grid-column: 2; }
.candidate-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.candidate { position: relative; padding: .9rem; border: 1px solid var(--line); border-radius: 13px; background: rgba(5,14,25,.45); }
.candidate.valid { border-color: rgba(120,242,176,.4); }
.candidate.blocked { border-color: rgba(255,111,121,.4); }
.candidate > div:first-child { display: flex; flex-direction: column; }
.verdict { align-self: flex-start; padding: .25rem .45rem; border: 1px solid #42637a; border-radius: 999px; color: var(--cyan); font-size: .67rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.candidate .verdict { position: absolute; top: .8rem; right: .8rem; }
.candidate.blocked .verdict, .verdict.danger { color: var(--red); border-color: #754148; }
.candidate dl { display: grid; grid-template-columns: repeat(3, 1fr); margin: .9rem 0 .5rem; padding: .65rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.candidate dl div { display: flex; flex-direction: column; }
.candidate p { min-height: 2.6em; margin-bottom: .7rem; font-size: .8rem; }
.candidate button { width: 100%; padding: .55rem; }
.empty { display: flex; min-height: 92px; flex-direction: column; align-items: center; justify-content: center; gap: .3rem; color: var(--muted); text-align: center; }
.draft-head { display: flex; justify-content: space-between; gap: .7rem; }
.draft-head > div { display: flex; flex-direction: column; }
#draft ol, .review-list { margin: .9rem 0; padding: 0; list-style: none; counter-reset: ops; }
#draft li, .review-list li { position: relative; padding: .55rem .4rem .55rem 2.2rem; border-top: 1px solid var(--line); color: #c7d5e5; font-size: .82rem; }
#draft li::before, .review-list li::before { position: absolute; left: .35rem; counter-increment: ops; content: counter(ops); display: grid; width: 1.25rem; height: 1.25rem; place-items: center; border: 1px solid #47647f; border-radius: 50%; color: var(--cyan); font-size: .65rem; }
.draft-actions, .approval-actions { display: flex; gap: .55rem; margin-top: .7rem; }
.draft-actions button, .approval-actions button { flex: 1; }
.approval-warning { display: flex; flex-direction: column; gap: .15rem; padding: .7rem; border: 1px solid #66512d; border-radius: 10px; color: var(--amber); background: rgba(255,202,102,.05); font-size: .78rem; }
.approval-warning span { color: var(--muted); }
.receipt { display: flex; flex-direction: column; gap: .3rem; padding: .8rem; border: 1px solid var(--line); border-radius: 10px; background: #091422; }
.receipt span { color: var(--muted); font-size: .8rem; }
.receipt code { color: var(--cyan); }
.ledger { max-height: 320px; overflow: auto; margin: .75rem 0 0; padding: 0; list-style: none; }
.ledger li { display: flex; gap: .55rem; padding: .55rem 0; border-top: 1px solid var(--line); }
.ledger li > div { display: flex; min-width: 0; flex-direction: column; }
.ledger strong { font-size: .78rem; text-transform: capitalize; }
.ledger small { overflow: hidden; color: var(--muted); font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }
.actor { align-self: flex-start; min-width: 44px; padding: .2rem .35rem; border-radius: 5px; color: #001c25; background: var(--cyan); font-size: .58rem; font-weight: 850; text-align: center; text-transform: uppercase; }
.actor.human { color: #231500; background: var(--amber); }
footer { display: flex; justify-content: space-between; gap: 1rem; max-width: 1480px; margin: 0 auto; padding: 2rem clamp(1rem, 3vw, 2.5rem); color: var(--muted); font-size: .76rem; }
footer a { color: var(--cyan); }

@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; }
  .candidates-panel, .approval-panel, .draft-panel, .evidence-panel { grid-column: 1; }
  .priorities { grid-row: auto; }
  .incident-strip { align-items: flex-start; flex-wrap: wrap; }
  .incident-strip dl { order: 3; width: 100%; justify-content: space-between; }
}

@media (max-width: 600px) {
  .topbar { align-items: flex-start; }
  .header-actions { align-items: flex-end; flex-direction: column; }
  .tool-status { display: none; }
  .incident-strip dl { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
  .candidate-grid { grid-template-columns: 1fr; }
  .legend { display: none; }
  .approval-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
