/* Контейнер-флекс для всех колонок */
.drilldown-menu {
  display: flex;
  gap: clamp(1.5em, 2vw, 3em);
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  position: relative;
  min-height: clamp(20rem, 40vh, 28rem); /* было 450px */
  align-items: flex-start;
  padding: clamp(0.5rem, 1vw, 1.25rem);
  box-sizing: border-box;
}

/* Уровень - может содержать несколько колонок */
.drilldown-level {
  display: flex;
  flex-shrink: 0;
  position: relative;
  height: 70vh;
  gap: 0;
}

.drilldown-level:not(.active) {
  display: none;
}

/* На десктопе показываем все активные уровни */
@media (min-width: 769px) {
  .drilldown-menu {
    overflow-x: auto;
    gap: clamp(1.5em, 2vw, 3em);
  }

  .drilldown-level.active {
    display: flex;
  }
  
  /* Добавляем gap только между разными уровнями */
  .drilldown-level + .drilldown-level {
    margin-left: 0;
  }
}

/* Каждая колонка отвечает за один уровень */
.drilldown-column {
  flex: 1 0 clamp(12rem, 18vw, 17.5rem); /* 200-280px */
  min-width: 12rem;
  max-width: 17.5rem;
  display: block;
  height: 100%;
  overflow-y: auto;
  border: 1px solid #e0e0e0;
  border-radius: 0.5rem;
  background: #fff;
  position: relative;
  box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.1);
}

/* Добавляю обратно комментарий для стилей склеивания колонок */

.drilldown-level .drilldown-column:not(:first-child),
.drilldown-level .drilldown-column:not(:last-child) {
  border-left: none !important;

  margin-left: 0 !important;
  box-shadow: none !important;
}

.drilldown-level .drilldown-column:not(:last-child)::after {
  display: none !important; 
}

/* Тень только на всем блоке уровня */
.drilldown-level {
  box-shadow: 0 0.125rem 0.5rem rgba(0,0,0,0.1);
  border-radius: 0.5rem;
}

/* Убираем тень с отдельных колонок, если в уровне больше одной */
.drilldown-level:has(.drilldown-column:nth-child(2)) .drilldown-column {
  box-shadow: none;
}

/* Fallback для браузеров без поддержки :has() */
.drilldown-level.multi-column .drilldown-column {
  box-shadow: none;
}

/* Добавляем тонкий визуальный разделитель между колонками одного уровня */
.drilldown-level .drilldown-column:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 0.5rem;
  right: 0;
  bottom: 0.5rem;
  width: 1px;
  background: linear-gradient(to bottom, transparent 0%, #f0f0f0 10%, #f0f0f0 90%, transparent 100%);
  z-index: 1;
}

/* Кастомный скроллбар */
.drilldown-column::-webkit-scrollbar {
  width: 0.375rem;
}
.drilldown-column::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 0.1875rem;
}
.drilldown-column::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 0.1875rem;
}
.drilldown-column::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Заголовок колонки для мобильной навигации */
.column-header {
  display: none;
  padding: 0.75rem 1rem;
  background: #f8f9fa;
  border-bottom: 1px solid #e0e0e0;
  font-weight: 600;
  color: #333;
  position: sticky;
  top: 0;
  z-index: 10;
}

.column-header .back-button {
  background: none;
  border: none;
  color: #007cba;
  cursor: pointer;
  padding: 0;
  margin-right: 0.5rem;
  font-size: 1rem;
}

.column-header .back-button:hover {
  color: #005a87;
}

/* Списки категорий */
.drilldown-column ul {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
}

/* Пункт */
.drilldown-column .menu-item {
  border-radius: 0.375rem;
  margin-bottom: 0.125rem;
  transition: background-color .2s;
  position: relative;
}

.drilldown-column .menu-item:hover {
  background: #f8f9fa;
  text-decoration: none;
  color: inherit;
}

.drilldown-column .menu-item.has-children::after {
  position: absolute;
  right: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  font-size: 1rem;
  pointer-events: none;
}

/* ИСПРАВЛЕНИЕ 2: Обновленные стили для новой структуры */
.item-header {
  display: flex;
  align-items: center;
  padding: 0.375rem 0.5rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  border-radius: 0.375rem;
  transition: background-color .2s;
}

.item-header:hover {
  background: #f0f4f8;
  text-decoration: none;
  color: inherit;
}

/* Ссылка теперь только на картинке и заголовке */
.item-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 0;
}

.item-link:hover {
  text-decoration: none;
  color: inherit;
}

.item-image {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 0.35rem;
  overflow: hidden;
  margin-right: 0.8rem;
  flex-shrink: 0;
  pointer-events: none;
}

.item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.item-image.fallback {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.6875rem;
  pointer-events: none;
}

.item-content {
  flex: 1;
  min-width: 0;
  pointer-events: none;
}

