:root {
  --bg: var(--tg-theme-secondary-bg-color, #f6f4ef);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1b1a);
  --hint: var(--tg-theme-hint-color, #8a857e);
  --line: var(--tg-theme-section-separator-color, #e6e1d8);
  --accent: #8c6a4e;
  --accent-text: #ffffff;
  --font: -apple-system, "SF Pro Text", system-ui, sans-serif;
  --sheet-h: 60vh;
}
@supports (height: 1dvh) { :root { --sheet-h: 60dvh; } }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body.sheet-open { overflow: hidden; }

.page {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Переключатели-сегменты */
.controls { display: flex; flex-direction: column; gap: 8px; }
.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 12px;
  background: var(--line);
}
.seg__btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 36px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: 500 15px/1.2 var(--font);
  cursor: pointer;
  position: relative;
  overflow-wrap: anywhere;
}
.seg--venue .seg__btn { font-size: 13px; min-height: 32px; }
.zoomrow { display: flex; align-items: center; gap: 8px; min-width: 0; }
.zoomrow__label { flex: 0 0 auto; font-size: 13px; color: var(--hint); }
.seg--zoom { flex: 1 1 auto; min-width: 0; }
.seg--zoom .seg__btn { font-size: 13px; min-height: 32px; padding: 6px 4px; }
.seg__btn::after { content: ""; position: absolute; inset: -4px 0; }
.seg__btn[aria-selected="true"] {
  background: var(--card);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--line);
}
.seg--variant .seg__btn[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: none;
}

/* Карточка */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
}
.card__photo { height: 160px; }
.card__body { padding: 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card__title { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.card__addr { margin: 0; font-size: 15px; color: var(--hint); overflow-wrap: anywhere; min-width: 0; }
.card__approx { margin: -2px 0 0; font-size: 12px; color: var(--hint); }

/* Строка адреса: адрес переносится в своей колонке, кнопка «Карта» справа не сжимается */
.addrrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; column-gap: 12px; }
.mapbtn {
  position: relative;
  height: 28px; margin-top: -4px; padding: 0 10px 0 8px;
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); border-radius: 14px;
  background: transparent; color: var(--hint);
  font: 500 13px/1 var(--font);
  white-space: nowrap; cursor: pointer;
}
/* зона касания 44 по высоте, невидимая */
.mapbtn::after { content: ""; position: absolute; left: -4px; right: -4px; top: -9px; bottom: -9px; }
.mapbtn:active { background: var(--line); }
.mapbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mapbtn__ico { flex: 0 0 auto; display: block; }
.mapbtn__ico--hide, .mapbtn.is-open .mapbtn__ico--show { display: none; }
.mapbtn.is-open .mapbtn__ico--hide { display: block; }

/* Аккордеон карты: 0 -> --map-h, карта внутри фиксированной высоты */
.mapbox {
  --map-h: 220px;
  height: 0; overflow: hidden;
  margin-top: -8px; /* съедаем gap колонки, пока свёрнута */
  transition: height 0.28s ease, margin-top 0.28s ease;
}
.mapbox.is-open { height: calc(var(--map-h) + 4px); margin-top: 0; }
@media (min-width: 420px) { .mapbox { --map-h: 240px; } }
@media (prefers-reduced-motion: reduce) { .mapbox { transition: none; } }

.preview {
  position: relative;
  height: var(--map-h);
  margin-top: 4px;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
  isolation: isolate;
}
.preview__map { position: absolute; inset: 0; }
.preview .map-missing, .sheet__map .map-missing {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; text-align: center; font-size: 13px; color: var(--hint);
}

