/**
 * LFP Accessories Upsell — Styles front-end
 *
 * Design inspiré de ooni.com : cartes épurées, bouton + rond, récap discret.
 * Mobile-first. Toutes les classes préfixées .lfp-acc-.
 * Pas de !important sauf nécessité absolue documentée.
 *
 * Variables CSS : personnalisables depuis le thème via :root { --lfp-acc-... }
 *
 * BUG-009 : mobile-first — les valeurs par défaut sont pour petit écran (375px).
 * Les tailles augmentent à 480px+ et 768px+.
 */

/* =========================================================================
   Variables CSS (override possible depuis le thème enfant)
   ========================================================================= */

:root {
	--lfp-acc-color-accent:          #e85d04;   /* orange LFP */
	--lfp-acc-color-accent-hover:    #c44d00;
	--lfp-acc-color-accent-light:    #fff3ec;
	--lfp-acc-color-text:            #1a1a1a;
	--lfp-acc-color-text-muted:      #6b7280;
	--lfp-acc-color-text-link:       #1a1a1a;
	--lfp-acc-color-border:          #e5e7eb;
	--lfp-acc-color-border-selected: #e85d04;
	--lfp-acc-color-bg-card:         #ffffff;
	--lfp-acc-color-bg-selected:     #fff8f5;
	--lfp-acc-color-bg-summary:      #f9fafb;
	--lfp-acc-color-price-sale:      #e85d04;
	--lfp-acc-color-toggle-border:          #374151;  /* gris foncé — contour visible sur mobile ET desktop (BUG-012) */
	--lfp-acc-color-toggle-checked:         #22c55e;  /* vert = sélectionné/validé (BUG-005) */
	--lfp-acc-color-toggle-checked-hover:   #16a34a;
	--lfp-acc-color-toggle-text:            #374151;
	--lfp-acc-radius-card:           8px;
	--lfp-acc-radius-toggle:         8px;   /* carré arrondi, pas cercle (BUG-011) */
	--lfp-acc-shadow-card:           0 1px 3px rgba(0, 0, 0, .08);
	--lfp-acc-shadow-card-selected:  0 2px 8px rgba(232, 93, 4, .18);
	--lfp-acc-font-size-name:        0.8125rem;  /* 13px — mobile default (BUG-009) */
	--lfp-acc-font-size-desc:        0.75rem;    /* 12px — mobile default (BUG-009) */
	--lfp-acc-font-size-price:       0.8125rem;  /* 13px — mobile default (BUG-009) */
	--lfp-acc-font-size-badge:       0.6875rem;  /* 11px */
	--lfp-acc-thumb-size:            44px;        /* mobile default (BUG-009) */
	--lfp-acc-toggle-size:           32px;        /* mobile default (BUG-009) */
}

/* =========================================================================
   Wrapper principal
   ========================================================================= */

/*
 * BUG-009/BUG-013 : le parent Woodmart .woocommerce-variation-add-to-cart
 * fait ~617px sur un viewport 375px. width: 100% hérite de cette largeur.
 * En mobile (< 480px) on force la largeur au viewport moins les marges
 * Woodmart (~80px cumulés). À 480px+ le parent ne déborde plus → width: 100%.
 * 80px validé visuellement en DevTools sur iPhone SE (375px).
 */

.lfp-acc-wrapper {
	width: calc(100vw - 80px) !important;
	max-width: 100% !important;
	min-width: 0;
	margin: 0 0 24px;
	padding: 20px 0 0;
	border-top: 1px solid var(--lfp-acc-color-border);
	box-sizing: border-box;
	overflow: hidden;
}

/* =========================================================================
   Titre et sous-titre
   ========================================================================= */

.lfp-acc-title {
	margin: 0 0 4px;
	padding: 0;
	font-size: 1rem;
	font-weight: 700;
	color: var(--lfp-acc-color-text);
	line-height: 1.3;
}

.lfp-acc-subtitle {
	margin: 0 0 16px;
	padding: 0;
	font-size: var(--lfp-acc-font-size-desc);
	color: var(--lfp-acc-color-text-muted);
	line-height: 1.4;
}

/* =========================================================================
   Liste des cartes
   ========================================================================= */

.lfp-acc-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
	width: 100%;
	max-width: 100%;
	min-width: 0;
	overflow: hidden;
	box-sizing: border-box;
}

