.kg-page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.kg-summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1rem;
}

.kg-stat-card,
.kg-stage-card,
.kg-detail-panel {
  background:
    linear-gradient(180deg, rgba(16, 24, 39, 0.96), rgba(8, 14, 26, 0.94)),
    var(--color-bg-secondary);
  border: 1px solid rgba(88, 211, 255, 0.12);
  border-radius: 1rem;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.28);
}

.kg-stat-card {
  padding: 1.25rem 1.35rem;
  min-height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kg-stat-label,
.kg-control-label,
.kg-detail-kicker,
.kg-detail-section-title {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: rgba(148, 163, 184, 0.9);
}

.kg-stat-value {
  font-size: clamp(1.5rem, 2vw, 2.2rem);
  line-height: 1;
  font-weight: 700;
  color: var(--color-text-primary);
}

.kg-stat-meta,
.kg-visible-caption,
.kg-detail-header p,
.kg-detail-text,
.kg-detail-empty p {
  color: var(--color-text-secondary);
  font-size: 0.92rem;
}

.kg-stage-card {
  padding: 1rem;
  position: relative;
  overflow: hidden;
}

.kg-stage-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 12% 12%, rgba(255, 126, 95, 0.14), transparent 34%),
    radial-gradient(circle at 86% 72%, rgba(27, 153, 255, 0.14), transparent 32%);
  pointer-events: none;
}

.kg-toolbar,
.kg-filter-row,
.kg-workspace {
  position: relative;
  z-index: 1;
}

.kg-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.kg-toolbar-main,
.kg-toolbar-actions,
.kg-filter-pills,
.kg-legend,
.kg-related-list,
.kg-detail-tags,
.kg-detail-mini-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.kg-toolbar-main {
  flex: 1;
}

.kg-toolbar-actions {
  justify-content: flex-end;
}

.kg-control {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 180px;
}

.kg-control-search {
  flex: 1;
  min-width: 280px;
}

.kg-select,
.kg-search-input {
  background: rgba(10, 15, 26, 0.78);
  border: 1px solid rgba(88, 211, 255, 0.14);
  color: var(--color-text-primary);
  border-radius: 0.85rem;
  padding: 0.85rem 1rem;
  font: inherit;
}

.kg-search-input::placeholder {
  color: var(--color-text-muted);
}

.kg-filter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.kg-type-pill,
.kg-related-chip,
.kg-detail-tag {
  border: 1px solid rgba(88, 211, 255, 0.12);
  border-radius: 999px;
  background: rgba(9, 15, 25, 0.72);
  color: var(--color-text-primary);
}

.kg-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  transition: transform var(--transition-base), border-color var(--transition-base), background var(--transition-base);
}

.kg-type-pill:hover,
.kg-related-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(88, 211, 255, 0.32);
}

.kg-type-pill.is-active {
  border-color: rgba(88, 211, 255, 0.44);
  background: rgba(16, 24, 39, 0.92);
}

.kg-type-dot,
.kg-legend-dot,
.kg-mini-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--kg-type-color);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.06);
  flex: 0 0 auto;
}

.kg-type-count {
  color: var(--color-text-secondary);
  font-size: 0.8rem;
}

.kg-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.9fr) minmax(320px, 0.85fr);
  gap: 1rem;
}

.kg-canvas-shell {
  position: relative;
  min-height: 720px;
  border-radius: 1rem;
  overflow: hidden;
  border: 1px solid rgba(88, 211, 255, 0.12);
  background: #06111f;
}

.kg-svg {
  width: 100%;
  height: 100%;
  min-height: 720px;
  display: block;
  cursor: grab;
}

.kg-svg:active {
  cursor: grabbing;
}

.kg-canvas-backdrop {
  fill: #04101c;
}

.kg-canvas-grid {
  opacity: 1;
}

.kg-canvas-glow {
  opacity: 1;
}

.kg-canvas-actions {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 2;
  display: flex;
  gap: 0.5rem;
}

.kg-canvas-btn,
.kg-canvas-fit {
  border: 1px solid rgba(88, 211, 255, 0.18);
  background: rgba(6, 17, 31, 0.82);
  color: var(--color-text-primary);
  border-radius: 0.85rem;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0 0.85rem;
  font: inherit;
  cursor: pointer;
}

/* ── Overlay states (loading / empty) ── */
.kg-overlay-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--color-text-secondary);
  background: linear-gradient(180deg, rgba(4, 16, 28, 0.1), rgba(4, 16, 28, 0.78));
  z-index: 3;
  transition: opacity 0.25s ease;
  pointer-events: auto;
}

/* CRITICAL: re-apply display:none when hidden attribute is set.
   Without this, display:grid above overrides the hidden attribute. */
.kg-overlay-state[hidden] {
  display: none !important;
}

/* ── Floating tooltip ── */
.kg-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  padding: 0.55rem 0.8rem;
  background: rgba(6, 17, 31, 0.94);
  border: 1px solid rgba(88, 211, 255, 0.22);
  border-radius: 0.65rem;
  color: var(--color-text-primary);
  font-size: 0.82rem;
  line-height: 1.45;
  max-width: 300px;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.kg-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.kg-tooltip-name {
  font-weight: 600;
  color: var(--color-text-primary);
}

.kg-tooltip-type {
  color: var(--color-text-secondary);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.1rem;
}

.kg-tooltip-stat {
  color: var(--color-text-secondary);
  font-size: 0.78rem;
  margin-top: 0.1rem;
}

/* ── Legend ── */
.kg-legend {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  z-index: 2;
  padding: 0.75rem 0.9rem;
  border-radius: 0.95rem;
  background: rgba(6, 17, 31, 0.82);
  border: 1px solid rgba(88, 211, 255, 0.12);
}

