:root {
  --bg: #f5f5f7;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --text: #1d1d1f;
  --muted: #86868b;
  --line: rgba(0, 0, 0, 0.08);
  --fill: #ececef;          /* iOS grouped input fill */
  --fill-strong: #e3e3e8;
  --accent: #0a84ff;        /* iOS system blue */
  --accent-press: #0060df;
  --danger: #ff3b30;
  --radius-l: 20px;
  --radius-m: 13px;
  --radius-s: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--text); -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- map + top bar ---------- */
#map { position: absolute; top: 60px; bottom: 0; left: 0; right: 0; background: var(--bg); }
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 60px; z-index: 1000;
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: var(--panel); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
/* on desktop the two groups dissolve so all controls share one flex row */
.tb-main, .tb-tools { display: contents; }
.tb-label { display: inline; }

/* brand with gradient logo chip */
.brand { display: flex; align-items: center; gap: 9px; white-space: nowrap; flex-shrink: 0; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-size: 18px;
  background: linear-gradient(135deg, #ff8a5b, #ff3b6b); box-shadow: 0 3px 10px rgba(255, 59, 107, 0.35);
}
.brand .brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }

/* rounded search pill with inline icon */
.tb-search {
  display: flex; align-items: center; gap: 7px; flex: 1; min-width: 90px; max-width: 300px;
  height: 38px; padding: 0 14px; background: var(--fill); border-radius: 999px;
  transition: box-shadow .15s, background .15s;
}
.tb-search:focus-within { background: #fff; box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.25); }
.tb-search .ic { font-size: 14px; opacity: 0.5; flex-shrink: 0; }
.tb-search input { flex: 1; min-width: 0; height: 100%; border: none; background: transparent; outline: none; font-size: 14px; color: var(--text); }

/* pill-shaped selects */
.tb-pill {
  height: 38px; border: none; background: var(--fill); border-radius: 999px;
  padding: 0 14px; font-size: 14px; color: var(--text); outline: none; cursor: pointer;
  transition: box-shadow .15s, background .15s; flex-shrink: 0;
}
.tb-pill:hover { background: var(--fill-strong); }
.tb-pill:focus { box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.25); }

.tb-sep { width: 1px; height: 24px; background: var(--line); flex-shrink: 0; }

/* round icon-only button */
.tb-icon {
  width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 50%;
  background: var(--fill); font-size: 16px; line-height: 1;
  transition: background .15s, transform .05s;
}
.tb-icon:hover { background: var(--fill-strong); }
.tb-icon:active { transform: scale(0.92); }

/* subtle ghost buttons */
.tb-ghost {
  height: 38px; flex-shrink: 0; padding: 0 15px; border: none; border-radius: 999px;
  background: var(--fill); color: var(--text); font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, transform .05s;
}
.tb-ghost:hover { background: var(--fill-strong); }
.tb-ghost:active { transform: scale(0.97); }

/* primary action — gradient */
.tb-primary {
  height: 38px; flex-shrink: 0; padding: 0 17px; border: none; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #0a6cff); color: #fff;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 3px 10px rgba(10, 132, 255, 0.32); transition: filter .15s, transform .05s;
}
.tb-primary:hover { filter: brightness(1.06); }
.tb-primary:active { transform: scale(0.97); }

#empty-state {
  position: absolute; top: 56%; left: 50%; transform: translate(-50%, -50%); z-index: 500;
  color: var(--muted); background: var(--panel); backdrop-filter: blur(10px);
  padding: 18px 24px; border-radius: var(--radius-m); box-shadow: var(--shadow-sm); font-size: 14px;
}

/* ---------- floating side panels (article / changes) ---------- */
.panel {
  position: absolute; top: 72px; right: 14px; width: 380px; max-width: calc(100vw - 28px);
  max-height: calc(100vh - 90px); overflow: auto; z-index: 1100;
  background: var(--panel); backdrop-filter: saturate(180%) blur(24px); -webkit-backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--line); border-radius: var(--radius-l); padding: 20px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; margin: 0 28px 12px 0; }
