/* Duplicate section links can all be hidden when tabs are present. Collapse their empty container. */
html body #main .product-section-buttons:has(> .owner-duplicate-tab-link):not(:has(> :not(.owner-duplicate-tab-link, [hidden], script))) {
  display: none !important;
}
html body #main .product-section-buttons:has(> .owner-duplicate-tab-link) {
  margin-block: 0;
  padding-block: .25rem;
  border-block: 0;
}
html body #main .owner-product-tabs {
  margin-block: .35rem .4rem;
  padding-block: .3rem 0;
  border-block: 0;
}
html body #main .product-section-buttons:has(> .owner-duplicate-tab-link) a:not(.owner-duplicate-tab-link) {
  min-height: 44px;
}

  html body #main .owner-product .owner-product-copy > aside.extract-capsule-addon,
  html body #main aside.extract-capsule-addon {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: .45rem .75rem;
    box-sizing: border-box;
    padding: .7rem .8rem;
    margin: 0;
  }
  html body #main aside.extract-capsule-addon > img {
    grid-column: 1; grid-row: 1;
    width: 3.8rem !important; height: 3.8rem !important;
    max-width: 100%; object-fit: contain; margin: 0; align-self: start;
  }
  html body #main aside.extract-capsule-addon > .extract-capsule-addon-copy {
    grid-column: 2; grid-row: 1;
    display: grid; gap: .2rem; min-width: 0;
  }
  html body #main aside.extract-capsule-addon > .extract-capsule-addon-copy > * {
    margin-block: 0; line-height: 1.35;
  }
  html body #main aside.extract-capsule-addon > :is(button, a.button) {
    grid-column: 1 / -1; grid-row: 2;
    display: flex; justify-content: center;
    width: 100% !important; max-width: none !important;
    min-height: 44px; margin: 0; box-sizing: border-box;
  }

@media (max-width: 767px) {
  html body #main .breadcrumbs:has(+ .wrap > .product-detail),
  html body #main .owner-product-crumb {
    margin-block: 0;
    padding-block: .35rem .2rem;
  }
  html body #main .owner-product-crumb {
    width: min(calc(100% - 2.4rem), 100%); margin-inline: auto;
  }
  html body #main .product-detail.owner-product {
    padding-block: .35rem .5rem !important;
    row-gap: .45rem !important;
  }
  html body #main .owner-product .owner-product-title {
    margin-block: 0 .1rem;
  }
  html body #main .owner-product-copy > :is(.product-intro, p.product-summary) {
    margin-block: 0 .15rem;
  }
  html body #main .owner-product-copy > .product-contact {
    margin-block: .3rem 0;
  }
  html body #main .owner-product .owner-product-purchase > .order-box {
    margin-block: 0 !important;
  }
  html body #main .owner-product .owner-product-purchase + .mol-doctor-entry--purchase,
  html body #main .page-hero-copy > .mol-doctor-entry--purchase {
    margin-block: .15rem !important;
  }
  html body #main .product-detail:has(+ .product-section-buttons) + .product-section-buttons {
    border-block: 0;
  }
  html body #main .owner-product-tabs + #description {
    margin-block-start: .5rem;
  }

  /* Product cutouts have their own transparent margins. Use the recovered height for the picture. */
  html body:not([data-capsule-page-images]) #main .owner-product:not(.capsule-detail, .oil-product) > .owner-product-visual:has(> img:only-child, > .zoom-link > img:only-child) {
    height: clamp(185px, 32svh, 300px) !important;
    padding-block: .3rem !important;
    display: grid !important;
    place-items: center;
    box-sizing: border-box;
    overflow: hidden;
  }
  html body:not([data-capsule-page-images]) #main .owner-product:not(.capsule-detail, .oil-product) > .owner-product-visual > .zoom-link:has(> img:only-child) {
    display: grid; place-items: center;
    width: 100%; height: 100%; min-height: 0; max-height: 100%;
  }
  html body:not([data-capsule-page-images]) #main .owner-product:not(.capsule-detail, .oil-product) > .owner-product-visual :is(img:only-child) {
    width: auto !important; height: auto !important;
    max-width: 96% !important; max-height: calc(clamp(185px, 32svh, 300px) - .6rem) !important;
    object-fit: contain;
  }

  /* Legacy product pages put the image outside the title and purchase wrapper. */
  html body #main > .page-hero:has(> .page-hero-copy > #purchase):has(> .catalogue-photo--hero, > .page-packshot) {
    display: flex !important; flex-direction: column; align-items: stretch;
    gap: .45rem !important;
    padding-block: .45rem .75rem !important;
  }
  html body #main > .page-hero:has(> .catalogue-photo--hero, > .page-packshot) > .page-hero-copy:has(> #purchase) {
    display: contents !important;
  }
  html body #main > .page-hero > .page-hero-copy:has(> #purchase) > h1 {
    order: -3; margin: 0;
    font-size: clamp(1.65rem, 6.6vw, 1.95rem) !important;
    line-height: 1.14; text-wrap: balance;
  }
  html body #main > .page-hero > .page-hero-copy:has(> #purchase) > .product-back {
    order: -4; align-self: start; margin: 0 !important;
    line-height: 1.3;
  }
  html body #main > .page-hero > .page-hero-copy:has(> #purchase) > :is(.hero-summary, #purchase) {
    margin-block: 0 !important;
  }
  html body #main > .page-hero:has(> .page-hero-copy > #purchase) > :is(.catalogue-photo--hero, .page-packshot) {
    order: -2; align-self: center;
    width: 100% !important; height: clamp(210px, 35svh, 315px) !important;
    max-height: none !important; min-height: 0 !important;
    box-sizing: border-box; margin: 0 !important; padding: 0 !important;
    object-fit: contain;
  }
  html body #main > .page-hero:has(> .page-hero-copy > #purchase) > .page-packshot {
    height: clamp(245px, 41svh, 360px) !important;
  }
  html body #main > .page-hero:has(> .page-hero-copy > #purchase) > .page-packshot img {
    height: 100% !important; max-height: 100% !important; min-height: 0;
    width: auto !important; max-width: 96%; object-fit: contain;
  }
  html body #main > .page-hero:has(> .page-hero-copy > #purchase) + .content-shell {
    margin-block-start: 0; padding-block-start: .75rem !important;
  }
  html body #main > .page-hero:has(> .page-hero-copy > #purchase) + .content-shell > #description > .section-heading > h2 {
    margin-block-start: 0 !important; padding-block-start: 0; border-block-start: 0;
  }
  html body #main .page-hero-copy > #purchase, html body #main .owner-product-copy > #purchase {
    scroll-margin-block-start: clamp(4.5rem, calc(100svh - 13.5rem), 38rem);
  }
}

