:root {
  color-scheme: dark;
  --bg: #06111f;
  --surface: rgba(11, 24, 42, 0.88);
  --surface-2: rgba(16, 36, 59, 0.95);
  --ink: #e9f7ff;
  --muted: #8da5b8;
  --line: rgba(112, 227, 255, 0.2);
  --accent: #16c7d1;
  --accent-strong: #67e8f9;
  --warn: #a96110;
  --danger: #b42318;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(22, 199, 209, 0.16), transparent 28%),
    radial-gradient(circle at 78% 5%, rgba(155, 81, 224, 0.12), transparent 26%),
    linear-gradient(135deg, #04101c 0%, #081726 46%, #06111f 100%);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: rgba(12, 27, 45, 0.92);
  color: var(--ink);
  border-radius: 7px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  border-color: rgba(103, 232, 249, 0.72);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.app-shell {
  padding: 18px;
  width: 100%;
  max-width: 100vw;
}

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

.topbar h1 {
  margin: 0 0 4px;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 120px);
  gap: 8px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.22);
}

.stat span {
  display: block;
  font-size: 20px;
  font-weight: 750;
}

.stat small {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(780px, 1fr) 380px;
  gap: 14px;
  min-height: 780px;
}

.graph-stage,
.side-panel,
.data-zone {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.graph-stage {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 21, 36, 0.82);
}

.toolbar label {
  display: grid;
  gap: 5px;
  min-width: 120px;
  flex: 1 1 140px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar .search-field {
  min-width: 220px;
  flex: 2 1 240px;
}

.toolbar input,
.toolbar select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: rgba(5, 15, 28, 0.92);
  color: var(--ink);
}

.toggle-group {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  height: 36px;
  background: rgba(5, 15, 28, 0.92);
}

.toggle-group .toggle {
  border: 0;
  border-radius: 0;
  height: 34px;
  min-width: 64px;
  color: var(--muted);
}

.toggle-group .toggle.active {
  background: rgba(22, 199, 209, 0.18);
  color: var(--accent-strong);
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 18px;
}

.graph-wrap {
  position: relative;
  min-height: 720px;
  background:
    radial-gradient(circle at center, rgba(22, 199, 209, 0.08), transparent 58%),
    linear-gradient(rgba(103, 232, 249, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(103, 232, 249, 0.08) 1px, transparent 1px),
    #05101d;
  background-size: 100% 100%, 28px 28px, 28px 28px, 100% 100%;
}

#graphCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.tooltip {
  position: absolute;
  z-index: 5;
  max-width: 260px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.96);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.45;
}

.tooltip strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: 210px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8, 18, 32, 0.9);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  font-size: 12px;
}

.legend strong {
  display: block;
  margin-bottom: 8px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--muted);
}

.line-sample {
  display: inline-block;
  width: 32px;
  height: 0;
  border-top: 3px solid #5f6f89;
}

.line-sample.dashed {
  border-top-style: dashed;
}

.region-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 8px;
  margin-top: 6px;
}

.region-pill {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 5px;
  color: var(--muted);
}

.dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 12px;
  overflow: auto;
}

.panel-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(8, 18, 32, 0.66);
}

.selected-card {
  min-height: 230px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
}

#selectionBadge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--surface-2);
}

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

.detail-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.detail-title h3 {
  margin: 0;
  font-size: 18px;
}

.node-kind {
  border-radius: 999px;
  padding: 2px 8px;
  background: rgba(22, 199, 209, 0.16);
  color: var(--accent-strong);
  font-size: 12px;
}

.kv {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 7px 10px;
  margin: 10px 0;
  font-size: 13px;
}

.kv span:nth-child(odd) {
  color: var(--muted);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: #dceef7;
  background: rgba(12, 29, 49, 0.88);
  font-size: 12px;
  white-space: nowrap;
}

.input-card textarea {
  width: 100%;
  resize: vertical;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
  background: rgba(5, 15, 28, 0.92);
  line-height: 1.5;
}

.input-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.ai-result {
  min-height: 26px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.ai-result strong {
  color: var(--ink);
}

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

.top-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
  cursor: pointer;
  background: rgba(12, 29, 49, 0.74);
}

.top-item:hover {
  border-color: rgba(103, 232, 249, 0.72);
}

.top-item strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.top-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.data-zone {
  margin-top: 14px;
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 21, 36, 0.82);
}

.tab {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  height: 42px;
  min-width: 130px;
  color: var(--muted);
}

.tab.active {
  background: rgba(8, 18, 32, 0.9);
  color: var(--accent-strong);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.table-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.table-tools span {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  max-height: 360px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0d2238;
  color: #dceef7;
  text-align: left;
  font-weight: 650;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  vertical-align: top;
}

td {
  color: #c8d8e5;
}

tr:hover td {
  background: rgba(22, 199, 209, 0.08);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.status-potential {
  background: rgba(242, 153, 74, 0.18);
  color: #ffd199;
}

.status-active {
  background: rgba(22, 199, 209, 0.18);
  color: var(--accent-strong);
}

.money {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

  .stat-strip {
    grid-template-columns: repeat(4, 104px);
  }
}

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

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .stat-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: end;
    gap: 8px;
    padding: 10px;
  }

  .toolbar label,
  .toolbar .search-field {
    min-width: 0;
  }

  .toolbar .search-field {
    grid-column: 1 / -1;
  }

  .toggle-group {
    width: 100%;
  }

  .toggle-group .toggle {
    flex: 1;
    min-width: 0;
  }

  .icon-button {
    width: 100%;
  }

  .graph-wrap {
    min-height: 620px;
  }

  .legend {
    width: calc(100% - 24px);
    max-width: 360px;
  }

  .region-legend {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

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

  .topbar p {
    font-size: 12px;
  }

  .stat {
    padding: 8px 10px;
  }

  .stat span {
    font-size: 18px;
  }

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

  .toolbar .search-field {
    grid-column: auto;
  }

  .graph-wrap {
    min-height: 540px;
  }

  .legend {
    position: static;
    width: auto;
    margin: 8px;
  }

  .region-legend {
    display: none;
  }

  .side-panel {
    padding: 8px;
  }

  .panel-section {
    padding: 10px;
  }

  .kv {
    grid-template-columns: 78px 1fr;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    flex: 0 0 auto;
  }

  .table-tools {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }
}
