:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-muted: #faf9f6;
  --surface-sunken: #f2f1ec;
  --ink: #191c1f;
  --ink-soft: #3d4247;
  --muted: #767b81;
  --faint: #a4a8a9;
  --line: #e5e4de;
  --line-strong: #d2d1ca;
  --accent: #2f5d50;
  --danger: #a13b30;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --font-serif: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif SC", Georgia, serif;
  --mono: "SFMono-Regular", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
p,
dl,
dd,
dt,
ul,
figure {
  margin: 0;
  padding: 0;
}

ul,
ol {
  list-style: none;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

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

:focus-visible {
  outline: 2px solid rgba(25, 28, 31, 0.35);
  outline-offset: 2px;
}

::selection {
  background: rgba(47, 93, 80, 0.16);
}

[hidden] {
  display: none !important;
}

/* ---------- 滚动条 ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: #cecdc6 transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: #cecdc6;
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: #b8b7ae;
  border: 3px solid transparent;
  background-clip: padding-box;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease),
    color 0.16s var(--ease), transform 0.12s var(--ease);
}

.btn:hover {
  background: var(--surface-muted);
  border-color: #c4c3bb;
  color: var(--ink);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.btn-primary:hover {
  background: #2c3237;
  border-color: #2c3237;
  color: #fff;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--surface-sunken);
  border-color: transparent;
  color: var(--ink);
}

.btn-block {
  width: 100%;
  height: 40px;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12.5px;
}

.btn-danger {
  color: var(--danger);
  border-color: #e0cfcb;
}

.btn-danger:hover {
  background: #fbf4f2;
  border-color: #d8c0ba;
  color: var(--danger);
}

.link-btn {
  padding: 0;
  color: var(--ink-soft);
  font-size: 13px;
  border-bottom: 1px solid transparent;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.link-btn:hover {
  color: var(--accent);
  border-bottom-color: rgba(47, 93, 80, 0.35);
}

/* ---------- 表单 ---------- */
.field {
  display: block;
}

.field + .field {
  margin-top: 16px;
}

.field > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.input,
.textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0 12px;
  height: 40px;
  font-size: 14px;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.textarea {
  height: auto;
  min-height: 96px;
  padding: 10px 12px;
  line-height: 1.6;
  resize: vertical;
}

.input::placeholder,
.textarea::placeholder {
  color: #b3b6b5;
}

.input:hover,
.textarea:hover {
  border-color: var(--line-strong);
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: #b6b5ad;
  box-shadow: 0 0 0 3px rgba(25, 28, 31, 0.06);
}

.select {
  appearance: auto;
  padding-right: 8px;
  cursor: pointer;
}

.input-sm {
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

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

.form-grid .field + .field {
  margin-top: 0;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.field + .form-grid,
.form-grid + .field,
.form-grid + .form-grid {
  margin-top: 16px;
}

.new-street {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.new-street .input {
  flex: 1;
  height: 34px;
  font-size: 13px;
}

/* 身份多选 */
.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease),
    color 0.15s var(--ease);
}

.tag-toggle img {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  object-fit: cover;
  opacity: 0.8;
}

.tag-toggle:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
  color: var(--ink);
}

.tag-toggle[aria-pressed='true'] {
  border-color: #bfbeb6;
  background: #f4f2ec;
  color: var(--ink);
}

.tag-toggle[aria-pressed='true'] img {
  opacity: 1;
}

.form-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 12.5px;
}

.form-hint {
  color: var(--faint);
  font-size: 12px;
}

