/* Мобильная оптимизация для market.php и index.php */

/* ============================================
   0. СКРЫТИЕ ЗАГЛУШЕК ИЗОБРАЖЕНИЙ НА МОБИЛЬНЫХ
   ============================================ */

/* Скрываем заглушки изображений на мобильных - глобальные правила */
@media screen and (max-width: 767px) {
  /* Скрываем все изображения с no_image */
  img[src*="no_image"],
  img[src*="/images/market/no_image"],
  img[src*="images/market/no_image"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    position: absolute !important;
    left: -9999px !important;
  }
  
  /* Скрываем контейнеры с заглушками */
  .image_sm:has(img[src*="no_image"]),
  .image_sm:has(img[src*="/images/market/no_image"]),
  .image_sm:has(a[href*="no_image"]),
  .image_sm:has(a[href*="/images/market/no_image"]),
  .image_sm.no-image,
  .image_sm .no-image-hidden {
    display: none !important;
    visibility: hidden !important;
  }
  
  /* Скрываем ячейки таблицы с заглушками */
  td:has(.image_sm img[src*="no_image"]),
  td:has(.image_sm img[src*="/images/market/no_image"]),
  td:has(.image_sm a[href*="no_image"]),
  td:has(.image_sm a[href*="/images/market/no_image"]),
  td:first-child:has(.image_sm img[src*="no_image"]),
  td:first-child:has(.image_sm a[href*="no_image"]),
  td .no-image,
  td:first-child .no-image {
    display: none !important;
    visibility: hidden !important;
  }
}

/* ============================================
   1. ГЛОБАЛЬНАЯ МОБИЛЬНАЯ НАСТРОЙКА
   ============================================ */

@media screen and (max-width: 767px) {
  /* Отключаем горизонтальный скролл на мобильных */
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }
}

/* ============================================
   2. АДАПТАЦИЯ ТАБЛИЦ ТОВАРОВ В КАРТОЧКИ
   ============================================ */

