/*
 * SevSvet UI 2.0 — real responsive house sheet
 * The Leaflet popup remains the data source.
 */

:root {
  --house-sheet-surface: rgba(255, 255, 255, 0.985);
  --house-sheet-text: #142c2a;
  --house-sheet-muted: #71817f;
  --house-sheet-accent: #0b625a;
  --house-sheet-border: rgba(20, 44, 42, 0.09);
  --house-sheet-safe-bottom: env(safe-area-inset-bottom, 0px);
}

.house-sheet-root {
  position: fixed;
  inset: 0;
  z-index: 5000;

  display: flex;
  align-items: flex-end;
  justify-content: center;

  padding:
    12px
    10px
    max(10px, calc(10px + var(--house-sheet-safe-bottom)));

  pointer-events: none;
  visibility: hidden;
}

.house-sheet-root.is-open {
  visibility: visible;
}

.house-sheet-backdrop {
  position: absolute;
  inset: 0;

  border: 0;
  background: rgba(10, 29, 27, 0.14);

  opacity: 0;
  pointer-events: none;

  transition: opacity 170ms ease;
}

.house-sheet-root.is-open .house-sheet-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.house-sheet-panel {
  position: relative;
  z-index: 1;

  box-sizing: border-box;

  width: min(100%, 560px);
  max-height: min(74dvh, 700px);

  overflow: hidden;

  border: 1px solid var(--house-sheet-border);
  border-radius: 26px;

  color: var(--house-sheet-text);
  background: var(--house-sheet-surface);

  box-shadow:
    0 2px 8px rgba(15, 40, 38, 0.05),
    0 22px 56px rgba(15, 40, 38, 0.19);

  -webkit-backdrop-filter: blur(24px) saturate(145%);
  backdrop-filter: blur(24px) saturate(145%);

  opacity: 0;
  transform: translateY(34px) scale(0.985);

  pointer-events: auto;

  transition:
    opacity 180ms ease,
    transform 210ms cubic-bezier(0.22, 1, 0.36, 1);
}

.house-sheet-root.is-open .house-sheet-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.house-sheet-handle {
  display: block;

  width: 38px;
  height: 4px;
  margin: 9px auto 5px;

  border-radius: 999px;
  background: rgba(20, 44, 42, 0.15);
}