@layer molisan-package-columns {
  html body #main .owner-product .owner-product-copy > aside.extract-capsule-addon,
  html body #main aside.extract-capsule-addon {
    display: grid !important;
  }
  @media (max-width: 767px) {
    html body[data-product-reading][data-section] #main > section.page-hero:has(> .page-hero-copy > #purchase):has(> .catalogue-photo--hero, > .page-packshot) {
      display: flex !important;
      gap: .45rem !important;
      padding-block: .45rem .75rem !important;
    }
    html body[data-product-reading][data-section] #main > .page-hero:has(> .catalogue-photo--hero, > .page-packshot) > .page-hero-copy:has(> #purchase) {
      display: contents !important;
    }
    html body[data-product-reading][data-section] #main > .page-hero:has(> .catalogue-photo--hero, > .page-packshot) > .page-hero-copy:has(> #purchase) > .product-back.product-category-link {
      order: -4 !important;
      margin: 0 !important;
    }
    html body[data-product-reading][data-section] #main > .page-hero:has(> .catalogue-photo--hero, > .page-packshot) > .page-hero-copy:has(> #purchase) > h1 {
      order: -3 !important;
      margin: 0 !important;
    }
    html body #main .owner-product .owner-product-copy > .mol-doctor-entry--purchase,
    html body[data-product-reading][data-section] #main > .page-hero > .page-hero-copy:has(> #purchase) > .mol-doctor-entry--purchase {
      margin-block: .15rem !important;
    }
    html body #main .owner-product .owner-product-copy > .product-contact { margin-block: .3rem 0 !important; }
    html body #main .product-detail.full-product.owner-product,
    html body #main article.product-detail.owner-product {
      padding-block: .35rem .5rem !important;
      row-gap: .45rem !important;
    }
    html body #main .product-detail.owner-product > .owner-product-copy > .owner-product-title { margin-block: 0 .1rem !important; }
    html body:not([data-capsule-page-images]) #main .product-detail.owner-product:not(.capsule-detail, .oil-product) > .owner-product-visual:has(> img:only-child, > .zoom-link > img:only-child) {
      height: clamp(185px, 32svh, 300px) !important;
      max-height: none !important;
      padding-block: .3rem !important;
    }
    html body:not([data-capsule-page-images]) #main .product-detail.owner-product:not(.capsule-detail, .oil-product) > .owner-product-visual :is(img:only-child) {
      height: auto !important;
      max-height: calc(clamp(185px, 32svh, 300px) - .6rem) !important;
    }
  }
}

