/* =========================================================
   Шапка: верхнее меню, логотип, «Каталог», поиск, контакты, корзина, мегаменю
   Мобильный (< 1100px) — бургер и «шторка» на весь экран; десктоп — выпадающая панель.
   ========================================================= */
.site-header {
  --hdr-bg: #33271e;
  --hdr-fg: #ffffff;
  --hdr-soft: #fdf8f4;          /* кремовые кнопки на тёмном */
  --hdr-line: rgba(253, 248, 244, 0.55);
  --hdr-placeholder: #d9cdc4;
  --hdr-btn-bg: #fdf8f4;
  --hdr-btn-fg: #2e241d;

  position: relative;
  z-index: 100;
  font-family: var(--font-base, "Montserrat", sans-serif);
  color: var(--color-text, #2e241d);
}

.screen-reader-text {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link:focus { top: 8px; left: 8px; z-index: 2000; width: auto; height: auto; margin: 0; padding: 10px 16px; clip: auto; background: #fff; }

/* ---------- Верхнее меню (десктоп) ---------- */
.topbar { display: none; }

.topbar__list,
.mega__links-list { margin: 0; padding: 0; list-style: none; }

.topbar a,
.mega__links a { color: inherit; text-decoration: none; }

/* ---------- Основная полоса ---------- */
.site-header__bar {
  background: var(--hdr-bg);
  color: var(--hdr-fg);
}

.site-header__inner {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto 40px;
  grid-template-areas:
    "burger logo search-toggle cart"
    "contacts contacts contacts contacts"
    "search search search search";
  align-items: center;
  gap: 14px 12px;
  max-width: 1440px;
  margin-inline: auto;
  padding: 16px;
}

.burger        { grid-area: burger; }
.logo          { grid-area: logo; justify-self: center; }
.catalog-btn   { grid-area: catalog; display: none; }
.search-toggle { grid-area: search-toggle; }
.contacts      { grid-area: contacts; }
.search        { grid-area: search; display: none; }
.header-cart   { grid-area: cart; }

.is-search-open .search { display: flex; }

/* Кнопки-квадраты (бургер, корзина) */
.burger,
.header-cart {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--hdr-btn-bg);
  color: var(--hdr-btn-fg);
  cursor: pointer;
  text-decoration: none;
}

.burger__close { display: none; }
.is-open .burger__open { display: none; }
.is-open .burger__close { display: block; }

.header-cart__count {
  position: absolute;
  top: -5px;
  right: -5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #e10600;
  color: #fff;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 1;
}
.header-cart__count[hidden] { display: none; }

.search-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

/* Логотип */
.logo { display: inline-flex; align-items: center; color: inherit; text-decoration: none; }
.logo__img { display: block; width: auto; height: 38px; max-width: 100%; }
.logo__img--on-light { display: none; }
.logo__text { font-size: 1.25rem; font-weight: 600; }

/* Телефон и соцсети */
.contacts { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.contacts__phone {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.contacts__socials { display: flex; gap: 8px; margin: 0; padding: 0; list-style: none; }

.social {
  display: block;
  width: 26px;
  height: 26px;
  background: var(--hdr-soft, #fdf8f4);  /* цвет иконки: маска берёт форму из загруженного файла */
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
  transition: opacity 0.2s;
}
.social:hover { opacity: 0.75; }

/* Поиск */
.search { position: relative; align-items: center; }

.search__input {
  width: 100%;
  height: 44px;
  padding: 0 46px 0 16px;
  border: 1px solid var(--hdr-line);
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.9375rem;
  -webkit-appearance: none;
  appearance: none;
}
.search__input::placeholder { color: var(--hdr-placeholder); opacity: 1; }
.search__input::-webkit-search-cancel-button { display: none; }

.search__submit {
  position: absolute;
  top: 0;
  right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.8;
  cursor: pointer;
}

.burger:focus-visible,
.header-cart:focus-visible,
.search-toggle:focus-visible,
.catalog-btn:focus-visible,
.search__input:focus-visible,
.search__submit:focus-visible,
.contacts a:focus-visible { outline: 2px solid var(--hdr-soft); outline-offset: 3px; }

/* ---------- Мегаменю ---------- */
.mega { color: var(--color-text, #2e241d); }

.mega__inner {
  margin: 8px 16px 16px;
  padding: 8px;
  border-radius: 16px;
  background: var(--color-card, #f6f6f2);
}

.mega__catalog-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  margin-bottom: 18px;
  border-radius: 10px;
  background: #33271e;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 500;
  text-decoration: none;
}

.mega__cats,
.mega-brands { margin: 0; padding: 0 8px; list-style: none; }

.mega__cats { display: flex; flex-direction: column; gap: 22px; }

.mega-cat,
.mega-brands__first { display: grid; grid-template-columns: 60px minmax(0, 1fr); gap: 0 22px; align-items: start; }

.mega-cat__media,
.mega-brands__media { display: flex; justify-content: center; }
.mega-cat__media img,
.mega-brands__media img { display: block; width: auto; max-width: 60px; height: auto; max-height: 76px; object-fit: contain; }

.mega-cat__title,
.mega-brands__title {
  display: block;
  margin: 0 0 4px;
  color: var(--color-text, #2e241d);
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
}

.mega-cat__list,
.brand-list { margin: 0; padding: 0; list-style: none; }

.mega-cat__list a,
.brand-list a {
  display: block;
  padding: 1px 0;
  color: var(--color-muted, #a8948a);
  font-size: 1rem;
  line-height: 1.3;
  text-decoration: none;
  transition: color 0.2s;
}
.mega-cat__list a:hover,
.brand-list a:hover,
.mega-cat__title:hover { color: #000; }

.mega-cat__list a:focus-visible,
.brand-list a:focus-visible,
.mega-cat__title:focus-visible,
.mega__catalog-link:focus-visible,
.mega__links a:focus-visible { outline: 2px solid var(--color-primary, #33271e); outline-offset: 2px; border-radius: 4px; }

.mega-brands { margin-top: 26px; }
.mega-brands__col { padding-left: 82px; }

.mega__links { margin-top: 18px; padding: 16px 8px 8px; border-top: 1px solid #e6dfd8; }
.mega__links-list { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 0.9375rem; }

/* Мобильное «открыто»: шторка на весь экран, шапка остаётся тёмной */
@media (max-width: 1099.98px) {
  .site-header.is-open {
    position: fixed;
    inset: 0;
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #33271e;
  }
  .menu-open { overflow: hidden; }
}

/* ---------- Планшет ---------- */
@media (min-width: 700px) and (max-width: 1099.98px) {
  .site-header__inner { padding-inline: 40px; }
  .mega__inner { margin-inline: 40px; }
  .mega__cats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 24px; }
}

/* ---------- Десктоп ---------- */
@media (min-width: 1100px) {
  .topbar { display: block; background: var(--color-card, #f6f6f2); font-size: 0.875rem; }
  .topbar__list { display: flex; justify-content: center; gap: 28px; padding: 8px 16px; line-height: 1.2; }
  .topbar a:hover { text-decoration: underline; }
  .topbar a:focus-visible { outline: 2px solid var(--color-primary, #33271e); outline-offset: 2px; }

  .site-header__bar { transition: background-color 0.25s, color 0.25s; }

  .site-header__inner {
    grid-template-columns: 180px auto minmax(0, 1fr) auto 36px;
    grid-template-areas: "logo catalog search contacts cart";
    gap: 0 24px;
    min-height: 78px;
    padding: 0 80px;
  }

  .burger,
  .search-toggle,
  .mega__catalog-link,
  .mega__links { display: none; }

  .logo { justify-self: start; }
  .logo__img { height: 44px; }

  .catalog-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 24px;
    border: 0;
    border-radius: 10px;
    background: var(--hdr-btn-bg);
    color: var(--hdr-btn-fg);
    font: inherit;
    font-size: 1.25rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
  }

  .search,
  .is-search-open .search { display: flex; }

  .contacts { flex-direction: column; align-items: flex-start; gap: 6px; }
  .contacts__phone { font-size: 1.0625rem; }
  .social { width: 22px; height: 22px; }

  .header-cart { width: 36px; height: 36px; border-radius: 8px; }

  /* Каталог открыт: вся шапка светлая */
  .site-header.is-open {
    --hdr-bg: #f6f6f2;
    --hdr-fg: #2e241d;
    --hdr-soft: #2e241d;
    --hdr-line: #d9cdc4;
    --hdr-placeholder: #cbbfb5;
    --hdr-btn-bg: #33271e;
    --hdr-btn-fg: #ffffff;
  }
  .site-header.is-open .logo__img--on-dark { display: none; }
  .site-header.is-open .logo__img--on-light { display: block; }
  .site-header.is-open .header-cart,
  .site-header.is-open .catalog-btn { background: #33271e; color: #fff; }

  .search__input:focus-visible,
  .contacts a:focus-visible,
  .search__submit:focus-visible,
  .header-cart:focus-visible,
  .catalog-btn:focus-visible { outline-color: var(--hdr-soft); }

  /* Панель */
  .mega {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 50;
    border-radius: 0 0 24px 24px;
    background: var(--color-card, #f6f6f2);
    box-shadow: 0 24px 40px rgba(46, 36, 29, 0.12);
    animation: mega-in 0.22s ease;
  }

  .mega__inner {
    max-width: 1440px;
    max-height: calc(100vh - 130px);
    margin: 0 auto;
    padding: 28px 80px 44px;
    overflow-y: auto;
    border-radius: 0;
    background: transparent;
  }

  .mega__cats,
  .mega-brands { padding: 0; }

  .mega__cats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 28px 24px;
  }

  .mega-cat,
  .mega-brands__first { gap: 0 17px; }

  .mega-brands {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0 24px;
    margin-top: 44px;
  }
  .mega-brands__col { padding-left: 0; padding-top: calc(1.2 * 1.125rem + 4px); } /* ровняем со списком первой колонки */
}

@keyframes mega-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .mega { animation: none; }
  .site-header__bar,
  .catalog-btn,
  .social,
  .mega-cat__list a,
  .brand-list a { transition: none; }
}