.close {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; padding: 0; border: none;
  border-radius: 50%; background: var(--fill); color: var(--muted); font-size: 17px; line-height: 1;
}
.close:hover { background: var(--fill-strong); }

/* ---------- editor sheet ---------- */
.backdrop {
  position: absolute; inset: 0; z-index: 1200; display: flex; justify-content: center; align-items: center;
  background: rgba(0, 0, 0, 0.32); backdrop-filter: blur(3px); padding: 16px;
}
.sheet {
  width: 460px; max-width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--panel-solid); border-radius: var(--radius-l); box-shadow: var(--shadow); overflow: hidden;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 12px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.02em; }
.icon-btn {
  width: 30px; height: 30px; border: none; border-radius: 50%; background: var(--fill); color: var(--muted); font-size: 14px;
}
.icon-btn:hover { background: var(--fill-strong); }
.sheet-body { padding: 16px 20px; overflow-y: auto; }
.sheet-foot {
  display: flex; gap: 10px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--line);
}

.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
.field input[type=text], .field input:not([type]), .field input[type=url], .field input[type=search], .field textarea {
  width: 100%; border: none; background: var(--fill); border-radius: var(--radius-s);
  padding: 11px 13px; font-size: 15px; color: var(--text); outline: none; transition: box-shadow .15s;
}
.field input:focus, .field textarea:focus { box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.25); }
.field textarea { resize: vertical; min-height: 96px; line-height: 1.55; }
.field.two-col { display: flex; gap: 12px; }
.field.two-col > div { flex: 1; }
.field.two-col label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }

.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; }

.coords-chip {
  margin: 9px 0 0; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 7px;
  background: var(--fill); padding: 7px 12px; border-radius: 999px;
}
.coords-chip::before { content: "📍"; filter: grayscale(1); opacity: .6; }
.coords-chip.set { color: #1c7c3a; background: rgba(40, 167, 69, 0.12); }
.coords-chip.set::before { filter: none; opacity: 1; }

/* category pills */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  border: none; background: var(--fill); color: var(--text); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 500; transition: all .12s;
}
.pill:hover { background: var(--fill-strong); }
.pill.active { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(10, 132, 255, 0.35); }

.file-btn { display: inline-block; margin-top: 10px; }
.more-toggle {
  border: none; background: none; color: var(--accent); font-size: 14px; font-weight: 500; padding: 4px 0; margin-bottom: 10px;
}
.more-toggle:hover { color: var(--accent-press); }

/* buttons */
.btn-primary {
  border: none; background: var(--accent); color: #fff; border-radius: var(--radius-s);
  padding: 11px 22px; font-size: 15px; font-weight: 600; transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--accent-press); }
.btn-primary:active { transform: scale(0.98); }
.btn-soft {
  border: none; background: var(--fill); color: var(--text); border-radius: var(--radius-s);
  padding: 10px 16px; font-size: 14px; font-weight: 500;
}
.btn-soft:hover { background: var(--fill-strong); }
.btn-text { border: none; background: none; color: var(--accent); font-size: 15px; font-weight: 500; padding: 11px 14px; }
.btn-text:hover { color: var(--accent-press); }
.danger { color: var(--danger) !important; }