/* На мобильных устройствах преобразуем таблицы в карточки */
@media screen and (max-width: 767px) {
  /* Контейнер таблицы */
  #cart_interface {
    overflow-x: visible;
  }
  
  /* Скрываем заголовки таблицы на мобильных */
  #cart_interface table thead {
    display: none;
  }
  
  /* Скрываем первую строку tbody с заголовками */
  #cart_interface table tbody tr:first-child {
    display: none !important;
  }
  
  /* Преобразуем строки таблицы в карточки */
  #cart_interface table tbody tr {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
  }
  
  /* Ячейки таблицы становятся блоками */
  #cart_interface table tbody td {
    display: block;
    width: 100% !important;
    padding: 6px 0;
    text-align: left !important;
    border: none;
    position: relative;
    padding-left: 0;
    vertical-align: top;
  }
  
  /* Добавляем подписи к ячейкам через ::before */
  #cart_interface table tbody td::before {
    content: attr(data-label);
    font-weight: 500;
    color: #555;
    display: inline-block;
    min-width: 90px;
    margin-right: 6px;
    font-size: 12px;
  }
  
  /* Скрываем подпись для пустых data-label */
  #cart_interface table tbody td[data-label=""]::before {
    display: none;
  }
  
  /* Фото товара - специальная обработка */
  #cart_interface table tbody td:first-child {
    text-align: center;
    padding: 0 0 12px 0;
  }
  
  #cart_interface table tbody td:first-child::before {
    display: none;
  }
  
  #cart_interface table tbody td:first-child .image_sm {
    margin: 0 auto;
    display: block;
  }
  
  /* Изображения товаров на мобильных */
  #cart_interface .image_sm {
    width: 70px;
    height: 70px;
    margin: 0 auto;
  }
  
  #cart_interface .image_sm img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  
  /* Скрываем заглушку (no_image.png) на мобильных - усиленные правила */
  .image_sm img[src*="no_image"],
  .image_sm img[src*="/images/market/no_image"],
  .image_sm a[href*="no_image"] img,
  .image_sm a[href*="/images/market/no_image"] img,
  img[src*="no_image.png"],
  img[src*="/images/market/no_image.png"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
  }
  
  /* Скрываем контейнер и ячейку с заглушкой */
  .image_sm:has(img[src*="no_image"]),
  .image_sm:has(img[src*="/images/market/no_image"]),
  .image_sm:has(a[href*="no_image"]),
  .image_sm:has(a[href*="/images/market/no_image"]),
  table tbody td:first-child:has(.image_sm img[src*="no_image"]),
  table tbody td:first-child:has(.image_sm img[src*="/images/market/no_image"]),
  table tbody td:first-child:has(.image_sm a[href*="no_image"]),
  table tbody td:first-child:has(.image_sm a[href*="/images/market/no_image"]),
  .image_sm.no-image,
  table tbody td:first-child .no-image,
  table tbody td:first-child:has(.no-image) {
    display: none !important;
    visibility: hidden !important;
  }
  
  /* Дополнительная проверка через атрибуты */
  td[data-label=""]:has(.image_sm img[src*="no_image"]),
  td:first-child:has(.image_sm img[src*="no_image"]) {
    display: none !important;
  }
  
  /* Название товара - специальная обработка */
  #cart_interface table tbody td:nth-child(3) {
    padding-top: 8px;
    word-wrap: break-word;
  }
  
  #cart_interface table tbody td:nth-child(3) a {
    display: inline-block;
    margin-bottom: 2px;
    font-size: 13px;
    line-height: 1.4;
  }
  
  /* Для названия товара подпись должна быть на отдельной строке */
  #cart_interface table tbody td[data-label="Название:"]::before {
    display: block;
    margin-bottom: 4px;
  }
  
  /* Кнопка "в корзину" */
  #cart_interface table tbody td:last-child {
    padding-top: 8px;
    text-align: center !important;
  }
  
  #cart_interface table tbody td:last-child::before {
    display: none;
  }
  
  /* Выравнивание для полей с количеством */
  #cart_interface table tbody td[data-label="Количество:"] {
    text-align: left !important;
  }
  
  /* Поле количества */
  #cart_interface table tbody td[data-label="Количество:"] input[type="text"][name="kolvo"] {
    margin: 0;
    display: inline-block;
  }
  
  /* Сумма */
  #cart_interface table tbody td[data-label="Сумма:"] {
    font-weight: 600;
    color: #dc3545;
    font-size: 14px;
    padding: 8px 0 !important;
  }
  
  /* Кнопки справа - группируем в правой части карточки */
  #cart_interface table tbody tr {
    position: relative;
    padding-right: 100px !important;
    min-height: 120px;
  }
  
  /* Контейнер для кнопки обновить - справа по центру */
  #cart_interface table tbody td[data-label=""]:has(input[value="обновить"]) {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: flex-end;
    padding: 0 !important;
    width: auto !important;
    background: transparent;
    margin-top: -16px;
  }
  
  /* Контейнер для кнопки удалить - справа внизу */
  #cart_interface table tbody td:last-child[data-label=""] {
    position: absolute;
    right: 10px;
    bottom: 10px;
    top: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: flex-end;
    padding: 0 !important;
    width: auto !important;
    background: transparent;
    transform: none;
    margin-top: 0;
  }
  
  /* Кнопки обновить и удалить - компактные справа */
  #cart_interface table tbody td[data-label=""] input[type="submit"] {
    min-height: 32px;
    height: 32px;
    padding: 6px 12px !important;
    font-size: 12px !important;
    white-space: nowrap;
    flex-shrink: 0;
    box-sizing: border-box;
    line-height: 1.2;
    min-width: 85px;
    width: auto;
    margin: 0;
  }
  
  /* Специально для кнопки обновить */
  #cart_interface table tbody td[data-label=""] input[type="submit"][value="обновить"] {
    min-width: 85px;
  }
  
  /* Специально для кнопки удалить */
  #cart_interface table tbody td[data-label=""] input[type="submit"][value="удалить -"],
  #cart_interface table tbody td[data-label=""] input[type="submit"][value="удалить-"] {
    min-width: 85px;
  }
  
  /* Убираем подпись для ячеек с кнопками */
  #cart_interface table tbody td[data-label=""]::before {
    display: none !important;
  }
  
  /* Скрываем ячейки с кнопками в обычном потоке */
  #cart_interface table tbody td[data-label=""]:has(input[value="обновить"]),
  #cart_interface table tbody td:last-child[data-label=""] {
    display: block !important;
  }
  
  /* Ячейка с суммой - не должна перекрываться кнопками */
  #cart_interface table tbody td[data-label="Сумма:"] {
    padding-right: 0 !important;
    margin-right: 0;
  }
  
  /* Улучшаем отображение акта */
  #cart_interface table tbody td[data-label="Акт:"] {
    font-size: 11px;
    line-height: 1.3;
  }
  
  #cart_interface table tbody td[data-label="Акт:"] a {
    font-size: 11px;
    word-break: break-word;
  }
  
  /* Срок поставки */
  #cart_interface table tbody td[data-label="Срок поставки:"] {
    font-size: 12px;
    color: #666;
  }
  
  /* Улучшаем общий вид карточек */
  #cart_interface table tbody tr {
    transition: box-shadow 0.2s ease;
  }
  
  #cart_interface table tbody tr:active {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  }
  
  /* Поля ввода количества на мобильных */
  #cart_interface table tbody td input[type="text"][name="kolvo"] {
    width: auto;
    max-width: 80px;
    min-height: 32px;
    padding: 6px 8px;
    font-size: 13px;
    text-align: center;
    box-sizing: border-box;
    border: 1px solid #d7d7d7;
    border-radius: 4px;
    display: inline-block;
  }
  
  /* Ссылки на товары */
  #cart_interface table td a[href*="/market/product/"] {
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
  }
  
  /* Скрываем некоторые элементы на мобильных */
  #cart_interface table tbody td .helptxt {
    font-size: 11px;
    margin-top: 4px;
    display: block;
  }
}

