/**
 * @file
 * Sponsored content (articulos patrocinados) styles.
 *
 * Applies to any <article> that carries the `is-sponsored` class set by the
 * card components when the node has a banner term with a sponsor URL.
 *
 * ------------------------------------------------------------------
 * Per-site color customization
 * ------------------------------------------------------------------
 * Each site can override the sponsor accent colors via the
 * `css_variables_customizer` module. Add the desired overrides to the
 * site's patch file at
 *   config/sites/<site>/common/config_split.patch.css_variables_customizer.customizations.news_platform_artisan.yml
 *
 * Example (blogdebasket):
 *   adding:
 *     customizations:
 *       -
 *         overrides:
 *           '--sponsor-border-color':
 *             -
 *               value: '#e8710a'
 *           '--sponsor-badge-bg':
 *             -
 *               value: '#e8710a'
 *           '--sponsor-card-bg':
 *             -
 *               value: '#fff5eb'
 */

:root,
:host {
  /* Base accent — sites override via css_variables_customizer */
  --sponsor-border-color: var(--theme-warning);
  --sponsor-badge-bg: var(--theme-warning);
  --sponsor-badge-text: var(--theme-warning-content);
  --sponsor-card-bg: color-mix(in oklch, var(--theme-warning) 8%, transparent);
  --sponsor-card-bg-dark: #8e929c45;

  /* Dimensions & sizing */
  --sponsor-border-width: 4px;
  --sponsor-logo-height: 30px;
  --sponsor-logo-max-width: 60px;
  --sponsor-logo-border-radius: 8px;
  --sponsor-badge-font-size: calc(var(--theme-font-size) * 0.75);
  --sponsor-badge-padding-y: calc(var(--theme-spacing) * 1.5);
  --sponsor-badge-padding-x: calc(var(--theme-spacing) * 3);
  --sponsor-card-top-padding: calc(var(--theme-spacing) * 4);
}

/* Dark mode: a tinted color background looks washed out on a dark base.
   We swap to a neutral semi-transparent slate that gives readable contrast
   against any sponsor border color. Each site can override
   --sponsor-card-bg-dark via css_variables_customizer if it wants its own
   dark-mode tint.
   The selector is more specific than :root to win the cascade against
   the inline overrides emitted by css_variables_customizer. */
html[data-theme=dark] {
  --sponsor-card-bg: var(--sponsor-card-bg-dark);
}

/* ============================================================
   Sponsored LISTING card wrapper
   Scoped to the card components only (by data-component-id prefix) so
   these rules never leak into the article detail page, which also has
   is-sponsored but needs a different, much lighter treatment.
   ============================================================ */

article.is-sponsored[data-component-id^="news_platform_artisan:card"] {
  position: relative;
  background-color: var(--sponsor-card-bg);
  border-left: var(--sponsor-border-width) solid var(--sponsor-border-color);
  padding: var(--sponsor-card-top-padding) calc(var(--theme-spacing) * 4) calc(var(--theme-spacing) * 4) calc(var(--theme-spacing) * 4);
  border-top-right-radius: var(--theme-radius);
  border-bottom-right-radius: var(--theme-radius);
}

/* Horizontal card: override the default 3/4 aspect-ratio on the image so
   it displays at its natural ratio inside the sponsored card. */
article.is-sponsored[data-component-id="news_platform_artisan:card"] .card__image img {
  aspect-ratio: auto;
  height: auto;
}

/* card-highlight is fully image-dominant (text and tags overlaid on the
   image) so the beige background and padding would never show. We strip
   the bg and padding on this layout only — but KEEP the orange left border
   accent so the sponsor mark is still visible. */
article.is-sponsored[data-component-id$=":card-highlight"] {
  background-color: transparent;
  padding: 0;
}

/* ============================================================
   Sponsored ARTICLE DETAIL page
   Subtle orange left border on the whole <article> element, replicating
   the listing cards pattern without the heavy beige background.
   ============================================================ */

article.article.is-sponsored {
  border-left: var(--sponsor-border-width) solid var(--sponsor-border-color);
  padding-left: calc(var(--theme-spacing) * 4);
  margin-top: calc(var(--theme-spacing) * 4);
  margin-bottom: calc(var(--theme-spacing) * 4);
}

/* ============================================================
   Sponsor badge
   ============================================================ */

.sponsor-badge,
a.sponsor-badge {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: calc(var(--theme-spacing) * 2);
  padding: var(--sponsor-badge-padding-y) var(--sponsor-badge-padding-x);
  background-color: var(--sponsor-badge-bg);
  color: var(--sponsor-badge-text);
  font-family: var(--theme-body-font-family);
  font-weight: 700;
  text-transform: uppercase;
  font-size: var(--sponsor-badge-font-size);
  line-height: 1.2;
  letter-spacing: 0.02em;
  border-radius: 0 0 calc(var(--theme-radius) * 0.75) 0;
  text-decoration: none;
  white-space: nowrap;
  width: max-content;
  max-width: calc(100% - (var(--theme-spacing) * 4));
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}

a.sponsor-badge:hover,
a.sponsor-badge:focus-visible {
  filter: brightness(0.95);
  text-decoration: underline;
  color: var(--sponsor-badge-text);
}

