:root {
  --ink: #14232b;
  --muted: #5b6b73;
  --line: #e3e0d8;
  --paper: #fbfaf7;
  --accent: #0d6e6e;
  --open: #17824f;
  --customers: #b86e00;
  --closed: #c0392b;
  --unknown: #667085;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(20, 35, 43, 0.16);
  --top: max(10px, env(safe-area-inset-top));
  --sheet-h: 168px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }
#app.sheet-open { --sheet-h: 62dvh; }

/* ---------- map ---------- */
.mapwrap { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: #e8e6df; z-index: 0; }
.leaflet-container { font: inherit; }
.leaflet-bottom { bottom: var(--sheet-h); transition: bottom 0.28s ease; }
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution { font-size: 11px; }

.pin { background: none; border: 0; }
.pin svg { display: block; transform-origin: 50% 100%; transition: transform 0.15s ease; filter: drop-shadow(0 2px 3px rgba(20, 35, 43, 0.35)); }
.pin-selected svg { transform: scale(1.35); }
.pin-mine::after {
  content: ""; position: absolute; right: -3px; top: -3px; width: 11px; height: 11px;
  border-radius: 50%; background: #1d4ed8; border: 2px solid #fff;
}
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1d6fe8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(29, 111, 232, 0.22); }

.crosshair { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; z-index: 500; display: none; }
#app.placing .crosshair { display: block; }

.placebar {
  position: absolute; left: 10px; right: 10px; bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 1200; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; max-width: 460px; margin: 0 auto;
}
.placebar p { margin: 0 0 12px; font-weight: 600; }

