:root {
  color-scheme: light;
  --red-950: #451419;
  --red-900: #5f1920;
  --red-800: #7b1f27;
  --red-700: #9c2c34;
  --gold-500: #c89b4b;
  --gold-200: #ead7ad;
  --ink-950: #201b19;
  --ink-700: #5f5752;
  --ink-500: #8a817b;
  --paper: #fbf8f2;
  --paper-soft: #f4eee4;
  --line: rgba(69, 20, 25, 0.12);
  --shadow: 0 16px 44px rgba(35, 18, 12, 0.16);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink-950);
  background: #d8d2c7;
}

button, input, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app-shell, .map-shell, #map {
  position: relative;
  width: 100%;
  height: 100%;
}

#map { z-index: 1; background: #e8e3d8; }

.leaflet-container {
  font-family: inherit;
  background: #e8e3d8;
}

.leaflet-control-attribution {
  margin: 0 6px 6px 0 !important;
  padding: 3px 7px !important;
  border-radius: 7px;
  color: var(--ink-500);
  background: rgba(251, 248, 242, 0.82) !important;
  backdrop-filter: blur(12px);
}

.leaflet-control-zoom { display: none; }

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--red-900);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .04em;
  background: #eee8dd;
  transition: opacity .35s ease, visibility .35s ease;
}

.map-loading.is-hidden { opacity: 0; visibility: hidden; }

.loading-mark {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(123, 31, 39, .18);
  border-top-color: var(--red-800);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.top-card {
  position: absolute;
  z-index: 500;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  padding: 15px 14px 11px;
  border: 1px solid rgba(255, 255, 255, .78);
  border-radius: 22px;
  background: rgba(251, 248, 242, .94);
  box-shadow: 0 10px 30px rgba(39, 25, 19, .13);
  backdrop-filter: blur(18px) saturate(1.1);
}

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

.brand-mark {
  position: relative;
  flex: 0 0 auto;
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--red-700), var(--red-950));
  box-shadow: 0 7px 16px rgba(123, 31, 39, .23);
}

.brand-mark::before,
.brand-mark::after,
.brand-mark span::before,
.brand-mark span::after,
.brand-mark span {
  content: "";
  position: absolute;
  width: 3px;
  height: 17px;
  border-radius: 3px;
  background: #f3dca7;
  transform-origin: 50% 100%;
}
.brand-mark::before { transform: rotate(-72deg); }
.brand-mark::after { transform: rotate(-36deg); }
.brand-mark span { transform: rotate(0deg); }
.brand-mark span::before { transform: rotate(36deg); transform-origin: 50% 100%; }
.brand-mark span::after { transform: rotate(72deg); transform-origin: 50% 100%; }

