/* ============================================================
   RAGuard — Animated Runtime Gateway  (drop-in for .arch)
   Vanilla CSS · theme-aware (light now, dark-ready)
   All selectors scoped under .gw
   ============================================================ */

.gw {
  position: relative;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) clamp(280px, 30vw, 372px) minmax(150px, 1fr);
  align-items: center;
  gap: clamp(26px, 6vw, 92px);
  margin-top: 8px;
  padding: 16px 4px 8px;
}

/* ---------- Columns of nodes ---------- */
.gw-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  z-index: 2;
}

.gw-col-cap {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-4);
  margin-bottom: 2px;
  padding-left: 2px;
}
.gw-col-right .gw-col-cap { text-align: right; padding-right: 2px; padding-left: 0; }

.gw-node {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 13px;
  box-shadow: var(--shadow-1);
  transition: border-color .35s ease, box-shadow .35s ease, transform .35s ease;
  position: relative;
}
.gw-col-right .gw-node { flex-direction: row-reverse; text-align: right; }

.gw-node-ic {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
}
.gw-node-ic svg { width: 18px; height: 18px; }
.gw-node-ic img { width: 19px; height: 19px; object-fit: contain; }

.gw-node-tx { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.gw-node-tx b { font-size: 0.82rem; font-weight: 600; color: var(--fg-1); white-space: nowrap; }
.gw-node-tx em { font-style: normal; font-size: 0.66rem; color: var(--fg-4); white-space: nowrap; }

/* active node = currently transacting */
.gw-node.active {
  border-color: var(--brand-line);
  box-shadow: 0 0 0 1px var(--brand-line), 0 8px 22px rgba(11, 0, 206, .14);
  transform: translateX(var(--gw-shift, 0));
}
.gw-col-left .gw-node.active { --gw-shift: 4px; }
.gw-col-right .gw-node.active { --gw-shift: -4px; }
.gw-node.blocked { border-color: color-mix(in srgb, var(--red) 45%, var(--line-2)); }
.gw-node.blocked .gw-node-ic { background: var(--red-soft); color: var(--red); }

/* ---------- Core gateway ---------- */
.gw-core {
  position: relative;
  z-index: 3;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--brand-soft) 220%);
  border: 1px solid var(--brand-line);
  border-radius: var(--radius-lg, 24px);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}
.gw-core::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-3) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: .55;
  pointer-events: none;
}
.gw-core-glow {
  position: absolute;
  top: -40%;
  left: 50%;
  transform: translateX(-50%);
  width: 130%;
  height: 80%;
  background: radial-gradient(50% 50% at 50% 50%, color-mix(in srgb, var(--brand-3) 30%, transparent), transparent 70%);
  pointer-events: none;
  opacity: .5;
}

.gw-core-head { display: flex; align-items: center; gap: 11px; position: relative; }
.gw-core-mark {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-3) 100%);
  color: #fff;
  box-shadow: 0 6px 16px rgba(11, 0, 206, .28);
}
.gw-core-mark svg { width: 26px; height: 22px; }
.gw-core-headtext { flex: 1; min-width: 0; }
.gw-core-title { font-size: 0.98rem; font-weight: 700; color: var(--fg-1); letter-spacing: -0.01em; }
.gw-core-sub { font-size: 0.68rem; color: var(--fg-3); }

.gw-live {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono, monospace);
  font-size: 0.58rem; font-weight: 600; letter-spacing: 0.12em;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 3px 8px;
}
.gw-live i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: gw-pulse 2s ease-in-out infinite; }

/* scan lane — packets enter here */
.gw-scan {
  position: relative;
  height: 44px;
  border-radius: 11px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.gw-scan-grid {
  position: absolute; inset: 0;
  background-image: linear-gradient(90deg, color-mix(in srgb, var(--brand) 12%, transparent) 1px, transparent 1px);
  background-size: 14px 100%;
  opacity: .5;
}
.gw-scan-label {
  font-family: var(--font-mono, monospace);
  font-size: 0.64rem; letter-spacing: 0.06em;
  color: var(--fg-4);
  position: relative; z-index: 2;
  transition: color .25s ease;
}
.gw-scan-beam {
  position: absolute; top: 0; bottom: 0; width: 38%;
  left: -40%;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--brand-3) 42%, transparent), transparent);
  pointer-events: none;
  opacity: 0;
}
.gw-scan.scanning .gw-scan-beam { animation: gw-beam .62s cubic-bezier(.4,0,.2,1) 1; }
.gw-scan.scanning .gw-scan-label { color: var(--brand); }
.gw-scan.verdict-block { border-color: color-mix(in srgb, var(--red) 50%, var(--line-2)); }
.gw-scan.verdict-block .gw-scan-label { color: var(--red); }
.gw-scan.verdict-redact { border-color: color-mix(in srgb, var(--warning) 50%, var(--line-2)); }
.gw-scan.verdict-redact .gw-scan-label { color: var(--warning); }
.gw-scan.verdict-allow .gw-scan-label { color: var(--green); }