/* Molisani's legacy solution styles target the purchase section and its canonical URL. */
@layer molisan-package-columns {
  @media (max-width: 767px) {
    body#top #main .full-product.owner-product:has(> .product-summary > #purchase) {
      row-gap: .45rem !important;
    }
    body#top #main .full-product.owner-product:has(> .product-summary > #purchase) > .product-summary > .owner-product-title {
      margin-block: 0 .1rem !important;
    }
    body#top:not([data-capsule-page-images]) #main .full-product.owner-product:not(.capsule-detail, .oil-product):has(> .product-summary > #purchase) > .owner-product-visual:has(> .zoom-link > img:only-child) {
      height: clamp(185px, 32svh, 300px) !important;
      max-height: none !important;
      padding-block: .3rem !important;
    }
    body#top #main .full-product.owner-product:has(> .product-summary > #purchase) > .owner-product-visual > .zoom-link:has(> img:only-child) {
      height: 100% !important;
      max-height: 100% !important;
    }
    body#top:not([data-capsule-page-images]) #main .full-product.owner-product:not(.capsule-detail, .oil-product):has(> .product-summary > #purchase) > .owner-product-visual > .zoom-link > img:only-child {
      height: auto !important;
      max-height: calc(clamp(185px, 32svh, 300px) - .6rem) !important;
    }
  }
}

@layer molisan-link-standard {
/* The CMS stores indications as list items, links separated by line breaks,
   and occasionally a single link wrapping every line of the list. */
html body :is(main, #main) :where(.prose, .legacy-article, .article-body, .skin-care-panel, .product-text, .original-product-description, .full-details) :is(
  li a[href], br + a[href], a[href]:has(+ br + a[href]), a[href]:has(> br ~ br),
  p > a[href*="recommendations/"], p > a[href*="applications/"], p > a[href*="classic/"], p > a[href*="pirveli/"], p > a[href*="disinfectant/"]
):not(:is(.button, .btn, .ui-action, .mol-action, [role="button"], [href*="/img/doc/"], [href$=".pdf" i])):not(:has(img, picture, svg)),
html body :is(main, #main) :is(.application-materials, .product-description-content > section) > :is(ul, ol) > li > a[href]:not(:is(.button, .btn, .ui-action, [role="button"])):not(:has(img, picture, svg)),
html body :is(main, #main) .material-list > a[href]:not(:has(img, picture)) {
  color: #a84225 !important;
  font-weight: 700 !important;
}

html body :is(main, #main) :where(.prose, .legacy-article, .article-body, .skin-care-panel, .product-text, .original-product-description, .full-details, .application-materials) li:has(> a[href]:only-child):not(:has(img, picture, svg))::marker {
  color: #a84225;
}

/* The generic inline-link style removes the lower edge of document buttons. */
html body :is(main, #main) .detail-accordions .prose a:is([href*="/img/doc/"], [href$=".pdf" i]) {
  border-bottom: 1px solid #b7c3af !important;
}
}

html body :is(main, #main) .detail-accordions .prose > p > a:is([href*="/img/doc/"], [href$=".pdf" i]) {
  display: flex;
  inline-size: fit-content;
  margin-block: .35rem;
}
html body :is(main, #main) .detail-accordions .prose > p > a:is([href*="/img/doc/"], [href$=".pdf" i]) + br,
html body :is(main, #main) .detail-accordions .prose > p > a:is([href*="/img/doc/"], [href$=".pdf" i]) + br + br {
  display: none;
}
html body :is(main, #main) .detail-accordions .prose:has(a:is([href*="/img/doc/"], [href$=".pdf" i])) > p:last-child {
  margin-block-end: 0 !important;
}

/* Leave flexible space above the package selector, keeping the purchase action at the foot of each card. */
@media (min-width: 681px) {
  main#main .product-grid > .product-card > .card-link:has(.card-prices) {
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
  }
  main#main .product-grid > .product-card > .card-link > .card-info:has(.card-prices) {
    display: flex;
    flex-direction: column;
    flex: 1 0 auto;
  }
  main#main .product-grid > .product-card > .card-link > .card-info > .card-prices,
  main#main .catalogue-grid > .catalogue-card > .product-card-price,
  main#main .product-collection > .product-tile > .product-info > .product-card-price,
  main#main .purpose-related-grid > .purpose-related-card > .purpose-related-info > .mol-pack-choice {
    margin-top: auto !important;
  }

  main#main .capsule-collection .product-collection > .product-tile {
    padding-bottom: 1rem !important;
  }
  main#main .product-grid > .product-card .card-info > :is(.card-description, .oil-description),
  main#main .catalogue-grid > .catalogue-card > .catalogue-use,
  main#main .product-collection > .product-tile .product-info > .product-purpose,
  main#main .purpose-related-grid > .purpose-related-card .purpose-related-info > .purpose-related-summary {
    flex-grow: 1 !important;
  }

  main#main .product-grid > .product-card .card-info > .card-prices.mol-pack-choice {
    flex-grow: 1 !important;
    align-content: end !important;
  }
  /* Older topic cards can include a plain-text price alongside the interactive packages. */
  main#main .product-grid > .product-card .card-prices.mol-pack-choice > span:not([class]):has(> b) {
    grid-row: 1 / span 2;
    align-self: center;
  }
}