/* Кнопки */
.btn {
  position: relative;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  font: 600 15px/1 var(--font);
  cursor: pointer;
  white-space: nowrap;
}
.btn::after { content: ""; position: absolute; left: 0; right: 0; top: -2px; bottom: -2px; }
.btn--ghost { background: transparent; color: var(--accent); padding: 0 8px; font-weight: 500; }
.btn--icon {
  width: 44px; height: 44px; padding: 0; border-radius: 22px;
  background: transparent; color: var(--hint);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn--icon::after { display: none; }
.btn:focus-visible, .seg__btn:focus-visible, .preview:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.foot { margin: 4px 0 0; font-size: 12px; color: var(--hint); text-align: center; }

/* Подложка и шторка */
.backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0; transition: opacity 0.25s ease;
}
.backdrop.is-on { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001;
  max-width: 520px; margin: 0 auto;
  height: var(--sheet-h);
  display: flex; flex-direction: column;
  background: var(--card);
  color: var(--text);
  border-radius: 20px 20px 0 0;
  transform: translateY(105%);
  transition: transform 0.28s ease, height 0.28s ease, border-radius 0.28s ease;
  visibility: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.is-open { transform: translateY(0); visibility: visible; }
.sheet.is-full { height: 100%; border-radius: 0; }
.sheet.is-dragging { transition: none; }

.sheet__head { flex: 0 0 auto; touch-action: none; padding-top: env(safe-area-inset-top, 0); }
.sheet:not(.is-full) .sheet__head { padding-top: 0; }
.sheet__grab {
  display: block; width: 100%; height: 22px; padding: 0; border: 0; background: transparent; cursor: pointer;
}
.sheet__grab span { display: block; width: 36px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--hint); opacity: 0.4; }
.sheet__bar { display: flex; align-items: center; gap: 4px; padding: 0 8px 8px 16px; min-width: 0; }
.sheet__title {
  flex: 1 1 auto; min-width: 0; margin: 0;
  font-size: 16px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet__map { position: relative; flex: 1 1 auto; min-height: 0; background: var(--bg); overflow: hidden; isolation: isolate; }
.sheet__canvas { position: absolute; inset: 0; }

/* Элементы поверх карты (виджет и шторка). Цвета свои, не темы: карта светлая и в тёмной теме. */
.mapctl-zoom, .mapctl-scale, .mapctl-open { position: absolute; z-index: 5001; }
.mapctl-zoom {
  left: 8px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 4px;
}
.mapctl-zoom__btn {
  position: relative;
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.92); color: #1c1b1a;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}
/* зона касания: 44 по ширине, по высоте ~36 без нахлёста на соседнюю кнопку (между ними 4 px) */
.mapctl-zoom__btn::after { content: ""; position: absolute; left: -8px; right: -8px; top: -2px; bottom: -2px; }
.mapctl-zoom__btn[data-dz="1"]::after { top: -6px; }
.mapctl-zoom__btn[data-dz="-1"]::after { bottom: -6px; }
.mapctl-zoom__btn:active { background: #e9e6e0; }
.mapctl-zoom__btn:disabled { color: #b9b5ae; cursor: default; }
.mapctl-zoom__btn:focus-visible, .mapctl-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mapctl-open {
  right: 8px; top: 8px;
  height: 26px; padding: 0 8px 0 7px; border: 0; border-radius: 13px;
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255, 255, 255, 0.85); color: #1c1b1a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  font: 500 12px/1 var(--font);
  cursor: pointer;
}
.mapctl-open::after { content: ""; position: absolute; left: -6px; right: -8px; top: -8px; bottom: -8px; }

/* Линейка масштаба: подпись над скобкой */
.mapctl-scale {
  left: 8px; bottom: 8px;
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 1px 5px 3px; border-radius: 5px;
  background: rgba(255, 255, 255, 0.85); color: #1c1b1a;
  pointer-events: none;
}
.mapctl-scale--sheet { left: 8px; bottom: 8px; }
.mapctl-scale__text { font: 500 12px/1.15 var(--font); white-space: nowrap; }
.mapctl-scale__bar {
  display: block; height: 5px; margin-top: 1px;
  border: 1.5px solid #1c1b1a; border-top: 0;
}
.mapctl-scale:empty, .mapctl-scale.is-off { display: none; }
