/* ==========================================================================
   TOP-MEDIA – Mobile Produktlisten (Theme 1.7.0, Phase B, Variante A4)
   --------------------------------------------------------------------------
   Gilt nur unter 980 px. Desktop (ab 980 px) bleibt unverändert.
   Geladen nach responsive.css (inc/shop-loop.php), versioniert mit TMPMELA_ASSET_VER.

   Geltungsbereich (Klassen per Filter woocommerce_product_loop_start):
   - ul.products.tm-card  alle WooCommerce-Produktlisten: Kartengestaltung
   - ul.products.tm-grid  nur Shop/Kategorie/Schlagwort/Suche und Startseiten-Listen:
                          2 Spalten (ab 600 px 3 Spalten). Nicht: Ähnliche Produkte,
                          Zubehör, Cross-Sells (Karussells) – siehe custom.js.

   Zentrale Gestaltungswerte als CSS-Variablen (unten in .tm-card änderbar).
   Preisfarbe kommt unverändert aus dem bestehenden CSS (Phase D).
   ========================================================================== */

@media only screen and (max-width: 979px) {

	/* ---------- Gestaltungswerte ---------- */
	.woocommerce ul.products.tm-card {
		--tm-gap: 8px;
		--tm-card-border: #e5e5e5;
		--tm-card-radius: 6px;
		--tm-card-pad: 5px 5px 8px;  /* 1.7.2: Bild näher an den Rahmen (vorher 6/7/8) */
		--tm-title-size: 13.5px;
		--tm-title-line: 18px;
		--tm-title-color: #333;
		--tm-price-size: 16px;
		--tm-price-weight: 600;      /* 1.7.2: ruhiger als 700 */
		--tm-btn-size: 35px;      /* sichtbare Größe des Warenkorb-Symbols (wie bisher im Theme) */
		--tm-btn-tap: 44px;       /* tatsächliche Tippfläche */
		--tm-btn-bg: #232f3e;
	}

	/* ---------- Raster (nur tm-grid, nie in Owl-Karussells) ---------- */
	.woocommerce ul.products.tm-grid:not(.owl-carousel) {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		grid-gap: var(--tm-gap); /* ältere Safari (vor 12) */
		gap: var(--tm-gap);
		margin: 0 0 16px;
		padding: 0;
	}
	.woocommerce ul.products.tm-grid:not(.owl-carousel)::before,
	.woocommerce ul.products.tm-grid:not(.owl-carousel)::after {
		display: none;
	}
	/* 1.7.6: responsive.css setzt Produktbreiten (50 %, 49,4 %, 100 % mit !important) wieder wie in
	   1.6.2 für alle Listen; im Raster gilt die Rasterzelle. Höhere Spezifität statt :where(). */
	.woocommerce ul.products.tm-grid:not(.owl-carousel) li.product,
	.woocommerce-page ul.products.tm-grid:not(.owl-carousel) li.product,
	.woocommerce ul.products.tm-grid:not(.owl-carousel) li.product-category {
		width: auto !important;
	}
	.woocommerce ul.products.tm-grid:not(.owl-carousel) li.product {
		display: flex;
		width: auto;
		margin: 0;
		padding: 0;
		float: none;
		clear: none;
		text-align: left;
	}

	/* ---------- Karte ---------- */
	.woocommerce ul.products.tm-card li.product .container-inner {
		display: flex;
		flex-direction: column;
		width: 100%;
		margin: 0;
		padding: 0;
		background: #fff;
		border: 1px solid var(--tm-card-border);
		border-radius: var(--tm-card-radius);
	}
	.woocommerce ul.products.tm-card li.product .container-inner::after {
		display: none; /* senkrechte Trennlinie des Desktop-Rasters */
	}
	.woocommerce ul.products.tm-card li.product .product-block-inner {
		display: flex;
		flex-direction: column;
		flex: 1;
		padding: var(--tm-card-pad);
	}

	/* Bild vollständig, nicht beschnitten; Zweitbild (Hover) auf Touch-Geräten aus */
	.woocommerce ul.products.tm-card li.product .image-block {
		margin: 0 0 6px;
		padding: 0;
		border: 0;
	}
	.woocommerce ul.products.tm-card li.product .image-block img {
		display: block;
		width: 100%;
		height: auto;
		max-width: 100%;
		object-fit: contain;
	}
	.woocommerce ul.products.tm-card li.product .image-block .secondary-image {
		display: none;  /* 1.8.9: auch <picture class="secondary-image"> (WebP-Ausgabe), vorher nur img */
	}

	/* Titel, Preis und Button: Titel oben über die volle Breite,
	   darunter Preis links und Warenkorb-Symbol rechts */
	.woocommerce ul.products.tm-card li.product .product-detail-wrapper {
		display: grid;
		flex: 1;
		grid-template-columns: minmax(0, 1fr) auto;
		grid-template-rows: 1fr auto;
		grid-column-gap: 6px;
		column-gap: 6px;
		align-items: center;
		margin: 0;
		padding: 0;
		text-align: left;
	}
	.woocommerce ul.products.tm-card li.product .product-detail-wrapper > * {
		grid-column: 1 / -1; /* weitere Plugin-Ausgaben über die volle Breite */
	}
	.woocommerce ul.products.tm-card li.product .product-detail-wrapper > a.tm-loop-title {
		grid-row: 1;
		align-self: start;
	}
	.woocommerce ul.products.tm-card li.product .product-name {
		margin: 0 0 4px;
		padding: 0;
		height: auto;
		overflow: visible;
		white-space: normal;
		font-size: var(--tm-title-size);
		line-height: var(--tm-title-line);
		font-weight: 400;
		letter-spacing: 0;
		color: var(--tm-title-color);
	}

	.woocommerce ul.products.tm-card li.product .price {
		grid-row: 2;
		grid-column: 1;
		position: static;
		display: block;
		margin: 0;
		padding: 0;
		opacity: 1;
		text-align: left;
		letter-spacing: 0;
		font-size: var(--tm-price-size);
		line-height: 20px;
		font-weight: var(--tm-price-weight);
	}
	/* Kein Hover auf Touch-Geräten: Preis bleibt sichtbar */
	.woocommerce ul.products.tm-card li.product:hover .price {
		opacity: 1;
	}

	/* UVP nur in der mobilen Händler-Übersicht ausblenden (B2B Market).
	   Desktop und Produktdetailseite unverändert. */
	.woocommerce ul.products.tm-card li.product .price .b2b-rrp,
	.woocommerce ul.products.tm-card li.product .price .b2b-rrp + br {
		display: none;
	}

	.woocommerce ul.products.tm-card li.product .woocommerce-product-details__short-description {
		display: none;
	}
	/* Button-Bereich: vor dem Laden in .gridlist-buttonwrap, danach (custom.js)
	   in .product-block-hover – beide nehmen dieselbe Rasterzelle ein, kein Springen.
	   1.7.6: ohne :has() (ältere iPhones). Der jeweils leere Behälter ist 0 px hoch
	   (align-items: center im Raster) und fängt keine Tipps ab. */
	.woocommerce ul.products.tm-card li.product .product-block-hover,
	.woocommerce ul.products.tm-card li.product .gridlist-buttonwrap {
		grid-row: 2;
		grid-column: 2;
		position: static;
		display: block;
		width: auto;
		margin: 0;
		padding: 0;
		background: none;
		opacity: 1;
		pointer-events: none;
	}
	.woocommerce ul.products.tm-card li.product .product-block-hover .button,
	.woocommerce ul.products.tm-card li.product .gridlist-buttonwrap .button {
		pointer-events: auto;
	}
	.woocommerce ul.products.tm-card li.product .gridlist-buttonwrap .clear {
		display: none;
	}

	/* Warenkorb-Symbol: sichtbar 35 px, Tippfläche 44 px (unsichtbare Erweiterung) */
	.woocommerce ul.products.tm-card li.product .button {
		position: relative;
		display: block !important;  /* gegen woocommerce.css (0,7,2): inline-block */
		float: none;
		box-sizing: border-box;
		width: var(--tm-btn-size);
		height: var(--tm-btn-size);
		min-height: 0;
		margin: 0 !important;       /* gegen woocommerce.css (0,7,2): 0 2px */
		padding: 0;
		border: 0;
		border-radius: 4px;
		font-size: 0;
		line-height: var(--tm-btn-size);
		text-align: center;
		background-color: var(--tm-btn-bg);
		color: #fff;
	}
	.woocommerce ul.products.tm-card li.product .button::before {
		width: var(--tm-btn-size);
		height: var(--tm-btn-size);
		line-height: var(--tm-btn-size);
		top: 0;
	}
	.woocommerce ul.products.tm-card li.product .button::after {
		content: "";
		position: absolute;
		top: 50%;
		left: 50%;
		width: var(--tm-btn-tap);
		height: var(--tm-btn-tap);
		transform: translate(-50%, -50%);
	}
	.woocommerce ul.products.tm-card li.product .button:focus-visible {
		outline: 2px solid #1e3a8a;
		outline-offset: 2px;
	}

	/* Nicht direkt kaufbar (ausverkauft u. ä.): WooCommerce gibt hier „Weiterlesen“
	   als normalen Link zur Produktseite aus (kein AJAX-Warenkorb). Darstellung hell
	   mit Pfeil, damit er nicht wie ein aktiver Warenkorb-Button wirkt. */
	.woocommerce ul.products.tm-card li.product .button:not(.add_to_cart_button) {
		background-color: #fff;
		border: 1px solid #b5b5b5;
		color: #555;
	}
	.woocommerce ul.products.tm-card li.product .button:not(.add_to_cart_button)::before {
		content: "\f105";
		font-family: "FontAwesome";
		font-size: 20px;
		position: absolute;
		left: 0;
		right: 0;
		color: #555;
	}

	/* Link „Warenkorb anzeigen“ nach dem Hinzufügen: in der schmalen Karte ausgeblendet,
	   er würde die Button-Spalte sprengen. Rückmeldung geben Header-Warenkorb (Anzahl/Betrag),
	   Side Cart (Live) und das Häkchen am Button (Klasse „added“). */
	.woocommerce ul.products.tm-card li.product .added_to_cart {
		display: none;
	}

	/* Labels: Größe auf dem Smartphone kommt seit 1.7.2 aus den Einstellungen von
	   Advanced Woo Labels („Font size phone“), keine Theme-Regel mehr. */
}

