:root {
  color-scheme: light;
  --bg: #f4f8ff;
  --surface: #ffffff;
  --surface-strong: #edf4ff;
  --surface-soft: #eaf6ff;
  --ink: #15243d;
  --muted: #66758c;
  --hairline: #d5e2f2;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --teal: #0284c7;
  --green: #0ea5e9;
  --gold: #f59e0b;
  --shadow: 0 18px 50px rgba(24, 58, 115, 0.14);
  --shadow-soft: 0 10px 26px rgba(24, 58, 115, 0.08);
  --radius: 8px;
  --font: "Inter", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #0d1628;
  --surface: #121e33;
  --surface-strong: #172842;
  --surface-soft: #12304b;
  --ink: #eef6ff;
  --muted: #a5b8d1;
  --hairline: #29415f;
  --accent: #60a5fa;
  --accent-dark: #93c5fd;
  --teal: #38bdf8;
  --green: #22d3ee;
  --gold: #fbbf24;
  --shadow: 0 22px 54px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 12px 32px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: 0;
  overflow-x: hidden;
}

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

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 18px;
  gap: 14px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #0f3b73, #2563eb);
  color: var(--surface);
  font-weight: 900;
  box-shadow: inset 0 -5px 0 color-mix(in srgb, var(--teal) 72%, transparent);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(21px, 3vw, 29px);
  line-height: 1.05;
  font-weight: 850;
}

.brand-block p,
.eyebrow {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 750;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

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

.map-panel,
.side-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.map-panel {
  display: grid;
  grid-template-rows: auto auto minmax(360px, 1fr);
  isolation: isolate;
}

.map-panel:fullscreen,
.map-panel.is-fullscreen-fallback {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

.map-panel.is-fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 50;
}

body.map-fullscreen-fallback {
  overflow: hidden;
}

.map-toolbar {
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(110px, 150px) 42px 42px;
  gap: 9px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  background: var(--surface-strong);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

select,
.form-grid input,
.form-grid textarea,
.coordinate-grid input,
.extra-row input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  padding: 9px 11px;
}

textarea {
  resize: vertical;
}

select:focus,
input:focus,
textarea:focus,
.search-box:focus-within {
  border-color: color-mix(in srgb, var(--teal) 72%, var(--hairline));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 17%, transparent);
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}

.stat-chip {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.stat-chip strong {
  display: block;
  font-size: 19px;
  line-height: 1.05;
}

.stat-chip span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.china-map {
  width: 100%;
  height: 100%;
  min-height: 470px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--surface) 94%, var(--teal)) 1px, transparent 1px),
    linear-gradient(color-mix(in srgb, var(--surface) 94%, var(--green)) 1px, transparent 1px);
  background-size: 36px 36px;
}

.map-note {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(420px, calc(100% - 28px));
  min-height: 36px;
  padding: 8px 11px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 13px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.map-note.hide {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 16px 11px;
}

.panel-header h2 {
  margin-top: 2px;
  font-size: 22px;
}

.city-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 12px;
  scrollbar-width: thin;
}

.city-pill {
  min-height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface-strong);
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.city-pill.active {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

.person-list {
  min-height: 0;
  overflow: auto;
  padding: 0 16px 16px;
  display: grid;
  align-content: start;
  gap: 10px;
  scrollbar-width: thin;
}

.person-card {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.person-card:hover,
.person-card.active {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--teal) 62%, var(--hairline));
  box-shadow: var(--shadow-soft);
}

.person-color {
  width: 10px;
  height: 44px;
  border-radius: 999px;
  background: var(--accent);
}

.person-main {
  min-width: 0;
}

.person-main h3 {
  font-size: 16px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.person-main p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.person-badge {
  align-self: start;
  max-width: 78px;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--teal);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  padding: 30px 18px;
  border: 1px dashed var(--hairline);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button,
.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.17s ease, filter 0.17s ease, background 0.17s ease, border-color 0.17s ease;
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid var(--hairline);
  background: var(--surface-strong);
  color: var(--ink);
}

.icon-button.quiet {
  background: transparent;
}

.icon-button.active {
  border-color: color-mix(in srgb, var(--teal) 62%, var(--hairline));
  background: var(--ink);
  color: var(--surface);
}

.icon-button[hidden] {
  display: none;
}

.primary-button,
.secondary-button,
.danger-button,
.small-button {
  min-width: 42px;
  padding: 0 14px;
  font-weight: 750;
  text-decoration: none;
}

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

.secondary-button {
  border: 1px solid var(--hairline);
  background: var(--surface-strong);
  color: var(--ink);
}

