:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --line: #e2e6ef;
  --line-strong: #b5bdcb;
  --ink-0: #0f172a;
  --ink-1: #475569;
  --ink-2: #7a8699;
  --ink-3: #b4bcc9;

  --c-monitor: #ea580c;     /* n8n — orange like user's ref */
  --c-monitor-bg: #fff1e6;
  --c-health: #ea580c;      /* health checker — same system orange */
  --c-health-bg: #fff1e6;
  --c-actor: #06b6d4;       /* actor — teal/cyan */
  --c-actor-bg: #e0f7fa;
  --c-ticket: #0891b2;
  --c-ticket-bg: #e0f7fb;
  --c-omc: #0284c7;
  --c-omc-bg: #e0f2fe;
  --c-incident: #d97706;
  --c-incident-bg: #fef3c7;
  --c-security: #dc2626;
  --c-security-bg: #fee2e2;
  --c-dev: #059669;
  --c-dev-bg: #d1fae5;
  --c-resolved: #10b981;

  --sev1: #dc2626;
  --sev2: #ea580c;
  --sev3: #ca8a04;
  --sev4: #2563eb;

  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Inter Tight', 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink-0);
  font-family: var(--sans);
  min-height: 100vh;
}

.app {
  max-width: 1760px;
  margin: 0 auto;
  padding: 24px 28px 36px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.header .sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 6px;
}
.header-right {
  display: flex;
  gap: 24px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.header-right .kv { display: flex; gap: 8px; }
.header-right .kv .v { color: var(--ink-0); font-weight: 600; }

.narrator {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}
.narrator .step-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.15em;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 82px;
  text-align: center;
}
.narrator .step-title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}
.narrator .step-title .accent { color: var(--c-omc); }
.narrator .scenario-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 4px;
  color: #fff;
  font-weight: 700;
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 18px;
  align-items: start;
}

.diagram-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  overflow: hidden;
}

svg.flow { display: block; width: 100%; height: auto; }

/* Rules panel */
.rules {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 16px;
}
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}
.panel-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-head .t {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--ink-1);
  text-transform: uppercase;
  font-weight: 700;
}
.panel-head .badge {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--c-omc);
  padding: 3px 8px;
  border: 1px solid var(--c-omc);
  border-radius: 4px;
  letter-spacing: 0.1em;
  font-weight: 600;
}
.panel-head .badge.idle {
  color: var(--ink-3);
  border-color: var(--line);
}

.kb-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.kb-tab {
  flex: 1;
  padding: 9px 8px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-2);
  text-align: center;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-right: 1px solid var(--line);
  position: relative;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.kb-tab:last-child { border-right: none; }
.kb-tab .kb-tab-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3);
  transition: background 0.2s, box-shadow 0.2s;
}
.kb-tab.active {
  color: var(--c-omc);
  background: #fff;
}
.kb-tab.active .kb-tab-dot {
  background: var(--c-omc);
  box-shadow: 0 0 0 3px var(--c-omc-bg);
}
.kb-tab.reading .kb-tab-dot {
  background: var(--c-omc);
  animation: kb-pulse 1s ease-in-out infinite;
}
@keyframes kb-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(2, 132, 199, 0.5); }
  50% { box-shadow: 0 0 0 5px rgba(2, 132, 199, 0); }
}

.panel-body {
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.75;
  color: var(--ink-1);
  max-height: 280px;
  min-height: 240px;
  overflow: hidden;
  position: relative;
}
.md-line {
  padding: 1px 0;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.3s, transform 0.3s;
}
.md-line.visible { opacity: 1; transform: translateX(0); }
.md-line.comment { color: var(--ink-3); }
.md-line.key { color: var(--c-monitor); font-weight: 700; }
.md-line.match {
  color: var(--c-incident);
  background: var(--c-incident-bg);
  padding: 2px 8px;
  border-left: 2px solid var(--c-incident);
  margin: 2px -16px 2px -16px;
  padding-left: 14px;
}
.md-line.decision {
  color: var(--c-dev);
  background: var(--c-dev-bg);
  padding: 2px 8px;
  border-left: 2px solid var(--c-dev);
  margin: 2px -16px 2px -16px;
  padding-left: 14px;
  font-weight: 700;
}

