/* ============================================================
   v2 — «Тихая роскошь»
   Нейтральная палитра, монохромный акцент, воздух, мягкие тени.
   Тема (light/dark) зеркалит Telegram через [data-theme] на :root.
   Палитра — собственная (не зависит от --tg-theme-*),
   чтобы вид всегда был выверенным.
   ============================================================ */

:root, :root[data-theme="light"] {
  /* фоны и поверхности */
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #ffffff;
  --elev: #ffffff;

  /* текст */
  --text: #15151a;
  --text-2: #5b5b63;
  --text-3: #9a9aa2;

  /* линии и акцент */
  --hairline: rgba(18,18,24,.09);
  --hairline-strong: rgba(18,18,24,.14);
  --accent: #16161a;          /* монохромный «чернильный» акцент */
  --accent-text: #ffffff;
  --link: #1f6feb;

  /* маркеры (независимы от темы Telegram) */
  --marker-surface: #ffffff;
  --marker-text: #15151a;
  --marker-ring: rgba(18,18,24,.10);

  /* тени — многослойные, мягкие */
  --shadow-1: 0 1px 2px rgba(18,18,24,.05), 0 1px 1px rgba(18,18,24,.03);
  --shadow-2: 0 2px 6px rgba(18,18,24,.06), 0 8px 20px rgba(18,18,24,.08);
  --shadow-3: 0 4px 12px rgba(18,18,24,.08), 0 18px 48px rgba(18,18,24,.16);

  --scrim: rgba(20,20,26,.34);
}

:root[data-theme="dark"] {
  --bg: #0e0f11;
  --surface: #1a1b1f;
  --surface-2: #212328;
  --elev: #202227;

  --text: #f4f4f6;
  --text-2: #a6a6ae;
  --text-3: #6d6d76;

  --hairline: rgba(255,255,255,.10);
  --hairline-strong: rgba(255,255,255,.16);
  --accent: #f4f4f6;          /* в тёмной — почти белый «ink» */
  --accent-text: #15151a;
  --link: #5aa2ff;

  --marker-surface: #24262b;
  --marker-text: #f4f4f6;
  --marker-ring: rgba(255,255,255,.14);

  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 2px 8px rgba(0,0,0,.45), 0 10px 28px rgba(0,0,0,.5);
  --shadow-3: 0 6px 18px rgba(0,0,0,.5), 0 22px 60px rgba(0,0,0,.62);

  --scrim: rgba(0,0,0,.55);
}

:root {
  /* геометрия */
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 26px;
  --r-pill: 999px;
  --ease: cubic-bezier(.22,.61,.36,1);
  --ease-spring: cubic-bezier(.2,.8,.2,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.01em;
}

/* ===================== Топбар ===================== */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1000;
  display: flex; gap: 10px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 12px;
  background: linear-gradient(var(--bg) 38%, color-mix(in srgb, var(--bg) 60%, transparent) 72%, rgba(0,0,0,0));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

#searchWrap {
  flex: 1; display: flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-md); box-shadow: var(--shadow-1);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
#searchWrap:focus-within {
  border-color: var(--hairline-strong);
  box-shadow: var(--shadow-2);
}
.search-ic { flex: 0 0 20px; color: var(--text-3); display: block; }
#search {
  flex: 1; min-width: 0; height: 100%; border: none; outline: none;
  background: transparent; color: var(--text);
  font-family: inherit; font-size: 16px; letter-spacing: -0.01em;
}
#search::placeholder { color: var(--text-3); }
#search::-webkit-search-cancel-button { -webkit-appearance: none; }

#themeBtn, #filterBtn {
  width: 46px; height: 46px; flex: 0 0 46px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--hairline); border-radius: var(--r-md);
  background: var(--surface); color: var(--text-2);
  box-shadow: var(--shadow-1); cursor: pointer; font-size: 19px; line-height: 1;
  transition: transform .08s var(--ease), box-shadow .18s var(--ease), color .18s var(--ease);
}
#themeBtn:active, #filterBtn:active { transform: scale(.94); }
.filter-ic, .search-ic { pointer-events: none; }

/* ===================== Чипы-фильтры ===================== */
#chips {
  position: absolute; top: calc(env(safe-area-inset-top) + 66px); left: 0; right: 0;
  z-index: 1000; display: flex; gap: 8px; overflow-x: auto;
  padding: 4px 14px 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
#chips::-webkit-scrollbar { display: none; }
#chips.hidden { display: none; }

