/*
 * Shared header geometry contract.
 * The design compiler writes the values from Layout Settings to :root.
 * Keep this bridge independent of the selected Header component so a logo
 * and desktop menu spacing setting follows Header v0 through Header v4.
 */

@media (min-width: 901px) {
  body[data-deceti-header="header-v0"] .deceti-megamenu,
  body[data-deceti-header="header-v1"] .deceti-megamenu,
  body[data-deceti-header="header-v2"] .sd2-main-nav .deceti-megamenu,
  body[data-deceti-header="header-v3"] .cys3-menu,
  body[data-deceti-header="header-v4"] .ch4-menu {
    gap: var(--spacing-menu-gap, 12px) !important;
  }
}

body[data-deceti-header="header-v0"] :is(.deceti-header-module--logo, .deceti-logo) img,
body[data-deceti-header="header-v1"] .deceti-logo img,
body[data-deceti-header="header-v2"] .sd2-brand img,
body[data-deceti-header="header-v3"] .cys3-logo img,
body[data-deceti-header="header-v4"] .ch4-logo img {
  width: var(--header-logo-max-width, 280px) !important;
  max-width: var(--header-logo-max-width, 280px) !important;
  height: auto !important;
  max-height: var(--header-logo-max-height, 72px) !important;
  object-fit: contain;
}

/* One submenu typography token follows every selectable Header component.
 * Keep the selectors here, in the shared header contract, so a theme's
 * legacy menu stylesheet cannot silently replace the saved admin value. */
body[data-deceti-header="header-v0"] .deceti-submenu a,
body[data-deceti-header="header-v1"] .deceti-submenu a,
body[data-deceti-header="header-v2"] .deceti-submenu a,
body[data-deceti-header="header-v3"] :is(.deceti-submenu, .cys3-submenu) a,
body[data-deceti-header="header-v4"] .ch4-submenu a {
  font-size: var(--font-navigation-submenu-size, 13px) !important;
}

/* Avoid a saved desktop size crowding the mobile Header controls. */
@media (max-width: 900px) {
  body[data-deceti-header] :is(.deceti-header-module--logo img, .deceti-logo img, .sd2-brand img, .cys3-logo img, .ch4-logo img) {
    max-width: min(var(--header-logo-max-width, 280px), 44vw) !important;
    max-height: min(var(--header-logo-max-height, 72px), 18vw) !important;
  }
}

/* Navigation geometry belongs to the shared layout contract, not to a
 * palette override. It preserves the original v0 item rhythm after the old
 * hover-color bridge is removed. */
@media (min-width: 901px) {
  /* Header v4 uses a wide navigation row. Keep its first menu item aligned
   * with the left content edge instead of centering the whole menu. */
  body[data-deceti-header="header-v4"] .ch4-menu {
    justify-content: flex-start !important;
  }

  body[data-deceti-header="header-v0"] .deceti-megamenu > li > a,
  body[data-deceti-header="header-v1"] .deceti-megamenu > li > a,
  body[data-deceti-header="header-v2"] .sd2-main-nav .deceti-megamenu > li > a,
  body[data-deceti-header="header-v3"] .cys3-menu > li > a,
  body[data-deceti-header="header-v4"] .ch4-menu > li > a {
    display: flex;
    align-items: center;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 12px !important;
    font-family: var(--font-navigation-family, Arial, sans-serif) !important;
    font-size: var(--font-navigation-size, 18px) !important;
    font-weight: var(--font-navigation-weight, 700) !important;
    line-height: 1.15 !important;
  }
}

@media (min-width: 1181px) {
  body[data-deceti-header="header-v4"] .ch4-menu {
    margin-left: 60px !important;
  }
}

/* Header v4 previously reserved a centered 1320px shell and a fixed 320px
 * logo column. Let the logo own only its rendered width and give the desktop
 * row more room, so a larger logo and a left-aligned menu can coexist. */
@media (min-width: 981px) {
  body[data-deceti-header="header-v4"] .ch4-header__inner {
    width: min(calc(100% - 24px), 1520px) !important;
    grid-template-columns: auto minmax(0, 1fr) auto !important;
  }
}

/* On medium desktop widths the phone number is the expendable item. Keeping
 * the icon, account and cart leaves the navigation row intact instead of
 * pushing it to the right or forcing it over the logo. */
