:root {
  color-scheme: light;
  --ink: #162130;
  --muted: #687587;
  --line: #dce3ea;
  --panel: #ffffff;
  --surface: #f4f7fa;
  --navy: #17324d;
  --teal: #0c7c86;
  --teal-soft: #e6f5f6;
  --orange: #c77810;
  --orange-soft: #fff4dd;
  --red: #bd3b43;
  --red-soft: #fdebed;
  --green: #2a805a;
  --green-soft: #e8f5ed;
  --shadow: 0 12px 32px rgba(17, 42, 66, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--surface);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, #eef5f7 0, #f4f7fa 220px, #f4f7fa 100%);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--teal);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.shell {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 0 18px;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #fff;
  background: var(--navy);
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
}

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

.top-actions,
.button-row,
.filter-row,
.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.button,
.button-secondary,
.button-danger,
.button-quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 650;
  text-decoration: none;
  transition: 150ms ease;
}

.button {
  color: #fff;
  background: var(--teal);
}

.button:hover {
  background: #08656d;
  text-decoration: none;
}

.button-secondary {
  color: var(--navy);
  background: #fff;
  border-color: var(--line);
}

.button-secondary:hover,
.button-quiet:hover {
  border-color: #a8b7c6;
  background: #f9fbfc;
  text-decoration: none;
}

.button-danger {
  color: var(--red);
  background: #fff;
  border-color: #edc2c7;
}

.button-quiet {
  min-height: 32px;
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}

.button[aria-busy="true"] {
  opacity: 0.7;
  pointer-events: none;
}

.hero {
  padding: 30px 0 20px;
}

.hero h2 {
  max-width: 780px;
  margin: 0;
  color: var(--navy);
  font-size: clamp(28px, 4vw, 52px);
  line-height: 1.08;
  letter-spacing: 0;
}

.hero p {
  max-width: 760px;
  margin: 15px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2,
.panel-header h3,
.panel-header p {
  margin: 0;
}

.panel-header h2,
.panel-header h3 {
  color: var(--navy);
  font-size: 16px;
  line-height: 1.25;
}

.panel-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.panel-body {
  padding: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field-full {
  grid-column: 1 / -1;
}

.field label {
  color: #3c4b5a;
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fbfcfd;
  border: 1px solid #cbd6e0;
  border-radius: 5px;
  outline: 0;
}

.field input:focus,
.field select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(12, 124, 134, 0.12);
}

.field-help,
.note,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.note {
  padding: 12px 14px;
  background: #f7fafb;
  border-left: 3px solid #9bb6c4;
}

.note-warning {
  background: var(--orange-soft);
  border-color: #e0a340;
}

.note-danger {
  background: var(--red-soft);
  border-color: var(--red);
}

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

.link-block {
  display: block;
  padding: 16px;
  color: var(--ink);
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.link-block:hover {
  border-color: #9db4c2;
  box-shadow: 0 8px 20px rgba(17, 42, 66, 0.08);
  text-decoration: none;
  transform: translateY(-1px);
}

.link-block strong,
.link-block span {
  display: block;
}

.link-block strong {
  color: var(--navy);
  font-size: 15px;
}

.link-block span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.metric {
  min-width: 0;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-label,
.metric-value {
  display: block;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 4px;
  color: var(--navy);
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
}

.metric-danger .metric-value {
  color: var(--red);
}

.metric-warning .metric-value {
  color: var(--orange);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 20px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
}

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

.filter label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.filter select,
.filter input {
  min-height: 34px;
  padding: 6px 8px;
  background: #fff;
  border: 1px solid #cbd6e0;
  border-radius: 5px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid #edf1f4;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #fbfcfd;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  color: #30404f;
}

tbody tr:hover {
  background: #f8fbfc;
}

.cell-title {
  color: var(--navy);
  font-weight: 750;
}

.cell-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.badge-high {
  color: var(--red);
  background: var(--red-soft);
}

.badge-review {
  color: #8d5d06;
  background: var(--orange-soft);
}

.badge-shared {
  color: var(--teal);
  background: var(--teal-soft);
}

.badge-ok {
  color: var(--green);
  background: var(--green-soft);
}

.empty-state {
  padding: 44px 20px;
  color: var(--muted);
  text-align: center;
}

.warning-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.warning-list li {
  padding: 9px 11px;
  color: #79500c;
  background: var(--orange-soft);
  border-left: 3px solid #e0a340;
  white-space: normal;
}

.graph-layout {
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  min-height: 680px;
}

.graph {
  overflow: auto;
  min-height: 680px;
  background: #fbfdfe;
}

.mindmap {
  display: grid;
  gap: 12px;
  min-width: 980px;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(12, 124, 134, 0.04) 1px, transparent 1px) 0 0 / 24px 24px,
    #fbfdfe;
}

.mindmap-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) 20px minmax(145px, 0.9fr) 20px minmax(160px, 1fr) 20px minmax(150px, 0.95fr) 20px minmax(170px, 1.1fr);
  align-items: center;
  gap: 8px;
  min-height: 84px;
}

