:root {
  --ink: #16212b;
  --muted: #66747d;
  --faint: #98a4aa;
  --line: #d8e0e2;
  --soft-line: #e9eeef;
  --paper: #f6f8f7;
  --surface: #ffffff;
  --navy: #1f4f59;
  --navy-dark: #183f48;
  --cyan: #2a9ca5;
  --cyan-soft: #e3f2f1;
  --orange: #c97437;
  --orange-soft: #fbede1;
  --road: #6b7682;
  --road-soft: #edf0f2;
  --danger: #b34c45;
  --danger-soft: #fae9e8;
  --shadow: 0 16px 42px rgba(24, 56, 65, 0.08);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 680px;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 76px;
  padding: 0 28px;
}

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

.brand-mark {
  align-items: center;
  background: var(--navy);
  color: #fff;
  display: flex;
  font-family: Georgia, serif;
  font-size: 23px;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.eyebrow, .section-kicker, .readout-label {
  color: var(--faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
  margin: 0 0 7px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 19px; letter-spacing: 0.02em; line-height: 1; margin: 0; }
h2 { font-size: 16px; letter-spacing: 0.02em; line-height: 1.3; margin: 0; }
h3 { font-size: 15px; line-height: 1.3; margin: 0 0 5px; }

.topbar-meta {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 11px;
  gap: 9px;
  letter-spacing: 0.04em;
}

.live-dot { background: var(--cyan); border-radius: 50%; box-shadow: 0 0 0 4px var(--cyan-soft); height: 7px; width: 7px; }
.meta-divider { background: var(--line); height: 13px; margin: 0 4px; width: 1px; }

.workspace { display: grid; flex: 1; grid-template-columns: 420px minmax(0, 1fr); min-height: 0; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

.search-section, .parse-section, .source-section, .results-section { padding: 24px 24px 0; }
.search-section { border-bottom: 1px solid var(--soft-line); padding-bottom: 23px; }
.parse-section { border-bottom: 1px solid var(--soft-line); padding-bottom: 22px; }
.source-section { border-bottom: 1px solid var(--soft-line); padding-bottom: 20px; }
.results-section { flex: 1; min-height: 250px; }

.section-heading { align-items: flex-start; display: flex; justify-content: space-between; margin-bottom: 18px; }
.compact-heading { align-items: center; margin-bottom: 14px; }
.crs-chip, .status-label, .result-count {
  background: var(--cyan-soft);
  color: var(--navy);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 6px 8px;
}
.status-label { background: #edf3ed; color: #4a745d; letter-spacing: 0.02em; }
.result-count { background: var(--road-soft); color: var(--muted); min-width: 24px; text-align: center; }

.field-label { color: var(--muted); display: block; font-size: 11px; font-weight: 600; margin: 0 0 7px; }
.field-label span { color: var(--faint); font-size: 10px; font-weight: 400; margin-left: 3px; }

.search-control { display: grid; grid-template-columns: minmax(0, 1fr) 88px; }
input {
  background: #fbfcfc;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  min-height: 43px;
  outline: 0;
  padding: 0 12px;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
  width: 100%;
}
input::placeholder { color: #aab4b7; }
input:focus { background: #fff; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(42, 156, 165, 0.12); }
.search-control input { border-right: 0; }

#submit-button {
  align-items: center;
  background: var(--navy);
  border: 1px solid var(--navy);
  color: #fff;
  display: flex;
  font-size: 12px;
  gap: 6px;
  justify-content: center;
  min-height: 43px;
  transition: background 160ms ease, transform 160ms ease;
}
#submit-button:hover { background: var(--navy-dark); }
#submit-button:active { transform: translateY(1px); }
#submit-button:disabled { cursor: wait; opacity: 0.65; }
.button-arrow { font-size: 16px; line-height: 1; }
.field-hint { color: var(--faint); font-size: 11px; line-height: 1.6; margin: 9px 0 19px; }
.context-grid { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }

.parse-grid { display: grid; gap: 9px 12px; grid-template-columns: 1fr 1fr; }
.parse-item { min-width: 0; }
.parse-key { color: var(--faint); display: block; font-size: 10px; margin-bottom: 4px; }
.parse-value { color: var(--ink); display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.parse-value.is-empty { color: #b7c0c2; }

.source-toggles { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.source-toggle { align-items: center; background: #fbfcfc; border: 1px solid var(--soft-line); display: flex; gap: 9px; min-height: 53px; padding: 9px 10px; transition: background 160ms ease, border-color 160ms ease; }
.source-toggle:hover { background: #f5faf9; border-color: var(--line); }
.source-toggle input { height: 1px; opacity: 0; position: absolute; width: 1px; }
.toggle-control { background: #d7dfe0; border: 2px solid #d7dfe0; border-radius: 50%; flex: 0 0 auto; height: 15px; position: relative; transition: background 160ms ease, border-color 160ms ease; width: 15px; }
.toggle-control::after { background: #fff; border-radius: 50%; content: ""; height: 5px; left: 3px; opacity: 0; position: absolute; top: 3px; transition: opacity 160ms ease; width: 5px; }
.source-toggle input:checked + .toggle-control { background: var(--cyan); border-color: var(--cyan); }
.source-toggle-amap input:checked + .toggle-control { background: var(--orange); border-color: var(--orange); }
.source-toggle input:checked + .toggle-control::after { opacity: 1; }
.source-toggle input:focus-visible + .toggle-control { box-shadow: 0 0 0 3px rgba(42, 156, 165, 0.15); }
.source-toggle input:disabled + .toggle-control { background: #edf0f0; border-color: #edf0f0; }
.source-toggle:has(input:disabled) { cursor: not-allowed; opacity: 0.58; }
.source-copy { display: grid; gap: 3px; min-width: 0; }
.source-copy strong { color: var(--ink); font-size: 12px; }
.source-copy small { color: var(--faint); font-size: 10px; }

.state-panel { padding: 30px 10px 24px; text-align: center; }
.state-symbol { color: var(--cyan); font-family: Georgia, serif; font-size: 28px; line-height: 1; margin-bottom: 15px; }
.state-panel p { color: var(--muted); font-size: 12px; line-height: 1.65; margin: 0 auto; max-width: 250px; }
.state-panel.error .state-symbol { color: var(--danger); }
.state-panel.error h3 { color: var(--danger); }
.state-panel.no-result .state-symbol { color: var(--orange); }
.state-panel.no-result h3 { color: #945524; }

.candidate-list { display: grid; gap: 8px; padding-bottom: 18px; }
.candidate-item {
  background: #fbfcfc;
  border: 1px solid var(--soft-line);
  border-left: 3px solid var(--road);
  padding: 13px 13px 12px;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.candidate-item:hover, .candidate-item.is-active { background: #f5faf9; border-color: #b9dedd; transform: translateX(2px); }
.candidate-item.type-entrance_poi { border-left-color: var(--orange); }
.candidate-item.type-subject_poi { border-left-color: var(--cyan); }
.candidate-item.type-road_anchor { border-left-color: var(--road); }
.candidate-item.type-geocode { border-left-color: var(--navy); }
.candidate-topline { align-items: flex-start; display: flex; gap: 9px; justify-content: space-between; }
.candidate-name { font-size: 13px; font-weight: 700; line-height: 1.45; margin: 0; }
.candidate-score { color: var(--navy); flex: 0 0 auto; font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; font-weight: 700; }
.candidate-badge { color: var(--muted); font-size: 10px; margin: 8px 0 4px; }
.provider-pill { display: inline-block; font-size: 9px; font-weight: 700; margin-right: 5px; padding: 2px 5px; }
.provider-pill-geovis { background: var(--cyan-soft); color: var(--navy); }
.provider-pill-amap { background: var(--orange-soft); color: #945524; }
.candidate-address { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 0 0 10px; }
.candidate-coords { align-items: center; border-top: 1px solid var(--soft-line); color: var(--ink); display: flex; font-family: "SFMono-Regular", Consolas, monospace; font-size: 10px; gap: 8px; justify-content: space-between; padding-top: 9px; }
.candidate-coords span:last-child { color: var(--faint); font-family: inherit; }
.candidate-conflicts { color: var(--danger); font-size: 10px; line-height: 1.5; margin: 8px 0 0; }
.candidate-source { color: var(--faint); font-size: 10px; line-height: 1.5; margin: 6px 0 0; }

.sidebar-footer { border-top: 1px solid var(--line); color: var(--faint); display: flex; font-size: 10px; gap: 8px; justify-content: center; letter-spacing: 0.02em; padding: 16px 12px; }
.footer-separator { color: var(--line); }

.map-panel { background: #dfe7e4; min-height: 0; position: relative; }
#map { height: 100%; min-height: 420px; width: 100%; }
.leaflet-container { background: #e4ebe8; font-family: inherit; }
.leaflet-control-zoom { border: 0 !important; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a { color: var(--navy) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { border-radius: 0; }
.leaflet-popup-content { font-family: inherit; font-size: 12px; line-height: 1.5; margin: 13px 15px; }
.popup-title { font-weight: 700; margin-bottom: 5px; }
.popup-meta { color: var(--muted); font-size: 11px; }

.map-overlay { left: 18px; pointer-events: none; position: absolute; right: 18px; z-index: 500; }
.map-overlay-top { align-items: flex-start; display: flex; justify-content: space-between; top: 18px; }
.map-overlay-bottom { align-items: flex-end; bottom: 14px; display: flex; justify-content: space-between; }
.map-readout, .legend, .map-note { background: rgba(255, 255, 255, 0.94); box-shadow: 0 8px 25px rgba(24, 56, 65, 0.12); pointer-events: auto; }
.map-readout { display: grid; gap: 5px; min-width: 180px; padding: 11px 13px; }
.map-readout #map-location { font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }
.icon-button { background: rgba(255,255,255,.94); border: 0; box-shadow: 0 8px 25px rgba(24, 56, 65, 0.12); color: var(--navy); font-size: 22px; height: 42px; pointer-events: auto; width: 42px; }
.icon-button:hover { background: #fff; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 10px 12px; }
.legend, .map-note { color: var(--muted); font-size: 10px; }
.legend span { align-items: center; display: inline-flex; gap: 5px; }
.legend-dot { border-radius: 50%; display: inline-block; height: 8px; width: 8px; }
.legend-entrance { background: var(--orange); }
.legend-subject { background: var(--cyan); }
.legend-road { background: var(--road); }
.legend-geocode { background: var(--navy); }
.legend-geovis { background: var(--cyan); }
.legend-amap { background: var(--orange); }
.map-note { padding: 10px 12px; }

.poi-marker { align-items: center; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 3px 8px rgba(19, 46, 54, .24); display: flex; height: 18px; justify-content: center; width: 18px; }
.poi-marker::after { background: #fff; border-radius: 50%; content: ""; height: 4px; width: 4px; }
.poi-marker-entrance { background: var(--orange); }
.poi-marker-subject { background: var(--cyan); }
.poi-marker-road { background: var(--road); }
.poi-marker-geocode { background: var(--navy); }

@media (max-width: 900px) {
  .app-shell { min-height: 100vh; }
  .topbar { min-height: 68px; padding: 0 17px; }
  .topbar-meta { font-size: 10px; }
  .workspace { display: flex; flex-direction: column; overflow: auto; }
  .sidebar { border-right: 0; overflow: visible; order: 2; }
  .map-panel { flex: 0 0 54vh; min-height: 420px; order: 1; }
  #map { min-height: 420px; }
  .search-section, .parse-section, .source-section, .results-section { padding-left: 18px; padding-right: 18px; }
  .sidebar-footer { display: none; }
}

@media (max-width: 520px) {
  .brand-mark { height: 32px; width: 32px; }
  .eyebrow { font-size: 8px; }
  h1 { font-size: 17px; }
  .topbar-meta { display: none; }
  .map-overlay { left: 10px; right: 10px; }
  .map-overlay-bottom { align-items: flex-start; flex-direction: column; gap: 7px; }
  .map-note { align-self: flex-end; }
  .legend { gap: 8px; }
}
