.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
  box-sizing: border-box;
}
.lede {
  color: var(--muted);
  margin: 0.25rem 0 1rem;
}
.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.06);
  background: #fff;
}
.catalog {
  margin-top: 12px;
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th,
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  text-align: center;
  white-space: nowrap;
}
.table .price {
  white-space: nowrap;
}
.table .qty {
  width: 84px;
}
.table td:first-child img {
  width: 130px !important;
  min-width: 130px !important;
  height: 130px !important;
  object-fit: contain;
}
.qty-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.qty-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.qty-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.link {
  color: var(--accent);
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
}
.link:hover {
  text-decoration: underline;
}

.breadcrumbs {
  margin: 8px 0 12px;
  font-size: 14px;
  color: var(--muted);
}
.breadcrumbs a {
  color: inherit;
  text-decoration: none;
}
.breadcrumbs a:hover {
  text-decoration: underline;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin: 12px 0 20px;
}
.category-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: box-shadow 0.15s ease, transform 0.05s ease;
}
.category-card:hover {
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.06);
  transform: translateY(-1px);
}
.category-name {
  font-weight: 600;
}

/* Cart drawer */
.cart-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.08);
  z-index: 1000;
}
.cart-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
}
.cart-toggle {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.cart-summary {
  display: flex;
  gap: 16px;
  color: #111;
  font-weight: 600;
}
.cart-panel {
  display: none;
  padding: 10px 16px 14px;
  border-top: 1px dashed var(--border);
  max-height: 60vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-x: auto;
}
.cart-drawer.open .cart-panel {
  display: block;
}

.cart-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 8px;
  min-width: 520px; /* чтобы колонки не схлопывались */
}
.cart-table th,
.cart-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.cart-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 8px;
}
.btn {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
.btn-accent {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}
.btn[disabled] {
  opacity: 0.5;
  cursor: default;
}
.comment {
  width: 100%;
  min-height: 70px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
.muted {
  color: var(--muted);
}
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1100;
}
.modal.open {
  display: block;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.modal-dialog {
  position: relative;
  margin: 6vh auto;
  width: min(92%);
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  max-height: 92vh;
  overflow: hidden; /* чтобы прокрутка была в теле модалки, а не у диалога */
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-title {
  font-size: 20px;
  font-weight: 800;
}
.modal-close {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}
.modal-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  margin-top: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  max-height: calc(92vh - 56px); /* ~ высота заголовка + внутренние отступы */
}
.prop-table {
  width: 100%;
  border-collapse: collapse;
}
.prop-table th,
.prop-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.prop-table th {
  width: 40%;
  text-align: left;
  color: var(--muted);
  font-weight: 600;
}
.buy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}
.buy-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.buy-qty {
  width: 90px;
  text-align: right;
}
@media (max-width: 720px) {
  .modal-body {
    grid-template-columns: 1fr;
  }
}
/* Catalog layout with left filters */
.catalog-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 12px;
  align-items: start;
}
.catalog-layout > * {
  min-width: 0;
}
@media (max-width: 960px) {
  .catalog-layout {
    grid-template-columns: 1fr;
  }
}
.filter-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
}
.filter-title {
  font-weight: 700;
  margin: 4px 0 10px;
}
.brand-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.brand-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 320px;
  overflow: auto;
}
.brand-list li {
  margin: 2px 0;
}
.filter-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}
/* Контролы каталога */
.catalog-controls {
  margin: 6px 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.mode-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}
/* ---------- Мобильные улучшения ---------- */

/* Планшеты и уже: фильтры сверху, карта/корзина компактнее */
@media (max-width: 960px) {
  /* Фильтры отделяем от таблицы */
  .filter-card {
    margin-bottom: 12px;
  }

  /* Панель корзины: разрешаем перенос и уплотняем */
  .cart-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .cart-summary {
    width: 100%;
    justify-content: space-between;
  }
}