/* Severity matrix */
.sev-row {
  display: grid;
  grid-template-columns: 58px 1fr 62px;
  gap: 10px;
  padding: 9px 14px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  transition: background 0.3s;
}
.sev-row:last-child { border-bottom: none; }
.sev-row.active { background: var(--c-omc-bg); }
.sev-tag {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 3px;
  color: #fff;
  letter-spacing: 0.05em;
  text-align: center;
}
.sev1 { background: var(--sev1); }
.sev2 { background: var(--sev2); }
.sev3 { background: var(--sev3); }
.sev4 { background: var(--sev4); }
.sev-desc { color: var(--ink-1); font-size: 11px; }
.sev-sla { font-family: var(--mono); font-size: 10px; color: var(--ink-2); text-align: right; }

/* Controls */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.ctrl-left { display: flex; gap: 10px; align-items: center; }
.btn {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--ink-0);
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--ink-0); color: #fff; border-color: var(--ink-0); }
.btn.primary:hover { background: var(--c-omc); border-color: var(--c-omc); }

.scenario-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.scn-btn {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--ink-1);
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 11px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
}
.scn-btn:hover { border-color: var(--ink-3); color: var(--ink-0); }
.scn-btn.active {
  border-color: var(--c-omc);
  background: var(--c-omc-bg);
  color: var(--c-omc);
}
.scn-btn .dot { width: 8px; height: 8px; border-radius: 50%; }
.scn-btn em { font-style: normal; color: var(--ink-3); font-weight: 400; margin-left: 4px; font-size: 10px; }
.scn-btn.active em { color: var(--c-omc); opacity: 0.8; }

.timeline {
  display: flex;
  gap: 4px;
  align-items: center;
  flex: 1;
  max-width: 380px;
  margin: 0 16px;
}
.timeline .tl-step {
  flex: 1;
  height: 5px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.timeline .tl-step.done { background: var(--c-omc); }
.timeline .tl-step.active::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--c-omc);
  animation: fill-step linear forwards;
  animation-duration: var(--step-dur, 2s);
}
@keyframes fill-step {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

/* ============== SVG styles — THICKER LINES ============== */
.node-box {
  fill: #fff;
  stroke: var(--line-strong);
  stroke-width: 2;
  transition: fill 0.3s, stroke 0.3s;
}
.node-box.actor {
  fill: var(--c-actor-bg);
  stroke: var(--c-actor);
  stroke-width: 2.5;
}
.node-box.team-box { stroke-width: 2; }

.node-box.active {
  fill: var(--c-omc-bg);
  stroke: var(--c-omc);
  stroke-width: 3;
  filter: drop-shadow(0 6px 18px rgba(2, 132, 199, 0.25));
}
.node-box.active-violet, .node-box.active-monitor {
  fill: var(--c-monitor-bg);
  stroke: var(--c-monitor);
  stroke-width: 3;
  filter: drop-shadow(0 6px 18px rgba(234, 88, 12, 0.25));
}
.node-box.active-health {
  fill: var(--c-health-bg);
  stroke: var(--c-health);
  stroke-width: 3;
  filter: drop-shadow(0 6px 18px rgba(234, 88, 12, 0.25));
}
.node-box.active-amber {
  fill: var(--c-incident-bg);
  stroke: var(--c-incident);
  stroke-width: 3;
  filter: drop-shadow(0 6px 18px rgba(217, 119, 6, 0.25));
}
.node-box.active-red {
  fill: var(--c-security-bg);
  stroke: var(--c-security);
  stroke-width: 3;
  filter: drop-shadow(0 6px 18px rgba(220, 38, 38, 0.25));
}
.node-box.active-green {
  fill: var(--c-dev-bg);
  stroke: var(--c-dev);
  stroke-width: 3;
  filter: drop-shadow(0 6px 18px rgba(5, 150, 105, 0.25));
}
.node-box.failing {
  fill: var(--c-security-bg);
  stroke: var(--c-security);
  stroke-width: 3;
  animation: shake 0.5s ease-in-out 2;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-1.5px); }
  75% { transform: translateX(1.5px); }
}

.kb-box {
  fill: #fff;
  stroke: var(--c-omc);
  stroke-width: 1.8;
  stroke-opacity: 0.5;
  transition: all 0.3s;
}
.kb-box.reading {
  fill: var(--c-omc-bg);
  stroke-opacity: 1;
  stroke-width: 2.5;
  filter: drop-shadow(0 4px 12px rgba(2, 132, 199, 0.25));
}

