:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --subtle: #e2e8f0;
  --line: #cbd5e1;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --risk: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto 18px;
  max-width: 1480px;
}

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

.mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #eff6ff;
  color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.meta {
  color: var(--muted);
  display: flex;
  gap: 14px;
  font-size: 13px;
  white-space: nowrap;
}

.workspace {
  max-width: 1480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 16px;
}

.map-panel,
.inspector,
.readout {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.map-panel {
  overflow: hidden;
}

.toolbar {
  min-height: 74px;
  display: grid;
  grid-template-columns: 190px minmax(280px, 1fr) 150px 110px;
  gap: 12px;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--subtle);
}

.control,
.search {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
}

.search svg,
.control svg {
  flex: 0 0 auto;
}

.control {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
}

select.control {
  appearance: none;
}

button.control {
  cursor: pointer;
  justify-content: center;
}

.stage {
  position: relative;
  overflow: auto;
  background:
    radial-gradient(circle at 50% 34%, rgba(37, 99, 235, 0.08), transparent 27%),
    linear-gradient(#fff, #f8fafc);
}

#graph {
  width: 100%;
  min-width: 1050px;
  min-height: 650px;
  display: block;
}

.territory {
  fill-opacity: 0.45;
  stroke-width: 1.4;
  stroke-opacity: 0.55;
}

.territory-label {
  font-size: 18px;
  font-weight: 780;
  fill: #334155;
}

.edge {
  fill: none;
  stroke: #94a3b8;
  stroke-width: 1.6;
  opacity: 0.28;
}

.edge.primary {
  opacity: 0.5;
  stroke-width: 2.2;
}

.edge.connected {
  opacity: 0.95;
  stroke: var(--accent);
  stroke-width: 3;
}

.edge.risk.connected {
  stroke: var(--risk);
}

.node {
  cursor: pointer;
}

.node-card {
  fill: #fff;
  stroke-width: 1.5;
  filter: drop-shadow(0 10px 18px rgba(15, 23, 42, 0.12));
}

.node-label {
  fill: #111827;
  font-weight: 760;
  font-size: 15px;
  text-anchor: middle;
  dominant-baseline: middle;
}

.node-sub {
  fill: #64748b;
  font-size: 11px;
  text-anchor: middle;
}

.node .dot {
  fill: var(--accent);
}

.node.selected .node-card {
  stroke-width: 3;
}

.selection-ring {
  opacity: 0;
  fill: none;
  stroke: rgba(37, 99, 235, 0.24);
  stroke-width: 18;
}

.node.selected .selection-ring {
  opacity: 1;
}

.node.faded {
  opacity: 0.22;
}

.center .node-card {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 4;
}

.center .node-label {
  font-size: 24px;
}

.center .node-sub {
  font-size: 13px;
}

.inspector {
  padding: 18px;
  align-self: stretch;
  min-height: 680px;
}

.inspector-kicker {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.inspector h2 {
  margin: 10px 0 6px;
  font-size: 24px;
}

.inspector p {
  color: #475569;
  line-height: 1.48;
}

.chip-row,
.connected-list,
.evidence-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 18px;
  padding: 0;
  list-style: none;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #334155;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
}

.inspector h3 {
  margin: 18px 0 10px;
  font-size: 14px;
}

.connected-list li,
.evidence-list li {
  border: 1px solid var(--subtle);
  border-radius: 8px;
  padding: 10px;
  color: #475569;
  line-height: 1.35;
  font-size: 13px;
}

.readout {
  grid-column: 1 / 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
}

.readout-card {
  padding: 16px;
  border-right: 1px solid var(--subtle);
}

.readout-card:last-child {
  border-right: 0;
}

.readout-card h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.readout-card p,
.readout-card li {
  color: #475569;
  font-size: 13px;
  line-height: 1.45;
}

.readout-card ul {
  margin: 0;
  padding-left: 18px;
}

.empty {
  color: var(--muted);
}

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

  .inspector {
    min-height: auto;
  }

  .readout {
    grid-column: 1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .meta {
    white-space: normal;
    flex-wrap: wrap;
  }

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

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

  .readout-card {
    border-right: 0;
    border-bottom: 1px solid var(--subtle);
  }
}