/* Телефоны: адаптивная верстка */
@media (max-width: 720px) {
  /* Контейнер таблицы — горизонтальный скролл */
  .card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Таблица — минимальная ширина для скролла */
  .table {
    min-width: 600px;
  }

  .table th,
  .table td {
    padding: 8px 6px;
    font-size: 13px;
  }

  /* Уменьшаем изображения товаров */
  .table td:first-child img {
    width: 80px !important;
    min-width: 80px !important;
    height: 80px !important;
  }

  .table td:first-child {
    min-width: 90px;
  }

  .table .qty {
    width: 60px;
  }

  /* Грид категорий — одна колонка на узких экранах */
  .category-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .category-card {
    padding: 12px 14px;
  }

  /* Модалка — почти на весь экран */
  .modal-dialog {
    width: 98%;
    overflow-y: auto;
    padding: 12px;
    margin: 2vh auto;
    max-height: 94vh;
  }

  .modal-body {
    grid-template-columns: 1fr;
    gap: 12px;
    max-height: calc(94vh - 56px);
  }

  /* Изображение в модалке */
  .modal-body > div:first-child img {
    width: 100%;
    max-width: 200px;
    height: auto;
    display: block;
    margin: 0 auto;
  }

  /* Корзина-панель */
  .cart-drawer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.08);
    z-index: 1000;

    /* важное: ограничиваем высоту всей корзины и разрешаем вертикальный скролл */
    max-height: 70vh;
    display: flex;
    flex-direction: column;
  }

  .cart-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    flex: 0 0 auto;
  }

  .cart-summary {
    justify-content: space-between;
    font-size: 14px;
  }

  .cart-bar > div:last-child {
    display: flex;
    gap: 8px;
  }

  .cart-bar > div:last-child .btn,
  .cart-bar > div:last-child .cart-toggle {
    flex: 1;
    text-align: center;
  }

  /* содержимое корзины — прокручиваемое */
  .cart-panel {
    display: none;
    padding: 10px 16px 14px;
    border-top: 1px dashed var(--border);
    max-height: calc(70vh - 48px); /* ~ высота cart-bar */
    overflow-y: auto;
    overscroll-behavior: contain;
    overflow-x: auto;
    flex: 1 1 auto;
  }

  .cart-drawer.open .cart-panel {
    display: block;
  }

  .cart-table {
    min-width: 480px;
  }

  /* Фильтры — компактнее */
  .filter-card {
    padding: 10px;
  }

  .brand-list {
    max-height: 200px;
  }

  .filter-actions {
    flex-direction: column;
    gap: 6px;
  }

  .filter-actions .btn {
    width: 100%;
    text-align: center;
  }

  /* Кнопки и контролы */
  .btn {
    padding: 10px 12px;
    font-size: 14px;
  }

  .qty-btn {
    width: 32px;
    height: 32px;
  }

  .qty-wrap {
    gap: 4px;
  }

  /* Строка покупки в модалке */
  .buy-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .buy-controls {
    justify-content: space-between;
  }

  .buy-qty {
    flex: 1;
    min-width: 60px;
  }

  /* Комментарий к заказу */
  .comment {
    min-height: 60px;
  }

  /* Режим добавления и сортировка — в колонку */
  .catalog-layout > div > div:first-child {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .catalog-layout > div > div:first-child > div {
    width: 100%;
    justify-content: space-between;
  }

  /* Хлебные крошки */
  .breadcrumbs {
    font-size: 12px;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 4px;
  }
  /* Переопределение инлайновых стилей */
  [style*="display: flex"][style*="justify-content: space-between"] {
    flex-wrap: wrap !important;
  }

  /* Блок переключателя режима и сортировки */
  .catalog-layout > div > div[style*="display: flex"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  /* Вложенные flex-блоки */
  .catalog-layout
    > div
    > div[style*="display: flex"]
    > div[style*="display: flex"] {
    width: 100% !important;
    flex-wrap: wrap !important;
  }

  /* Поиск с кнопкой */
  div[style*="display:flex"][style*="gap:8px"] {
    flex-direction: column !important;
  }

  div[style*="display:flex"][style*="gap:8px"] .brand-search {
    width: 100% !important;
  }

  div[style*="display:flex"][style*="gap:8px"] .btn {
    width: 100% !important;
  }
  /* Контролы каталога — адаптив */
  .catalog-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .mode-controls {
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .sort-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .sort-controls select {
    width: 100%;
  }

  .search-controls {
    flex-direction: column;
  }

  .search-controls .brand-search {
    width: 100%;
  }

  .search-controls .btn {
    width: 100%;
  }
}

/* Очень узкие экраны (< 420px) */
@media (max-width: 420px) {
  .table {
    min-width: 500px;
  }

  .table th,
  .table td {
    padding: 6px 4px;
    font-size: 12px;
  }

  .table td:first-child img {
    width: 60px !important;
    min-width: 60px !important;
    height: 60px !important;
  }

  .table td:first-child {
    min-width: 70px;
  }

  .btn {
    padding: 8px 10px;
    font-size: 13px;
  }

  .qty-btn {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .cart-summary {
    font-size: 13px;
    flex-direction: column;
    gap: 4px;
  }

  .modal-title {
    font-size: 16px;
  }

  .prop-table th,
  .prop-table td {
    padding: 4px 6px;
    font-size: 13px;
  }

  .category-card {
    padding: 10px 12px;
  }

  .category-name {
    font-size: 14px;
  }

  h1 {
    font-size: 20px;
  }
  .mode-controls {
    flex-direction: column;
  }

  .mode-controls > span {
    width: 100%;
    margin-bottom: 4px;
  }

  .mode-controls div[role="group"] {
    width: 100%;
    display: flex;
  }

  .mode-controls div[role="group"] .btn {
    flex: 1;
  }
  /* Кнопки режима — в колонку */
  div[role="group"][style*="display:flex"] {
    flex-direction: column !important;
    width: 100% !important;
  }

  div[role="group"][style*="display:flex"] .btn {
    width: 100% !important;
  }

  /* Сортировка — в колонку */
  div[style*="display: flex"][style*="gap: 8px"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  select#sort {
    width: 100% !important;
  }
}
/* Ландшафтная ориентация на телефонах */
@media (max-width: 720px) and (orientation: landscape) {
  .modal-dialog {
    margin: 2vh auto;
    max-height: 96vh;
  }

  .cart-drawer {
    max-height: 50vh;
  }

  .modal-body > div:first-child img {
    max-width: 120px;
  }
}

/* Улучшение тач-взаимодействия */
@media (hover: none) and (pointer: coarse) {
  .qty-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .btn {
    min-height: 44px;
  }

  .category-card {
    min-height: 48px;
  }

  .link:hover {
    text-decoration: none;
  }
}

/* Контролы поиска в левой колонке */
.search-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

/* Компактная адаптация хедера для формы поиска */
@media (max-width: 720px) {
  .header-actions form[action$="/catalog/search"] {
    width: 100%;
    justify-content: space-between;
  }
  .header-actions form[action$="/catalog/search"] input[type="search"] {
    flex: 1;
    min-width: 0;
  }
}

/* Таблица: горизонтальный скролл на узких экранах */
@media (max-width: 720px) {
  .card {
    overflow-x: auto;
    border-radius: 8px;
  }
  .table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .table th,
  .table td {
    padding: 8px 6px;
    font-size: 13px;
  }
  .table td:first-child {
    min-width: 100px;
    width: 100px;
  }
  .table td:nth-child(3) {
    min-width: 150px;
    max-width: 220px;
    white-space: normal;
    word-wrap: break-word;
  }
}

/* Force flex layout and scroll behavior for cart drawer/panel */
.cart-drawer {
  display: flex !important;
  flex-direction: column !important;
  max-height: 70vh !important;
}

.cart-bar {
  flex: 0 0 auto !important;
}

.cart-panel {
  display: none;
  padding: 10px 16px 14px;
  border-top: 1px dashed var(--border);
  overflow-y: auto !important;
  overscroll-behavior: contain !important;
  overflow-x: auto;
  flex: 1 1 auto !important;
  max-height: calc(70vh - 48px) !important; /* ~ height of cart-bar */
}
.cart-drawer.open .cart-panel {
  display: block !important;
}