/* Tablet: 3 Spalten derselben Karte */
@media only screen and (min-width: 600px) and (max-width: 979px) {
	.woocommerce ul.products.tm-grid:not(.owl-carousel) {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		grid-gap: 12px;
		gap: 12px;
	}
}

/* ==========================================================================
   Oberer Bereich der Produktarchive (Shop, Kategorie, Schlagwort, Suche)
   ========================================================================== */

/* Kurze Ergebnisanzahl nur mobil; Desktop zeigt unverändert den WooCommerce-Text */
.tm-result-count-short {
	display: none;
}

@media only screen and (max-width: 979px) {

	/* Ergebnisanzahl „914 Artikel“: Langtext bleibt für Screenreader im HTML */
	body.woocommerce .woocommerce-result-count {
		display: flex;
		align-items: center;
		font-size: 0;
		line-height: 20px;
		letter-spacing: 0;
		word-spacing: 0;
	}
	body.woocommerce .woocommerce-result-count .tm-result-count-short {
		display: inline;
		font-size: 15px;
		line-height: 20px;
		color: #444;
		white-space: nowrap;
	}

	/* Abstände Pfadnavigation, Titelbereich, Einleitung/Hinweise */
	body.woocommerce.archive .page-title {
		margin: 0;
		padding: 8px 0 4px;
		min-height: 0;
	}
	body.woocommerce.archive .woocommerce-breadcrumb {
		margin: 0;
		padding: 0;
		font-size: 14px;
		line-height: 20px;
	}
	body.woocommerce.archive .page-description,
	body.woocommerce.archive .term-description {
		margin: 6px 0 10px;
		padding: 0 0 8px;
		border-bottom: 1px solid #e5e5e5;
	}
	body.woocommerce.archive .page-description p,
	body.woocommerce.archive .term-description p {
		margin: 0;
	}
	body.woocommerce.archive .woocommerce-notices-wrapper:empty {
		display: none;
	}

	/* Ergebnisanzahl und Sortierung in einer Zeile (Container .category-toolbar aus custom.js) */
	body.woocommerce.archive .category-toolbar {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 8px;
		margin: 0 0 10px;
		padding: 0;
		border: 0;
		min-height: 0;
	}
	body.woocommerce.archive .category-toolbar > .woocommerce-result-count,
	body.woocommerce.archive .category-toolbar > .woocommerce-ordering {
		flex: 0 1 auto;
		width: auto;
		float: none;
		margin: 0;
		padding: 0;
		text-align: left;
	}
	body.woocommerce.archive .category-toolbar > .woocommerce-ordering {
		flex: 0 1 200px;
		min-width: 0;
	}
	/* Sortierung: Das Theme ersetzt das Auswahlfeld per jQuery customSelect durch
	   span.customSelect und setzt feste Breiten als Inline-Stil. !important ist hier nötig,
	   damit das Feld bei 320 px nicht über den Rand ragt. */
	body.woocommerce.archive .category-toolbar .woocommerce-ordering {
		position: relative;
	}
	body.woocommerce.archive .category-toolbar .woocommerce-ordering .customSelect {
		box-sizing: border-box;
		display: block !important;
		width: 100%;
		line-height: 34px;
		font-size: 15px;
	}
	body.woocommerce.archive .category-toolbar .woocommerce-ordering .customSelectInner {
		box-sizing: border-box;
		width: 100% !important;
		overflow: hidden;           /* 1.7.2: lange Bezeichnungen dürfen die Seite nicht verbreitern */
		text-overflow: ellipsis;    /* (Ursache: white-space:nowrap ohne Begrenzung); mobil kürzere */
		white-space: nowrap;        /* Bezeichnungen aus js/shop-loop.js, daher normalerweise ungekürzt */
		vertical-align: top;        /* 1.7.3: inline-block mit overflow:hidden liegt sonst auf der
		                               Unterkante der Zeile und machte das Feld 50 statt 36 px hoch */
	}
	body.woocommerce.archive .category-toolbar .woocommerce-ordering select.orderby {
		top: 0;
		left: 0;
		width: 100% !important;
		height: 100% !important;
		font-size: 16px !important; /* verhindert Zoom beim Antippen unter iOS */
	}
	body.woocommerce.archive .category-toolbar .gridlist-toggle {
		display: none;
	}

	/* Seitennummern umbrechen statt seitlich überzustehen (bestand bereits in 1.6.2:
	   Seite 2 des Shops war bei 390 px 501 px breit) */
	body.woocommerce.archive nav.woocommerce-pagination ul.page-numbers {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: 4px;
		white-space: normal;
		border: 0;
	}
	body.woocommerce.archive nav.woocommerce-pagination ul.page-numbers li {
		float: none;
		margin: 0;
	}

	/* Kategoriebeschreibung: etwa 3 Zeilen, „Mehr lesen“.
	   1.7.6: Kürzung steht schon im ersten Seitenaufbau (CSS), nicht mehr per JavaScript.
	   Markup aus inc/shop-loop.php: input.tm-desc-check, div.term-description, label.tm-desc-toggle
	   (Geschwister). Welche Breiten kürzen, sagen die Klassen tm-desc-c1/c2/c3 (siehe unten). */
	.tm-desc-check {
		position: absolute;
		width: 1px;
		height: 1px;
		margin: 0;
		padding: 0;
		opacity: 0;
		pointer-events: none;
	}
	.tm-desc-toggle {
		align-items: center;
		min-height: 44px;
		margin: -6px 0 6px;
		padding: 0 2px;
		border: 0;
		background: none;
		color: #1e3a8a;
		font-size: 15px;
		font-weight: 600;
		text-decoration: underline;
		text-transform: none;
		letter-spacing: 0;
		cursor: pointer;
	}
	.tm-desc-toggle .tm-desc-less,
	.tm-desc-check:checked ~ .tm-desc-toggle .tm-desc-more {
		display: none;
	}
	.tm-desc-check:checked ~ .tm-desc-toggle .tm-desc-less {
		display: inline;
	}
	.tm-desc-check:focus ~ .tm-desc-toggle {
		outline: 2px solid #1e3a8a;
		outline-offset: 2px;
	}
}