.eyebrow {
  margin: 0 0 2px;
  color: var(--red-700);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.brand-row h1 { margin: 0; font-size: 18px; line-height: 1.25; letter-spacing: .02em; }

.icon-button,
.locate-button,
.map-fab,
.detail-close {
  display: grid;
  place-items: center;
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 36px;
  height: 36px;
  margin-left: auto;
  border-radius: 12px;
  background: transparent;
}

.icon-button svg,
.locate-button svg,
.map-fab svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search-row { display: flex; gap: 8px; margin-top: 12px; }

.search-box {
  flex: 1;
  min-width: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.search-box:focus-within { border-color: rgba(123, 31, 39, .42); box-shadow: 0 0 0 3px rgba(123, 31, 39, .08); }
.search-box svg { width: 19px; height: 19px; flex: 0 0 auto; fill: none; stroke: var(--ink-500); stroke-width: 1.8; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 14px; color: var(--ink-950); }
.search-box input::placeholder { color: #a29992; }

.clear-search {
  display: none;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  color: #796f69;
  background: #eee8e0;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.clear-search.is-visible { display: block; }

.locate-button {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 14px;
  color: #fff;
  background: var(--red-800);
  box-shadow: 0 6px 14px rgba(123, 31, 39, .23);
}
.locate-button.is-loading svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; transform: scale(.82); } }

.filter-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.filter-meta strong { font-size: 12px; color: var(--ink-700); }
.text-filter { padding: 4px 8px; border: 0; border-radius: 8px; color: var(--ink-500); background: transparent; font-size: 12px; cursor: pointer; }
.text-filter[aria-pressed="true"] { color: var(--red-800); background: #f3e4df; font-weight: 700; }

.town-filters {
  display: flex;
  gap: 7px;
  margin: 8px -14px -2px;
  padding: 2px 14px 5px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.town-filters::-webkit-scrollbar { display: none; }

.town-chip {
  flex: 0 0 auto;
  min-height: 31px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-700);
  background: rgba(255,255,255,.82);
  font-size: 12px;
  white-space: nowrap;
  scroll-snap-align: start;
  cursor: pointer;
}
.town-chip span { margin-left: 3px; color: var(--ink-500); font-variant-numeric: tabular-nums; }
.town-chip.is-active { border-color: var(--red-800); color: #fff; background: var(--red-800); box-shadow: 0 5px 12px rgba(123, 31, 39, .18); }
.town-chip.is-active span { color: rgba(255,255,255,.74); }

.map-fab {
  position: absolute;
  right: 14px;
  bottom: 244px;
  z-index: 450;
  width: 44px;
  height: 44px;
  border-radius: 15px;
  color: var(--red-800);
  background: rgba(251, 248, 242, .96);
  box-shadow: 0 9px 22px rgba(39, 25, 19, .18);
  transition: bottom .28s ease;
}

.result-panel {
  position: absolute;
  z-index: 600;
  left: 8px;
  right: 8px;
  bottom: max(8px, env(safe-area-inset-bottom));
  height: 220px;
  padding: 0 10px 10px;
  border: 1px solid rgba(255,255,255,.78);
  border-radius: 24px;
  background: rgba(251, 248, 242, .97);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
  transition: height .28s cubic-bezier(.22,.8,.25,1);
}
.result-panel.is-expanded { height: min(68vh, 610px); }

.panel-handle { width: 100%; height: 24px; display: grid; place-items: center; border: 0; background: transparent; cursor: pointer; }
.panel-handle span { width: 40px; height: 4px; border-radius: 999px; background: #d8d0c7; }

.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 7px 9px; }
.panel-heading h2 { margin: 0; font-size: 17px; }
.count-badge { min-width: 32px; padding: 5px 8px; border-radius: 999px; color: var(--red-800); background: #f1e1dc; font-size: 12px; font-weight: 800; text-align: center; }

.facility-list { height: calc(100% - 64px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }

.facility-item {
  width: 100%;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px 8px;
  border: 0;
  border-top: 1px solid var(--line);
  text-align: left;
  background: transparent;
  cursor: pointer;
}
.facility-item:first-child { border-top: 0; }
.facility-item:active { background: #f4ece4; }

.facility-index { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 12px; color: var(--red-800); background: #f3e4df; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.facility-main { min-width: 0; }
.facility-name { display: block; margin-bottom: 4px; overflow: hidden; color: var(--ink-950); font-size: 14px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.facility-address { display: block; overflow: hidden; color: var(--ink-500); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.facility-status { align-self: start; margin-top: 3px; padding: 3px 6px; border-radius: 6px; color: #44715a; background: #e8f1eb; font-size: 10px; white-space: nowrap; }
.facility-status.is-unmapped { color: #946c36; background: #f7edda; }

.empty-state { padding: 26px 0; color: var(--ink-500); text-align: center; font-size: 13px; }

.detail-panel { position: fixed; inset: 0; z-index: 1000; visibility: hidden; }
.detail-panel.is-open { visibility: visible; }
.detail-scrim { position: absolute; inset: 0; background: rgba(32, 27, 25, .38); opacity: 0; transition: opacity .25s ease; }
.detail-panel.is-open .detail-scrim { opacity: 1; }

.detail-card {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: max(8px, env(safe-area-inset-bottom));
  max-height: min(76vh, 720px);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 26px;
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(36, 20, 18, .28);
  transform: translateY(calc(100% + 24px));
  transition: transform .3s cubic-bezier(.22,.8,.25,1);
  overflow: hidden;
}
.detail-panel.is-open .detail-card { transform: translateY(0); }

.detail-close { position: absolute; z-index: 2; top: 13px; right: 13px; width: 34px; height: 34px; border-radius: 50%; color: var(--ink-700); background: #eee7de; font-size: 23px; }
.detail-scroll { padding: 24px 20px 20px; overflow-y: auto; }
.detail-scroll h2 { margin: 5px 46px 8px 0; font-size: 22px; line-height: 1.35; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-tags span { padding: 5px 8px; border-radius: 7px; color: var(--red-800); background: #f2e2de; font-size: 11px; }
.detail-tags span:last-child { color: #51705f; background: #e7f0ea; }
.detail-tags span:last-child.is-unmapped { color: #946c36; background: #f7edda; }

.detail-list { margin: 18px 0 0; }
.detail-list div { display: grid; grid-template-columns: 68px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.detail-list dt { color: var(--ink-500); font-size: 12px; }
.detail-list dd { margin: 0; color: var(--ink-700); font-size: 13px; line-height: 1.55; }
.detail-list a { color: var(--red-700); text-decoration: none; font-weight: 700; }

.description-section { padding-top: 5px; border-top: 1px solid var(--line); }
.description-section h3 { margin: 10px 0 7px; font-size: 14px; }
.description-section p, .about-lead, .about-note { margin: 0; color: var(--ink-700); font-size: 13px; line-height: 1.75; }

.detail-actions { display: grid; grid-template-columns: .8fr 1.2fr; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(251,248,242,.97); }
.detail-actions button, .detail-actions a { min-height: 46px; display: grid; place-items: center; border-radius: 14px; font-size: 14px; font-weight: 800; text-decoration: none; cursor: pointer; }
.secondary-action { border: 1px solid rgba(123,31,39,.18); color: var(--red-800); background: #fff; }
.primary-action { border: 0; color: #fff; background: linear-gradient(135deg, var(--red-700), var(--red-900)); box-shadow: 0 8px 18px rgba(123,31,39,.22); }

.about-card .detail-scroll { padding-bottom: 28px; }
.about-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.about-stat { padding: 13px 8px; border-radius: 14px; background: var(--paper-soft); text-align: center; }
.about-stat strong { display: block; color: var(--red-800); font-size: 20px; font-variant-numeric: tabular-nums; }
.about-stat span { display: block; margin-top: 2px; color: var(--ink-500); font-size: 10px; }
.about-note { padding: 13px 14px; border-left: 3px solid var(--gold-500); border-radius: 0 10px 10px 0; background: #f6efe2; }

.toast { position: fixed; z-index: 1500; left: 50%; bottom: calc(238px + env(safe-area-inset-bottom)); max-width: calc(100% - 40px); padding: 10px 14px; border-radius: 12px; color: #fff; background: rgba(32,27,25,.9); box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 12px; opacity: 0; pointer-events: none; transform: translate(-50%, 10px); transition: opacity .2s ease, transform .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.marker-dot { width: 18px; height: 18px; border: 3px solid #fff; border-radius: 50%; background: var(--red-800); box-shadow: 0 3px 9px rgba(69,20,25,.34); }
.marker-dot.is-selected { width: 24px; height: 24px; border-width: 4px; background: var(--gold-500); box-shadow: 0 0 0 5px rgba(200,155,75,.2), 0 4px 12px rgba(69,20,25,.35); }
.leaflet-tooltip { padding: 7px 9px; border: 0; border-radius: 9px; color: var(--ink-950); background: rgba(251,248,242,.97); box-shadow: 0 6px 18px rgba(30,20,16,.14); font-size: 12px; font-weight: 700; }
.leaflet-tooltip::before { display: none; }

@media (min-width: 760px) {
  .top-card { right: auto; width: 400px; top: 18px; left: 18px; }
  .result-panel { top: 275px; bottom: 18px; left: 18px; right: auto; width: 400px; height: auto; border-radius: 22px; }
  .result-panel.is-expanded { height: auto; }
  .panel-handle { display: none; }
  .panel-heading { padding-top: 15px; }
  .facility-list { height: calc(100% - 60px); }
  .map-fab { right: 24px; bottom: 28px; }
  .detail-card, .about-card { left: auto; right: 22px; bottom: 22px; width: 430px; max-height: calc(100vh - 44px); }
  .toast { bottom: 28px; }
}

@media (max-width: 380px) {
  .top-card { top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; padding-top: 12px; }
  .brand-row h1 { font-size: 16px; }
  .result-panel { left: 6px; right: 6px; }
  .map-fab { right: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
