/* ========================================================================== 
   Tee-Express – Product Cards
   Layout, Bricks/WooCommerce-Kaufbereich und variable Produkte.
   Diese Datei muss überall geladen werden, wo .product-card verwendet wird.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Kartenlayout und gleichmäßige Zeilen
   -------------------------------------------------------------------------- */

/* Verhindert, dass einzelne Grid-/Flex-Kinder wegen ihres Inhalts schrumpfen
   oder ihre vorgesehene Breite überschreiten. */
.product-card .product-card__content,
.product-card .product-card__footer,
.product-card .product-card-cart {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}

@supports (grid-template-rows: subgrid) {
  .product-grid > .product-card {
    display: grid;
    grid-row: span 5;
    grid-template-rows: subgrid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0;
    min-width: 0;
  }

  /* Zeile 1: Produktbild */
  .product-grid > .product-card > a {
    grid-row: 1;
  }

  /* Zeilen 2–5: Karteninhalt */
  .product-grid .product-card__content {
    display: grid;
    grid-row: 2 / span 4;
    grid-template-rows: subgrid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0;
  }

  /* Zeile 2: Kategorie, Titel, Beschreibung */
  .product-grid .product-card__content > :first-child {
    grid-row: 1;
    padding-bottom: var(--space-md);
  }

  /* Zeilen 3–5: Footer */
  .product-grid .product-card__footer {
    display: grid;
    grid-row: 2 / span 3;
    grid-template-rows: subgrid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0;
  }

  /* Zeile 3: Preis */
  .product-grid .product-card__footer > .brxe-product-price {
    grid-row: 1;
    padding-bottom: var(--space-xs);
  }

  /* Zeile 4: Grundpreis, Versand, Lieferzeit */
  .product-grid .product-card__legal {
    grid-row: 2;
    padding-bottom: var(--space-sm);
  }

  /* Zeile 5: Variantenwahl und Warenkorb */
  .product-grid .product-card-cart {
    grid-row: 3;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

  .product-grid .product-card-cart > form,
  .product-grid .product-card-cart > a:not([hidden]) {
    margin-top: auto;
  }
}

/* Bezieht die Container Query bei normalen Listings auf den Innenbereich
   der Karte. Dort ist die Breite durch die Karte vorgegeben; der Footer
   selbst muss kein Query-Container mehr sein. */
.product-grid .product-card__content {
  container: te-card-buy / inline-size;
}

/* Für Karten-Templates, deren Footer ein DIREKTES Kind der Karte ist
   (z. B. alternative Teaser-/Empfehlungs-Templates). */
.product-card > .product-card__footer {
  container: te-card-buy / inline-size;
}

/* --------------------------------------------------------------------------
   2. Allgemeine Inhalte der Produktkarte
   -------------------------------------------------------------------------- */

.product-card[data-stock-status="outofstock"] img {
  filter: grayscale(100%);
  opacity: 0.75;
}

.product-card .product-card__legal * {
  font-size: 0.875rem !important;
}

.product-card .delivery-time-1-3-tage {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  color: var(--clr-success, #2e7d32);
  font-weight: 600;
}

.product-card .delivery-time-1-3-tage::before {
  content: "";
  width: 0.5em;
  height: 0.5em;
  flex: 0 0 0.5em;
  border-radius: 50%;
  background: currentColor;
}

/* Maximal ein Produkt-Badge pro Badge-Gruppe anzeigen. */
.product-card .product-card__badges > .product-badge:not(:first-child) {
  display: none;
}

/* Inline-Metadaten (z. B. Kategorie und Merkmale) mit Trennpunkten. */
.product-card .inline-list > * {
  display: inline;
}

.product-card .inline-list > * > * {
  display: inline;
  white-space: normal;
}

.product-card .inline-list--dot > *:not(:last-child)::after {
  content: " · ";
}

/* Kurzbeschreibung auf zwei Zeilen begrenzen. */
.product-card .product-card-excerpt {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.product-card .product-card-excerpt > p {
  display: inline;
  margin: 0;
}

.product-card .product-card-excerpt > p + p::before {
  content: " ";
}

/* --------------------------------------------------------------------------
   3. Gemeinsames Kaufbereich-Layout: einfache und variable Produkte
   -------------------------------------------------------------------------- */

.product-card .product-card-cart {
  --product-card-control-height: 2.75rem;
}

.product-card .product-card-cart form.cart.brx-loop-product-form,
.product-card .product-card-cart .teecv-purchase-row {
  display: flex !important;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: var(--space-sm, 0.5rem);
  width: 100%;
  min-width: 0;
}

.product-card .product-card-cart form.cart.brx-loop-product-form {
  margin: 0;
}

.product-card .product-card-cart form.cart.brx-loop-product-form > .quantity,
.product-card .product-card-cart .teecv-purchase-row > .teecv-quantity {
  flex: 0 0 33.333%;
  width: 33.333%;
  min-width: 0;
}

.product-card .product-card-cart form.cart.brx-loop-product-form > .button,
.product-card .product-card-cart .teecv-purchase-row > .teecv-add-to-cart {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  width: auto !important;
  min-width: 0;
}

/* Standard-Mengenfeld und Button einfacher Produkte auf gleicher Höhe. */
.product-card .product-card-cart form.cart.brx-loop-product-form > .quantity,
.product-card .product-card-cart form.cart.brx-loop-product-form > .button {
  box-sizing: border-box;
  height: var(--product-card-control-height) !important;
  min-height: var(--product-card-control-height);
  margin: 0 !important;
  align-self: stretch !important;
}

.product-card .product-card-cart form.cart.brx-loop-product-form > .quantity {
  display: flex;
  align-items: stretch;
}

.product-card .product-card-cart form.cart.brx-loop-product-form > .quantity > .qty,
.product-card .product-card-cart form.cart.brx-loop-product-form > .quantity > .action {
  box-sizing: border-box;
  height: 100% !important;
  min-height: 0;
}

/* Der native Loop-Button ohne Mengenfeld bleibt volle Breite. */
.product-card .product-card-cart > .button {
  width: 100% !important;
  flex: 1 1 100%;
}

/* --------------------------------------------------------------------------
   4. Variationsformular und Packungsgrößen
   -------------------------------------------------------------------------- */

.product-card .product-card-cart .teecv-card-form {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-sm, 0.5rem);
  width: 100% !important;
  min-width: 0;
  margin: 0 !important;
  padding: 0 !important;
}

/* Anders als WP-/Bricks .screen-reader-text erscheint ein fokussierter
   Radio-Input nicht oben links. */
.teecv-visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.product-card .product-card-cart .teecv-pack-sizes {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.product-card .product-card-cart .teecv-pack-sizes__options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs, 0.25rem);
  min-width: 0;
}

.product-card .product-card-cart .teecv-pack-sizes__option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

/* Die übrige Optik kommt aus den Bricks-Buttonklassen am Label. */
.product-card .product-card-cart .teecv-pack-sizes__input:checked + .teecv-pack-sizes__option {
  background-color: var(--clr-primary);
  border-color: var(--clr-primary);
  color: var(--clr-text-on-primary);
  font-weight: 600;
}

.product-card .product-card-cart .teecv-pack-sizes__input:focus-visible + .teecv-pack-sizes__option {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.product-card .product-card-cart .teecv-pack-sizes__input:disabled + .teecv-pack-sizes__option {
  cursor: not-allowed;
  opacity: 0.38;
  text-decoration: line-through;
}

/* --------------------------------------------------------------------------
   5. Mengensteuerung und Warenkorb-Button für variable Produkte
   -------------------------------------------------------------------------- */

.product-card .product-card-cart .teecv-purchase-row > * {
  min-width: 0;
}

.product-card .product-card-cart .teecv-purchase-row--button-only > .teecv-add-to-cart {
  flex: 1 1 100%;
  width: 100% !important;
}

.product-card .product-card-cart .teecv-quantity {
  display: grid !important;
  grid-template-columns: 2rem minmax(0, 1fr) 2rem;
  min-width: 0;
  min-height: var(--product-card-control-height);
  border: 1px solid var(--clr-border);
  box-sizing: border-box;
}

.product-card .product-card-cart .teecv-quantity.is-hidden {
  display: none !important;
}

.product-card .product-card-cart .teecv-quantity__button,
.product-card .product-card-cart .teecv-quantity__input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0 !important;
  min-height: 100%;
  margin: 0 !important;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: center;
}

.product-card .product-card-cart .teecv-quantity__button {
  padding: 0 !important;
  cursor: pointer;
}

.product-card .product-card-cart .teecv-quantity__button:first-child {
  border-right: 1px solid var(--clr-border);
}

.product-card .product-card-cart .teecv-quantity__button:last-child {
  border-left: 1px solid var(--clr-border);
}

.product-card .product-card-cart .teecv-quantity__input {
  padding: 0.35rem 0.15rem !important;
  appearance: textfield;
  -moz-appearance: textfield;
}

.product-card .product-card-cart .teecv-quantity__input::-webkit-outer-spin-button,
.product-card .product-card-cart .teecv-quantity__input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.product-card .product-card-cart .teecv-add-to-cart {
  box-sizing: border-box;
  min-width: 0 !important;
  min-height: var(--product-card-control-height);
  margin: 0 !important;
  white-space: nowrap;
  background-color: var(--clr-accent);
  color: var(--clr-text);
  border: 1px solid var(--clr-text-accent);
  border-radius: var(--radius);
}

.product-card .product-card-cart .teecv-add-to-cart:hover {
  background-color: var(--clr-accent-hover);
}

.product-card .product-card-cart .teecv-add-to-cart:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* Nach Initialisierung durch JS den originalen Link ausblenden. */
.product-card .product-card-cart.teecv-card-variations-active > .teecv-card-fallback,
.product-card .product-card-cart.teecv-card-variations-active > a.product_type_variable.add_to_cart_button {
  display: none !important;
}

/* Progressive Enhancement: Ohne JS bleibt der Fallback-Link sichtbar. */
.teecv-card-form[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   6. Responsive Kaufbereich – abhängig von der Karten-INNENbreite

   Normales Listing: .product-card__content ist Query-Container.
   Bei 16px Padding links/rechts und 1px Kartenrahmen entspricht
   <272px Content-Breite annähernd <306px äußerer Kartenbreite.

   Andere Templates mit direkt angehängtem Footer nutzen denselben
   Schwellwert bezogen auf ihre Footer-Breite.
   -------------------------------------------------------------------------- */

@container te-card-buy (width < 272px) {
  .product-card-cart form.cart.brx-loop-product-form,
  .product-card-cart .teecv-purchase-row {
    flex-direction: column !important;
    flex-wrap: nowrap;
  }

  .product-card-cart form.cart.brx-loop-product-form > .quantity,
  .product-card-cart form.cart.brx-loop-product-form > .button,
  .product-card-cart .teecv-purchase-row > .teecv-quantity,
  .product-card-cart .teecv-purchase-row > .teecv-add-to-cart {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: 100%;
  }
}