/* result lists */
.results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 180px; overflow: auto; }
.results li {
  padding: 10px 12px; border-radius: var(--radius-s); margin-bottom: 6px; cursor: pointer; font-size: 14px;
  background: var(--fill); transition: background .12s;
}
.results li:hover { background: var(--fill-strong); }
.notes { font-size: 12.5px; color: #b8860b; margin-top: 8px; }
.error { color: var(--danger); font-size: 13.5px; margin-top: 6px; }

/* article view */
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.row button { height: 36px; padding: 0 16px; border: none; border-radius: var(--radius-s); background: var(--fill); font-size: 14px; font-weight: 500; }
.row button:hover { background: var(--fill-strong); }
#article-meta { font-size: 13px; color: var(--muted); margin-bottom: 10px; line-height: 1.6; }
.article-body { line-height: 1.65; font-size: 15px; }
.article-body img { max-width: 100%; border-radius: var(--radius-s); margin: 8px 0; }
.jump-link { display: inline-block; margin: 4px 0; color: var(--accent); text-decoration: none; font-weight: 500; }
.jump-link:hover { text-decoration: underline; }
#changes-list { list-style: none; margin: 4px 0 0; padding: 0; }
#changes-list li { padding: 10px 12px; border-radius: var(--radius-s); margin-bottom: 6px; background: var(--fill); cursor: pointer; font-size: 13.5px; }
#changes-list li:hover { background: var(--fill-strong); }

/* group outings (组团) */
#article-groups { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
#article-groups h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.group-form { margin: 8px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.group-form input { flex: 1 1 100px; border: none; background: var(--fill); border-radius: var(--radius-s); padding: 8px 10px; font-size: 14px; outline: none; }
.group-form input:focus { box-shadow: 0 0 0 3px rgba(10,132,255,.25); }
.group-form .btn-primary { padding: 8px 16px; }
.outing { background: var(--fill); border-radius: var(--radius-m); padding: 10px 12px; margin: 8px 0; }
.outing.closed { opacity: .6; }
.outing-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.outing-prog { font-size: 12px; color: var(--accent); white-space: nowrap; }
.outing-parts { font-size: 13px; color: #444; margin-top: 6px; }
/* one participation entry, with hover-revealed edit/delete */
.part { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); }
.part:first-child { border-top: none; }
.part-label { flex: 1; min-width: 0; }
.part-acts { display: flex; gap: 4px; flex-shrink: 0; opacity: 0; transition: opacity .12s; }
.part:hover .part-acts, .part:focus-within .part-acts { opacity: 1; }
.icon-mini {
  width: 26px; height: 26px; border: none; border-radius: 7px; background: var(--fill-strong);
  color: var(--muted); font-size: 13px; line-height: 1; padding: 0;
}
.icon-mini:hover { background: #d9d9e0; color: var(--text); }
.icon-mini.danger:hover { background: var(--danger); color: #fff; }
.part-edit { margin: 2px 0 4px; }
.part-empty { color: var(--muted); padding: 4px 0; }
/* touch devices have no hover — always show the actions */
@media (hover: none) { .part-acts { opacity: 1; } }
.outing-when-row { margin-top: 4px; }
.outing-when { font-size: 12.5px; color: var(--accent); }
.outing.is-expired { opacity: .62; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; vertical-align: middle; }
.tag.soon { background: rgba(40,167,69,.14); color: #1c7c3a; }
.tag.expired { background: rgba(142,142,147,.18); color: #6b6b70; }
.tag.closed { background: rgba(255,59,48,.12); color: var(--danger); }
.pop-grp { display: inline-block; margin: 4px 0; color: #e67e22; font-weight: 600; font-size: 13px; }
/* filter chips in the 约局 panel */
.filter-bar { display: flex; gap: 6px; margin-bottom: 10px; }
.chip { border: none; background: var(--fill); color: var(--text); border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 500; }
.chip.active { background: var(--accent); color: #fff; }
/* active-group badge on a map pin */
.tsmap-pin .pin-badge {
  position: absolute; top: -6px; right: -8px; font-style: normal; font-size: 14px;
  background: #fff; border-radius: 50%; width: 18px; height: 18px; line-height: 18px; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.35); z-index: 2;
}
/* Featured pin — places with an active 团 (never clustered, prominent) */
.tsmap-pin.featured .pin.big { width: 38px; height: 38px; border-width: 3px; }
.tsmap-pin.featured .pin.big span { font-size: 18px; }
.tsmap-pin.featured .pin-badge { top: -4px; right: -10px; width: 20px; height: 20px; line-height: 20px; font-size: 15px; }
.tsmap-pin.featured .pulse {
  position: absolute; left: 20px; top: 19px; width: 8px; height: 8px; transform: translate(-50%, -50%);
  border-radius: 50%; background: rgba(230,126,34,.55); animation: tsmap-pulse 1.6s ease-out infinite; z-index: 0;
}
@keyframes tsmap-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(230,126,34,.55); }
  70%  { box-shadow: 0 0 0 18px rgba(230,126,34,0); }
  100% { box-shadow: 0 0 0 0 rgba(230,126,34,0); }
}
.featured-label { font-weight: 700; color: #c0392b; }

/* category-colored teardrop markers */
.tsmap-pin { background: transparent; border: none; }
.tsmap-pin .pin {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.35); display: flex; align-items: center; justify-content: center; border: 2.5px solid #fff;
}
.tsmap-pin .pin span { transform: rotate(45deg); font-size: 14px; line-height: 1; }
/* brief bounce when the map is navigated to a pin (shared 团 link, panels, etc.).
   translateY is applied outside rotate(-45deg) so it moves vertically in screen space
   while keeping the teardrop shape. */
@keyframes pinBounce {
  0%, 100% { transform: translateY(0) rotate(-45deg); }
  30%      { transform: translateY(-13px) rotate(-45deg) scale(1.06); }
  60%      { transform: translateY(-5px) rotate(-45deg); }
}
.tsmap-pin.pin-flash .pin { animation: pinBounce .6s ease 2; }
.tsmap-pin.pin-flash { z-index: 1200 !important; }
/* marker name labels — bound on demand (viewport + zoom) by updateLabels() for perf */
.leaflet-tooltip.marker-label {
  background: #fff; color: #1d1d1f; font-weight: 600; font-size: 12px;
  border: none; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.2); padding: 3px 8px; white-space: nowrap;
}
.leaflet-tooltip.marker-label::before { display: none; }   /* hide the little arrow */

/* Leaflet chrome refinements */
.leaflet-popup-content-wrapper { border-radius: var(--radius-m) !important; box-shadow: var(--shadow) !important; }
.leaflet-popup-content { margin: 14px 16px !important; font-size: 14px; line-height: 1.5; }
.leaflet-popup-content strong { font-size: 15px; }
.leaflet-popup-content .popup-view {
  margin-top: 8px; border: none; background: var(--accent); color: #fff; border-radius: 8px; padding: 7px 13px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.leaflet-tooltip { border-radius: 8px !important; border: none !important; box-shadow: var(--shadow-sm) !important; font-size: 12.5px !important; font-weight: 500; padding: 5px 9px !important; }
.leaflet-control-layers { border-radius: var(--radius-s) !important; box-shadow: var(--shadow-sm) !important; border: 1px solid var(--line) !important; }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  /* top bar becomes two rows: [logo + search]  /  [scrollable tools] */
  /* solid bg (no backdrop-filter) so the fixed FAB anchors to the viewport, not the bar */
  #topbar {
    height: 100px; flex-direction: column; align-items: stretch; gap: 8px; padding: 8px 12px;
    background: rgba(255, 255, 255, 0.97); backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tb-main, .tb-tools { display: flex; align-items: center; gap: 8px; }
  .tb-main { width: 100%; }
  .brand-name { display: none; }
  .tb-search { flex: 1; max-width: none; }
  /* the tools row scrolls sideways instead of overflowing */
  .tb-tools { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tb-tools::-webkit-scrollbar { display: none; }
  .tb-sep { display: none; }

  #map { top: 100px; }
  .panel { top: 108px; left: 8px; right: 8px; width: auto; max-width: none; overflow-x: hidden; max-height: calc(100vh - 120px); padding: 16px; }
  /* let the headcount badge wrap under the title instead of overflowing on narrow screens */
  .outing-head { flex-wrap: wrap; }
  .part-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .part-acts { opacity: 1; }

  /* 新增 collapses into a floating action button */
  .tb-primary {
    position: fixed; bottom: 20px; right: 16px; z-index: 1150;
    width: 56px; height: 56px; padding: 0; border-radius: 50%; font-size: 26px;
    box-shadow: 0 6px 20px rgba(10, 132, 255, 0.45);
  }
  .tb-label { display: none; }

  /* editor + sheets slide up from the bottom (native feel) */
  .backdrop { align-items: flex-end; padding: 0; }
  .sheet { width: 100%; max-width: none; max-height: 92vh; border-radius: var(--radius-l) var(--radius-l) 0 0; }
}

/* very narrow phones: tighten the tools row */
@media (max-width: 380px) {
  .tb-ghost { padding: 0 12px; }
  .tb-pill { padding: 0 11px; }
}