.mindmap-arrow {
  color: #98acb9;
  font-size: 19px;
  font-weight: 800;
  text-align: center;
}

.map-card {
  display: grid;
  min-height: 68px;
  padding: 10px 11px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid #8aa2b1;
  border-radius: 6px;
  box-shadow: 0 5px 16px rgba(17, 42, 66, 0.07);
}

.map-card:hover {
  border-color: #91aebb;
  box-shadow: 0 8px 20px rgba(17, 42, 66, 0.12);
  transform: translateY(-1px);
}

.map-card.map-cluster {
  border-left-color: var(--navy);
}

.map-card.map-node {
  border-left-color: #365d78;
}

.map-card.map-site,
.map-card.map-listener {
  border-left-color: var(--teal);
}

.map-card.map-origin {
  border-left-color: var(--orange);
}

.map-card.is-conflict {
  border-color: #e0aeb3;
  border-left-color: var(--red);
  background: #fff8f8;
}

.map-card small,
.map-card strong {
  display: block;
}

.map-card small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.map-card strong {
  margin-top: 4px;
  overflow: hidden;
  color: var(--navy);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: normal;
}

.map-card span {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-origins {
  display: grid;
  gap: 5px;
}

.map-origin-chip {
  padding: 7px 8px;
  color: #7b520d;
  background: var(--orange-soft);
  border: 1px solid #efd9a7;
  border-radius: 5px;
  font-size: 11px;
}

.map-empty {
  display: grid;
  min-height: 620px;
  place-items: center;
  color: var(--muted);
}

.details {
  overflow: auto;
  border-left: 1px solid var(--line);
}

.details-body {
  padding: 18px;
}

.details dl {
  margin: 0;
}

.details dt {
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.details dd {
  margin: 3px 0 0;
  color: var(--ink);
  word-break: break-word;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.footer {
  padding: 28px 0 36px;
  color: var(--muted);
  font-size: 12px;
}

#toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  display: grid;
  gap: 8px;
  max-width: min(420px, calc(100vw - 40px));
}

.toast {
  padding: 11px 14px;
  color: #fff;
  background: var(--navy);
  border-radius: 6px;
  box-shadow: 0 12px 24px rgba(17, 42, 66, 0.2);
}

.toast-success {
  background: var(--green);
}

.toast-error {
  background: var(--red);
}

@media (max-width: 1000px) {
  .content-grid,
  .graph-layout {
    grid-template-columns: 1fr;
  }

  .details {
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 24px, 1480px);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid,
  .link-grid {
    grid-template-columns: 1fr;
  }

  .field-full {
    grid-column: auto;
  }

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

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .filter {
    min-width: 0;
  }

  .graph,
  .graph-layout {
    min-height: 560px;
  }

  .mindmap {
    min-width: 980px;
  }
}