/* Стрелка для показа наличия подкатегорий */
.expand-arrow {
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 1rem;
  flex-shrink: 0;
  cursor: pointer;
}

.expand-arrow::after {
  content: '›';
}

.menu-item.has-children .expand-arrow {
  display: flex;
}

.menu-item:not(.has-children) .expand-arrow {
  display: none;
}

/* На десктопе вся область кликабельна для hover эффектов */
@media (min-width: 769px) {
  .item-header {
    cursor: pointer;
  }

  .expand-arrow {
    pointer-events: none;
  }
}

/* ИСПРАВЛЕНИЕ 3: Компактный стиль для названия и счетчика */
.item-title {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: #333;
  font-size: 0.875rem;
  line-height: 1.4;
  margin: 0;
  pointer-events: none;
}

.item-title:hover {
  color: #007cba;
}

/* ИСПРАВЛЕНИЕ 3: Компактное отображение счетчика */
.item-count {
  font-size: 0.6875rem;
  color: #999;
  font-weight: 500;
  margin-left: 0.25rem;
  opacity: 0.8;
}

/* ИСПРАВЛЕНИЕ 3: Альтернативный вариант - счетчик справа */
.item-content-with-count {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.item-title-compact {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-count-right {
  font-size: 0.6875rem;
  color: #999;
  font-weight: 500;
  margin-left: 0.5rem;
  flex-shrink: 0;
}

/* Состояние пустой колонки */
.drilldown-column.empty {
  display: none;
}

/* Мобильная навигация */
.mobile-navigation {
  display: none;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: #666;
}

.breadcrumb-item {
  cursor: pointer;
  color: #007cba;
}

.breadcrumb-item:hover {
  text-decoration: underline;
}

.breadcrumb-separator {
  color: #999;
}

/* Адаптив */
@media (max-width: 1024px) {
  .drilldown-column {
    min-width: 10.5rem;
    max-width: 15rem;
  }
}

@media (max-width: 768px) {
  .drilldown-menu {
    display: block;
    overflow-x: visible;
    /* ИСПРАВЛЕНИЕ 1: Убираем фиксированную высоту на мобильных */
    min-height: auto;
    /* Правильные отступы для мобильных */
    padding: 2.5rem 0.625rem 0.625rem 0.625rem;
    gap: 0;
  }
  
  .mobile-navigation {
    display: block;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    padding: 0.5rem 1rem;
    z-index: 30;
  }
  
  .drilldown-level {
    display: block;
    box-shadow: none; /* Убираем тень уровня на мобильных */
    /* ИСПРАВЛЕНИЕ 1: Убираем фиксированную высоту на мобильных */
    height: auto;
  }
  
  .drilldown-level:not(.active) {
    display: none;
  }
  
  .drilldown-level.active {
    display: block;
  }

  /* ИСПРАВЛЕНИЕ 3: Объединяем колонки в одну на мобильных */
  .drilldown-column {
    min-width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 70vh;
    margin-bottom: 0;
    border-radius: 0.5rem;
    border: 1px solid #e0e0e0;
    box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.1);
  }

  /* Прячем все колонки кроме первой на каждом уровне */
  .drilldown-level .drilldown-column:not(:first-child) {
    display: none;
  }

  /* Объединяем содержимое всех колонок в первую */
  .drilldown-level.mobile-merged .drilldown-column:first-child ul {
    max-height: none;
  }

  /* Убираем стили склеивания на мобильных */
  .drilldown-level .drilldown-column:not(:first-child) {
    border-left: 1px solid #e0e0e0;
    border-radius: 0.5rem;
    margin-left: 0;
  }
  
  .drilldown-level .drilldown-column:not(:last-child) {
    border-radius: 0.5rem;
  }
  
  .drilldown-level .drilldown-column:not(:last-child)::after {
    display: none;
  }
  
  .column-header {
    display: flex;
    align-items: center;
    border-radius: 0.5rem;
  }
  
  /* Восстанавливаем размеры для мобильных */
  .item-header {
    padding: 0.75rem;
  }
  
  .item-image {
    width: 3.8rem;
    height: 3.8rem;
    margin-right: 1rem;
  }
}

@media (max-width: 480px) {
  .drilldown-column {
    max-height: 60vh;
  }
}

/* Дополнительные стили для улучшения UI */
.drilldown-menu-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  color: #666;
}

.drilldown-menu-empty {
  text-align: center;
  padding: 2.5rem 1.25rem;
  color: #666;
  font-style: italic;
}

/* Плавная анимация появления новых уровней */
.drilldown-level {
  opacity: 0;
  transform: translateX(0.625rem);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.drilldown-level.active {
  opacity: 1;
  transform: translateX(0);
}

.drilldown-menu > p:empty {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
}

.drilldown-level .drilldown-column:first-child {
  border-radius: 0.5rem !important;
}