/* =========================================================================
   Carte accessoire — Mobile-first (horizontal, tailles réduites)
   BUG-009 : calcul 375px − Woodmart sidebar padding (~30px)
   = ~345px disponible. 44 (img) + 32 (toggle) + 8*2 (gaps) + 8*2 (pad) + 2 (border)
   = 110px fixe → ~235px pour le body. OK.
   ========================================================================= */

.lfp-acc-card {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 8px;
	padding: 8px;
	width: 100%;
	max-width: 100%;
	min-width: 0;
	box-sizing: border-box;
	overflow: hidden;
	background: var(--lfp-acc-color-bg-card);
	border: 1px solid var(--lfp-acc-color-border);
	border-radius: var(--lfp-acc-radius-card);
	box-shadow: var(--lfp-acc-shadow-card);
	transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
	position: relative;
}

/* État sélectionné — ajouté par JS en Phase 3 */
.lfp-acc-card--selected {
	border-color: var(--lfp-acc-color-border-selected);
	background: var(--lfp-acc-color-bg-selected);
	box-shadow: var(--lfp-acc-shadow-card-selected);
}

/* =========================================================================
   Image de la carte
   BUG-009 : flex-basis fixe, img contrainte par max-width pour que les
   attributs HTML width/height de wp_get_attachment_image() ne débordent pas.
   ========================================================================= */

.lfp-acc-card__image {
	flex: 0 0 var(--lfp-acc-thumb-size);
	width: var(--lfp-acc-thumb-size);
	height: var(--lfp-acc-thumb-size);
	overflow: hidden;
}

/* Force toutes les images du bloc à ne jamais déborder (attrs HTML width/height) */
.lfp-acc-wrapper img {
	max-width: 100%;
	height: auto;
}

.lfp-acc-card__image a {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 4px;
	overflow: hidden;
}

.lfp-acc-thumb {
	display: block;
	width: 100%;
	height: 100%;
	max-width: var(--lfp-acc-thumb-size);
	max-height: var(--lfp-acc-thumb-size);
	object-fit: cover;
	border-radius: 4px;
}

/* =========================================================================
   Corps de la carte (nom, description, prix, variante)
   BUG-009 : min-width: 0 + overflow: hidden empêche les enfants longs
   de pousser le toggle hors de la carte.
   ========================================================================= */

.lfp-acc-card__body {
	flex: 1 1 0%;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
	overflow: hidden;
}

/* Chaque enfant du body est un flex item (column) — forcer min-width: 0
   pour que les éléments WC (prix, badges) ne forcent pas une largeur min-content */
.lfp-acc-card__body > * {
	min-width: 0;
	max-width: 100%;
}

.lfp-acc-card__name {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	font-size: var(--lfp-acc-font-size-name);
	font-weight: 600;
	color: var(--lfp-acc-color-text-link);
	text-decoration: none;
	line-height: 1.3;
	word-break: break-word;
	overflow-wrap: break-word;
}

.lfp-acc-card__name:hover,
.lfp-acc-card__name:focus {
	color: var(--lfp-acc-color-accent);
	text-decoration: none;
	outline: none;
}