/* ============================================
   2. ОПТИМИЗАЦИЯ КНОПОК "В КОРЗИНУ"
   ============================================ */

@media screen and (max-width: 767px) {
  /* Кнопки в корзине на мобильных - компактные */
  #cart_interface input[type="submit"][id="button"],
  #cart_interface input[type="submit"][name="buy"] {
    min-height: 36px;
    padding: 8px 16px;
    font-size: 13px;
    width: auto;
    max-width: none;
    margin: 4px 0;
    display: inline-block;
    box-sizing: border-box;
    cursor: pointer;
    border-radius: 4px;
    line-height: 1.2;
  }
  
  /* Кнопки "обновить" и "удалить" в одной строке */
  #cart_interface table tbody td[data-label=""] {
    text-align: center !important;
    padding: 8px 0 !important;
  }
  
  /* Кнопка "обновить" - компактная */
  #cart_interface table tbody td input[type="submit"][value="обновить"] {
    min-height: 32px;
    padding: 6px 14px;
    font-size: 12px;
    margin-right: 8px;
  }
  
  /* Кнопка "удалить" - компактная */
  #cart_interface table tbody td input[type="submit"][value="удалить -"] {
    min-height: 32px;
    padding: 6px 14px;
    font-size: 12px;
  }
  
  /* Итоговая строка с суммой - последняя строка в корзине */
  #cart_interface table tbody tr:last-child {
    background: #f8f8f8;
    padding: 15px 10px !important;
    margin-top: 15px;
    border-radius: 8px;
    display: block !important;
    text-align: center;
  }
  
  #cart_interface table tbody tr:last-child td {
    display: inline !important;
    padding: 5px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
  }
  
  #cart_interface table tbody tr:last-child td::before {
    display: none !important;
  }
}

