/* ==========================================================================
   КИРПИЧ КЕРАМИКА — МОБИЛЬНАЯ АДАПТАЦИЯ (frontend/mobile.css)
   Подключается после существующих стилей.
   ========================================================================== */

@media screen and (max-width: 860px) {
  /* -------------------------------------------------------------
     1. Шапка сайта и верхняя контактная панель
     ------------------------------------------------------------- */
  .v3-header {
    width: 100%;
  }

  .v3-top-bar {
    padding: 0.4rem 0;
  }

  .v3-top-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem 0.75rem;
  }

  .v3-brand-col {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    min-width: 0;
  }

  .v3-logo {
    font-size: 1.15rem;
    line-height: 1.2;
    white-space: nowrap;
  }

  .v3-tagline {
    font-size: 0.72rem;
    line-height: 1.2;
    white-space: normal;
    color: var(--text-muted);
  }

  .v3-top-contact {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    white-space: nowrap;
  }

  .v3-phone {
    font-size: 0.88rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .v3-callback-link {
    font-size: 0.8rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.4rem;
  }

  .k-mobile-nav {
    display: block;
    position: relative;
  }

  .k-mobile-nav summary {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.6rem;
    box-sizing: border-box;
  }

  .k-mobile-nav nav {
    top: calc(100% + 4px);
    right: 0;
    max-width: min(90vw, 260px);
    box-shadow: var(--shadow-md);
  }

  .k-mobile-nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 0.4rem 0.6rem;
    box-sizing: border-box;
  }

  /* -------------------------------------------------------------
     2. Панель каталога (Sticky Catalog Bar) и Поиск
     ------------------------------------------------------------- */
  .k-sticky-catalog .v3-main-bar {
    padding-block: 0.4rem;
  }

  .k-sticky-catalog .v3-main-container {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem;
  }

  .k-sticky-catalog .v3-catalog-btn {
    min-height: 44px;
    padding: 0.55rem 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .k-sticky-catalog .v3-action-summary {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .k-shortcuts {
    gap: 0.35rem;
    margin: 0.25rem 0 0;
  }

  .k-shortcuts a,
  .k-shortcut-link {
    min-height: 34px;
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    box-sizing: border-box;
  }

  /* -------------------------------------------------------------
     3. Формы и поля ввода (предотвращение зума iOS, 16px)
     ------------------------------------------------------------- */
  .v3-search-input,
  .form-control,
  .k-form input,
  .k-form textarea,
  .k-form select,
  .k-buy-row input,
  .k-cart-row input,
  .k-filters input,
  .k-filters select {
    font-size: 16px !important;
  }

  /* -------------------------------------------------------------
     4. Отступы секций и заголовков (убираем лишние 70px)
     ------------------------------------------------------------- */
  .k-product-page,
  .k-category-page,
  .k-content-page {
    padding-top: 1.25rem !important;
    padding-bottom: 2rem !important;
    margin-block: 0 !important;
  }

  .v3-hero-section {
    padding-top: 1rem !important;
    padding-bottom: 1.5rem !important;
  }

  .v3-hero-section + .v3-catalog-section {
    padding-top: 1rem !important;
  }

  #top > section {
    padding-block: 2rem !important;
  }

  #top > section.v3-brands-section,
  .v3-brands-section {
    padding-block: 1.25rem !important;
  }

  #contacts.v3-company-section,
  #top > section#contacts {
    padding-bottom: 2rem !important;
  }

  .k-breadcrumbs {
    margin-top: 0 !important;
    margin-bottom: 0.75rem !important;
  }

  /* -------------------------------------------------------------
     5. Товарные страницы, галерея и карточки
     ------------------------------------------------------------- */
  .k-product-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 1.25rem !important;
  }

  .k-gallery-open {
    width: 100%;
    max-height: 360px;
    border-radius: var(--radius-md);
  }

  .k-gallery-main {
    max-height: 340px;
    min-height: 180px;
    object-fit: contain;
  }

  .k-gallery-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.5rem;
  }

  .k-gallery-thumbs button {
    min-width: 48px;
    min-height: 44px;
    width: auto;
    height: 48px;
    flex: 0 0 54px;
    padding: 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    cursor: pointer;
  }

  .k-product-actions {
    display: grid;
    gap: 0.75rem;
    margin-block: 1rem;
  }

  .k-product-actions .k-buy-row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.6rem;
  }

  .k-product-actions .k-buy-row label {
    flex: 1 1 90px;
  }

  .k-product-actions .k-buy-row input {
    height: 44px;
    min-height: 44px;
    box-sizing: border-box;
  }

  .k-product-actions .k-buy-row .btn,
  .k-product-actions .k-buy-row .k-add {
    flex: 2 1 140px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .k-product-actions .k-buy-row .k-favorite {
    flex: 0 0 44px;
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .k-product-actions .k-page-links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .k-product-actions .k-page-links .btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .k-card-actions {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 0.4rem;
  }

  .k-card-actions .k-favorite,
  .k-card-actions .k-add {
    min-height: 44px;
    box-sizing: border-box;
  }

  .k-card-actions .k-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* -------------------------------------------------------------
     6. Корзина, калькулятор и формы
     ------------------------------------------------------------- */
  .k-cart-row {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 0.65rem;
    align-items: start;
  }

  .k-cart-row input {
    min-height: 44px;
  }

  .k-cart-row .btn,
  .k-cart-row button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .k-company-grid,
  .k-calculator-grid,
  .k-form-fields,
  .k-booklet-body {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 0.85rem;
  }

  .btn,
  .k-form button,
  .k-filters button {
    min-height: 44px;
    box-sizing: border-box;
  }

  /* -------------------------------------------------------------
     7. Модальные окна и диалоги фото
     ------------------------------------------------------------- */
  .modal-window {
    max-height: 90vh;
    max-height: 90dvh;
    display: flex;
    flex-direction: column;
    margin: 1rem auto;
    width: min(94vw, 540px);
    box-sizing: border-box;
  }

  .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
    max-height: calc(90vh - 70px);
    max-height: calc(90dvh - 70px);
    padding: 1rem;
    box-sizing: border-box;
  }

  .modal-close-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  .k-photo-dialog {
    max-height: 94vh;
    max-height: 94dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem;
    box-sizing: border-box;
  }

  .k-photo-dialog form button {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .k-photo-dialog img {
    max-height: 75vh;
    max-height: 75dvh;
  }

  .v3-popover-box {
    max-height: 80vh;
    max-height: 80dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ==========================================================================
   Ключевые изменения для мобильных экранов: 320px – 430px
   ========================================================================== */
@media screen and (max-width: 430px) {
  /* 1. Шапка: убираем лишнюю высоту 205px, делаем компактной */
  .v3-top-bar {
    padding: 0.35rem 0;
  }

  .v3-top-container {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.35rem 0.5rem;
  }

  .v3-brand-col {
    grid-column: 1 / 2;
  }

  .v3-logo {
    font-size: 1.05rem;
  }

  .v3-tagline {
    display: none; /* скрываем подзаголовок на сверхмалых экранах для компактности шапки */
  }

  .v3-top-contact {
    grid-column: 2 / 3;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    margin-left: 0;
  }

  .v3-phone {
    font-size: 0.82rem;
    min-height: 36px;
    line-height: 1.2;
  }

  .v3-callback-link {
    font-size: 0.75rem;
    min-height: 24px;
    padding: 0;
    line-height: 1.2;
  }

  .k-mobile-nav {
    grid-column: 3 / 4;
  }

  .k-mobile-nav summary {
    min-height: 44px;
    min-width: 44px;
    padding: 0.35rem;
  }

  /* 2. Поиск отдельной строкой, каталог и действия компактно в верхней строке */
  .k-sticky-catalog .v3-main-bar {
    padding-block: 0.35rem;
  }

  .k-sticky-catalog .v3-main-container {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 0.4rem;
    align-items: center;
  }

  /* Первая строка: Каталог слева, Избранное/Корзина справа */
  .k-sticky-catalog .v3-catalog-details {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
  }

  .k-sticky-catalog .v3-catalog-btn {
    min-height: 44px;
    padding: 0.5rem 0.65rem;
    font-size: 0.85rem;
  }

  .k-sticky-catalog .v3-actions-group {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
    display: flex;
    justify-content: flex-end;
    gap: 0.35rem;
    margin-left: auto;
  }

  .k-sticky-catalog .v3-action-summary {
    min-height: 44px;
    min-width: 44px;
    padding: 0.45rem !important;
  }

  /* Вторая строка: Поиск на всю отдельную строку */
  .k-sticky-catalog .v3-search-wrapper {
    grid-column: 1 / -1;
    grid-row: 2 / 3;
    width: 100%;
    margin: 0;
    position: relative;
  }

  .k-sticky-catalog .v3-search-bar {
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
  }

  .k-sticky-catalog .v3-search-input {
    width: 100%;
    min-height: 44px;
    height: 44px;
    padding: 0.55rem 0.85rem 0.55rem 2.2rem !important;
    font-size: 16px !important;
    box-sizing: border-box;
  }

  /* Результаты поиска строго под полем поиска, не выходят за экран */
  .k-sticky-catalog .v3-search-results {
    position: absolute !important;
    top: calc(100% + 4px) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 65vh !important;
    max-height: 65dvh !important;
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 200;
  }

  /* Третья строка: быстрые категории */
  .k-sticky-catalog .k-shortcuts {
    grid-column: 1 / -1;
    grid-row: 3 / 4;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.2rem;
    margin-top: 0.15rem;
    scrollbar-width: none;
  }

  .k-sticky-catalog .k-shortcuts::-webkit-scrollbar {
    display: none;
  }

  .k-shortcuts a,
  .k-shortcut-link {
    flex-shrink: 0;
  }

  /* Выпадающее меню каталога */
  .v3-menu-dropdown {
    min-width: 0;
    width: min(92vw, 300px);
    max-height: 70vh;
    max-height: 70dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .v3-menu-dropdown a {
    min-height: 40px;
    display: flex;
    align-items: center;
  }

  /* 3. Отступы контента на 320–430px */
  #k-view > .container {
    padding-inline: 12px;
  }

  .k-product-page,
  .k-category-page,
  .k-content-page {
    padding-top: 0.85rem !important;
    padding-bottom: 1.5rem !important;
  }

  .v3-hero-section {
    padding-top: 0.75rem !important;
    padding-bottom: 1.25rem !important;
  }

  #top > section {
    padding-block: 1.5rem !important;
  }

  /* Товарные кнопки на 320–430px */
  .k-product-actions .k-buy-row {
    display: grid;
    grid-template-columns: 80px minmax(0, 1fr) 44px;
    gap: 0.45rem;
  }

  .k-product-actions .k-buy-row label {
    grid-column: 1 / 2;
  }

  .k-product-actions .k-buy-row .btn,
  .k-product-actions .k-buy-row .k-add {
    grid-column: 2 / 3;
    min-width: 0;
    padding-inline: 0.4rem;
    font-size: 0.88rem;
  }

  .k-product-actions .k-buy-row .k-favorite {
    grid-column: 3 / 4;
  }

  .k-product-actions .k-page-links {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Корзина на 320–430px */
  .k-cart-row {
    grid-template-columns: 60px minmax(0, 1fr);
    gap: 0.5rem;
  }
}
