/* ==========================================================================
   responsive.css — Адаптивная вёрстка (320px, 375px, 480px, 768px, 1024px, 1280px+)
   Защита от переполнения, однострочная мобильная шапка 60px, карточный прайс-лист
   ========================================================================== */

/* Базовая защита от горизонтального переполнения во всех grid/flex-контейнерах */
.site-header__inner,
.hero-split__grid,
.hero-split__content,
.hero-split__media,
.service-detail-layout,
.doctor-profile,
.reviews-layout,
.contacts-layout,
.legal-layout,
.site-footer__grid,
.card,
.doctor-card,
.service-card,
.review-card,
.modal,
.estimate-tray,
.price-table-wrap {
  min-width: 0;
}

.doctor-card__name,
.service-card__title,
.review-card__body,
.contacts-item__value,
.legal-section,
.site-footer__link,
.modal__title {
  overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
   1280px+ — Десктоп повышенной ширины
   -------------------------------------------------------------------------- */
@media (min-width: 1280px) {
  .hero-split__grid {
    gap: var(--space-16);
  }

  .bento-gallery {
    grid-auto-rows: 240px;
  }
}

/* --------------------------------------------------------------------------
   < 1024px — Планшет и переход к компактной однострочной шапке 60px
   -------------------------------------------------------------------------- */
@media (max-width: 1023.98px) {
  :root {
    --header-height: var(--header-height-mobile);
    --header-height-scrolled: var(--header-height-mobile);
  }

  .site-header__inner {
    height: var(--header-height-mobile);
    gap: var(--space-2);
    flex-wrap: nowrap;
  }

  .site-header.is-scrolled .site-header__inner {
    height: var(--header-height-mobile);
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
  }

  .site-header.is-scrolled .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-mark svg {
    width: 20px;
    height: 20px;
  }

  .brand-title {
    font-size: 0.88rem;
  }

  .brand-subtitle {
    font-size: 0.68rem;
  }

  /* Скрываем десктоп-меню и длинный текстовый телефон */
  .site-nav,
  .header-phone {
    display: none;
  }

  /* Включаем однострочный 4-элементный слот:
     [Логотип СПбГУВМ] + [Иконка звонка 44x44] + [Записаться] + [Бургер 44x44] */
  .site-header__brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  .site-header__actions {
    gap: var(--space-2);
    flex-shrink: 0;
  }

  .header-phone-btn,
  .header-burger {
    display: inline-flex;
    background-color: var(--bg-soft);
    border: 1px solid var(--border-control);
    color: var(--palette-navy-950);
  }

  .header-book-btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: var(--text-sm);
    background-color: var(--palette-navy-950);
    border-color: var(--palette-navy-950);
  }

  /* Складываем 2-колоночные макеты страниц */
  .hero-split__grid,
  .service-detail-layout,
  .doctor-profile,
  .reviews-layout,
  .contacts-layout,
  .legal-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .doctor-profile__sidebar,
  .review-form-card,
  .legal-toc {
    position: static;
  }

  .doctors-grid,
  .services-grid,
  .grid--3,
  .grid--4,
  .stats-strip,
  .site-footer__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bento-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 200px;
  }
}

/* --------------------------------------------------------------------------
   < 768px — Мобильный макет + карточная трансформация .price-table--responsive
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
  /* Предотвращение авто-зума iOS Safari при фокусе на полях ввода */
  .input,
  .select,
  .textarea {
    font-size: 16px;
  }

  .form-grid-2,
  .reviews-grid,
  .grid--2 {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero-split__meta {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
  }

  .hero-split__caption {
    position: static;
    border-radius: 0;
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.16);
  }

  .hero-split__frame {
    aspect-ratio: auto;
  }

  .hero-split__frame img {
    aspect-ratio: 16 / 10;
  }

  /* Карточная трансформация таблицы цен без горизонтального скролла */
  .price-table--responsive {
    display: block;
    width: 100%;
  }

  .price-table--responsive thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .price-table--responsive tbody {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-3);
    background-color: var(--bg-soft);
  }

  .price-table--responsive tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-navy-xs);
  }

  .price-table--responsive tbody tr:hover {
    background-color: var(--bg-surface);
  }

  .price-table--responsive td {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px var(--space-3);
    padding: 0;
    border: 0;
    min-width: 0;
  }

  .price-table--responsive td[data-label]::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    flex: 0 0 auto;
  }

  /* Первая ячейка с названием услуги — всегда во всю ширину карточки */
  .price-table--responsive td:first-child {
    flex-direction: column;
    align-items: flex-start;
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
  }

  .price-table--responsive td:last-child {
    padding-top: var(--space-1);
  }

  .price-table--responsive .price-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
    gap: var(--space-2);
    width: 100%;
  }

  .price-table--responsive .price-add-btn,
  .price-table--responsive .price-book-btn {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    font-size: var(--text-sm);
  }

  /* Мобильный стандарт touch targets >= 44px и аккуратная геометрия кнопок */
  .btn--sm {
    min-height: 44px;
    padding: 10px 14px;
    font-size: var(--text-sm);
  }

  .doctor-card__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
  }

  .doctor-card__actions .btn {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    font-size: var(--text-sm);
  }

  .service-card__footer .btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: var(--text-sm);
  }

  .section__header > .btn,
  .section__header > .btn-group {
    width: 100%;
  }

  .page-hero__actions .btn {
    min-height: 48px;
  }

  .bm-quick-chip {
    min-height: 44px;
    padding: 8px 14px;
  }

  .toast__close {
    width: 44px;
    height: 44px;
  }

  /* Модальное окно и смета на мобильных */
  .modal-backdrop {
    padding: var(--space-2);
    align-items: flex-end;
  }

  .modal {
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-md) var(--radius-md);
  }

  .modal__header,
  .modal__body,
  .modal__footer {
    padding-inline: var(--space-4);
  }

  .modal__footer {
    justify-content: stretch;
  }

  .modal__footer .btn {
    flex: 1 1 140px;
    min-height: 48px;
  }

  .modal__footer .btn--ghost {
    background-color: var(--bg-soft);
    border-color: var(--border-subtle);
    color: var(--brand-primary);
  }

  .estimate-tray {
    bottom: var(--space-2);
    width: calc(100% - 16px);
    padding: var(--space-3);
  }

  .estimate-tray__bar {
    flex-direction: column;
    align-items: stretch;
  }

  .estimate-tray__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .estimate-tray__actions .btn--on-dark {
    grid-column: 1 / -1;
    min-height: 44px;
  }

  .estimate-tray__item .btn {
    min-height: 44px;
    min-width: 78px;
  }

  .toast-region {
    top: calc(var(--header-height-mobile, 60px) + var(--space-2));
    bottom: auto;
    left: var(--space-2);
    right: var(--space-2);
    width: auto;
  }

  body.has-estimate-tray .toast-region {
    bottom: auto;
  }

  .cookie-banner {
    left: var(--space-2);
    right: var(--space-2);
    bottom: var(--space-2);
    width: auto;
  }

  body.has-estimate-tray .cookie-banner {
    bottom: 162px;
  }

  body.has-estimate-tray .site-footer {
    padding-bottom: 170px;
  }

  .cookie-banner__actions {
    justify-content: stretch;
  }

  .cookie-banner__actions .btn {
    width: 100%;
    min-height: 44px;
    font-size: var(--text-sm);
  }

  .filter-pills {
    gap: var(--space-2);
  }

  .pill {
    min-height: 44px;
    font-size: 0.8125rem;
    padding: 8px 14px;
  }

  .filter-pills--rail {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    padding-bottom: 4px;
    mask-image: linear-gradient(to right, #000 0%, #000 92%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, #000 0%, #000 92%, transparent 100%);
  }

  .filter-pills--rail::-webkit-scrollbar {
    display: none;
  }

  .filter-pills--rail .pill {
    flex: 0 0 auto;
    white-space: nowrap;
    scroll-snap-align: start;
  }
}