/* ============================================
   3. АДАПТАЦИЯ ПАГИНАЦИИ
   ============================================ */

@media screen and (max-width: 767px) {
  .paginator {
    margin: 20px 0;
    padding: 0 10px;
  }
  
  .paginator .page-links {
    text-align: center;
  }
  
  .paginator .page-links a,
  .paginator .page-links strong {
    display: inline-block;
    min-width: 44px;
    min-height: 44px;
    line-height: 44px;
    padding: 0 8px;
    margin: 4px 2px;
    font-size: 14px;
    text-align: center;
    border-radius: 4px;
    box-sizing: border-box;
  }
  
  .paginator .page-links a {
    background: #f5f5f5;
    color: #333;
    text-decoration: none;
    transition: background 0.2s ease;
  }
  
  .paginator .page-links a:hover {
    background: #dc3545;
    color: #fff;
  }
  
  .paginator .page-links strong {
    background: #dc3545;
    color: #fff;
    font-weight: 600;
  }
  
  /* Скрываем некоторые элементы пагинации на очень маленьких экранах */
  @media screen and (max-width: 480px) {
    .paginator .page-links {
      font-size: 12px;
    }
    
    .paginator .page-links a,
    .paginator .page-links strong {
      min-width: 36px;
      min-height: 36px;
      line-height: 36px;
      padding: 0 6px;
      margin: 2px 1px;
      font-size: 12px;
    }
  }
}

/* ============================================
   4. ОПТИМИЗАЦИЯ ФОРМ ПОИСКА НА ГЛАВНОЙ СТРАНИЦЕ
   ============================================ */

@media screen and (max-width: 767px) {
  /* Контейнер форм поиска на главной */
  .row .col-xs-6.col-lg-4 {
    width: 100% !important;
    margin-bottom: 12px !important;
  }
  
  /* Формы поиска */
  .row form {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  
  /* Поля ввода */
  .row form input[type="text"] {
    width: 100% !important;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14px;
    box-sizing: border-box;
    border: 1px solid #d7d7d7;
    border-radius: 4px;
  }
  
  /* Кнопки поиска */
  .row form input[type="submit"][id="button"] {
    width: 100% !important;
    min-height: 44px;
    padding: 10px 18px;
    font-size: 14px;
    box-sizing: border-box;
    cursor: pointer;
  }
  
  /* Кнопка "Перейти в магазин" */
  .row .col-xs-6.col-lg-4 a.button {
    width: 100%;
    min-height: 44px;
    padding: 10px 18px;
    font-size: 14px;
    display: inline-block;
    text-align: center;
    box-sizing: border-box;
    text-decoration: none;
  }
  
  /* Подсказка о валидации */
  #searchHintIndex {
    font-size: 12px;
    padding: 8px 0;
  }
}

/* ============================================
   5. ОПТИМИЗАЦИЯ БАННЕРА НА ГЛАВНОЙ СТРАНИЦЕ
   ============================================ */

@media screen and (max-width: 767px) {
  img.displayed {
    max-width: 100%;
    height: auto;
    object-fit: cover;
  }
}

/* ============================================
   6. ОБЩИЕ УЛУЧШЕНИЯ ДЛЯ МОБИЛЬНЫХ
   ============================================ */