.danger-button {
  background: color-mix(in srgb, #d83b2d 11%, var(--surface));
  color: #d83b2d;
  border: 1px solid color-mix(in srgb, #d83b2d 25%, var(--hairline));
}

.small-button {
  min-height: 36px;
  padding: 0 11px;
  background: var(--ink);
  color: var(--surface);
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
  flex: 0 0 auto;
}

dialog {
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
}

dialog::backdrop {
  background: rgba(12, 16, 13, 0.38);
  backdrop-filter: blur(5px);
}

.detail-drawer {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  margin: auto 12px auto auto;
}

.drawer-content {
  position: relative;
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: drawerIn 0.24s ease both;
}

.drawer-close {
  position: sticky;
  top: 12px;
  float: right;
  margin: 12px;
  z-index: 2;
}

.detail-hero {
  padding: 26px 24px 18px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-soft);
}

.detail-hero h2 {
  margin-right: 58px;
  font-size: 30px;
  line-height: 1.1;
}

.detail-route {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 700;
}

.detail-route span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-section {
  padding: 18px 24px;
  border-bottom: 1px solid var(--hairline);
}

.detail-section h3 {
  margin-bottom: 11px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-grid {
  display: grid;
  gap: 10px;
}

.info-line {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  font-size: 14px;
}

.info-line span:first-child {
  color: var(--muted);
}

.info-line span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.drawer-actions {
  display: flex;
  gap: 9px;
  padding: 18px 24px 24px;
}

.form-dialog {
  width: min(760px, calc(100vw - 22px));
  max-height: calc(100vh - 22px);
  margin: auto;
}

.person-form {
  max-height: calc(100vh - 22px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: popIn 0.21s ease both;
}

.form-head,
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--hairline);
}

.form-head {
  justify-content: space-between;
}

.form-head h2 {
  margin-top: 2px;
  font-size: 24px;
}

.form-grid,
.coordinate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
  padding: 18px 20px;
}

.form-grid label,
.coordinate-grid label {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.form-grid label span,
.coordinate-grid label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.wide {
  grid-column: 1 / -1;
}

.coordinate-box {
  margin: 0 20px 18px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.coordinate-box summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 760;
}

.coordinate-grid {
  padding: 0 14px 14px;
}

.extra-fields {
  padding: 0 20px 18px;
}

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

.section-title h3 {
  font-size: 16px;
}

#extraFields {
  display: grid;
  gap: 9px;
}

.extra-row {
  display: grid;
  grid-template-columns: minmax(92px, 0.45fr) minmax(140px, 1fr) 42px;
  gap: 8px;
  align-items: center;
}

.form-actions {
  border-top: 1px solid var(--hairline);
  border-bottom: 0;
  flex-wrap: wrap;
}

.action-spacer {
  flex: 1 1 auto;
}

.share-popover {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 16, 13, 0.36);
  backdrop-filter: blur(5px);
}

.share-popover-card {
  width: min(520px, 100%);
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.share-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--hairline);
}

.share-popover textarea {
  width: calc(100% - 28px);
  min-height: 118px;
  margin: 14px;
  padding: 11px;
  resize: vertical;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  color: var(--surface);
  background: var(--ink);
  box-shadow: var(--shadow);
  transform: translateY(14px);
  opacity: 0;
  animation: toastIn 0.2s ease forwards, toastOut 0.24s ease 2.8s forwards;
}

@keyframes drawerIn {
  from {
    opacity: 0;
    transform: translateX(28px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(12px);
  }
}

@media (max-width: 1020px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    min-height: 380px;
  }

  .person-list {
    max-height: 460px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

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

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(42px, 1fr));
  }

  .topbar-actions .primary-button {
    grid-column: span 3;
  }

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

  .map-toolbar select {
    grid-column: 1 / -1;
    order: 3;
  }

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

  .china-map {
    min-height: 420px;
  }

  .form-grid,
  .coordinate-grid,
  .extra-row {
    grid-template-columns: 1fr;
  }

  .extra-row .icon-button {
    justify-self: end;
  }

  .detail-drawer {
    width: calc(100vw - 20px);
    margin: auto 10px 10px;
  }

  .drawer-content {
    max-height: min(78vh, calc(100vh - 20px));
  }

  .detail-hero h2 {
    font-size: 26px;
  }

  .info-line {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .form-actions .danger-button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .primary-button,
  .secondary-button,
  .danger-button {
    width: 100%;
  }

  .drawer-actions {
    flex-direction: column;
  }
}
