:root {
  --ink: #1f2933;
  --muted: #65717d;
  --line: #d7dde3;
  --line-strong: #bcc6cf;
  --surface: #ffffff;
  --surface-soft: #f5f7f8;
  --canvas: #eef1f3;
  --accent: #315fb5;
  --accent-wash: #e9effa;
  --selected: #a5630f;
  --selected-wash: #f7e8bf;
  --upstream: #7654a6;
  --upstream-wash: #eee8f8;
  --downstream: #b97819;
  --downstream-wash: #fff0d6;
  --shadow: 0 10px 28px rgba(25, 35, 45, 0.08);
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(49, 95, 181, 0.28);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 318px) minmax(0, 1fr);
  width: 100%;
  height: 100%;
  background: var(--surface);
  transition: grid-template-columns 160ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 54px minmax(0, 1fr);
}

.sidebar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 5px 0 18px rgba(25, 35, 45, 0.04);
  overflow: hidden;
}

.brand {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 34px;
  gap: 10px;
  align-items: center;
  min-height: 72px;
  padding: 12px 12px 12px 14px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid #263e58;
  border-radius: 6px;
  color: #ffffff;
  background: #263e58;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 800;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  line-height: 1.15;
  font-weight: 700;
}

.brand-copy p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: #394857;
  background: var(--surface);
  font-weight: 700;
}

.icon-button:hover {
  border-color: #8e9ba7;
  background: var(--surface-soft);
}

.sidebar-toggle {
  justify-self: end;
}

.app-shell.sidebar-collapsed .brand {
  grid-template-columns: 1fr;
  padding: 10px;
}

.app-shell.sidebar-collapsed .brand-mark,
.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .index-controls,
.app-shell.sidebar-collapsed .item-list {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  justify-self: center;
}

.index-controls {
  padding: 13px 14px 11px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}

.search-field {
  display: block;
}

.search-field input {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  font-size: 13px;
}

.search-field input::placeholder {
  color: #89949e;
}