/* Gekürzte Darstellung je Breitenbereich (nur wenn der Server die Klasse gesetzt hat) */
@media only screen and (max-width: 399px) {
	body.woocommerce .tm-desc-check.tm-desc-c1:not(:checked) ~ .term-description {
		position: relative;
		max-height: 59px; /* 3 Zeilen à 19,5 px (13 px Schrift, auf Staging gemessen) */
		padding-bottom: 0;
		overflow: hidden;
	}
	body.woocommerce .tm-desc-check.tm-desc-c1:not(:checked) ~ .term-description::after {
		display: block;
	}
	body.woocommerce .tm-desc-check.tm-desc-c1 {
		display: block;
	}
	body.woocommerce .tm-desc-toggle.tm-desc-c1 {
		display: inline-flex;
	}
}
@media only screen and (min-width: 400px) and (max-width: 599px) {
	body.woocommerce .tm-desc-check.tm-desc-c2:not(:checked) ~ .term-description {
		position: relative;
		max-height: 59px;
		padding-bottom: 0;
		overflow: hidden;
	}
	body.woocommerce .tm-desc-check.tm-desc-c2:not(:checked) ~ .term-description::after {
		display: block;
	}
	body.woocommerce .tm-desc-check.tm-desc-c2 {
		display: block;
	}
	body.woocommerce .tm-desc-toggle.tm-desc-c2 {
		display: inline-flex;
	}
}
@media only screen and (min-width: 600px) and (max-width: 979px) {
	body.woocommerce .tm-desc-check.tm-desc-c3:not(:checked) ~ .term-description {
		position: relative;
		max-height: 59px;
		padding-bottom: 0;
		overflow: hidden;
	}
	body.woocommerce .tm-desc-check.tm-desc-c3:not(:checked) ~ .term-description::after {
		display: block;
	}
	body.woocommerce .tm-desc-check.tm-desc-c3 {
		display: block;
	}
	body.woocommerce .tm-desc-toggle.tm-desc-c3 {
		display: inline-flex;
	}
}
@media only screen and (max-width: 979px) {
	/* Verlauf am unteren Rand der gekürzten Beschreibung (eingeblendet je Breitenbereich oben) */
	body.woocommerce .tm-desc-check:not(:checked) ~ .term-description::after {
		display: none;
		content: "";
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		height: 20px;
		background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff);
	}
	/* Tastatur: Fokus auf einen Link in der Beschreibung zeigt sie vollständig */
	body.woocommerce .tm-desc-check:not(:checked) ~ .term-description:focus-within {
		max-height: none;
	}
	body.woocommerce .tm-desc-check:not(:checked) ~ .term-description:focus-within::after {
		display: none;
	}
}

/* Desktop (ab 980 px) und Breiten ohne Kürzung: Schalter unsichtbar */
.tm-desc-check,
.tm-desc-toggle {
	display: none;
}

/* 1.7.2: Seitenrand der Produktarchive auf dem Smartphone 12 px statt 20 px (mehr Platz für
   die Produktbilder). responsive.css setzt den Rand für alle Seiten mit !important
   (max-width 767px); diese Regel gilt nur für Shop/Kategorie/Schlagwort/Suche. */
@media only screen and (max-width: 767px) {
	body.woocommerce.archive .main-content-inner {
		margin-left: 12px !important;
		margin-right: 12px !important;
	}
}

/* 1.8.9: Geräte ohne echtes Überfahren (iPhone, iPad, Android): kein Zweitbild per Hover einblenden.
   Eine Einblendung beim Antippen verhindert in WebKit, dass der erste Tipp den Produktlink öffnet. */
@media (hover: none) {
	.woocommerce ul.products li.product .secondary-image,
	.woocommerce-page ul.products li.product .secondary-image { display: none !important; }
}
