:root {
  color-scheme: light dark;
  --bg: light-dark(#f3f5f8, #0d1117);
  --surface: light-dark(#ffffff, #151b23);
  --surface-2: light-dark(#eef2f7, #1d2632);
  --surface-3: light-dark(#e4eaf2, #263140);
  --text: light-dark(#172033, #e8edf4);
  --muted: light-dark(#61708a, #9caabd);
  --border: light-dark(#d5dce6, #313d4d);
  --accent: light-dark(#2457d6, #78a6ff);
  --accent-soft: light-dark(#e4ecff, #1c3260);
  --service: light-dark(#2e63d6, #6e9eff);
  --data: light-dark(#8a48c7, #bd82ef);
  --infra: light-dark(#078476, #42cabb);
  --product: light-dark(#be6b11, #f3aa54);
  --risk: light-dark(#c13d4b, #ff7d89);
  --confirmed: light-dark(#087f5b, #56d6a4);
  --stated: light-dark(#9a6700, #f0b85d);
  --unknown: light-dark(#6b7280, #a8b1bf);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1580px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(28px, 4vw, 44px); letter-spacing: -0.04em; }
h2 { letter-spacing: -0.02em; }

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

.top-actions { display: flex; align-items: end; gap: 10px; }
.search-box { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.search-box input {
  width: min(330px, 42vw);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 11px;
}

.secondary-button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 9px 12px;
  cursor: pointer;
}
.secondary-button:hover { background: var(--surface-3); }
.full-width { width: 100%; }
.primary-button {
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: light-dark(#ffffff, #081323);
  padding: 10px 12px;
  cursor: pointer;
  margin-top: 18px;
  margin-bottom: 8px;
  font-weight: 700;
}

.view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-bottom: 9px;
}
.view-tabs button {
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: 8px 13px;
  cursor: pointer;
}
.view-tabs button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 16px;
  align-items: start;
}

.map-panel, .inspector {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 28px light-dark(rgba(28, 42, 67, 0.08), rgba(0, 0, 0, 0.22));
}

.map-panel { overflow: hidden; }
.map-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px 13px;
  border-bottom: 1px solid var(--border);
}
.map-heading h2 { margin-bottom: 0; font-size: 21px; }

.legend { display: flex; flex-wrap: wrap; justify-content: end; gap: 8px 12px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 9px; height: 9px; border-radius: 3px; background: var(--service); }
.dot.data { background: var(--data); }
.dot.infra { background: var(--infra); }
.dot.product { background: var(--product); }
.dot.risk { background: var(--risk); }

.map-viewport {
  position: relative;
  min-height: 590px;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--border) 36%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--border) 36%, transparent) 1px, transparent 1px);
  background-size: 28px 28px;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.map-viewport.dragging { cursor: grabbing; }
#map { display: block; width: 100%; height: 590px; user-select: none; }

.map-help {
  position: absolute;
  left: 12px;
  bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  color: var(--muted);
  padding: 6px 8px;
  font-size: 11px;
  pointer-events: none;
}
.zoom-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: 38px 64px 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  overflow: hidden;
  box-shadow: 0 4px 16px light-dark(rgba(28, 42, 67, 0.1), rgba(0, 0, 0, 0.25));
  z-index: 3;
}
.zoom-controls button {
  min-height: 36px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}
.zoom-controls button:last-child { border-right: 0; }
.zoom-controls button:hover { background: var(--surface-2); }
.zoom-controls button:disabled { color: var(--muted); cursor: default; }
.empty-search {
  position: absolute;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 12px 16px;
  color: var(--muted);
}

.cluster-rect { fill: color-mix(in srgb, var(--surface-2) 60%, transparent); stroke: var(--border); stroke-width: 1; }
.cluster-title { fill: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.edge { stroke: var(--border); stroke-width: 2; fill: none; marker-end: url(#arrow); }
.edge-label { fill: var(--muted); font-size: 11px; text-anchor: middle; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.edge, .edge-label { transition: opacity 140ms ease, stroke-width 140ms ease, stroke 140ms ease, fill 140ms ease; }
.edge.related { stroke: var(--accent); stroke-width: 5; opacity: 1; }
.edge-label.related { fill: var(--accent); font-weight: 700; opacity: 1; }
.edge.selection-dimmed, .edge-label.selection-dimmed { opacity: 0.1; }

.node { cursor: pointer; outline: none; }
.node rect { fill: var(--surface); stroke-width: 2; filter: url(#node-shadow); transition: opacity 120ms ease, stroke-width 120ms ease; }
.node.service rect { stroke: var(--service); }
.node.data rect { stroke: var(--data); }
.node.infra rect { stroke: var(--infra); }
.node.product rect { stroke: var(--product); }
.node.risk rect { stroke: var(--risk); }
.node .node-label { fill: var(--text); font-size: 14px; font-weight: 700; }
.node .node-subtitle { fill: var(--muted); font-size: 11px; }
.node .status-dot.confirmed { fill: var(--confirmed); }
.node .status-dot.stated { fill: var(--stated); }
.node .status-dot.unknown { fill: var(--unknown); }
.node.selected rect { stroke-width: 5; }
.node.related rect { stroke-width: 4; }
.node.related { opacity: 1; }
.node.selection-dimmed { opacity: 0.2; }
.node.dimmed { opacity: 0.13; }
.node.match rect { stroke-width: 5; }
.edge.dimmed, .edge-label.dimmed { opacity: 0.08; }

.inspector {
  position: sticky;
  top: 14px;
  padding: 17px;
  min-height: 590px;
}
.overview-card h2, .node-card h2 { margin: 7px 0 8px; font-size: 23px; }
.overview-card p, .node-summary { color: var(--muted); line-height: 1.48; }
.overview-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin: 16px 0; }
.metric { border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); padding: 10px; }
.metric strong { display: block; font-size: 22px; }
.metric span { color: var(--muted); font-size: 12px; }
.overview-card ul, .inspector-section ul { padding-left: 19px; line-height: 1.45; }

.node-card-head { display: flex; justify-content: space-between; gap: 8px; }
.type-pill, .confidence-pill { display: inline-block; border-radius: 999px; padding: 5px 8px; font-size: 11px; font-weight: 700; }
.type-pill { background: var(--surface-2); }
.confidence-pill.confirmed { background: color-mix(in srgb, var(--confirmed) 18%, transparent); color: var(--confirmed); }
.confidence-pill.stated { background: color-mix(in srgb, var(--stated) 18%, transparent); color: var(--stated); }
.confidence-pill.unknown { background: color-mix(in srgb, var(--unknown) 18%, transparent); color: var(--unknown); }

.facts { margin: 15px 0; }
.facts div { display: grid; grid-template-columns: 105px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.inspector-section { margin-top: 17px; }
.inspector-section h3 { margin-bottom: 7px; font-size: 14px; }
.source-note { color: var(--muted); line-height: 1.45; }

.deep-card-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: light-dark(rgba(13, 20, 34, 0.54), rgba(0, 0, 0, 0.72));
  backdrop-filter: blur(6px);
}
.deep-card-backdrop[hidden] { display: none; }
.deep-card {
  width: min(1040px, 100%);
  max-height: min(880px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px light-dark(rgba(21, 33, 56, 0.28), rgba(0, 0, 0, 0.6));
}
.deep-card-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(8px);
}
.deep-card-header h2 { margin-bottom: 8px; font-size: clamp(25px, 4vw, 36px); }
.deep-card-lead { margin-bottom: 0; color: var(--muted); line-height: 1.5; }
.icon-button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 24px;
}
.deep-card-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 20px 24px 28px;
}
.deep-section {
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
  padding: 15px 16px;
}
.deep-section.wide { grid-column: 1 / -1; }
.deep-section h3 { margin-bottom: 9px; font-size: 16px; }
.deep-section p { margin-bottom: 0; color: var(--muted); line-height: 1.55; }
.deep-section ul { margin: 0; padding-left: 20px; line-height: 1.55; }
.deep-code {
  margin: 9px 0 0;
  border-radius: 9px;
  background: light-dark(#111827, #080c12);
  color: #dce8ff;
  padding: 11px 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.stack-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.stack-list li {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: 5px 8px;
}

footer { padding: 13px 2px 0; color: var(--muted); font-size: 12px; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .inspector { position: static; min-height: 0; }
}

@media (max-width: 680px) {
  .app-shell { padding: 12px; }
  .topbar, .map-heading { align-items: stretch; flex-direction: column; }
  .top-actions { align-items: stretch; flex-direction: column; }
  .search-box input { width: 100%; }
  .legend { justify-content: start; }
  .view-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
  .map-viewport, #map { min-height: 500px; height: 500px; }
  .deep-card-backdrop { padding: 8px; }
  .deep-card { max-height: calc(100vh - 16px); }
  .deep-card-header { padding: 17px; }
  .deep-card-content { grid-template-columns: 1fr; padding: 14px 17px 20px; }
  .deep-section.wide { grid-column: auto; }
}