.node-title {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  fill: var(--ink-0);
}
.node-sub {
  font-family: var(--mono);
  font-size: 10px;
  fill: var(--ink-2);
  letter-spacing: 0.03em;
}
.node-tag {
  font-family: var(--mono);
  font-size: 9px;
  fill: var(--ink-2);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
}

/* CONNECTORS — THICKER */
.edge {
  fill: none;
  stroke: #9aa3b2;
  stroke-width: 2.5;
  stroke-dasharray: 5 6;
}
.edge.edge-rag {
  stroke: var(--c-omc);
  stroke-width: 1.5;
  stroke-dasharray: 2 4;
  opacity: 0.3;
}
.edge.edge-rag-return {
  stroke: var(--c-omc);
  stroke-width: 1.5;
  stroke-dasharray: 2 4;
  opacity: 0.25;
}
.edge.edge-rag.active, .edge.edge-rag-return.active {
  opacity: 1;
  stroke-width: 2.5;
  stroke-dasharray: 6 6;
  animation: edge-flow 0.8s linear infinite;
  filter: drop-shadow(0 0 4px rgba(2, 132, 199, 0.5));
}
.edge.edge-self-mon {
  stroke: var(--c-monitor);
  stroke-width: 1.3;
  stroke-dasharray: 3 3;
  opacity: 0.55;
  fill: none;
}

.edge.edge-escalate {
  stroke: var(--c-incident);
  stroke-width: 2;
  stroke-dasharray: 2 4;
  opacity: 0.4;
}
.edge.edge-escalate.active {
  opacity: 1;
  stroke-width: 3;
  stroke-dasharray: 6 6;
  animation: edge-flow 0.8s linear infinite;
  filter: drop-shadow(0 0 5px rgba(217, 119, 6, 0.5));
}
.edge.edge-cross {
  stroke: var(--c-incident);
  stroke-width: 1.3;
  stroke-dasharray: 2 3;
  opacity: 0.2;
}
.edge.edge-cross.active {
  opacity: 1;
  stroke-width: 3;
  stroke-dasharray: 6 6;
  stroke: var(--c-monitor);
  animation: edge-flow 0.8s linear infinite;
  filter: drop-shadow(0 0 5px rgba(234, 88, 12, 0.5));
}
.edge.edge-outcome {
  stroke: #c6ccda;
  stroke-width: 1.3;
  stroke-dasharray: 2 3;
  opacity: 0.25;
}
.edge.edge-outcome.active {
  opacity: 1;
  stroke-width: 3;
  stroke-dasharray: 6 6;
  animation: edge-flow 0.8s linear infinite;
}
.edge.edge-outcome.active.resolved { stroke: var(--c-resolved); filter: drop-shadow(0 0 5px rgba(16, 185, 129, 0.5)); }
.edge.edge-outcome.active.noop { stroke: var(--ink-2); filter: drop-shadow(0 0 5px rgba(122, 134, 153, 0.4)); }
.edge.edge-outcome.active.reroute { stroke: var(--c-monitor); filter: drop-shadow(0 0 5px rgba(234, 88, 12, 0.5)); }
.edge.edge-outcome.active.escalated { stroke: var(--c-security); filter: drop-shadow(0 0 5px rgba(220, 38, 38, 0.5)); }

.outcome-box {
  fill: #fff;
  stroke: var(--line-strong);
  stroke-width: 2;
  transition: all 0.3s;
}
.outcome-box.active.out-resolved-bx {
  fill: #e7faf2; stroke: var(--c-resolved); stroke-width: 3;
  filter: drop-shadow(0 6px 16px rgba(16, 185, 129, 0.25));
}
.outcome-box.active.out-noop-bx {
  fill: #f4f5f9; stroke: var(--ink-2); stroke-width: 3;
}
.outcome-box.active.out-reroute-bx {
  fill: var(--c-monitor-bg); stroke: var(--c-monitor); stroke-width: 3;
  filter: drop-shadow(0 6px 16px rgba(234, 88, 12, 0.25));
}
.outcome-box.active.out-esc-bx {
  fill: var(--c-security-bg); stroke: var(--c-security); stroke-width: 3;
  filter: drop-shadow(0 6px 16px rgba(220, 38, 38, 0.25));
}
.edge.active {
  stroke-dasharray: 7 7;
  stroke-width: 3.5;
  animation: edge-flow 0.8s linear infinite;
}
.edge.active.cyan { stroke: var(--c-omc); filter: drop-shadow(0 0 5px rgba(2, 132, 199, 0.5)); }
.edge.active.violet, .edge.active.monitor { stroke: var(--c-monitor); filter: drop-shadow(0 0 5px rgba(234, 88, 12, 0.5)); }
.edge.active.pink, .edge.active.health { stroke: var(--c-health); filter: drop-shadow(0 0 5px rgba(234, 88, 12, 0.5)); }
.edge.active.amber { stroke: var(--c-incident); filter: drop-shadow(0 0 5px rgba(217, 119, 6, 0.5)); }
.edge.active.red { stroke: var(--c-security); filter: drop-shadow(0 0 5px rgba(220, 38, 38, 0.5)); }
.edge.active.green { stroke: var(--c-dev); filter: drop-shadow(0 0 5px rgba(5, 150, 105, 0.5)); }
@keyframes edge-flow { to { stroke-dashoffset: -24; } }