/* ---------- top bar ---------- */
.topbar {
  position: absolute; top: var(--top); left: 10px; right: 10px; z-index: 1100;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 10px;
  min-height: 52px; padding: 8px 10px 10px 10px;
  background: rgba(255, 255, 255, 0.96); border-radius: var(--radius); box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { flex: none; }
.brand h1 { margin: 0; font-size: 17px; line-height: 1.15; letter-spacing: -0.01em; }
.brand p { margin: 0; font-size: 13px; color: var(--muted); }
.lang { display: flex; flex: none; background: #f1efe9; border-radius: 10px; padding: 3px; }
.lang button { border: 0; background: none; border-radius: 8px; padding: 6px 9px; font-size: 13px; font-weight: 600; color: var(--muted); min-height: 32px; }
.lang button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(20, 35, 43, 0.18); }

/* ---------- address search ---------- */
.search { flex: 0 0 100%; display: flex; align-items: center; gap: 6px; background: #f1efe9; border-radius: 12px; padding: 0 4px 0 12px; }
.search:focus-within { box-shadow: 0 0 0 2px var(--accent); background: #fff; }
.search input { flex: 1; min-width: 0; height: 42px; border: 0; background: none; font-size: 16px; outline: none; }
.search input:focus-visible { outline: none; }
.search input::placeholder { color: var(--muted); }
.search button { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 0; border-radius: 10px; background: none; color: var(--muted); }
.search .q-go { background: var(--accent); color: #fff; }
.search.busy .q-go svg { animation: pulse 1s ease-in-out infinite; }
.results { flex: 0 0 100%; list-style: none; margin: 0; padding: 0; max-height: 46dvh; overflow-y: auto; }
.results button { display: block; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; padding: 10px 4px; }
.results b { display: block; font-weight: 600; }
.results span { display: block; font-size: 13.5px; color: var(--muted); }
.origin-dot { width: 22px; height: 22px; border-radius: 50%; background: #14232b; border: 4px solid #fff; box-shadow: 0 0 0 2px #14232b, 0 3px 8px rgba(20, 35, 43, 0.4); }

/* ---------- filters ---------- */
.filters {
  position: absolute; top: calc(var(--top) + 114px); left: 0; right: 0; z-index: 1090;
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 10px 10px; scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 13px;
  border-radius: 18px; border: 1px solid var(--line); background: #fff; font-size: 14px; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(20, 35, 43, 0.12);
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip[aria-pressed="true"] .n { color: rgba(255, 255, 255, 0.72); }
.chip[aria-pressed="true"] .dot { box-shadow: 0 0 0 2px #fff; }

/* ---------- sheet ---------- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--sheet-h); z-index: 1100;
  display: flex; flex-direction: column; background: #fff; border-radius: 18px 18px 0 0;
  box-shadow: 0 -6px 24px rgba(20, 35, 43, 0.16); transition: height 0.28s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
.handle { flex: none; display: block; width: 100%; height: 24px; border: 0; background: none; padding: 0; }
.handle span { display: block; width: 40px; height: 4px; border-radius: 2px; background: #cfcbc0; margin: 0 auto; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px 18px; }
#app:not(.sheet-open) .sheet-body { overflow: hidden; }

.list-head { display: flex; flex-direction: column; gap: 1px; padding: 0 2px 8px; }
.list-head strong { font-size: 17px; }
.list-head span { font-size: 13px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: 0;
  border-top: 1px solid var(--line); padding: 11px 2px; min-height: 62px;
}
.row .mini { flex: none; width: 30px; display: flex; justify-content: center; }
.row .txt { flex: 1; min-width: 0; }
.row .name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { display: block; font-size: 13.500px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub b { font-weight: 600; }
.row .dist { flex: none; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.a-open { color: var(--open); }
.a-customers { color: var(--customers); }
.a-closed { color: var(--closed); }
.a-unknown { color: var(--unknown); }
.empty, .foot { color: var(--muted); font-size: 13px; padding: 14px 2px 0; margin: 0; }
.foot { border-top: 1px solid var(--line); }
.foot a { color: inherit; }

/* ---------- detail ---------- */
.linkbtn { border: 0; background: none; padding: 6px 0 10px; color: var(--accent); font-weight: 600; font-size: 14px; }
.detail h2, .form h2 { margin: 0 0 2px; font-size: 21px; line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.detail .kind { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 12px; font-weight: 700; color: #fff; font-size: 16px; }
.badge.b-open { background: var(--open); }
.badge.b-customers { background: var(--customers); }
.badge.b-closed { background: var(--closed); }
.badge.b-unknown { background: var(--unknown); }
.facts { margin: 14px 0 0; padding: 0; }
.facts div { display: flex; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.facts dt { flex: none; width: 108px; color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.source { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1 1 auto; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: #fff; font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--closed); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-quiet { flex: 0 0 100%; border: 0; min-height: 36px; color: var(--muted); font-weight: 500; font-size: 14px; }

/* ---------- form ---------- */
.form .field { margin-top: 16px; }
.form label, .form .label { display: block; font-weight: 600; font-size: 14.500px; margin-bottom: 7px; }
.form input[type="text"], .form textarea {
  width: 100%; border: 1px solid #cfcbc0; border-radius: 12px; padding: 11px 12px; background: #fff; font-size: 16px;
}
.form textarea { min-height: 76px; resize: vertical; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  flex: 1 1 auto; min-height: 44px; padding: 8px 12px; border-radius: 12px; border: 1px solid #cfcbc0; background: #fff;
  text-align: center; font-size: 15px;
}
.seg.col { flex-direction: column; }
.seg.col button { text-align: left; }
.seg button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.notice { margin: 16px 0 0; padding: 10px 12px; background: #f1efe9; border-radius: 12px; font-size: 13.500px; color: #3f4d54; }

/* ---------- floating buttons ---------- */
.fabs {
  position: absolute; right: 12px; bottom: calc(var(--sheet-h) + 14px); z-index: 1050;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px; transition: bottom 0.28s ease, opacity 0.2s ease;
}
.fab {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; min-width: 48px; padding: 0;
  border-radius: 24px; border: 0; background: #fff; color: var(--ink); box-shadow: var(--shadow);
}
.fab.busy svg { animation: pulse 1s ease-in-out infinite; }
.fab.on { color: #1d6fe8; }
.fab-primary { background: var(--accent); color: #fff; padding: 0 16px 0 13px; font-weight: 600; font-size: 15px; }
@keyframes pulse { 50% { opacity: 0.35; } }

.toast {
  position: absolute; left: 50%; top: calc(var(--top) + 168px); transform: translateX(-50%); z-index: 1300;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: min(88vw, 420px);
  box-shadow: var(--shadow); text-align: center;
}

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid #1d6fe8; outline-offset: 2px; }

/* ---------- phone only ---------- */
@media (max-width: 899px) {
  #app.sheet-open .fabs { opacity: 0; pointer-events: none; }
  #app.placing .sheet, #app.placing .filters { display: none; }
  #app.placing { --sheet-h: 0px; }
}
#app.placing .fabs { display: none; }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 400px minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); background: #fff; }
  .mapwrap { position: relative; inset: auto; grid-column: 2; grid-row: 1 / -1; border-left: 1px solid var(--line); }
  .topbar, .filters, .sheet { position: static; grid-column: 1; box-shadow: none; border-radius: 0; }
  .topbar { grid-row: 1; padding: 18px 20px 12px; background: #fff; }
  .brand h1 { font-size: 20px; }
  .filters { grid-row: 2; flex-wrap: wrap; overflow: visible; padding: 2px 20px 16px; border-bottom: 1px solid var(--line); }
  .chip { box-shadow: none; }
  .sheet { grid-row: 3; height: auto; min-height: 0; transition: none; padding-bottom: 0; }
  .handle { display: none; }
  .sheet-body, #app:not(.sheet-open) .sheet-body { overflow-y: auto; padding: 16px 20px 24px; }
  .row:hover { background: #f7f5f0; }
  .fabs { right: 16px; bottom: 30px; }
  .leaflet-bottom { bottom: 0; }
  .leaflet-control-zoom { display: block; }
  .toast { left: calc(400px + (100% - 400px) / 2); top: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