@media (min-width: 981px) and (max-width: 1399px) {
  body[data-deceti-header="header-v4"] .ch4-phone__copy {
    display: none !important;
  }
}

@media (min-width: 981px) and (max-width: 1180px) {
  body[data-deceti-header="header-v4"] .ch4-logo img {
    width: min(var(--header-logo-max-width, 280px), 220px) !important;
    max-width: min(var(--header-logo-max-width, 280px), 220px) !important;
    max-height: min(var(--header-logo-max-height, 72px), 72px) !important;
  }

  body[data-deceti-header="header-v4"] .ch4-menu {
    gap: 6px !important;
    margin-left: 0 !important;
  }

  body[data-deceti-header="header-v4"] .ch4-menu > li > a {
    padding-inline: 6px !important;
    font-size: min(var(--font-navigation-size, 18px), 16px) !important;
  }
}

/* Header v3 reserves the actual logo width. Menu items may wrap inside their
 * column, never underneath the logo or the account/cart controls. These rules
 * use the saved logo and typography settings after any Design & UI Publish. */
@media (min-width: 980.01px) {
  body[data-deceti-header="header-v3"] .cys3-header__inner {
    --cys3-logo-column: var(--header-logo-max-width, 280px);
    --cys3-logo-inset: clamp(0px, calc((100vw - 1180px) * .68), 68px);
    position: relative;
    width: min(1760px, calc(100% - 56px));
    min-height: 100px;
    padding-left: var(--cys3-logo-inset);
    grid-template-columns: var(--cys3-logo-column) minmax(0, 1fr) auto;
    column-gap: 16px;
    overflow: visible;
  }
  body[data-deceti-header="header-v3"] .cys3-logo {
    position: absolute;
    top: 12px;
    left: var(--cys3-logo-inset);
    z-index: 2;
    width: var(--cys3-logo-column);
    max-width: none;
    margin: 0;
    transform: none;
  }
  body[data-deceti-header="header-v3"] .cys3-logo img {
    width: 100% !important;
    max-width: 100% !important;
    object-position: left center;
  }
  body[data-deceti-header="header-v3"] .cys3-nav {
    grid-column: 2;
    min-width: 0;
    transform: none;
  }
  body[data-deceti-header="header-v3"] .cys3-menu {
    justify-content: flex-start;
    flex-wrap: wrap;
    row-gap: 0 !important;
  }
  body[data-deceti-header="header-v3"] .cys3-header__actions {
    grid-column: 3;
    gap: 12px;
  }
}
@media (min-width: 980.01px) and (max-width: 1699px) {
  body[data-deceti-header="header-v3"] .cys3-free-shipping { display: none; }
}
@media (min-width: 980.01px) and (max-width: 1499px) {
  body[data-deceti-header="header-v3"] .cys3-header__inner {
    --cys3-logo-column: min(var(--header-logo-max-width, 280px), 240px);
  }
}

/* A long cart summary must not consume the navigation column. Its full text
 * remains in the accessible button name and the amount is in the dropdown. */
@media (min-width: 980.01px) and (max-width: 1499px) {
  body[data-deceti-header="header-v3"] .cys3-cart #mini-cart { width: 44px; }
  body[data-deceti-header="header-v3"] .cys3-cart #mini-cart > button {
    display: grid !important;
    place-items: center;
    width: 44px !important;
    min-width: 44px !important;
    padding: 0 !important;
    font-size: 0 !important;
  }
  body[data-deceti-header="header-v3"] .cys3-cart #mini-cart > button i {
    margin: 0 !important;
    font-size: 20px !important;
  }
  body[data-deceti-header="header-v3"] .cys3-cart #mini-cart > button::after { display: none !important; }
}
@media (min-width: 980.01px) and (max-width: 1180px) {
  body[data-deceti-header="header-v3"] .cys3-header__inner {
    --cys3-logo-column: min(var(--header-logo-max-width, 280px), 200px);
  }
  body[data-deceti-header="header-v3"] .cys3-menu { column-gap: min(var(--spacing-menu-gap, 12px), 8px) !important; }
  body[data-deceti-header="header-v3"] .cys3-menu > li > a {
    padding-inline: 6px !important;
    font-size: min(var(--font-navigation-size, 18px), 16px) !important;
  }
}
