/* =========================================================
   AT-DSG PWA Mobile Styles  v4
   ========================================================= */

/* ============================================================
   LOGO — новый дизайн с иконкой (все устройства)
   ============================================================ */
.logo {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  height: auto !important;
  gap: 10px !important;
  text-decoration: none !important;
}

.logo__img-icon {
  height: 54px !important;
  width: 54px !important;
  object-fit: contain !important;
  flex-shrink: 0 !important;
  display: block !important;
}

.logo__brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.logo__name {
  font-size: 22px;
  font-weight: 800;
  color: #1b3a6b;
  letter-spacing: -0.3px;
  line-height: 1;
}

.logo__text {
  display: block !important;
  font-size: 9px !important;
  font-weight: 500 !important;
  color: #71717a !important;
  letter-spacing: 0.3px;
  line-height: 1.3;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ============================================================
   CATEGORY CARDS — текст по центру (все версии)
   ============================================================ */
.category-card__title {
  text-align: center !important;
  width: 100%;
}

/* ============================================================
   WELCOME SCREEN
   ============================================================ */
#pwa-welcome {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 24px) 28px env(safe-area-inset-bottom, 24px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#pwa-welcome.hidden {
  opacity: 0;
  transform: scale(1.04);
  pointer-events: none;
}

.pwa-welcome__logo {
  width: 120px;
  height: 120px;
  margin-bottom: 28px;
  animation: pwa-logo-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes pwa-logo-in {
  from { opacity: 0; transform: scale(0.6); }
  to   { opacity: 1; transform: scale(1); }
}

.pwa-welcome__brand {
  font-size: 32px;
  font-weight: 800;
  color: #1b3a6b;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
  animation: pwa-fade-up 0.5s 0.15s ease both;
}

.pwa-welcome__tagline {
  font-size: 13px;
  color: #71717a;
  text-align: center;
  line-height: 1.5;
  max-width: 260px;
  margin-bottom: 0;
  animation: pwa-fade-up 0.5s 0.25s ease both;
}

@keyframes pwa-fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   BOTTOM NAVIGATION
   ============================================================ */
#pwa-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #fff;
  border-top: 1px solid #e4e4e7;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -1px 20px rgba(0,0,0,0.06);
}

html.pwa-mode #pwa-bottom-nav { display: flex; }

.pwa-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: #71717a;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}

