:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #687078;
  --line: #d8ded8;
  --panel: #ffffff;
  --paper: #f7f5ef;
  --teal: #0f766e;
  --coral: #d95d39;
  --gold: #b7791f;
  --violet: #6b5b95;
  --leaf: #4d7c0f;
  --shadow: 0 18px 50px rgba(32, 33, 36, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.04), transparent 38%),
    linear-gradient(180deg, #fbfaf6 0%, var(--paper) 100%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 28px 18px;
  border-bottom: 1px solid rgba(104, 112, 120, 0.18);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 2vw, 2.25rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.18;
  letter-spacing: 0;
}

h3 {
  margin: 0 0 12px;
  font-size: 0.88rem;
  letter-spacing: 0;
}

.header-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 999px;
  color: var(--teal);
  background: rgba(15, 118, 110, 0.07);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(430px, 1fr) 330px;
  gap: 18px;
  height: calc(100vh - 88px);
  padding: 18px;
}

.domain-rail,
.tree-shell,
.detail-panel {
  min-height: 0;
  border: 1px solid rgba(104, 112, 120, 0.18);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.domain-rail {
  padding: 12px;
  overflow: auto;
}

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

.domain-button {
  display: grid;
  grid-template-columns: 8px 1fr;
  gap: 12px;
  width: 100%;
  min-height: 72px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: inherit;
  background: transparent;
  text-align: left;
}

.domain-button:hover,
.domain-button.active {
  border-color: rgba(32, 33, 36, 0.15);
  background: #fff;
}

.domain-color {
  width: 8px;
  height: 100%;
  border-radius: 999px;
  background: var(--domain-color);
}

.domain-name {
  display: block;
  margin-bottom: 4px;
  font-weight: 800;
  line-height: 1.16;
}

.domain-meta {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.tree-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.toolbar {
  flex-wrap: wrap;
  padding: 12px;
  border-bottom: 1px solid rgba(104, 112, 120, 0.18);
  background: rgba(255, 255, 255, 0.84);
}

.search-box,
.select-box {
  display: grid;
  gap: 4px;
}

.search-box {
  flex: 1 1 150px;
  min-width: 150px;
}

.select-box {
  flex: 0 1 130px;
}

.search-box span,
.select-box span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

input,
select {
  height: 36px;
  width: 100%;
  border: 1px solid rgba(104, 112, 120, 0.28);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input {
  padding: 0 10px;
}

select {
  padding: 0 8px;
}

.icon-button,
.text-button {
  height: 34px;
  border: 1px solid rgba(104, 112, 120, 0.28);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.icon-button {
  width: 34px;
  font-size: 1.1rem;
}

.text-button {
  padding: 0 10px;
}

.tree-stage {
  position: relative;
  overflow: auto;
  background-image:
    linear-gradient(rgba(104, 112, 120, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(104, 112, 120, 0.08) 1px, transparent 1px);
  background-size: 32px 32px;
}

#treeSvg {
  display: block;
  min-width: 100%;
  min-height: 100%;
}

.tree-link {
  fill: none;
  stroke: rgba(104, 112, 120, 0.34);
  stroke-width: 2;
}

.node-card {
  filter: drop-shadow(0 9px 18px rgba(32, 33, 36, 0.1));
}

.node-rect {
  fill: #fff;
  stroke: rgba(104, 112, 120, 0.24);
  stroke-width: 1;
  rx: 8;
}

.node-card.selected .node-rect {
  stroke: var(--domain-color);
  stroke-width: 2;
}

.node-card.match .node-rect {
  fill: #fff8e8;
  stroke: var(--gold);
}

.node-title {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
}

.node-meta {
  fill: var(--muted);
  font-size: 11px;
}

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

.node-toggle {
  fill: #fff;
  stroke: var(--domain-color);
  stroke-width: 2;
}

.node-toggle-text {
  fill: var(--domain-color);
  font-size: 15px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.detail-panel {
  padding: 18px;
  overflow: auto;
}

.summary {
  margin: 12px 0 16px;
  color: #4c5358;
  font-size: 0.92rem;
  line-height: 1.55;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 14px;
}

.metric-grid div {
  padding: 12px;
  border: 1px solid rgba(104, 112, 120, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

dd {
  margin: 4px 0 0;
  font-size: 1.35rem;
  font-weight: 900;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 0 18px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(32, 33, 36, 0.07);
  color: #42484d;
  font-size: 0.76rem;
  font-weight: 700;
}

.panel-section {
  padding-top: 16px;
  border-top: 1px solid rgba(104, 112, 120, 0.18);
}

.panel-section + .panel-section {
  margin-top: 16px;
}

.link-list,
.task-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.link-list li,
.task-list li {
  padding: 10px;
  border: 1px solid rgba(104, 112, 120, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  line-height: 1.38;
}

.note-title {
  display: block;
  color: var(--ink);
  font-weight: 800;
}

.note-path {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.77rem;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 220px minmax(360px, 1fr);
    grid-template-rows: minmax(520px, 1fr) auto;
    height: auto;
    min-height: calc(100vh - 88px);
  }

  .detail-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .domain-rail {
    max-height: 270px;
  }

  .tree-stage {
    min-height: 520px;
  }
}
