:root {
  --bg: #eef4f7;
  --surface: rgba(255, 255, 255, .78);
  --surface-solid: #ffffff;
  --ink: #102030;
  --muted: #64748b;
  --line: #667b8f;
  --active: #f59e0b;
  --active-2: #22c55e;
  --blue: #2563eb;
  --pink: #db2777;
  --green: #16a34a;
  --yellow: #ca8a04;
  --cyan: #0891b2;
  --violet: #7c3aed;
  --shadow: 0 18px 48px rgba(16, 32, 48, .16);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 8%, rgba(37, 99, 235, .14), transparent 32%),
    radial-gradient(circle at 88% 18%, rgba(219, 39, 119, .12), transparent 28%),
    linear-gradient(135deg, #f8fbfd 0%, var(--bg) 54%, #dce9ef 100%);
}

button,
input {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid rgba(55, 75, 94, .18);
  border-radius: 10px;
  padding: 0 12px;
  background: rgba(255, 255, 255, .82);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease, border-color .16s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(16, 32, 48, .12);
}

button.is-active,
.primary-action {
  border-color: #112235;
  background: #112235;
  color: #fff;
}

#compactButton[aria-pressed="true"] {
  border-color: #112235;
  background: #112235;
  color: #fff;
}

.primary-action {
  background: linear-gradient(135deg, #112235, #24516e);
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  min-height: 100vh;
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 58px;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 52px);
  line-height: .95;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  margin: 0 0 12px;
  font-size: 15px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 8px;
}

.search-box {
  display: grid;
  gap: 5px;
  min-width: min(280px, 100%);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.search-box input {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(55, 75, 94, .18);
  border-radius: 10px;
  padding: 0 12px;
  outline: none;
  background: rgba(255, 255, 255, .84);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.mode-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px;
  border: 1px solid rgba(55, 75, 94, .14);
  border-radius: 16px;
  background: rgba(255, 255, 255, .55);
  backdrop-filter: blur(8px);
}

.mode-strip button {
  flex: 0 0 auto;
}

.workspace {
  display: grid;
  grid-template-columns: 230px minmax(520px, 1fr) 300px;
  gap: 10px;
  min-height: 0;
}

.rail {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}

.rail-card,
.detail-card,
.canvas-panel {
  border: 1px solid rgba(55, 75, 94, .16);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.rail-card,
.detail-card {
  padding: 14px;
}

.scenario-list,
.layer-list {
  display: grid;
  gap: 8px;
}

.scenario-button,
.layer-button {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 0;
  padding: 10px;
  text-align: left;
  border-radius: 12px;
}

.layer-button[aria-pressed="true"] {
  background: rgba(255, 255, 255, .82);
  color: var(--ink);
}

.layer-button[aria-pressed="false"] {
  border-color: rgba(245, 158, 11, .38);
  background: #fff7ed;
}

.scenario-button span,
.layer-button span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.canvas-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(55, 75, 94, .12);
}

.canvas-toolbar strong {
  display: block;
  font-size: 17px;
}

.canvas-toolbar span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.canvas-actions {
  display: flex;
  gap: 8px;
}

.atlas-canvas {
  position: relative;
  min-height: 0;
  background:
    linear-gradient(rgba(16, 32, 48, .04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 32, 48, .04) 1px, transparent 1px),
    radial-gradient(circle at 50% 15%, rgba(255, 255, 255, .9), rgba(240, 247, 251, .55));
  background-size: 28px 28px, 28px 28px, 100% 100%;
  overflow: hidden;
}

#atlasSvg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 640px;
  cursor: grab;
}

#atlasSvg.is-panning {
  cursor: grabbing;
}

.zoom-hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  padding: 8px 11px;
  border: 1px solid rgba(55, 75, 94, .14);
  border-radius: 999px;
  background: rgba(255, 255, 255, .8);
  color: #405064;
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.layer-band {
  opacity: .58;
  stroke: rgba(55, 75, 94, .18);
  stroke-width: 1;
}