.filter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.filter-grid label {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.filter-grid label > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.filter-grid select {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 24px 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: #374553;
  background: var(--surface);
  font-size: 12px;
  text-overflow: ellipsis;
}

.index-meta {
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.item-list {
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

.list-section-label {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 14px 7px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid #e9edf0;
  color: #5e6b77;
  background: rgba(247, 249, 250, 0.96);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.list-section-label:first-child {
  border-top: 0;
}

.item-row {
  --section-color: var(--accent);
  position: relative;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  width: 100%;
  min-height: 58px;
  padding: 9px 12px 9px 14px;
  border: 0;
  border-bottom: 1px solid #edf0f2;
  color: inherit;
  background: var(--surface);
  text-align: left;
}

.item-row::before {
  content: "";
  position: absolute;
  inset: 8px auto 8px 0;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--section-color);
  opacity: 0.72;
}

.item-row:hover {
  background: #f7f9fa;
}

.item-row.active {
  background: #eef3f9;
  box-shadow: inset 3px 0 0 var(--section-color);
}

.item-row-label {
  align-self: start;
  color: #31404e;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.item-row-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.item-row-title {
  color: #273542;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.item-row-decl {
  color: #74808b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-list {
  padding: 24px 16px;
  color: var(--muted);
  font-size: 13px;
}

.main-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

.toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 10px 16px 10px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.toolbar-title {
  min-width: 0;
}

.current-label {
  color: #253544;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
}

.current-title {
  max-width: 760px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.toolbar-actions,
.zoom-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 0 0 auto;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface);
}

.segmented button {
  min-height: 32px;
  padding: 0 11px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  color: #52606d;
  background: transparent;
  font-size: 11px;
  font-weight: 700;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button:hover {
  background: var(--surface-soft);
}

.segmented button.active {
  color: #21457c;
  background: var(--accent-wash);
}

.fit-button {
  width: 42px;
  font-size: 10px;
}

.mobile-view-switch {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(320px, 390px);
  min-width: 0;
  min-height: 0;
  transition: grid-template-columns 160ms ease;
}

.app-shell.detail-collapsed .workspace {
  grid-template-columns: minmax(360px, 1fr) 42px;
}

.graph-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

.graph-toolbar {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 6px 12px;
  border-bottom: 1px solid #d9dfe4;
  background: #f7f8f9;
}

.graph-stats,
.legend {
  display: flex;
  gap: 7px;
  align-items: center;
  color: #65717d;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.stat-pill {
  padding: 3px 7px;
  border: 1px solid #d4dbe1;
  border-radius: 4px;
  background: #ffffff;
}

.legend {
  flex-wrap: wrap;
  justify-content: flex-end;
  max-height: 28px;
  overflow: hidden;
}

.legend span {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--section-color, var(--accent));
}

.graph-viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: #f1f3f4;
  background-image: linear-gradient(#dfe4e8 1px, transparent 1px),
    linear-gradient(90deg, #dfe4e8 1px, transparent 1px);
  background-size: 28px 28px;
  touch-action: none;
  cursor: grab;
}

.graph-viewport.dragging {
  cursor: grabbing;
}

.dependency-graph {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.graph-edge {
  fill: none;
  stroke: #aab5bf;
  stroke-width: 1.3;
  marker-end: url(#arrowDefault);
  transition: opacity 120ms ease, stroke 120ms ease, stroke-width 120ms ease;
}

.graph-edge.dim {
  opacity: 0.22;
}

.graph-edge.active {
  stroke: #315fc0;
  stroke-width: 2.2;
  marker-end: url(#arrowActive);
}

.graph-node {
  --section-color: var(--accent);
  --section-wash: var(--accent-wash);
  cursor: pointer;
  outline: none;
  transition: opacity 120ms ease;
}

.graph-node.dim {
  opacity: 0.34;
}

.graph-node .node-box {
  fill: var(--section-wash);
  stroke: var(--section-color);
  stroke-width: 1.5;
  transition: fill 120ms ease, stroke 120ms ease, stroke-width 120ms ease;
}

.graph-node:hover .node-box,
.graph-node:focus-visible .node-box {
  stroke-width: 2.3;
}

.graph-node.selected .node-box {
  fill: var(--selected-wash);
  stroke: var(--selected);
  stroke-width: 2.7;
}

.graph-node.upstream .node-box {
  fill: var(--upstream-wash);
  stroke: var(--upstream);
  stroke-width: 2.1;
}

.graph-node.downstream .node-box {
  fill: var(--downstream-wash);
  stroke: var(--downstream);
  stroke-width: 2.1;
}

.node-label {
  fill: #253544;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.graph-empty {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 12px;
}

.detail-panel {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.detail-rail {
  display: flex;
  justify-content: center;
  padding-top: 9px;
  border-right: 1px solid #e8ecef;
  background: #f7f8f9;
}

.detail-toggle {
  width: 28px;
  height: 28px;
}

.detail-scroll {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.app-shell.detail-collapsed .detail-scroll {
  display: none;
}

.detail-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--line);
}

.detail-kicker {
  display: flex;
  gap: 7px;
  align-items: center;
}

.detail-kind,
.detail-section-tag {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: #53616e;
  background: #f7f8f9;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-section-tag {
  --section-color: var(--accent);
  --section-wash: var(--accent-wash);
  border-color: var(--section-color);
  color: var(--section-color);
  background: var(--section-wash);
}

.detail-header h2 {
  margin: 13px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.detail-heading {
  margin: 7px 0 0;
  color: #5d6b77;
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.detail-source-link {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  margin-top: 13px;
  color: #245aa8;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.detail-source-link:hover {
  text-decoration: underline;
}

.lean-mark {
  padding: 2px 5px;
  border-radius: 3px;
  color: #ffffff;
  background: #263e58;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 8px;
}

.detail-section {
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
}

.detail-section h3 {
  margin: 0 0 10px;
  color: #4a5865;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.statement {
  color: #2d3b47;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  line-height: 1.58;
  overflow-wrap: anywhere;
}

.statement p {
  margin: 0 0 10px;
}

.statement pre {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
}

.statement code {
  padding: 1px 3px;
  border-radius: 3px;
  background: #eef1f3;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.relation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.relation-column h4 {
  margin: 0 0 7px;
  color: #596774;
  font-size: 10px;
}

.relation-list {
  display: grid;
  gap: 5px;
}

.relation-link {
  --section-color: var(--accent);
  display: flex;
  gap: 7px;
  align-items: center;
  width: 100%;
  min-height: 29px;
  padding: 4px 7px;
  border: 1px solid #dde2e6;
  border-radius: 4px;
  color: #354451;
  background: #fafbfc;
  text-align: left;
  font-size: 10px;
}

.relation-link:hover {
  border-color: #b8c2cb;
  background: #f3f5f6;
}

.relation-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--section-color);
}

.relation-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.relation-empty {
  color: #8a949d;
  font-size: 10px;
}

.lean-facts {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0;
  font-size: 10px;
}

.lean-facts dt {
  color: #74808a;
  font-weight: 700;
}

.lean-facts dd {
  min-width: 0;
  margin: 0;
  color: #34424f;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.fatal-error {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 20;
  width: min(520px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 18px;
  border: 1px solid #ae4c43;
  border-radius: 6px;
  color: #71372d;
  background: #fff7f5;
  box-shadow: var(--shadow);
  font-size: 13px;
  white-space: pre-wrap;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: minmax(320px, 1fr) minmax(290px, 340px);
  }

  .toolbar {
    align-items: flex-start;
  }

  .toolbar-actions {
    gap: 6px;
  }

  .legend {
    display: none;
  }
}

@media (max-width: 820px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(210px, 34vh) minmax(520px, 66vh);
    height: 100vh;
  }

  .app-shell.sidebar-collapsed {
    grid-template-rows: 52px minmax(520px, calc(100vh - 52px));
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    min-height: 58px;
    grid-template-columns: 36px minmax(0, 1fr) 34px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .index-controls {
    padding-top: 9px;
    padding-bottom: 8px;
  }

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

  .main-panel {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .toolbar {
    min-height: 66px;
    padding: 9px 10px 9px 12px;
  }

  .toolbar-actions .segmented {
    display: none;
  }

  .mobile-view-switch {
    display: flex;
    width: calc(100% - 20px);
    margin: 8px 10px 0;
  }

  .mobile-view-switch button {
    flex: 1;
  }

  .workspace,
  .app-shell.detail-collapsed .workspace {
    display: block;
    min-height: 0;
  }

  .graph-panel,
  .detail-panel {
    height: 100%;
  }

  .workspace[data-mobile-view="graph"] .detail-panel,
  .workspace[data-mobile-view="detail"] .graph-panel {
    display: none;
  }

  .detail-panel {
    grid-template-columns: 0 minmax(0, 1fr);
    border-left: 0;
  }

  .detail-rail {
    display: none;
  }

  .detail-scroll {
    display: block !important;
  }

  .graph-toolbar {
    min-height: 36px;
  }

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

@media (max-width: 480px) {
  .toolbar-title {
    max-width: calc(100% - 128px);
  }

  .current-label {
    font-size: 17px;
  }

  .current-title {
    max-height: 32px;
    overflow: hidden;
  }

  .zoom-controls {
    gap: 4px;
  }

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

  .item-row {
    grid-template-columns: 66px minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