@media screen and (max-width: 767px) {
  /* Улучшаем отступы контента */
  .market-page #main .wf-wrap,
  .market-page #content {
    padding-left: 10px;
    padding-right: 10px;
  }
  
  /* Заголовки страниц (в том числе на карточке товара) */
  .market-page .row h1 {
    font-size: 22px;
    line-height: 1.25;
    margin: 10px 0 8px 0;
    padding: 0 10px;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .market-page .row h2 {
    font-size: 20px;
    margin: 15px 0 10px 0;
    padding: 0 10px;
  }
  
  .market-page .row p {
    font-size: 14px;
    padding: 0 10px;
    margin: 10px 0;
  }
  
  /* Улучшаем читаемость текста */
  #cart_interface table tbody td {
    font-size: 13px;
    line-height: 1.4;
  }
  
  /* Цены */
  #cart_interface table tbody td .defprice {
    font-size: 11px;
    display: block;
    margin-top: 2px;
  }
  
  /* Артикул и другие поля */
  #cart_interface table tbody td[data-label="Артикул:"] {
    font-size: 12px;
    color: #666;
  }
  
  /* Цена за штуку */
  #cart_interface table tbody td[data-label="Цена:"] {
    font-weight: 600;
    color: #333;
  }
  
  /* Сумма */
  #cart_interface table tbody td[data-label="Сумма:"] {
    font-weight: 600;
    color: #dc3545;
    font-size: 14px;
  }
  
  /* Скрываем поиск на странице корзины - через условие в PHP */
}

/* ============================================
   7. СКРЫТИЕ ГРУПП МАРОК И ТОВАРОВ НА МОБИЛЬНЫХ
   ============================================ */

@media screen and (max-width: 767px) {
  /* Скрываем группы марок и товаров на мобильных */
  .market-page .col-lg-2,
  .market-page .col-lg-3 {
    display: none !important;
  }
  
  /* Товары занимают всю ширину на мобильных */
  .market-page .col-xs-6.col-lg-7,
  .market-page .col-lg-7 {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ============================================
   8. СТИКИ КОРЗИНА НА МОБИЛЬНЫХ
   ============================================ */

@media screen and (max-width: 767px) {
  /* Sticky корзина внизу экрана на мобильных */
  .mobile-cart-sticky {
    position: fixed !important;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #dc3545;
    padding: 12px 15px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    text-align: center;
    display: block !important;
  }
  
  .mobile-cart-sticky a {
    color: #fff !important;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 16px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  
  .mobile-cart-sticky svg {
    width: 20px;
    height: 20px;
    fill: #fff !important;
  }
  
  .mobile-cart-text {
    color: #fff !important;
  }
  
  /* Добавляем отступ снизу для контента, чтобы не перекрывался корзиной */
  .market-page #main {
    padding-bottom: 70px !important;
  }
  
  /* Скрываем корзину в обычном меню на мобильных */
  .header-bar .main-nav #small_cart {
    display: none;
  }
}

/* Скрываем мобильную корзину на десктопе */
.mobile-cart-sticky {
  display: none;
}

@media screen and (min-width: 768px) {
  .mobile-cart-sticky {
    display: none !important;
  }
}

@media screen and (max-width: 767px) {
  .mobile-cart-sticky {
    display: block !important;
  }
}

/* ============================================
   9. УВЕДОМЛЕНИЕ О ДОБАВЛЕНИИ В КОРЗИНУ
   ============================================ */

/* Toast уведомление */
.market-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #28a745;
  color: #fff;
  padding: 16px 24px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  display: none;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  font-weight: 500;
  animation: slideInRight 0.3s ease;
  max-width: 90%;
}

.market-toast.show {
  display: flex;
}

.market-toast.error {
  background: #dc3545;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@media screen and (max-width: 767px) {
  .market-toast {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: calc(100% - 20px);
    font-size: 14px;
    padding: 12px 18px;
  }
}

/* ============================================
   10. МОБИЛЬНОЕ МЕНЮ
   ============================================ */

/* Скрываем мобильное меню на десктопе */
.mobile-menu-toggle,
.mobile-menu-overlay,
.mobile-menu {
  display: none;
}