.lfp-acc-card__desc {
	margin: 0;
	padding: 0;
	font-size: var(--lfp-acc-font-size-desc);
	color: var(--lfp-acc-color-text-muted);
	line-height: 1.4;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* =========================================================================
   Prix
   ========================================================================= */

/* BUG-013 : overflow: visible (au lieu de hidden) pour laisser flex-wrap fonctionner.
   Le parent .lfp-acc-card__body a overflow: hidden + min-width: 0 qui contient
   la propagation de min-content (BUG-009). */
.lfp-acc-card__price {
	display: flex;
	align-items: baseline;
	flex-wrap: wrap;
	gap: 4px;
	line-height: 1.2;
	min-width: 0;
	max-width: 100%;
}

/* Prix standard WooCommerce (get_price_html retourne des spans WC) */
.lfp-acc-card__price .price {
	font-size: var(--lfp-acc-font-size-price);
	font-weight: 700;
	color: var(--lfp-acc-color-text);
}

.lfp-acc-card__price .price del {
	color: var(--lfp-acc-color-text-muted);
	font-weight: 400;
	font-size: 0.75rem;
}

.lfp-acc-card__price .price ins {
	text-decoration: none;
	font-weight: 700;
	color: var(--lfp-acc-color-price-sale);
}

/* Prix remisé via notre plugin */
.lfp-acc-price--original {
	color: var(--lfp-acc-color-text-muted);
	font-size: 0.75rem;
	font-weight: 400;
	text-decoration: line-through;
}

.lfp-acc-price--sale {
	color: var(--lfp-acc-color-price-sale);
	font-size: var(--lfp-acc-font-size-price);
	font-weight: 700;
	text-decoration: none;
}

.lfp-acc-price__badge {
	display: inline-block;
	flex-shrink: 0;
	background: var(--lfp-acc-color-accent);
	color: #fff;
	font-size: var(--lfp-acc-font-size-badge);
	font-weight: 700;
	line-height: 1;
	padding: 2px 5px;
	border-radius: 3px;
	vertical-align: middle;
}

/* =========================================================================
   Sélecteur de variante
   ========================================================================= */

.lfp-acc-card__variant {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin-top: 2px;
}

.lfp-acc-variant-label {
	font-size: 0.75rem;
	color: var(--lfp-acc-color-text-muted);
}

/* screen-reader-text standard WordPress */
.lfp-acc-variant-label.screen-reader-text {
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	width: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
}

.lfp-acc-variant-select {
	width: 100%;
	max-width: 140px;
	padding: 4px 24px 4px 6px;
	font-size: 0.75rem;
	border: 1px solid var(--lfp-acc-color-border);
	border-radius: 4px;
	background-color: #fff;
	color: var(--lfp-acc-color-text);
	appearance: none;
	-webkit-appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 6px center;
	cursor: pointer;
	box-sizing: border-box;
}

.lfp-acc-variant-select:focus {
	border-color: var(--lfp-acc-color-accent);
	outline: 2px solid rgba(232, 93, 4, .25);
	outline-offset: 0;
}

/* =========================================================================
   Bouton toggle +/✓
   ========================================================================= */

/* BUG-010 : Woodmart cible les <button> dans .summary/.cart avec une spécificité élevée
   (ex: .summary .cart button { background: ... }). On utilise .lfp-acc-wrapper pour
   augmenter la spécificité de nos règles et garantir qu'elles gagnent. */
.lfp-acc-wrapper .lfp-acc-card__toggle {
	flex: 0 0 var(--lfp-acc-toggle-size);
	width: var(--lfp-acc-toggle-size);
	height: var(--lfp-acc-toggle-size);
	border-radius: var(--lfp-acc-radius-toggle);
	border: 2px solid var(--lfp-acc-color-toggle-border);
	background: transparent;
	color: var(--lfp-acc-color-toggle-text);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	transition: border-color .15s ease, background .15s ease, color .15s ease, transform .1s ease;
	-webkit-tap-highlight-color: transparent;
}

/* BUG-012 (3ème itération) : le contour foncé par défaut (--toggle-border: #374151)
   est le même sur mobile et desktop. Le hover/focus non sélectionné reste foncé.
   Le vert n'apparaît QUE pour [aria-pressed="true"]. */

/* Hover non sélectionné : légèrement plus foncé que le défaut */
.lfp-acc-wrapper .lfp-acc-card__toggle[aria-pressed="false"]:hover {
	border-color: var(--lfp-acc-color-text);
	color: var(--lfp-acc-color-text);
}

/* Hover sélectionné : vert foncé */
.lfp-acc-wrapper .lfp-acc-card__toggle[aria-pressed="true"]:hover {
	border-color: var(--lfp-acc-color-toggle-checked-hover);
	background: var(--lfp-acc-color-toggle-checked-hover);
	color: #fff;
}

/* Focus non sélectionné : contour foncé (pas vert) */
.lfp-acc-wrapper .lfp-acc-card__toggle[aria-pressed="false"]:focus,
.lfp-acc-wrapper .lfp-acc-card__toggle[aria-pressed="false"]:focus-visible {
	outline: 2px solid var(--lfp-acc-color-toggle-border);
	outline-offset: 2px;
	border-color: var(--lfp-acc-color-toggle-border);
	background: transparent;
	box-shadow: none;
}

/* Focus sélectionné : contour vert */
.lfp-acc-wrapper .lfp-acc-card__toggle[aria-pressed="true"]:focus-visible {
	outline: 2px solid var(--lfp-acc-color-toggle-checked);
	outline-offset: 2px;
}

.lfp-acc-wrapper .lfp-acc-card__toggle:active {
	transform: scale(.9);
}

/* État "sélectionné" — ajouté par JS (aria-pressed="true") */
.lfp-acc-wrapper .lfp-acc-card__toggle[aria-pressed="true"] {
	background: var(--lfp-acc-color-toggle-checked);
	border-color: var(--lfp-acc-color-toggle-checked);
	color: #fff;
}

.lfp-acc-toggle__icon {
	font-size: 1rem;
	font-weight: 300;
	line-height: 1;
	transition: transform .15s ease;
}

.lfp-acc-wrapper .lfp-acc-card__toggle[aria-pressed="true"] .lfp-acc-toggle__icon {
	transform: rotate(45deg); /* Phase 3 : JS changera en ✓ */
}

/* =========================================================================
   Prix total dynamique (produit principal + accessoires sélectionnés)
   Toujours visible. Mis à jour par JS en temps réel.
   BUG-009 : contrainte viewport comme le wrapper (parent Woodmart déborde).
   ========================================================================= */

/* BUG-009 (6ème itération) : en mobile, .summary-inner = 275px de contenu.
   flex-direction: column pour empiler TOTAL + prix au lieu de les mettre côte à côte.
   Restauré en row à 480px+. */
.lfp-acc-total {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 2px;
	/* BUG-013 : même stratégie viewport que le wrapper (80px paddings Woodmart cumulés) */
	width: calc(100vw - 80px) !important;
	max-width: 100% !important;
	min-width: 0;
	box-sizing: border-box;
	overflow: hidden;
	margin-top: 12px;
	padding-top: 12px;
	border-top: 1px solid var(--lfp-acc-color-border);
}

.lfp-acc-total__label {
	font-size: 0.75rem;
	font-weight: 500;
	color: var(--lfp-acc-color-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.lfp-acc-total__price {
	font-size: 1.25rem;
	font-weight: 700;
	color: var(--lfp-acc-color-text);
	line-height: 1.1;
	letter-spacing: -0.01em;
}

/* Force les éléments WC imbriqués (bdi, span.amount) à ne pas déborder */
.lfp-acc-total__price .woocommerce-Price-amount,
.lfp-acc-total__price bdi {
	white-space: nowrap;
}

/* =========================================================================
   Responsive — 480px+ (écrans moyens : tailles confortables)
   ========================================================================= */

@media (min-width: 480px) {
	/* BUG-013 : à 480px+ le parent Woodmart ne déborde plus → width: 100% classique */
	.lfp-acc-wrapper {
		width: 100% !important;
	}

	:root {
		--lfp-acc-thumb-size:       60px;
		--lfp-acc-toggle-size:      36px;
		--lfp-acc-font-size-name:   0.9375rem;  /* 15px */
		--lfp-acc-font-size-desc:   0.8125rem;  /* 13px */
		--lfp-acc-font-size-price:  0.9375rem;  /* 15px */
	}

	.lfp-acc-card {
		gap: 12px;
		padding: 12px;
	}

	.lfp-acc-card__body {
		gap: 3px;
	}

	.lfp-acc-card__desc {
		white-space: normal;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: unset;
	}

	.lfp-acc-card__price .price del,
	.lfp-acc-price--original {
		font-size: 0.8125rem;
	}

	.lfp-acc-variant-select {
		max-width: 160px;
		padding: 4px 28px 4px 8px;
		font-size: 0.8125rem;
		background-position: right 8px center;
	}

	.lfp-acc-toggle__icon {
		font-size: 1.25rem;
	}

	.lfp-acc-total {
		width: 100% !important;
		flex-direction: row;
		align-items: baseline;
		justify-content: space-between;
		gap: 4px 8px;
		margin-top: 16px;
		padding-top: 14px;
	}

	.lfp-acc-total__label {
		font-size: 0.875rem;
	}

	.lfp-acc-total__price {
		font-size: 1.5rem;
	}
}

/* =========================================================================
   Responsive — 768px+ (tablette et desktop)
   ========================================================================= */

@media (min-width: 768px) {
	.lfp-acc-wrapper {
		padding-top: 24px;
		margin-bottom: 28px;
	}

	.lfp-acc-list {
		gap: 10px;
	}

	.lfp-acc-card {
		padding: 16px;
		gap: 16px;
	}
}

/* =========================================================================
   Accessibilité : réduit les animations si préférence système
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
	.lfp-acc-card,
	.lfp-acc-card__toggle,
	.lfp-acc-toggle__icon {
		transition: none;
	}
}