/* enforcement chip pipeline */
.gw-pipe { display: flex; flex-wrap: wrap; gap: 6px; }
.gw-chip {
  font-family: var(--font-mono, monospace);
  font-size: 0.62rem; font-weight: 500;
  color: var(--fg-3);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 3px 9px;
  transition: all .25s ease;
}
.gw-chip.lit { color: var(--brand); background: var(--brand-soft); border-color: var(--brand-line); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 8%, transparent); }
.gw-chip.lit-amber { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 10%, transparent); }
.gw-chip.lit-red { color: var(--red); background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 35%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 10%, transparent); }

/* dark verdict console */
.gw-console {
  background: var(--bg-ink, #0B0B17);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.05);
}
.gw-verdict {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono, monospace);
  font-size: 0.74rem; font-weight: 600;
  color: #E6E6F0;
  min-height: 18px;
}
.gw-verdict .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #555; transition: background .25s; }
.gw-verdict .tag {
  font-size: 0.58rem; letter-spacing: 0.08em; font-weight: 700;
  padding: 2px 6px; border-radius: 5px;
  background: rgba(255,255,255,.08); color: #cfcfe0;
  transition: all .25s;
}
.gw-verdict.v-allow .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.gw-verdict.v-allow .tag { background: color-mix(in srgb, var(--green) 26%, transparent); color: #c9f5d8; }
.gw-verdict.v-redact .dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.gw-verdict.v-redact .tag { background: color-mix(in srgb, var(--warning) 28%, transparent); color: #ffe6b8; }
.gw-verdict.v-block .dot { background: var(--red); box-shadow: 0 0 8px var(--red); }
.gw-verdict.v-block .tag { background: color-mix(in srgb, var(--red) 30%, transparent); color: #ffd2d2; }
.gw-verdict.v-opa .dot { background: var(--brand-3); box-shadow: 0 0 8px var(--brand-3); }
.gw-verdict.v-opa .tag { background: color-mix(in srgb, var(--brand-3) 32%, transparent); color: #dcd9ff; }
.gw-vtext { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.gw-meta {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono, monospace);
  font-size: 0.62rem; color: #9a9ab4;
}
.gw-meta .sep { opacity: .4; }
.gw-meta b { color: #cfcfe6; font-weight: 600; }

/* ---------- Wires + packets overlay ---------- */
.gw-wires {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}
.gw-wire { fill: none; stroke: var(--line-2); stroke-width: 1.5; stroke-dasharray: 3 7; stroke-linecap: round; opacity: .85; animation: gw-flow 2.4s linear infinite; }
.gw-wire.hot { stroke: url(#gw-grad); stroke-width: 2.2; stroke-dasharray: 4 5; opacity: 1; animation: gw-flow 0.7s linear infinite; }
.gw-wire.hot-bad { stroke: var(--red); }

.gw-packets { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.gw-packet {
  position: absolute; top: 0; left: 0;
  width: 16px; height: 16px; border-radius: 50%;
  display: grid; place-items: center;
  will-change: transform; transform: translate(-100px, -100px);
  box-shadow: 0 0 10px 1px currentColor;
}
.gw-packet::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; background: radial-gradient(currentColor, transparent 70%); opacity: .35; }
.gw-packet svg { width: 9px; height: 9px; position: relative; z-index: 2; }
.gw-packet.p-req { background: linear-gradient(135deg, var(--brand), var(--brand-3)); color: var(--brand-3); }
.gw-packet.p-resp { background: var(--green); color: var(--green); }
.gw-packet.p-redact { background: var(--warning); color: var(--warning); }
.gw-packet.p-bad { background: var(--red); color: var(--red); }
.gw-packet svg { color: #fff; }
.gw-packet.pop { animation: gw-pop .3s ease both; }
.gw-packet.die { animation: gw-die .42s cubic-bezier(.4,0,.2,1) both; }

/* ---------- keyframes ---------- */
@keyframes gw-flow { to { stroke-dashoffset: -20; } }
@keyframes gw-beam { 0% { left: -40%; opacity: 0; } 12% { opacity: 1; } 88% { opacity: 1; } 100% { left: 102%; opacity: 0; } }
@keyframes gw-pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }
@keyframes gw-pop { from { transform: translate(var(--gx), var(--gy)) scale(0); } to { transform: translate(var(--gx), var(--gy)) scale(1); } }
@keyframes gw-die {
  0% { transform: translate(var(--gx), var(--gy)) scale(1); }
  35% { transform: translate(var(--gx), var(--gy)) scale(1.5); }
  100% { transform: translate(var(--gx), var(--gy)) scale(0); opacity: 0; }
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .gw { gap: clamp(14px, 4vw, 40px); grid-template-columns: minmax(54px, .7fr) clamp(220px, 42vw, 320px) minmax(54px, .7fr); }
  .gw-node { padding: 8px; justify-content: center; }
  .gw-node-tx { display: none; }
  .gw-col-cap { text-align: center; padding: 0; font-size: 0.55rem; }
  .gw-col-right .gw-col-cap { text-align: center; }
}
@media (max-width: 560px) {
  .gw { grid-template-columns: 48px 1fr 48px; gap: 10px; }
  .gw-core { padding: 12px; }
  .gw-node-ic { width: 30px; height: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .gw-wire, .gw-wire.hot, .gw-live i, .gw-scan.scanning .gw-scan-beam { animation: none !important; }
}