.house-sheet-scroll {
  box-sizing: border-box;

  max-height: calc(min(74dvh, 700px) - 18px);
  padding: 0 10px 10px;

  overflow-x: hidden;
  overflow-y: auto;

  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.house-sheet-scroll > .house-popup-card,
.house-sheet-scroll > .house-popup {
  width: 100% !important;
  max-width: none !important;

  margin: 0 !important;

  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.house-sheet-scroll button,
.house-sheet-scroll [role="button"] {
  min-height: 44px;
}

/*
 * Leaflet continues to build and refresh the source popup,
 * but the source itself is visually hidden while the sheet is active.
 */
html.house-sheet-active .leaflet-popup-pane {
  visibility: hidden;
  pointer-events: none;
}

/* Phones */
@media (max-width: 767px) {
  .house-sheet-root {
    padding:
      8px
      8px
      max(8px, calc(8px + var(--house-sheet-safe-bottom)));
  }

  .house-sheet-panel {
    width: 100%;
    max-height: min(76dvh, 720px);
    border-radius: 25px;
  }

  .house-sheet-scroll {
    max-height: calc(min(76dvh, 720px) - 18px);
    padding-right: 8px;
    padding-left: 8px;
  }
}

/* Small phones */
@media (max-width: 359px) {
  .house-sheet-root {
    padding-right: 5px;
    padding-left: 5px;
  }

  .house-sheet-panel {
    max-height: 79dvh;
    border-radius: 22px;
  }

  .house-sheet-scroll {
    max-height: calc(79dvh - 18px);
    padding-right: 5px;
    padding-left: 5px;
  }
}

/* Tablets */
@media (min-width: 768px) and (max-width: 1099px) {
  .house-sheet-root {
    padding-bottom: max(22px, calc(22px + var(--house-sheet-safe-bottom)));
  }

  .house-sheet-panel {
    width: min(560px, calc(100vw - 48px));
    max-height: min(72dvh, 720px);
  }

  .house-sheet-scroll {
    max-height: calc(min(72dvh, 720px) - 18px);
  }
}

/* Desktop: side panel */
@media (min-width: 1100px) {
  .house-sheet-root {
    align-items: center;
    justify-content: flex-end;

    padding: 24px;
  }

  .house-sheet-backdrop {
    background: rgba(10, 29, 27, 0.07);
  }

  .house-sheet-panel {
    width: min(430px, calc(100vw - 48px));
    max-height: calc(100dvh - 48px);

    border-radius: 26px;

    transform: translateX(28px) scale(0.985);
  }

  .house-sheet-root.is-open .house-sheet-panel {
    transform: translateX(0) scale(1);
  }

  .house-sheet-handle {
    display: none;
  }

  .house-sheet-scroll {
    max-height: calc(100dvh - 50px);
    padding-top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .house-sheet-panel,
  .house-sheet-backdrop {
    transition: none;
  }
}


/* =========================================================
   SevSvet UI2 — taller responsive house sheet
   Показываем карточку целиком, скролл оставляем только как fallback.
   ========================================================= */

@media (max-width: 767px) {
  .house-sheet-root {
    padding:
      8px
      8px
      max(8px, calc(8px + var(--house-sheet-safe-bottom)));
  }

  .house-sheet-panel {
    /*
     * Оставляем сверху небольшой визуальный зазор.
     * Высота подстраивается под содержимое, но может занять почти весь экран.
     */
    height: auto;
    max-height: calc(100dvh - 104px);

    border-radius: 26px;
  }

  .house-sheet-scroll {
    height: auto;
    max-height: calc(100dvh - 126px);

    /*
     * Прокрутка появится только тогда, когда содержимое
     * физически не помещается на экране.
     */
    overflow-x: hidden;
    overflow-y: auto;
  }

  /*
   * Убираем старые внутренние ограничения Leaflet-карточки.
   * Теперь высотой управляет только внешний responsive sheet.
   */
  .house-sheet-scroll .house-popup-card,
  .house-sheet-scroll .house-popup,
  .house-sheet-scroll .house-popup-content,
  .house-sheet-scroll .house-popup-body,
  .house-sheet-scroll .house-popup-details,
  .house-sheet-scroll .house-popup-sections,
  .house-sheet-scroll .house-popup-scroll {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;

    overflow: visible !important;
  }

  /*
   * Нижние действия остаются видимыми и не сжимаются.
   */
  .house-sheet-scroll .house-popup-actions,
  .house-sheet-scroll .house-popup-footer,
  .house-sheet-scroll .popup-actions {
    position: relative;
    z-index: 3;

    flex-shrink: 0;
  }
}

/* Невысокие телефоны: оставляем чуть больше верхнего зазора. */
@media (max-width: 767px) and (max-height: 720px) {
  .house-sheet-panel {
    max-height: calc(100dvh - 72px);
  }

  .house-sheet-scroll {
    max-height: calc(100dvh - 94px);
  }
}

/* Современные высокие телефоны. */
@media (max-width: 767px) and (min-height: 800px) {
  .house-sheet-panel {
    max-height: calc(100dvh - 118px);
  }

  .house-sheet-scroll {
    max-height: calc(100dvh - 140px);
  }
}


/* Toasts must stay above the responsive house sheet and backdrop. */
.app-toast {
  position: fixed !important;
  z-index: 7000 !important;

  left: 50% !important;
  right: auto !important;
  bottom: max(
    22px,
    calc(22px + env(safe-area-inset-bottom, 0px))
  ) !important;

  width: min(calc(100vw - 32px), 440px);
  max-width: calc(100vw - 32px);

  transform: translate(-50%, 18px);
  pointer-events: none;
}

.app-toast.is-visible {
  transform: translate(-50%, 0);
}

/* При открытой нижней карточке показываем уведомление над её нижними кнопками. */
html.house-sheet-active .app-toast {
  bottom: max(
    112px,
    calc(112px + env(safe-area-inset-bottom, 0px))
  ) !important;
}

@media (min-width: 1100px) {
  html.house-sheet-active .app-toast {
    right: 470px !important;
    left: auto !important;
    bottom: 28px !important;

    transform: translateY(18px);
  }

  html.house-sheet-active .app-toast.is-visible {
    transform: translateY(0);
  }
}


/* Global favorite replacement countdown.
   Fixed typography prevents visual width jumping. */
.house-sheet-scroll [data-favorite-house].is-cooldown {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;

  cursor: not-allowed;
  opacity: 0.82;
}


/* =========================================================
   SevSvet — standard Leaflet popup is an internal source only.
   It must never be visible to the user, including during close.
   ========================================================= */

#mapPoints .leaflet-popup-pane,
#mapPoints .leaflet-popup,
#mapPoints .leaflet-popup-content-wrapper,
#mapPoints .leaflet-popup-content,
#mapPoints .leaflet-popup-tip-container,
#mapPoints .leaflet-popup-tip,
.map-points .leaflet-popup-pane,
.map-points .leaflet-popup,
.map-points .leaflet-popup-content-wrapper,
.map-points .leaflet-popup-content,
.map-points .leaflet-popup-tip-container,
.map-points .leaflet-popup-tip {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