.chip {
  flex: 0 0 auto; height: 38px; display: inline-flex; align-items: center; gap: 8px;
  padding: 0 14px 0 5px; border-radius: var(--r-pill);
  border: 1px solid var(--hairline); background: var(--surface); color: var(--text-2);
  font-family: inherit; font-size: 13.5px; font-weight: 500; letter-spacing: -0.01em;
  cursor: pointer; user-select: none; box-shadow: var(--shadow-1);
  transition: color .16s var(--ease), border-color .16s var(--ease),
              box-shadow .16s var(--ease), transform .08s var(--ease), opacity .16s var(--ease);
}
.chip:not(.on) { opacity: .66; }
.chip:active { transform: scale(.95); }
.chip.on {
  color: var(--text); opacity: 1; border-color: transparent;
  box-shadow: var(--shadow-2), 0 0 0 1.5px color-mix(in srgb, var(--cc) 42%, transparent);
}
.chip-ic {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1;
  background: color-mix(in srgb, var(--cc) 16%, var(--surface));
  transition: background .16s var(--ease);
}
.chip.on .chip-ic { background: color-mix(in srgb, var(--cc) 26%, var(--surface)); }
.chip-lb { white-space: nowrap; }
.chip-ct {
  font-size: 11.5px; font-weight: 600; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.chip.on .chip-ct { color: var(--text-2); }

/* ===================== Карта ===================== */
#map { position: absolute; inset: 0; z-index: 1; background: var(--bg); }

.marker-wrap { position: absolute; width: 0; height: 0; }

/* атрибуция MapLibre — обязательна, делаем деликатной */
.maplibregl-ctrl-attribution {
  font-size: 10px; opacity: .55;
  background: color-mix(in srgb, var(--surface) 70%, transparent) !important;
  border-radius: 8px 0 0 0;
}
.maplibregl-ctrl-attribution a { color: var(--text-3); }
.maplibregl-ctrl-bottom-right { z-index: 900; }

/* пин-маркер: аккуратный круг на поверхности темы, тонкое кольцо цвета категории */
.pin {
  position: absolute; left: 0; top: 0;
  width: 34px; height: 34px; border-radius: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  background: var(--marker-surface);
  box-shadow:
    0 0 0 1px var(--marker-ring),
    0 0 0 3px color-mix(in srgb, var(--pin) 60%, transparent),
    0 4px 12px rgba(0,0,0,.18);
  transition: transform .14s var(--ease-spring), box-shadow .14s var(--ease);
  cursor: pointer;
}
.pin:active { transform: translate(-50%, -50%) scale(.9); }
.pin span { font-size: 16px; line-height: 1; }

/* выбранный пин: крупнее, мягкое свечение цвета категории */
.pin.is-active {
  transform: translate(-50%, -50%) scale(1.18);
  background: var(--marker-surface);
  box-shadow:
    0 0 0 1px var(--marker-ring),
    0 0 0 3px color-mix(in srgb, var(--pin) 90%, transparent),
    0 0 0 9px color-mix(in srgb, var(--pin) 20%, transparent),
    0 8px 22px rgba(0,0,0,.26);
}
.pin.is-active:active { transform: translate(-50%, -50%) scale(1.12); }

/* мягкое появление маркеров (только при загрузке/смене фильтра) */
@keyframes markerIn {
  from { opacity: 0; transform: translate(-50%, -38%) scale(.6); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.pin.spawn, .cluster.spawn {
  animation: markerIn .34s var(--ease-spring) both;
}

/* кластер: чистый круг с числом, нейтральное кольцо */
.cluster {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -50%);
  min-width: 40px; height: 40px; padding: 0 12px; border-radius: var(--r-pill);
  display: flex; align-items: center; justify-content: center;
  background: var(--marker-surface); color: var(--marker-text);
  font-family: inherit; font-size: 14px; font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  box-shadow:
    0 0 0 1px var(--marker-ring),
    0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent),
    0 5px 16px rgba(0,0,0,.2);
  cursor: pointer; transition: transform .14s var(--ease-spring);
}
.cluster:active { transform: translate(-50%, -50%) scale(.92); }

/* ===================== Нижняя карточка ===================== */
#scrim {
  position: absolute; inset: 0; z-index: 1500; background: var(--scrim);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  opacity: 1; transition: opacity .28s var(--ease);
}
#scrim.hidden { opacity: 0; pointer-events: none; }

#sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1600;
  background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  padding: 0 20px;
  max-height: 86vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateY(0); transition: transform .34s var(--ease-spring);
  border-top: 1px solid var(--hairline);
}
#sheet.hidden { transform: translateY(110%); }

#sheetGrab {
  position: sticky; top: 0; z-index: 2;
  touch-action: none; cursor: grab; user-select: none;
  margin: 0 -20px; padding: 12px 20px 8px;
  background: linear-gradient(var(--surface) 70%, rgba(0,0,0,0));
}
#sheetGrab:active { cursor: grabbing; }
#sheetHandle {
  width: 40px; height: 5px; border-radius: 3px;
  background: var(--text-3); opacity: .4; margin: 0 auto;
}