/* --------------------------------------------------------------------------
   < 480px — Смартфоны (375px — 479px)
   -------------------------------------------------------------------------- */
@media (max-width: 479.98px) {
  .brand-subtitle {
    display: none;
  }

  .brand-title {
    font-size: 0.84rem;
    white-space: normal;
    line-height: 1.12;
  }

  .header-book-btn__full {
    display: none;
  }

  .header-book-btn__short {
    display: inline;
  }

  .header-book-btn {
    max-width: none;
    white-space: nowrap;
    padding: 0 14px;
    font-size: 0.8125rem;
    line-height: 1;
    min-height: 44px;
  }

  .doctors-grid,
  .services-grid,
  .grid--3,
  .grid--4,
  .stats-strip,
  .site-footer__grid,
  .bento-gallery {
    grid-template-columns: minmax(0, 1fr);
  }

  .bento-gallery {
    grid-auto-rows: 210px;
  }

  .bento-item--wide,
  .bento-item--tall {
    grid-column: span 1;
    grid-row: span 1;
  }

  .btn-group,
  .hero-split__actions,
  .page-hero__actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .btn-group .btn,
  .hero-split__actions .btn,
  .page-hero__actions .btn,
  .section__header > .btn {
    width: 100%;
    justify-content: center;
  }

  .btn-group .btn--ghost {
    background-color: var(--bg-soft);
    border-color: var(--border-subtle);
    color: var(--brand-primary);
  }

  .service-card__footer {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }

  .service-card__footer .btn {
    width: 100%;
  }

  .modal__footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .modal__footer .btn {
    width: 100%;
    flex: 0 0 auto;
  }

  .stepper__item {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: var(--space-3);
  }

  .stepper__item:not(:last-child)::after {
    left: 17px;
    top: 40px;
  }

  .stepper__num {
    width: 36px;
    height: 36px;
    font-size: var(--text-sm);
  }

  .lightbox {
    padding: var(--space-2);
  }

  .lightbox__nav {
    width: 44px;
    height: 44px;
  }
}

/* --------------------------------------------------------------------------
   < 375px — Узкие экраны (320px — 374px)
   Гарантия однострочной шапки 60px без переполнения и обрезания элементов
   -------------------------------------------------------------------------- */
@media (max-width: 374.98px) {
  :root {
    --container-gutter: 10px;
  }

  .site-header__inner {
    gap: 6px;
  }

  .site-header__brand {
    gap: 6px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand-mark svg {
    width: 18px;
    height: 18px;
  }

  .brand-title {
    font-size: 0.76rem;
    line-height: 1.1;
    overflow-wrap: break-word;
  }

  .site-header__actions {
    gap: 4px;
  }

  .header-phone-btn,
  .header-burger {
    width: 44px;
    height: 44px;
  }

  .header-book-btn {
    max-width: none;
    white-space: nowrap;
    padding: 0 10px;
    font-size: 0.78rem;
    line-height: 1;
    letter-spacing: -0.01em;
  }

  .card,
  .doctor-section-card,
  .contacts-card,
  .review-form-card,
  .legal-section {
    padding: var(--space-4);
  }
}

@media (max-width: 359.98px) {
  .brand-title {
    font-size: 0.68rem;
  }
}