.kg-legend-item,
.kg-mini-stat {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--color-text-secondary);
  font-size: 0.82rem;
}

/* ── Edges ── */
.kg-edge {
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.55;
  pointer-events: stroke;
  transition: opacity 0.2s ease, stroke 0.2s ease, stroke-width 0.2s ease;
}

.kg-edge.edge-joins {
  stroke: rgba(244, 178, 102, 0.62);
}

.kg-edge.edge-has_measure {
  stroke: rgba(88, 211, 255, 0.22);
}

.kg-edge.edge-filters_via {
  stroke: rgba(86, 204, 120, 0.62);
  stroke-dasharray: 7 7;
}

.kg-edge.edge-means {
  stroke: rgba(255, 158, 181, 0.74);
}

.kg-edge.edge-computes {
  stroke: rgba(88, 211, 255, 0.62);
  stroke-dasharray: 8 6;
}

.kg-edge.is-highlight {
  opacity: 0.96;
  stroke-width: 3;
}

.kg-edge.is-muted {
  opacity: 0.08;
}

.kg-edge.has-match {
  opacity: 0.78;
}

.kg-edge.is-edge-hovered {
  opacity: 1;
  stroke-width: 3.5;
}

/* ── Nodes ── */
.kg-node {
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.kg-node-hitarea {
  fill: transparent;
  stroke: none;
  pointer-events: all;
}

.kg-node-ring {
  fill: rgba(255, 255, 255, 0.02);
  stroke: rgba(255, 255, 255, 0.14);
  stroke-width: 1;
  transition: stroke 0.2s ease, stroke-width 0.2s ease, fill 0.2s ease;
}

.kg-node-core {
  stroke: rgba(255, 255, 255, 0.76);
  stroke-width: 2.2;
  filter: drop-shadow(0 0 16px rgba(255, 255, 255, 0.06));
  transition: filter 0.2s ease, stroke-width 0.2s ease;
}

/* ── Node labels — per-kind sizing ── */
.kg-node-label {
  fill: rgba(240, 244, 248, 0.94);
  font-weight: 700;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.node-table .kg-node-label { font-size: 14px; }
.node-date .kg-node-label { font-size: 13px; }
.node-dimension .kg-node-label { font-size: 13px; }
.node-concept .kg-node-label { font-size: 12px; }
.node-measure .kg-node-label { font-size: 11px; }

/* Hidden labels become visible on hover */
.kg-node-label.is-hidden-label {
  opacity: 0;
}

.kg-node.is-hovered .kg-node-label.is-hidden-label {
  opacity: 1;
}

/* ── Node states ── */
.kg-node.is-selected .kg-node-ring {
  stroke: rgba(255, 255, 255, 0.74);
  stroke-width: 2;
}

.kg-node.is-selected .kg-node-core {
  stroke-width: 3;
  filter: drop-shadow(0 0 18px rgba(255, 255, 255, 0.18));
}

.kg-node.is-hovered .kg-node-core {
  filter: drop-shadow(0 0 10px var(--kg-node-color, #58d3ff)) drop-shadow(0 0 22px var(--kg-node-color, #58d3ff));
  stroke-width: 3;
}

.kg-node.is-hovered .kg-node-ring {
  stroke: rgba(255, 255, 255, 0.38);
  stroke-width: 2;
}

.kg-node.is-neighbor .kg-node-ring,
.kg-node.is-match .kg-node-ring {
  stroke: rgba(88, 211, 255, 0.65);
}

.kg-node.is-muted {
  opacity: 0.24;
}

/* ── Detail panel ── */
.kg-detail-panel {
  padding: 1.15rem;
  min-height: 720px;
  position: relative;
  overflow: auto;
}

.kg-detail-empty,
.kg-detail-header,
.kg-detail-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.kg-detail-header h3,
.kg-detail-empty h3 {
  font-size: 1.5rem;
  line-height: 1.15;
  color: var(--color-text-primary);
}

.kg-detail-tags {
  margin: 1rem 0 1.2rem;
}

.kg-detail-tag {
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
}

.kg-detail-section + .kg-detail-section {
  margin-top: 1.1rem;
}

.kg-property-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.kg-property-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
  font-size: 0.92rem;
}

.kg-property-row dt {
  color: var(--color-text-secondary);
}

.kg-property-row dd {
  color: var(--color-text-primary);
}

.kg-related-chip {
  padding: 0.48rem 0.8rem;
  font: inherit;
  cursor: pointer;
}

.kg-related-chip.is-static {
  cursor: default;
}

.kg-empty-inline {
  color: var(--color-text-muted);
}

/* ── Responsive ── */
@media (max-width: 1260px) {
  .kg-summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .kg-workspace {
    grid-template-columns: 1fr;
  }

  .kg-detail-panel {
    min-height: auto;
  }
}

@media (max-width: 860px) {
  .kg-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kg-toolbar,
  .kg-filter-row {
    flex-direction: column;
    align-items: stretch;
  }

  .kg-toolbar-main,
  .kg-toolbar-actions {
    width: 100%;
  }

  .kg-toolbar-actions {
    justify-content: stretch;
  }

  .kg-toolbar-actions .btn {
    flex: 1 1 auto;
  }

  .kg-canvas-shell,
  .kg-svg,
  .kg-detail-panel {
    min-height: 560px;
  }
}

@media (max-width: 560px) {
  .kg-summary-grid {
    grid-template-columns: 1fr;
  }

  .kg-property-row {
    grid-template-columns: 1fr;
  }
}
