:root {
  color-scheme: light;
  --system-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  --ink: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #8e8e93;
  --separator: rgba(60, 60, 67, 0.18);
  --fill: rgba(120, 120, 128, 0.12);
  --glass: rgba(250, 250, 252, 0.86);
  --blue: #007aff;
  --red: #ff3b30;
  --green: #248a3d;
  --shadow: 0 12px 38px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);
  font-family: var(--system-font);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { color: var(--ink); background: #d9ddd9; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { color: inherit; cursor: pointer; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.map-workspace, #map { position: fixed; inset: 0; }
#map { z-index: 0; background: #dce2dc; }
.leaflet-container { font-family: var(--system-font); }
.leaflet-control-attribution {
  margin: 0 12px 10px 0 !important;
  padding: 3px 7px !important;
  border-radius: 5px 0 0 0;
  background: rgba(255, 255, 255, 0.72) !important;
  color: #69696d;
  font-size: 9px !important;
  backdrop-filter: blur(12px);
}

.glass-panel {
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
}

.map-toolbar {
  position: fixed;
  z-index: 500;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  height: 58px;
  padding: 8px 9px 8px 12px;
  display: grid;
  grid-template-columns: minmax(190px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border-radius: 12px;
}

.brand-lockup { min-width: 0; display: flex; align-items: center; gap: 10px; }
.brand-symbol {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--ink);
  color: white;
}
.brand-symbol svg { width: 18px; height: 18px; stroke-width: 2.25; }
.brand-lockup h1 { margin: 0; font-size: 15px; line-height: 1.2; font-weight: 680; letter-spacing: 0; }
.brand-lockup span:last-child { display: block; margin-top: 2px; color: var(--secondary); font-size: 10px; }

.group-filter {
  min-width: 0;
  display: flex;
  justify-content: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.group-filter::-webkit-scrollbar { display: none; }
.group-button {
  height: 32px;
  padding: 0 12px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 560;
  white-space: nowrap;
}
.group-button:hover { background: var(--fill); color: var(--ink); }
.group-button.active { background: #ffffff; color: var(--ink); box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1); }

.toolbar-actions, .dock-actions, .inspector-footer > div { display: flex; align-items: center; gap: 6px; }
.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}
.icon-button:hover { background: #ffffff; }
.icon-button:active { transform: scale(0.96); }
.icon-button svg { width: 18px; height: 18px; stroke-width: 2; }
.icon-button.primary { background: var(--blue); color: white; }
.icon-button.primary:hover { background: #0875e1; }
.icon-button.compact { width: 32px; height: 32px; border-radius: 7px; background: transparent; }
.icon-button.compact svg { width: 16px; height: 16px; }
.icon-button.danger:hover, .command-button.danger { color: var(--red); }
.icon-button:disabled { opacity: 0.32; cursor: default; transform: none; }

.map-search {
  width: 176px;
  height: 40px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 9px;
  background: var(--fill);
}
.map-search svg { width: 15px; height: 15px; flex: 0 0 auto; color: var(--tertiary); }
.map-search input { width: 100%; min-width: 0; padding: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 12px; }
.map-search input::placeholder { color: var(--tertiary); }

.place-dock {
  position: fixed;
  z-index: 450;
  top: 86px;
  bottom: 16px;
  left: 14px;
  width: 340px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 12px;
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 160ms ease;
}
.place-dock.collapsed { transform: translateX(calc(-100% - 24px)); opacity: 0; pointer-events: none; }
.dock-header { height: 52px; padding: 10px 10px 9px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--separator); }
.dock-header > div:first-child { display: flex; align-items: baseline; gap: 7px; }
.dock-label { font-size: 13px; font-weight: 650; }
.dock-header strong { color: var(--secondary); font-size: 11px; font-weight: 550; }
.place-list { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; }

.group-block + .group-block { border-top: 1px solid var(--separator); }
.group-caption { padding: 15px 15px 7px; display: flex; align-items: center; justify-content: space-between; color: var(--secondary); font-size: 10px; font-weight: 650; text-transform: uppercase; }
.place-row {
  width: 100%;
  min-height: 62px;
  padding: 9px 12px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 9px;
  border: 0;
  border-top: 1px solid rgba(60, 60, 67, 0.09);
  background: transparent;
  text-align: left;
}
.group-caption + .place-row { border-top: 0; }
.place-row:hover, .place-row.selected { background: rgba(0, 122, 255, 0.08); }
.row-index { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--marker-color); color: white; font-size: 10px; font-weight: 750; }
.row-copy { min-width: 0; }
.row-copy strong, .row-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-copy strong { font-size: 12px; font-weight: 620; }
.row-copy span { margin-top: 3px; color: var(--secondary); font-size: 10px; }
.row-status { width: 7px; height: 7px; justify-self: center; border-radius: 50%; background: var(--green); }
.row-status.error { background: var(--red); }
.row-status.pending { background: #ff9f0a; }

.empty-action {
  margin: auto;
  padding: 20px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 600;
}
.empty-action svg { width: 26px; height: 26px; }
.place-list:empty + .empty-action { display: flex; }

.inspector {
  position: fixed;
  z-index: 460;
  left: 370px;
  bottom: 16px;
  width: min(480px, calc(100vw - 400px));
  min-height: 148px;
  padding: 17px 18px 15px;
  border-radius: 12px;
  animation: inspector-in 180ms ease-out;
}
.inspector[hidden] { display: none; }
@keyframes inspector-in { from { opacity: 0; transform: translateY(8px); } }
.inspector-close { position: absolute; top: 8px; right: 8px; }
.inspector-group { display: block; padding-right: 34px; color: var(--blue); font-size: 10px; font-weight: 650; }
.inspector h2 { margin: 5px 34px 0 0; font-size: 18px; line-height: 1.3; font-weight: 680; letter-spacing: 0; overflow-wrap: anywhere; }
.inspector > p { margin: 7px 36px 12px 0; color: var(--secondary); font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.candidate-field { margin-bottom: 12px; display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; }
.candidate-field[hidden] { display: none; }
.candidate-field span { color: var(--secondary); font-size: 10px; }
.candidate-field select {
  width: 100%;
  height: 34px;
  padding: 0 28px 0 9px;
  border: 1px solid var(--separator);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  outline: 0;
  font-size: 11px;
}
.inspector-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.inspector-footer code { color: var(--secondary); font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.command-button {
  height: 30px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 10px;
  font-weight: 600;
}
.command-button[hidden] { display: none; }
.command-button:hover { background: var(--fill); }
.command-button svg { width: 13px; height: 13px; }

.map-notice {
  position: fixed;
  z-index: 430;
  left: 50%;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 13px;
  border-radius: 9px;
  color: var(--secondary);
  transform: translateX(-50%);
  font-size: 11px;
}
.map-notice[hidden] { display: none; }

.map-marker { background: none; border: 0; }
.map-marker span {
  width: 30px;
  height: 36px;
  display: grid;
  place-items: center;
  position: relative;
  border: 2px solid white;
  border-radius: 15px 15px 15px 4px;
  background: var(--marker-color);
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
  transform: rotate(-45deg);
  font-size: 10px;
  font-weight: 760;
}
.map-marker span b { transform: rotate(45deg); font-weight: inherit; }
.map-marker.selected span { width: 36px; height: 42px; border-radius: 18px 18px 18px 5px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.34); }

.leaflet-control-zoom {
  margin-right: 14px !important;
  margin-bottom: 18px !important;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.72) !important;
  border-radius: 9px !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a { width: 36px !important; height: 36px !important; line-height: 34px !important; border-color: var(--separator) !important; background: var(--glass) !important; color: var(--ink) !important; backdrop-filter: blur(18px); }

.batch-dialog {
  width: min(540px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 40px));
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 14px;
  background: rgba(250, 250, 252, 0.96);
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(30px);
}
.batch-dialog::backdrop { background: rgba(0, 0, 0, 0.26); backdrop-filter: blur(6px); }
.batch-dialog form { padding: 22px; }
.sheet-header { margin-bottom: 22px; display: flex; align-items: flex-start; justify-content: space-between; }
.sheet-header > div > span { color: var(--blue); font-size: 10px; font-weight: 650; }
.sheet-header h2 { margin: 4px 0 0; font-size: 22px; font-weight: 690; letter-spacing: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 15px; }
.field > span { color: var(--secondary); font-size: 11px; font-weight: 560; }
.field input, .field textarea {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(118, 118, 128, 0.1);
  color: var(--ink);
  outline: 0;
}
.field input { height: 42px; padding: 0 12px; }
.field textarea { min-height: 220px; padding: 11px 12px; resize: vertical; line-height: 1.55; }
.field input:focus, .field textarea:focus { border-color: rgba(0, 122, 255, 0.55); box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12); }
.sheet-status { min-height: 24px; display: flex; justify-content: space-between; color: var(--secondary); font-size: 10px; }
.submit-button { width: 100%; height: 44px; border: 0; border-radius: 9px; background: var(--blue); color: white; font-weight: 650; }
.submit-button:hover { background: #0875e1; }
.submit-button:disabled { opacity: 0.55; cursor: wait; }

.toast {
  position: fixed;
  z-index: 1000;
  left: 50%;
  bottom: 26px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(29, 29, 31, 0.9);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 11px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .map-toolbar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .map-search { width: 40px; padding: 0 12px; }
  .map-search input { display: none; }
  .inspector { width: min(430px, calc(100vw - 400px)); }
}

@media (max-width: 700px) {
  .map-toolbar {
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
    right: 8px;
    height: 54px;
    grid-template-columns: minmax(116px, auto) minmax(0, 1fr) auto;
    gap: 7px;
    padding: 7px;
  }
  .brand-symbol { width: 32px; height: 32px; }
  .brand-lockup h1 { font-size: 13px; }
  .brand-lockup span:last-child { display: none; }
  .group-filter { justify-content: flex-start; }
  .group-button { height: 30px; padding: 0 9px; font-size: 11px; }
  .toolbar-actions { gap: 3px; }
  .toolbar-actions .icon-button { width: 36px; height: 36px; }
  .map-search, #fitButton { display: none; }

  .place-dock {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
    height: min(38vh, 330px);
    border-radius: 12px;
  }
  .place-dock.collapsed { transform: translateY(calc(100% + 18px)); }
  .dock-header { height: 46px; }
  .place-row { min-height: 58px; }

  .inspector {
    left: 8px;
    right: 8px;
    bottom: calc(min(38vh, 330px) + 16px + env(safe-area-inset-bottom));
    width: auto;
    min-height: 130px;
    padding: 14px;
  }
  .inspector h2 { font-size: 16px; }
  .inspector-footer { align-items: flex-end; }

  .leaflet-control-zoom { display: none; }
  .leaflet-control-attribution { margin-bottom: calc(min(38vh, 330px) + 14px) !important; }
  .batch-dialog { width: 100%; max-width: none; max-height: 86vh; margin: auto 0 0; border-radius: 14px 14px 0 0; }
  .batch-dialog form { padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); }
}

@media (max-width: 430px) {
  .map-toolbar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .brand-lockup > div { display: none; }
  .brand-lockup { min-width: 32px; }
  #toggleDockButton { display: none; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .field textarea { min-height: 190px; }
  .inspector-footer { flex-direction: column; align-items: stretch; }
  .inspector-footer > div { justify-content: flex-end; }
}
