:root {
  color-scheme: dark;
  --bg: #090a0f;
  --surface: rgba(18, 19, 27, 0.86);
  --surface-strong: rgba(22, 24, 33, 0.96);
  --surface-hover: rgba(42, 46, 62, 0.72);
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #edf2f7;
  --muted: #9aa3af;
  --faint: #67717f;
  --accent: #6d78ff;
  --accent-soft: rgba(109, 120, 255, 0.16);
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --panel-width: min(430px, calc(100vw - 32px));
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 24% 20%, rgba(45, 212, 191, 0.08), transparent 30%),
    radial-gradient(circle at 70% 70%, rgba(245, 158, 11, 0.07), transparent 28%),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell,
.graph-stage {
  height: 100%;
  width: 100%;
}

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 12, 18, 0.96);
  padding: 0 18px;
}

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

.brand h1 {
  margin: 0;
  max-width: min(58vw, 760px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0;
}

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

.topnav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-item,
.tool-button,
.small-button,
.icon-button,
.chip {
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(18, 19, 27, 0.7);
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav-item {
  min-height: 34px;
  border-radius: 7px;
  padding: 0 12px;
  font-size: 13px;
}

.nav-item:hover,
.tool-button:hover,
.small-button:hover,
.icon-button:hover,
.chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-hover);
}

.nav-item.is-active,
.tool-button.is-active,
.chip.is-active {
  border-color: rgba(109, 120, 255, 0.42);
  background: var(--accent-soft);
  color: #b9c1ff;
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  font-size: 20px;
}

.graph-stage {
  position: relative;
  padding-top: 64px;
}

.graph-canvas {
  position: absolute;
  inset: 64px 0 0;
  width: 100%;
  height: calc(100% - 64px);
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    #0a0b10;
  background-size: 44px 44px;
  touch-action: none;
  cursor: grab;
}

.graph-canvas.is-panning {
  cursor: grabbing;
}

.toolbar {
  position: fixed;
  right: 18px;
  top: 80px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(14, 15, 22, 0.96);
  padding: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  z-index: 1;
  color: var(--muted);
  font-size: 18px;
}

.search-box input {
  width: min(32vw, 330px);
  min-width: 190px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: rgba(9, 10, 15, 0.78);
  color: var(--text);
  padding: 0 68px 0 34px;
}

.search-box input:focus {
  border-color: rgba(109, 120, 255, 0.58);
  box-shadow: 0 0 0 3px rgba(109, 120, 255, 0.16);
}

.search-box .small-button {
  position: absolute;
  right: 5px;
  height: 28px;
}

.tool-button,
.small-button {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 600;
}

.small-button.primary {
  border-color: rgba(109, 120, 255, 0.48);
  background: var(--accent);
  color: white;
}

.detail-panel,
.filter-popover,
.sheet-popover,
.stats-strip {
  border: 1px solid var(--border);
  background: var(--surface-strong);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
}

.detail-panel {
  position: fixed;
  top: 80px;
  bottom: 18px;
  left: 18px;
  z-index: 45;
  display: flex;
  width: var(--panel-width);
  transform: translateX(calc(-1 * var(--panel-width) - 28px));
  flex-direction: column;
  overflow: hidden;
  border-radius: 12px;
  transition: transform 0.22s ease;
}

.detail-panel.is-open {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
}

.panel-header h2 {
  margin: 0;
  font-size: 15px;
}

.detail-content {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.empty-detail {
  display: grid;
  min-height: 280px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.node-title-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.node-badge {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  place-items: center;
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  font-size: 14px;
  font-weight: 700;
}

.node-title-row h3 {
  margin: 0;
  line-height: 1.35;
  font-size: 18px;
}

.node-type {
  display: inline-flex;
  margin-top: 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  padding: 3px 8px;
  font-size: 11px;
}

.detail-section {
  margin-top: 18px;
}

.detail-section h4 {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.detail-section p {
  margin: 0;
  color: #d8dee8;
  font-size: 13px;
  line-height: 1.72;
}

.property-list,
.relation-list {
  display: grid;
  gap: 8px;
}

.property-row,
.relation-button {
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  padding: 9px 10px;
}

.property-row {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 10px;
  font-size: 12px;
}

.property-row span:first-child {
  color: var(--muted);
}

.property-row span:last-child {
  overflow-wrap: anywhere;
}

.relation-button {
  width: 100%;
  color: var(--text);
  text-align: left;
}

.relation-button strong {
  color: #9fc4ff;
  font-weight: 650;
}

.relation-button span {
  color: var(--muted);
  font-size: 11px;
}

.filter-popover,
.sheet-popover {
  position: fixed;
  top: 133px;
  right: 18px;
  z-index: 60;
  display: none;
  width: min(390px, calc(100vw - 36px));
  max-height: min(68vh, 680px);
  overflow: auto;
  border-radius: 12px;
  padding: 14px;
}

.sheet-popover {
  width: min(430px, calc(100vw - 36px));
}

.filter-popover.is-open,
.sheet-popover.is-open {
  display: block;
}

.filter-section + .filter-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.section-title {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.sheet-help {
  margin: -3px 0 10px;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.5;
}

.sheet-list {
  display: grid;
  gap: 8px;
}

.sheet-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(18, 19, 27, 0.72);
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
}

.sheet-option.is-active {
  border-color: rgba(109, 120, 255, 0.48);
  background: var(--accent-soft);
}

.sheet-checkbox {
  display: grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: transparent;
  font-size: 12px;
  font-weight: 800;
}

.sheet-option.is-active .sheet-checkbox {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.sheet-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 650;
}

.sheet-count {
  color: var(--muted);
  font-size: 11px;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  border-radius: 8px;
  padding: 0 9px;
  font-size: 12px;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.stats-strip {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 40px;
  border-radius: 10px;
  padding: 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.detail-panel.is-open ~ .stats-strip {
  left: calc(var(--panel-width) + 34px);
}

.stat-value {
  color: var(--text);
  font-weight: 700;
}

@media (max-width: 820px) {
  .topbar {
    height: 58px;
    padding: 0 12px;
  }

  .brand h1 {
    max-width: 54vw;
    font-size: 14px;
  }

  .brand p,
  .topnav .nav-item:first-child {
    display: none;
  }

  .toolbar {
    top: 70px;
    left: 10px;
    right: 10px;
    flex-wrap: wrap;
  }

  .search-box {
    flex: 1 1 100%;
  }

  .search-box input {
    width: 100%;
  }

  .graph-canvas {
    inset: 58px 0 0;
    height: calc(100% - 58px);
  }

  .detail-panel {
    top: 126px;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    transform: translateY(calc(100% + 20px));
  }

  .detail-panel.is-open {
    transform: translateY(0);
  }

  .filter-popover,
  .sheet-popover {
    top: 154px;
    right: 10px;
    left: 10px;
    width: auto;
  }

  .stats-strip {
    left: 10px;
    right: 10px;
    justify-content: space-between;
    overflow: auto;
  }
}