/* галерея-герой */
.s-gallery {
  display: flex; gap: 10px; overflow-x: auto; margin: 4px -20px 18px 0; padding: 0 20px 0 0;
  scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.s-gallery::-webkit-scrollbar { display: none; }
.s-photo {
  flex: 0 0 auto; height: 252px; width: auto; max-width: 88%;
  border-radius: 18px; object-fit: cover; scroll-snap-align: start;
  background: var(--surface-2); cursor: zoom-in;
  box-shadow: var(--shadow-1);
  animation: photoIn .5s var(--ease) both;
}
.s-photo:first-child { max-width: 100%; }
@keyframes photoIn {
  from { opacity: 0; transform: scale(.985); }
  to   { opacity: 1; transform: scale(1); }
}

/* пилюли категорий — приглушённые */
.s-pills { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.s-date {
  margin-left: auto; padding-left: 8px;
  font-size: 12.5px; font-weight: 500; line-height: 1; white-space: nowrap;
  color: color-mix(in srgb, var(--text) 38%, transparent);
}
.s-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 500; line-height: 1; letter-spacing: -0.01em;
  color: color-mix(in srgb, var(--pc) 72%, var(--text));
  background: color-mix(in srgb, var(--pc) 13%, transparent);
}

.s-title {
  font-size: 25px; font-weight: 700; letter-spacing: -0.03em;
  margin: 2px 0 12px; line-height: 1.18; color: var(--text);
}

/* мета-ряды с тонкими разделителями */
.s-addr, .s-meta {
  display: flex; gap: 11px; align-items: flex-start;
  font-size: 15px; line-height: 1.4; color: var(--text-2);
  padding: 11px 0; margin: 0; text-decoration: none;
  border-top: 1px solid var(--hairline);
}
.s-addr { color: var(--text-2); }
a.s-addr { color: var(--text); }
a.s-addr .s-ico, a.s-meta .s-ico { color: var(--text-3); }
.s-ico { flex: 0 0 18px; text-align: center; opacity: .9; }
.s-link { color: var(--link); text-decoration: none; }

.s-text {
  font-size: 16px; line-height: 1.62; white-space: pre-wrap;
  margin: 16px 0 6px; color: var(--text);
  letter-spacing: -0.005em;
}

/* липкая панель действий */
.s-actions {
  position: sticky; bottom: 0;
  display: flex; gap: 10px;
  margin: 20px -20px 0;
  padding: 14px 20px calc(env(safe-area-inset-bottom) + 22px);
  background: var(--surface);
  border-top: 1px solid var(--hairline);
}
.s-actions::before {
  content: ""; position: absolute; left: 0; right: 0; top: -24px; height: 24px;
  background: linear-gradient(rgba(0,0,0,0), var(--surface));
  pointer-events: none;
}
.s-btn {
  flex: 1; text-align: center; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  height: 52px; padding: 0 14px; border-radius: var(--r-md);
  font-family: inherit; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em;
  background: var(--accent); color: var(--accent-text);
  box-shadow: var(--shadow-1);
  transition: transform .08s var(--ease), opacity .16s var(--ease);
}
.s-btn:active { transform: scale(.97); opacity: .92; }
.s-btn.ghost {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--hairline-strong); box-shadow: none;
}
.s-btn.icon { flex: 0 0 auto; width: 52px; padding: 0; }
.s-btn.icon svg { display: block; }

/* ===================== Лайтбокс ===================== */
#lightbox {
  position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.94);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
#lightbox.hidden { display: none; }
#lightbox.swipe { touch-action: pan-y; }
#lightbox.swipe #lbImg { -webkit-user-select: none; user-select: none; -webkit-user-drag: none; pointer-events: none; }
#lbImg { max-width: 96vw; max-height: 86vh; border-radius: 12px; box-shadow: 0 24px 80px rgba(0,0,0,.6); }
#lightbox button {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px; border: none; border-radius: 50%;
  background: rgba(255,255,255,.14); color: #fff; font-size: 26px; line-height: 1;
  cursor: pointer; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: background .16s var(--ease);
}
#lightbox button:active { background: rgba(255,255,255,.26); }
#lbPrev { left: 14px; }
#lbNext { right: 14px; }
#lbCount {
  position: absolute; bottom: calc(env(safe-area-inset-bottom) + 20px); left: 0; right: 0;
  text-align: center; color: #fff; font-size: 13.5px; font-weight: 500; opacity: .75;
  font-variant-numeric: tabular-nums;
}

.hidden { display: none; }