@media screen and (max-width: 767px) {
  /* Кнопка hamburger меню */
  .mobile-menu-toggle {
    display: flex !important;
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 10001;
    background: #dc3545;
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    padding: 0;
    align-items: center;
    justify-content: center;
  }
  
  .mobile-menu-toggle span {
    display: block;
    width: 24px;
    height: 3px;
    background: #fff;
    position: relative;
    transition: all 0.3s ease;
  }
  
  .mobile-menu-toggle span::before,
  .mobile-menu-toggle span::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 3px;
    background: #fff;
    left: 0;
    transition: all 0.3s ease;
  }
  
  .mobile-menu-toggle span::before {
    top: -8px;
  }
  
  .mobile-menu-toggle span::after {
    bottom: -8px;
  }
  
  .mobile-menu-toggle.active span {
    background: transparent;
  }
  
  .mobile-menu-toggle.active span::before {
    top: 0;
    transform: rotate(45deg);
  }
  
  .mobile-menu-toggle.active span::after {
    bottom: 0;
    transform: rotate(-45deg);
  }
  
  /* Мобильное меню */
  .mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    display: none;
  }
  
  .mobile-menu-overlay.show {
    display: block;
  }
  
  .mobile-menu {
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    max-width: 85%;
    height: 100%;
    background: #fff;
    z-index: 9999;
    overflow-y: auto;
    transition: right 0.3s ease;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
  }
  
  .mobile-menu.show {
    right: 0;
  }
  
  .mobile-menu-header {
    background: #dc3545;
    color: #fff;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .mobile-menu-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
  }
  
  .mobile-menu-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .mobile-menu-content {
    padding: 20px 0;
  }
  
  .mobile-menu-content ul {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  
  .mobile-menu-content li {
    border-bottom: 1px solid #f0f0f0;
  }
  
  .mobile-menu-content a {
    display: block;
    padding: 15px 20px;
    color: #333;
    text-decoration: none;
    font-size: 15px;
    transition: background 0.2s ease;
  }
  
  .mobile-menu-content a:hover {
    background: #f5f5f5;
  }
  
  /* Скрываем обычное меню на мобильных */
  .market-page .header-bar .main-nav {
    display: none;
  }
  
  /* Адаптируем меню для мобильного отображения */
  .mobile-menu-content .main-nav {
    display: block !important;
  }
  
  .mobile-menu-content .main-nav li {
    display: block;
    width: 100%;
    border-bottom: 1px solid #f0f0f0;
  }
  
  .mobile-menu-content .main-nav a {
    display: block;
    padding: 15px 20px;
    color: #333;
    text-decoration: none;
    font-size: 15px;
  }
  
  .mobile-menu-content .main-nav .sub-nav {
    position: static;
    display: none;
    box-shadow: none;
    background: #f8f8f8;
    padding-left: 20px;
  }
  
  .mobile-menu-content .main-nav li.has-children > a::after {
    content: ' ▼';
    float: right;
    font-size: 12px;
  }
  
  .mobile-menu-content .main-nav li.has-children.active > .sub-nav {
    display: block;
  }
  
  /* Обработка подменю в мобильном меню */
  .mobile-menu-content .main-nav > li > a {
    position: relative;
  }
}

/* Очень маленькие экраны (до 480px) */
@media screen and (max-width: 480px) {
  #cart_interface table tbody tr {
    padding: 10px;
    margin-bottom: 12px;
  }
  
  #cart_interface .image_sm {
    width: 70px;
    height: 70px;
  }
  
  #cart_interface table tbody td {
    font-size: 13px;
    padding: 6px 0;
  }
  
  #cart_interface table tbody td::before {
    font-size: 12px;
    min-width: 80px;
  }
  
  .market-page .row h2 {
    font-size: 18px;
  }
  
  .market-page .row p {
    font-size: 13px;
  }
  
  /* Кнопки на очень маленьких экранах */
  #cart_interface input[type="submit"][id="button"],
  #cart_interface input[type="submit"][name="buy"] {
    font-size: 13px;
    padding: 8px 16px;
  }
  
  /* Поля ввода */
  #cart_interface table tbody td input[type="text"][name="kolvo"] {
    max-width: 100px;
    font-size: 13px;
  }
}

/* ============================================
   11. АДАПТАЦИЯ КАРТОЧКИ ТОВАРА НА МОБИЛЬНЫХ
   ============================================ */