.pwa-nav__item.active { color: #1b3a6b; }
.pwa-nav__item:active { color: #1b3a6b; }

.pwa-nav__icon { font-size: 20px; line-height: 1; }
.pwa-nav__label { font-size: 10px; font-weight: 600; letter-spacing: 0.2px; }

.pwa-nav__icon-wrap { position: relative; display: inline-flex; }

.pwa-nav__badge {
  position: absolute;
  top: -3px;
  right: -7px;
  background: #ef4444;
  color: #fff;
  border-radius: 10px;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}

/* ============================================================
   MOBILE BROWSER — фикс overflow (все устройства <= 768px)
   ============================================================ */
@media (max-width: 768px) {

  /* 1. Сбрасываем min-width на всех уровнях — html, body, wrapper */
  html {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    width: 100% !important;
  }

  body {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden !important;
    position: relative !important;
  }

  .wrapper {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  /* 2. Контейнеры — 100% ширины */
  .container,
  #main-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* 3. Шапка: убираем фиксированную ширину */
  .header {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 0 !important;
    gap: 0 !important;
    margin: 0 !important;
  }

  /* 4. Верхняя строка header (телефон + email) — скрываем на мобильном */
  .header__row:first-child {
    display: none !important;
  }

  /* 5. Строка logo + search — горизонтальная, без переполнения */
  .header__row:nth-child(2) {
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-start !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 8px 12px !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  /* 6. Логотип — только иконка на мобильном (убираем текст AT-DSG) */
  .header__row:nth-child(2) .logo {
    flex-shrink: 0;
    gap: 0 !important;
  }

  .logo__img-icon {
    height: 38px !important;
    width: 38px !important;
  }

  /* На мобильном в браузере: только иконка, текст "AT-DSG" скрываем */
  .logo__brand,
  .header .logo .logo__brand,
  .header__row .logo .logo__brand {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    overflow: hidden !important;
  }

  /* 7. Поисковая строка — на всю оставшуюся ширину, новый дизайн */
  .search-form {
    flex: 1 !important;
    min-width: 0 !important;
    width: auto !important;
  }

  .search-form .search-from__form {
    display: flex !important;
    align-items: center;
    border: 1.5px solid #cbd5e1 !important;
    border-radius: 22px !important;
    background: #f8fafc !important;
    height: 40px !important;
    overflow: hidden;
    padding: 0 !important;
    justify-content: flex-start !important;
  }

  .search-form .search-form__input {
    flex: 1 !important;
    width: auto !important;
    min-width: 0 !important;
    height: 40px !important;
    line-height: 40px !important;
    font-size: 13px !important;
    padding: 0 10px !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    border-radius: 0 !important;
    box-sizing: border-box;
  }

  .search-form .search-form__button {
    flex-shrink: 0;
    height: 40px !important;
    width: 40px !important;
    min-width: 40px;
    border: none !important;
    background: #1b3a6b !important;
    color: #fff !important;
    border-radius: 0 22px 22px 0 !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* 8. Навигационное меню — горизонтальный скролл */
  .header__row:nth-child(3) {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding: 6px 0 6px 12px !important;
    scrollbar-width: none;
    border-top: 1px solid #f1f5f9;
  }
  .header__row:nth-child(3)::-webkit-scrollbar { display: none; }

  /* Навигация: от space-between к скролл-ряду с отступами */
  .navigation {
    display: flex !important;
    width: max-content !important;
    justify-content: flex-start !important;
    gap: 0 !important;
    flex-wrap: nowrap !important;
    height: auto !important;
    margin: 0 !important;
  }

  .navigation__item,
  .navigation__item.-link {
    display: inline-block !important;
    padding: 4px 14px !important;
    white-space: nowrap !important;
    font-size: 13px !important;
    border-right: 1px solid #e2e8f0;
    line-height: 1.5;
    text-decoration: none;
    color: #374151;
  }

  .navigation__item:last-child { border-right: none !important; }

  /* 9. Плашки категорий в шапке — горизонтальный скролл */
  .header-menu-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding: 6px 12px 10px !important;
    scrollbar-width: none;
    border-top: 1px solid #f1f5f9;
    width: 100%;
    box-sizing: border-box;
  }
  .header-menu-wrapper::-webkit-scrollbar { display: none; }

  .header-menu {
    display: inline-flex !important;
    gap: 6px;
    white-space: nowrap;
  }

  /* 10. Сетка категорий — 2 колонки */
  .main-categories {
    padding: 0 !important;
    overflow-x: visible !important;
    max-width: 100%;
  }

  .main-categories__grid,
  .main-categories__bottom-row {
    min-width: 0 !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  .main-categories__grid    { grid-auto-rows: 160px !important; }
  .main-categories__bottom-row { grid-auto-rows: 140px !important; }

  /* Mechatronics и Hydro (Torque Converters) — на всю ширину */
  .category-card--mechatronics { grid-column: 1 / -1 !important; grid-row: auto !important; }
  .category-card--hydro        { grid-column: 1 / -1 !important; }
  .category-card--gaskets,
  .category-card--friction,
  .category-card--pistons,
  .category-card--filters      { grid-column: auto !important; }
  .main-categories__bottom-row .category-card:nth-child(n) { grid-column: auto !important; }

  .category-card__title { font-size: 13px !important; }
  .category-card--mechatronics .category-card__title { font-size: 15px !important; }

  /* 11. Пустота после Torque Converters */
  .main-categories__bottom-row {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  .main-categories__bottom-row .category-card--link {
    grid-column: span 2 !important;
    min-height: 52px !important;
    height: 52px !important;
  }

  /* 12. Каталог — фильтры */
  .catalogue-filters {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ============================================================
   PWA MODE — дополнительные переопределения поверх browser-mobile
   ============================================================ */
@media (max-width: 768px) {

  html.pwa-mode .wrapper {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  html.pwa-mode .header {
    padding-top: env(safe-area-inset-top, 0px);
  }

  /* В PWA: логотип по центру, поиск — на отдельной строке */
  html.pwa-mode .header__row:nth-child(2) {
    flex-direction: column;
    align-items: center;
    padding: 14px 16px 10px !important;
    gap: 10px;
  }

  html.pwa-mode .header__row:nth-child(2) .logo {
    justify-content: center;
    width: 100%;
    gap: 8px !important;
  }

  /* В PWA: логотип по центру, колонка */
  html.pwa-mode .logo {
    flex-direction: column !important;
    align-items: center !important;
    gap: 6px !important;
  }

  html.pwa-mode .logo__img-icon {
    height: 64px !important;
    width: 64px !important;
  }

  /* В PWA показываем brand (скрытый в браузере) */
  html.pwa-mode .logo__brand {
    display: flex !important;
    align-items: center;
  }

  html.pwa-mode .logo__name {
    font-size: 22px !important;
    color: #1b3a6b !important;
  }

  html.pwa-mode .logo__text {
    display: block !important;
    color: #71717a !important;
    text-align: center;
    font-size: 9px !important;
  }

  /* В PWA: поиск на всю ширину, стиль другой */
  html.pwa-mode .search-form {
    width: 100% !important;
  }

  html.pwa-mode .search-form .search-from__form {
    border-radius: 14px !important;
    background: #f1f5f9 !important;
    border-color: #e2e8f0 !important;
    height: 46px !important;
  }

  html.pwa-mode .search-form .search-form__input {
    height: 44px !important;
    line-height: 44px !important;
    font-size: 14px !important;
    padding: 0 14px !important;
  }

  html.pwa-mode .search-form .search-form__button {
    height: 46px !important;
    border-radius: 0 14px 14px 0 !important;
  }

  /* В PWA: скрываем nav-строки и menu, заменяет bottom nav */
  html.pwa-mode .header__row:nth-child(3),
  html.pwa-mode .header-menu-wrapper {
    display: none !important;
  }

  /* В PWA: скрываем footer */
  html.pwa-mode footer#footer { display: none; }

  /* В PWA: контейнер */
  html.pwa-mode .container,
  html.pwa-mode #main-container {
    padding: 12px 12px 20px !important;
  }
}

/* ============================================================
   МАЛЕНЬКИЕ ЭКРАНЫ (iPhone SE, 375px)
   ============================================================ */
@media (max-width: 390px) {
  .main-categories__grid    { grid-auto-rows: 130px !important; }
  .main-categories__bottom-row { grid-auto-rows: 118px !important; }
  .category-card { border-radius: 12px; padding: 12px; }
}