/* ============================================================
   Sponsor logo inside the badge

   The sponsor image comes from a Media entity view mode ("thumbnail")
   which wraps the <img> in several divs:
     .media > .field > .field__item > img

   We flatten these with display: contents so the <img> inherits sizing
   directly, and we force explicit dimensions on the img itself.
   ============================================================ */

.sponsor-badge__logo {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
}

/* Flatten wrapper divs */
.sponsor-badge__logo > *,
.sponsor-badge__logo .media,
.sponsor-badge__logo .contextual-region,
.sponsor-badge__logo .field,
.sponsor-badge__logo .field__item {
  display: contents;
}

/* Hide any label rendered by the field */
.sponsor-badge__logo .field__label,
.sponsor-badge__logo .visually-hidden {
  display: none !important;
}

/* Final image: explicit dimensions, not inherited.
   aspect-ratio: auto overrides the default 3/4 aspect the card component
   applies to all its images. */
.sponsor-badge__logo img {
  display: block;
  aspect-ratio: auto !important;
  height: var(--sponsor-logo-height) !important;
  width: auto !important;
  max-width: var(--sponsor-logo-max-width);
  object-fit: contain !important;
  margin: 0;
  padding: 0 !important;
  background: transparent;
  border: none;
  border-radius: var(--sponsor-logo-border-radius) !important;
}

/* ============================================================
   Badge name
   ============================================================ */

.sponsor-badge__name {
  display: inline-block;
  white-space: nowrap;
}

/* Responsive: hide name on very narrow screens */
@media (max-width: 480px) {
  .sponsor-badge__name {
    display: none;
  }
}

/* ============================================================
   Sponsor block in the article DETAIL page (article-one)

   Pill-shaped header rendered between the breadcrumb and the title.
   Combines the "Patrocinado por" label, the sponsor logo and the
   sponsor name in a single horizontal element. Reuses the same
   --sponsor-* variables so each site's color override applies here too.
   ============================================================ */

/* ============================================================
   Global theme tweaks (NOT sponsor-related)
   Quick fixes shipped here to avoid going through the Vite build.
   Move to src/_base.css or _helpers.css on the next theme build.
   ============================================================ */

/* Separate the main content from the top nav border so it doesn't hug it */
main#main-content {
  margin-top: calc(var(--theme-spacing) * 4);
}

/* Breadcrumb vertical spacing inside the article header so it breathes
   away from the top nav and the sponsor pill below it. */
nav.breadcrumb {
  margin: 1rem 0;
}

.article__sponsor {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: calc(var(--theme-spacing) * 3);
  padding: calc(var(--theme-spacing) * 3) calc(var(--theme-spacing) * 5);
  margin-bottom: calc(var(--theme-spacing) * 6);
  background-color: var(--sponsor-card-bg);
  border: 1.5px solid var(--sponsor-border-color);
  border-radius: var(--theme-radius);
  text-decoration: none;
  color: var(--theme-base-content);
  font-family: var(--theme-body-font-family);
  width: 100%;
  transition: background-color 0.2s ease;
}

a.article__sponsor:hover,
a.article__sponsor:focus-visible {
  background-color: color-mix(in oklch, var(--sponsor-border-color) 14%, transparent);
  text-decoration: none;
  color: var(--theme-base-content);
}

.article__sponsor-label {
  font-size: calc(var(--theme-font-size) * 0.7);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sponsor-border-color);
  white-space: nowrap;
}

.article__sponsor-logo {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
}

/* Flatten media wrapper divs (same trick as the listing badge) */
.article__sponsor-logo .media,
.article__sponsor-logo .contextual-region,
.article__sponsor-logo .field,
.article__sponsor-logo .field__item {
  display: contents;
}

.article__sponsor-logo .field__label,
.article__sponsor-logo .visually-hidden {
  display: none !important;
}

.article__sponsor-logo img {
  display: block;
  aspect-ratio: auto !important;
  height: 32px !important;
  width: auto !important;
  max-width: 90px;
  object-fit: contain !important;
  border-radius: 4px;
  margin: 0;
  padding: 0 !important;
  background: transparent;
  border: none;
}

.article__sponsor-name {
  font-weight: 600;
  font-size: calc(var(--theme-font-size) * 0.95);
  color: var(--theme-base-content);
  white-space: nowrap;
}

/* Mobile-first responsive tweaks */
@media (max-width: 640px) {
  .article__sponsor {
    padding: calc(var(--theme-spacing) * 2) calc(var(--theme-spacing) * 4);
    gap: calc(var(--theme-spacing) * 2);
  }

  .article__sponsor-label {
    font-size: calc(var(--theme-font-size) * 0.65);
  }

  .article__sponsor-logo img {
    height: 26px !important;
    max-width: 70px;
  }

  .article__sponsor-name {
    font-size: calc(var(--theme-font-size) * 0.85);
  }
}

@media (max-width: 380px) {
  .article__sponsor {
    /* On very small screens, hide the "Patrocinado por" label so logo + name fit */
    gap: calc(var(--theme-spacing) * 2);
  }

  .article__sponsor-label {
    display: none;
  }
}