/* ---------- 通用块 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

.card-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
}

.empty {
  padding: 26px 16px;
  color: var(--faint);
  font-size: 13px;
  text-align: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 23px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  color: var(--ink-soft);
  font-size: 12px;
  white-space: nowrap;
}

.chip img {
  width: 13px;
  height: 13px;
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(25, 28, 31, 0.07);
}

.chip-plain {
  background: transparent;
  color: var(--muted);
}

/* ---------- 弹层 ---------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 22, 24, 0.34);
  animation: fadeIn 0.16s ease both;
}

.modal-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 620px;
  max-height: 86vh;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 26px 60px -20px rgba(20, 22, 24, 0.32);
  animation: panelIn 0.2s var(--ease) both;
  overflow: hidden;
}

.modal-root.is-closing .modal-backdrop {
  animation: fadeOut 0.14s ease both;
}

.modal-root.is-closing .modal-panel {
  animation: panelOut 0.14s ease both;
}

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

.modal-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

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

.modal-close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin: -3px -4px 0 0;
  border-radius: var(--radius-sm);
  color: var(--faint);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.modal-close:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

.modal-body {
  padding: 18px 20px;
  overflow: auto;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-muted);
}

/* ---------- 提示 ---------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 30px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(25, 28, 31, 0.92);
  color: #f7f6f2;
  font-size: 12.5px;
  box-shadow: 0 10px 24px -12px rgba(20, 22, 24, 0.6);
  animation: toastIn 0.2s var(--ease) both;
}

.toast.is-leaving {
  animation: toastOut 0.18s ease both;
}

.toast-error {
  background: #8d352b;
}

/* ---------- 灯箱 ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(16, 18, 20, 0.86);
  animation: fadeIn 0.16s ease both;
  cursor: zoom-out;
}

.lightbox img {
  max-width: min(1100px, 94vw);
  max-height: 90vh;
  width: auto;
  border-radius: 3px;
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.55);
}

/* ---------- 工具类 ---------- */
.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;
}

.is-hidden {
  display: none !important;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
  }
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
}

@keyframes panelOut {
  to {
    opacity: 0;
    transform: translateY(4px) scale(0.995);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

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

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 640px) {
  .modal-root {
    padding: 0;
    align-items: flex-end;
  }

  .modal-panel {
    max-height: 92vh;
    border-radius: 10px 10px 0 0;
    border-bottom: 0;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-head,
  .modal-foot {
    padding-left: 16px;
    padding-right: 16px;
  }

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

  .form-grid .span-2 {
    grid-column: auto;
  }
}

/* ---------- 基本信息自由条目（住户弹层） ---------- */
.custom-fields {
  display: grid;
  gap: 6px;
}

.custom-field {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) 26px;
  gap: 6px;
  align-items: center;
}

.custom-field .input-sm {
  height: 32px;
}

.custom-field-remove {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: var(--faint);
  font-size: 14px;
  line-height: 1;
}

.custom-field-remove:hover {
  color: var(--danger);
  background: var(--surface-sunken);
}

.custom-field-add {
  margin-top: 6px;
}

/* ---------- 底图弹层 ---------- */
.map-image-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.upload-picker-inline {
  position: relative;
  overflow: hidden;
}

.upload-picker-inline input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

/* ---------- 分区弹层 ---------- */
.zone-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 4px;
}

.zone-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(20, 22, 24, 0.18);
  transition: outline-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.zone-swatch:hover {
  transform: scale(1.08);
}

.zone-swatch[aria-pressed="true"] {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.zone-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1.5px solid var(--zone-line);
  border-radius: var(--radius-sm);
  background: var(--zone-fill);
}

.zone-preview-tag {
  flex: none;
  padding: 1px 7px;
  border-radius: 3px;
  background: var(--zone-ink);
  color: var(--zone-text, #fff);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  line-height: 1.7;
}

.zone-preview-note {
  color: var(--faint);
  font-size: 11.5px;
}

.zone-hint {
  color: var(--muted);
  font-size: 12px;
}

.zone-list {
  margin-top: 10px;
  border-top: 1px solid var(--line);
}

.zone-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.zone-dot {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(20, 22, 24, 0.16);
}

.zone-main {
  flex: 1;
  min-width: 0;
}

.zone-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 13.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone-meta {
  margin-top: 2px;
  color: var(--faint);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.zone-row .link-btn {
  color: var(--muted);
  font-size: 12px;
}

.zone-row .link-btn:hover {
  color: var(--ink);
}

.zone-row .zone-delete:hover {
  color: var(--danger);
}

.zone-empty {
  padding: 16px 0;
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.9;
}

/* 弹层底部左侧的次要动作（如删除） */
.modal-foot-start {
  margin-right: auto;
}