@media screen and (max-width: 767px) {
  /* Убираем горизонтальный скролл */
  html, body {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Основной контейнер страницы */
  .market-page #page,
  .market-page #main,
  .market-page .wf-wrap,
  .market-page .wf-container-main {
    max-width: 100% !important;
    overflow-x: hidden;
  }

  /* Контейнер row */
  .market-page .row {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 15px !important;
    margin: 0 !important;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  /* Основной контент страницы маркета (в том числе карточка товара) */
  .market-page main {
    padding: 0;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
  }

  /* Карточка товара - таблица с изображением и информацией */
  .market-page main > table[width="100%"],
  .market-page .row table[width="100%"] {
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse;
    table-layout: fixed !important;
  }
  
  /* Заголовок карточки товара */
  .market-page .row table[width="100%"] tbody tr:first-child td,
  .market-page main > table[width="100%"] tbody tr:first-child td {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    padding: 10px 0;
    text-align: left;
    box-sizing: border-box;
    overflow-wrap: break-word;
  }
  
  .market-page .row table[width="100%"] tbody tr:first-child td h4,
  .market-page main > table[width="100%"] tbody tr:first-child td h4 {
    font-size: 12px;
    margin: 0 0 6px 0;
    color: #666;
    font-weight: 500;
  }
  
  .market-page .row table[width="100%"] tbody tr:first-child td h1,
  .market-page main > table[width="100%"] tbody tr:first-child td h1 {
    font-size: 16px;
    margin: 0;
    line-height: 1.3;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    font-weight: 600;
  }
  
  /* Основная строка с изображением и информацией */
  .market-page .row table[width="100%"] tbody tr:nth-child(2),
  .market-page main > table[width="100%"] tbody tr:nth-child(2) {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
  
  /* Ячейка с изображением */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:first-child,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:first-child {
    width: 100% !important;
    max-width: 100% !important;
    padding: 15px 0;
    text-align: center;
    background: #f9f9f9;
    border-bottom: 1px solid #e0e0e0;
    box-sizing: border-box;
  }
  
  /* Изображение товара на мобильных */
  .market-page .row table[width="100%"] .image,
  .market-page main > table[width="100%"] .image {
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
  }
  
  .market-page .row table[width="100%"] .image img,
  .market-page main > table[width="100%"] .image img {
    width: 100%;
    height: auto;
    max-width: 100%;
    object-fit: contain;
  }
  
  /* Скрываем заглушку no_image на мобильных */
  .market-page .row table[width="100%"] .image img[src*="no_image"],
  .market-page .row table[width="100%"] .image a[href*="no_image"],
  .market-page main > table[width="100%"] .image img[src*="no_image"],
  .market-page main > table[width="100%"] .image a[href*="no_image"] {
    display: none !important;
  }
  
  .market-page .row table[width="100%"] .image:has(img[src*="no_image"]),
  .market-page .row table[width="100%"] .image:has(a[href*="no_image"]),
  .market-page main > table[width="100%"] .image:has(img[src*="no_image"]),
  .market-page main > table[width="100%"] .image:has(a[href*="no_image"]) {
    display: none !important;
  }
  
  /* Ячейка с информацией о товаре */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2),
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px 0;
    vertical-align: top;
    box-sizing: border-box;
    overflow-wrap: break-word;
  }
  
  /* Информация о товаре - характеристики */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) b,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) b {
    font-weight: 600;
    color: #333;
    display: inline-block;
    min-width: 100px;
    max-width: 100px;
    margin-right: 8px;
    font-size: 12px;
    vertical-align: top;
    flex-shrink: 0;
  }
  
  /* Значения характеристик - переносятся правильно */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) b + *,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) b + * {
    display: inline;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: calc(100% - 110px);
  }
  
  /* Улучшаем отступы между строками характеристик */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) br,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) br {
    display: block;
    margin: 0;
    line-height: 0.5;
    content: '';
    height: 0;
  }
  
  /* Цена товара */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) h3,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) h3 {
    font-size: 18px;
    margin: 10px 0 6px 0;
    color: #dc3545;
    font-weight: 600;
    line-height: 1.2;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .defprice,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .defprice {
    font-size: 13px;
    color: #666;
    display: block;
    margin-top: 4px;
    margin-bottom: 8px;
  }
  
  /* Кнопка "В корзину" - компактная */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) input[type="submit"][id="button"],
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) input[type="submit"][id="button"] {
    width: 100%;
    max-width: 100%;
    min-height: 36px;
    height: 36px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    margin: 8px 0 12px 0;
    box-sizing: border-box;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1.2;
  }
  
  /* Табы описания */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .container,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .container {
    width: 100%;
    padding: 0;
    margin: 20px 0 0 0;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .tabbable-panel,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .tabbable-panel {
    width: 100%;
  }
  
  /* Навигация табов */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .nav-tabs,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .nav-tabs {
    display: flex;
    flex-wrap: wrap;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 15px;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .nav-tabs li,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .nav-tabs li {
    flex: 1;
    min-width: 50%;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .nav-tabs li a,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .nav-tabs li a {
    display: block;
    padding: 12px 10px;
    text-align: center;
    font-size: 14px;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    word-wrap: break-word;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .nav-tabs li.active a,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .nav-tabs li.active a {
    border-bottom-color: #dc3545;
    color: #dc3545;
    font-weight: 600;
  }
  
  /* Содержимое табов */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .tab-content,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .tab-content {
    padding: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .tab-pane,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .tab-pane {
    font-size: 13px;
    line-height: 1.6;
    width: 100%;
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .tab-pane p,
  .market-page main > table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) .tab-pane p {
    margin: 10px 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
  }
  
  /* Дополнительные изображения */
  .market-page .row table[width="100%"] tbody tr:nth-child(3),
  .market-page main > table[width="100%"] tbody tr:nth-child(3) {
    display: block;
    width: 100%;
    max-width: 100%;
    padding: 15px 0;
    box-sizing: border-box;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(3) td {
    display: block;
    width: 100% !important;
    padding: 0;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(3) td .row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(3) td .image_sm {
    width: 100px;
    height: 100px;
    flex-shrink: 0;
  }
  
  .market-page .row table[width="100%"] tbody tr:nth-child(3) td .image_sm img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  
  /* Скрываем пустую третью ячейку */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:last-child:empty {
    display: none;
  }
  
  /* Аналогичные товары - заголовок */
  .market-page .row h2 {
    font-size: 20px;
    margin: 20px 10px 15px 10px;
    padding: 0;
  }
  
  /* Аналогичные товары - таблица */
  .market-page .row table[width="100%"]:not(:first-of-type) {
    width: 100% !important;
  }
  
  /* Скрываем поиск на мобильной версии */
  /* Поиск находится внутри main на всех страницах маркета */  
  /* На мобильных устройствах поиск не так важен, пользователи используют десктопную версию для поиска */
  .market-page main {
    display: none !important;
  }
  
  /* Улучшаем отображение характеристик товара */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) {
    padding: 12px 15px;
    font-size: 13px;
    line-height: 1.6;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  
  /* Характеристики товара - каждая на новой строке */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) b {
    display: inline-block;
    min-width: 100px;
    margin-right: 6px;
    margin-bottom: 0;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    vertical-align: top;
  }
  
  /* Значения характеристик - переносятся правильно */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) b + * {
    display: inline;
    font-size: 13px;
    line-height: 1.6;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  
  /* Улучшаем отступы между строками характеристик - br создает новую строку */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) br {
    display: block;
    margin: 0;
    line-height: 0.3;
    content: '';
  }
  
  /* Улучшаем отображение текста - каждая строка с характеристикой */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) {
    white-space: normal;
  }
  
  /* Улучшаем перенос длинных значений характеристик */
  .market-page .row table[width="100%"] tbody tr:nth-child(2) td:nth-child(2) > * {
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
  }
  
}