.layer-title {
  fill: rgba(16, 32, 48, .45);
  font-size: 17px;
  font-weight: 950;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.edge {
  fill: none;
  stroke: rgba(71, 90, 106, .42);
  stroke-width: 3;
  marker-end: url(#arrowDefault);
  transition: opacity .18s ease, stroke .18s ease, stroke-width .18s ease;
}

.edge.is-active {
  stroke: var(--active);
  stroke-width: 5;
  stroke-dasharray: 16 12;
  marker-end: url(#arrowActive);
  animation: edgeFlow 1s linear infinite;
}

.edge.is-related {
  stroke: #2563eb;
  stroke-width: 4;
}

.edge.is-muted {
  opacity: .13;
}

.edge-label {
  fill: #1c2f42;
  font-size: 12px;
  font-weight: 900;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, .9);
  stroke-width: 5px;
  text-anchor: middle;
}

.edge-label.is-muted {
  opacity: .18;
}

.node {
  cursor: pointer;
  transition: opacity .18s ease, filter .18s ease;
}

.node-card {
  stroke: rgba(16, 32, 48, .28);
  stroke-width: 2;
  filter: url(#softShadow);
}

.node-title {
  fill: #102030;
  font-size: 18px;
  font-weight: 950;
  text-anchor: middle;
  pointer-events: none;
}

.node-status {
  fill: rgba(16, 32, 48, .66);
  font-size: 10px;
  font-weight: 950;
  letter-spacing: .08em;
  text-anchor: middle;
  text-transform: uppercase;
  pointer-events: none;
}

.node-type {
  fill: rgba(16, 32, 48, .55);
  font-size: 11px;
  font-weight: 850;
  text-anchor: middle;
  pointer-events: none;
}

.node:hover .node-card,
.node.is-selected .node-card,
.node.is-match .node-card {
  stroke: var(--active);
  stroke-width: 4;
}

.node.is-selected .node-card {
  animation: selectedPulse 1.5s ease-in-out infinite;
}

.node.is-muted {
  opacity: .16;
}

.node.is-hidden {
  display: none;
}

.packet {
  fill: #ffd166;
  stroke: #8a5200;
  stroke-width: 2;
  filter: drop-shadow(0 0 8px rgba(245, 158, 11, .9));
  pointer-events: none;
}

.timeline {
  padding: 10px 14px 14px;
  border-top: 1px solid rgba(55, 75, 94, .12);
}

.timeline-track {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.timeline-step {
  position: relative;
  min-width: 0;
  padding: 10px 10px 10px 34px;
  border: 1px solid rgba(55, 75, 94, .16);
  border-radius: 12px;
  background: rgba(255, 255, 255, .68);
  font-size: 12px;
  font-weight: 900;
}

.timeline-step::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 14px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #94a3b8;
}

.timeline-step.is-active {
  border-color: rgba(245, 158, 11, .7);
  background: #fff7ed;
}

.timeline-step.is-active::before {
  background: var(--active);
  box-shadow: 0 0 0 6px rgba(245, 158, 11, .18);
}

.timeline-step span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.detail-card {
  transition: transform .18s ease, box-shadow .18s ease;
}

.detail-card.is-updating {
  animation: cardFlash .42s ease;
}

.detail-domain {
  display: inline-flex;
  margin: 0 0 10px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #e8eef3;
  color: #405064;
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.detail-card h2 {
  margin: 0 0 8px;
  color: #132435;
  font-size: 24px;
  line-height: 1.05;
  letter-spacing: 0;
  text-transform: none;
}

.detail-card p {
  margin: 0 0 14px;
  color: #334455;
  font-size: 14px;
  line-height: 1.45;
}

.detail-grid {
  display: grid;
  gap: 9px;
}

.detail-grid div {
  padding: 10px;
  border-radius: 12px;
  background: rgba(232, 238, 243, .76);
}

.detail-grid strong,
.doc-links strong {
  display: block;
  margin-bottom: 5px;
  color: #20354a;
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.detail-grid span {
  color: #334455;
  font-size: 13px;
  line-height: 1.35;
}

.doc-links {
  margin-top: 14px;
}

.doc-links a {
  display: block;
  margin-top: 7px;
  color: #0f5c8c;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.doc-links a:hover {
  text-decoration: underline;
}

.relation-highlight {
  border-left: 4px solid var(--active);
  padding-left: 10px;
}

#arrowDefault path {
  fill: rgba(71, 90, 106, .72);
}

#arrowActive path {
  fill: var(--active);
}

@keyframes edgeFlow {
  to {
    stroke-dashoffset: -28;
  }
}

@keyframes selectedPulse {
  0%, 100% {
    filter: url(#softShadow);
  }
  50% {
    filter: drop-shadow(0 0 18px rgba(245, 158, 11, .62));
  }
}

@keyframes cardFlash {
  0%, 100% {
    transform: translateY(0);
  }
  45% {
    transform: translateY(-3px);
    box-shadow: 0 22px 52px rgba(245, 158, 11, .24);
  }
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-rail {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .rail {
    grid-template-columns: 1fr;
  }

  .timeline-track {
    grid-template-columns: 1fr;
  }

  #atlasSvg {
    min-height: 520px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