.edge-label {
  font-family: var(--mono);
  font-size: 9px;
  fill: var(--ink-2);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}
.edge-label-bg { fill: #fff; }

.rag-bracket { stroke-dasharray: 3 4; }

/* Decision diamond */
.decision-diamond {
  fill: #fff;
  stroke: var(--line-strong);
  stroke-width: 2.5;
  transition: all 0.3s;
}
.decision-diamond.active {
  fill: #fff7e0;
  stroke: var(--c-incident);
  stroke-width: 3;
  filter: drop-shadow(0 6px 18px rgba(217, 119, 6, 0.3));
}

/* Pulse ring */
.pulse-ring {
  fill: none;
  stroke-width: 2.5;
  opacity: 0;
  transform-origin: center;
  transform-box: fill-box;
}
.pulse-ring.active {
  opacity: 1;
  animation: pulse-ring 1.8s ease-out infinite;
}
@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.18); opacity: 0; }
}

/* Packets */
.packet-group { opacity: 0; transition: opacity 0.25s; }
.packet-group.visible { opacity: 1; }
.packet-pill {
  fill: #fff;
  stroke-width: 2.5;
  filter: drop-shadow(0 5px 14px rgba(15, 23, 42, 0.18));
}
.packet-label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  fill: var(--ink-0);
}
.packet-sev {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  fill: #fff;
  letter-spacing: 0.05em;
}
.packet-sev1 .packet-pill { stroke: var(--sev1); }
.packet-sev1 .sev-chip-bg { fill: var(--sev1); }
.packet-sev2 .packet-pill { stroke: var(--sev2); }
.packet-sev2 .sev-chip-bg { fill: var(--sev2); }
.packet-sev3 .packet-pill { stroke: var(--sev3); }
.packet-sev3 .sev-chip-bg { fill: var(--sev3); }
.packet-sev4 .packet-pill { stroke: var(--sev4); }
.packet-sev4 .sev-chip-bg { fill: var(--sev4); }

/* Member dots */
.member-dot {
  fill: var(--line-strong);
  transition: fill 0.3s;
}
.member-dot.lit.amber { fill: var(--c-incident); filter: drop-shadow(0 0 5px currentColor); }
.member-dot.lit.green { fill: var(--c-dev); filter: drop-shadow(0 0 5px currentColor); }
.member-dot.lit.red { fill: var(--c-security); filter: drop-shadow(0 0 5px currentColor); }

/* Resolution flash */
.resolution-flash { opacity: 0; pointer-events: none; transform-origin: 590px 545px; }
.resolution-flash.show { animation: resolve-flash 1.1s ease-out; }
@keyframes resolve-flash {
  0% { opacity: 0; transform: scale(0.6); }
  50% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.15); }
}

.footer-note {
  text-align: center;
  margin-top: 20px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* Human operator supervision link (dashed, subtle) */
.edge-supervise {
  stroke: var(--c-actor);
  stroke-width: 1.8;
  stroke-dasharray: 4 3;
  opacity: 0.55;
  fill: none;
}


/* ============================================================
   Mobile PORTRAIT: rotate the demo to landscape — the 2-column
   layout needs the width. Turning the phone to landscape removes
   the rotation (orientation: landscape) and renders normally.
   ============================================================ */
@media (max-width: 600px) and (orientation: portrait) {
  html, body { overflow: hidden; height: 100%; }
  #rotateRoot {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vh;
    height: 100vw;
    transform-origin: top left;
    transform: translateX(100vw) rotate(90deg);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
