/* Complex page — mobile-first UX (max-width: 767px) */
:root {
  --complex-bottom-h: 56px;
  --complex-sticky-sub: 52px;
}

@media (max-width: 767px) {
  body.complex-mobile-page {
    padding-bottom: calc(var(--complex-bottom-h) + env(safe-area-inset-bottom, 0px) + 8px);
  }

  body.complex-mobile-page.complex-is-fatal .complex-bottom-bar,
  body.complex-mobile-page.complex-is-fatal .complex-sticky-bar {
    display: none !important;
  }

  /* ─── Липкая подшапка под site-header ─── */
  .complex-sticky-bar {
    position: fixed;
    top: var(--header-h, 80px);
    left: 0;
    right: 0;
    z-index: 850;
    background: #fff;
    border-bottom: 1px solid #eaeaea;
    box-shadow: 0 2px 12px rgba(31, 31, 34, 0.06);
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.28s ease, opacity 0.28s ease;
  }

  .complex-sticky-bar.is-visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .complex-sticky-bar__inner {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--complex-sticky-sub);
    padding: 8px 12px;
    max-width: 1360px;
    margin: 0 auto;
  }

  .complex-sticky-bar__title {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    font-weight: 700;
    color: #1f1f22;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .complex-sticky-bar__price {
    font-size: 13px;
    font-weight: 800;
    color: #1f1f22;
    white-space: nowrap;
  }

  .complex-sticky-bar__btn {
    flex-shrink: 0;
    min-height: 36px;
    padding: 0 12px;
    border-radius: 10px;
    border: none;
    background: #ff0000;
    color: #fff !important;
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  /* ─── Нижняя панель 70 / 30 ─── */
  .complex-bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1900;
    display: flex;
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 1px solid #eaeaea;
    box-shadow: 0 -4px 24px rgba(31, 31, 34, 0.08);
  }

  .complex-bottom-bar__primary {
    flex: 0 0 70%;
    max-width: 70%;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #ff0000;
    color: #fff !important;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    text-align: center;
    line-height: 1.2;
    padding: 8px 10px;
  }

  .complex-bottom-bar__secondary {
    flex: 1;
    min-width: 0;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #f4f4f6;
    border: 1px solid #e0e0e6;
    color: #1f1f22 !important;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    text-align: center;
    padding: 8px 6px;
  }

  /* Скрыть старый одиночный CTA */
  .mobile-sticky-cta {
    display: none !important;
  }

  /* ─── Теги над заголовком ─── */
  .complex-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
  }

  .complex-tags:empty {
    display: none;
  }

  .complex-tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    color: #5f5f69;
    border: 1px solid #d8d8df;
    background: #fafafa;
  }

  /* ─── Адрес ─── */
  .loc--address {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 0;
    cursor: pointer;
    font: inherit;
    color: var(--c-muted, #6b6b74);
    line-height: 1.5;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
  }

  .loc--address:active {
    opacity: 0.75;
  }

  .complex-maps-link {
    display: inline-block;
    margin-top: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #ff0000;
    text-decoration: none;
  }

  .complex-maps-link:hover {
    text-decoration: underline;
  }

  /* ─── Галерея: карусель ─── */
  .gallery.gallery--carousel-mode .gallery-grid--desktop {
    display: none !important;
  }

  .gallery.gallery--carousel-mode .gallery-carousel {
    display: block !important;
  }

  .gallery-carousel {
    display: none;
  }

  .gallery-carousel__viewport {
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    border-radius: 14px;
    background: #f1f2f5;
  }

  .gallery-carousel__track {
    display: flex;
    gap: 0;
  }

  .gallery-carousel__slide {
    flex: 0 0 100%;
    width: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    border: 0;
    padding: 0;
    margin: 0;
    display: block;
    height: 240px;
    background: #f1f2f5;
    cursor: pointer;
  }

  .gallery-carousel__slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  .gallery-carousel__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
    padding: 0 4px;
  }

  .gallery-carousel__counter {
    font-size: 13px;
    font-weight: 600;
    color: #6b6b74;
  }

  .gallery-carousel__dots {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .gallery-carousel__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    border: 0;
    padding: 0;
    background: #d8d8df;
    cursor: pointer;
  }

  .gallery-carousel__dot.is-active {
    background: #ff0000;
    transform: scale(1.15);
  }

  /* ─── Характеристики: горизонтальная лента ─── */
  .tech-scroll-outer {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 0 14px 6px;
    scrollbar-width: thin;
  }

  .tech-scroll-outer .tech-grid {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    width: max-content;
    min-width: 100%;
  }

  .tech-scroll-outer .tech-grid .card.tech-cell {
    flex: 0 0 auto;
    width: 148px;
    min-height: 120px;
    margin: 0;
  }

  /* ─── Ипотека: колонка результатов после ввода ─── */
  .mortgage-ya__grid {
    display: flex;
    flex-direction: column;
  }

  .mortgage-ya__controls {
    order: 1;
  }

  .mortgage-ya__result {
    order: 2;
  }

  /* ─── Карта: активация касанием ─── */
  .map-touch-wrap {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--c-line, #ececf1);
  }

  .map-touch-wrap:not(.map-touch-wrap--active) .complex-map-el {
    pointer-events: none;
  }

  .map-touch-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    border: 0;
    background: rgba(255, 255, 255, 0.92);
    color: #1f1f22;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    line-height: 1.4;
  }

  .map-touch-wrap--active .map-touch-overlay {
    display: none;
  }

  .complex-map-el {
    height: 280px;
  }

  /* Toast */
  .complex-toast {
    position: fixed;
    bottom: calc(var(--complex-bottom-h) + env(safe-area-inset-bottom, 0px) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 2000;
    padding: 10px 18px;
    border-radius: 12px;
    background: #1f1f22;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
  }

  .complex-toast.is-on {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  /* Anchor nav: horizontal scroll on mobile */
  .complex-anchor-nav {
    top: calc(var(--header-h, 80px) + var(--complex-sticky-sub, 0px));
  }
}

@media (min-width: 768px) {
  body.complex-mobile-page {
    padding-bottom: 0;
  }

  .complex-sticky-bar,
  .complex-bottom-bar,
  .complex-toast {
    display: none !important;
  }

  .map-touch-overlay {
    display: none !important;
  }

  .map-touch-wrap .complex-map-el {
    pointer-events: auto !important;
  }

  .map-touch-wrap {
    border-radius: 12px;
  }

  .tech-scroll-outer {
    overflow: visible;
    margin: 0;
    padding: 0;
  }

  .tech-scroll-outer .tech-grid {
    display: grid;
    width: auto;
    min-width: 0;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  }

  .tech-scroll-outer .tech-grid .card.tech-cell {
    width: auto;
    min-height: 0;
    flex: none;
  }

  .hero-side .cta,
  .hero-side .cta-light {
    display: inline-flex;
  }

  /* Anchor nav always visible on desktop */
  .complex-anchor-nav {
    top: var(--header-h, 80px);
  }
}
