/* ========================================
   STILI BASE REPEATER
   ======================================== */

/* ---------- RIGA REPEATER ---------- */
.acf-field[data-name="productRepeater"] .acf-row {
	background: #f8fafc;
	border: 2px solid #e2e8f0;
	border-radius: 12px;
	padding: 14px 10px !important;
	margin-bottom: 14px;
}

.acf-field[data-name="productRepeater"] .acf-row>td {
	padding: 10px 8px !important;
	vertical-align: middle !important;
}

.acf-field[data-name="productRepeater"] .acf-row .acf-label {
	display: none !important;
}

/* ---------- UNIFORMITÀ ALTEZZA CAMPI ---------- */
.acf-field[data-name="productRepeater"] .acf-input {
	min-height: 40px !important;
	padding: 0 !important;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

/* ---------- LARGHEZZA CAMPI ---------- */
.acf-field[data-name="productRepeater"] .acf-field[data-name="productName"] {
	width: 32% !important;
}

.acf-field[data-name="productRepeater"] .acf-field[data-name="numberOfPieces"] {
	width: 60px !important;
}

.acf-field[data-name="productRepeater"] .acf-field[data-name="singleProductPrice"] {
	width: 90px !important;
}

.acf-field[data-name="productRepeater"] .acf-field[data-name="qty_acquistata"] {
	width: 70px !important;
}

.acf-field[data-name="productRepeater"] .acf-field[data-name="productBook"] {
	width: 80px !important;
}

.acf-field[data-name="productRepeater"] .acf-field[data-name="productSold"] {
	width: 80px !important;
}

.acf-field[data-name="productRepeater"] .acf-field[data-name="productImage"] {
	width: 180px !important;
}

/* ---------- CAMPO QUANTITÀ ---------- */
.acf-field[data-name="numberOfPieces"] input {
	text-align: center;
	border: 2px solid #bbf7d0;
	background: #f0fdf4;
	border-radius: 8px;
	padding: 8px;
	font-size: 15px;
	font-weight: 600;
	color: #065f46;
	height: 40px;
}

/* ---------- CAMPO PREZZO ---------- */
.acf-field[data-name="singleProductPrice"] .acf-input {
	position: relative;
	min-height: 50px;
}

.acf-field[data-name="singleProductPrice"] input {
	border: 2px solid #fcd34d;
	background: #fffbeb;
	border-radius: 8px;
	padding: 8px 10px;
	font-size: 15px;
	font-weight: 700;
	color: #92400e;
	text-align: right;
	height: 40px;
	padding-left: 25px;
	width: 100%;
	box-sizing: border-box;
}

.acf-field[data-name="singleProductPrice"] .acf-input:before {
	content: "€";
	position: absolute;
	left: 10px;
	top: 50%;
	transform: translateY(-50%);
	font-weight: bold;
	color: #92400e;
	z-index: 1;
}

/* ---------- CAMPO QT. ACQUISTATA ---------- */
.acf-field[data-name="qty_acquistata"] input {
	background: #fffbeb;
	border: 2px solid #fcd34d;
	border-radius: 8px;
	padding: 8px 10px;
	font-size: 15px;
	font-weight: 700;
	color: #92400e;
	text-align: center;
	height: 40px;
	width: 100%;
	box-sizing: border-box;
}

.acf-field[data-name="qty_acquistata"] input::-webkit-inner-spin-button,
.acf-field[data-name="qty_acquistata"] input::-webkit-outer-spin-button {
	-webkit-appearance: none !important;
	margin: 0 !important;
}

/* ---------- CAMPO PRENOTATO ---------- */
.acf-field[data-name="productBook"] .acf-input {
	background: orange;
	border-radius: 8px;
	padding: 8px;
	border: 2px solid #ff8c00;
	text-align: center;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.acf-field[data-name="productBook"] input[type="checkbox"] {
	width: 22px;
	height: 22px;
	margin: 0;
	pointer-events: auto !important;
	touch-action: manipulation !important;
	cursor: pointer;
	position: relative;
	z-index: 10;
}

/* ---------- CAMPO VENDUTO ---------- */
.acf-field[data-name="productSold"] .acf-input {
	background: #90EE90;
	border-radius: 8px;
	padding: 8px;
	border: 2px solid #008000;
	text-align: center;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.acf-field[data-name="productSold"] input[type="checkbox"] {
	width: 22px;
	height: 22px;
	margin: 0;
}

/* ---------- CAMPO IMMAGINE ---------- */
.acf-field[data-name="productImage"] .acf-image-uploader {
	border: 2px solid #e9d5ff;
	background: #faf5ff;
	border-radius: 8px;
	padding: 6px;
	text-align: center;
	min-height: 50px;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: center;
}

.acf-field[data-name="productImage"] .image-wrap img {
	max-height: 40px;
	width: auto;
	border-radius: 6px;
	object-fit: contain;
}

/* ========================================
   CAMPO RELATIONSHIP (SELECT PRODOTTO)
   ======================================== */

.acf-field-relationship .acf-relationship {
	display: flex !important;
	flex-direction: column !important;
	border: 0 !important;
	border-radius: 8px !important;
	background: #fff !important;
	padding: 0 !important;
	max-height: 400px !important;
	position: relative !important;
}

.acf-field-relationship .acf-relationship:focus-within {
	border-color: #2271b1 !important;
	box-shadow: 0 0 0 1px #2271b1, 0 2px 8px rgba(34, 113, 177, 0.15) !important;
}

.acf-relationship:not(.has-selected-product) {
	min-height: 40px !important;
}

.acf-relationship .filter.-search {
	margin: 0 !important;
	width: 100% !important;
	height: 30px;
	display: flex;
	align-items: center;
}

.acf-relationship .filter.-search input {
	padding: 8px 16px 8px 8px !important;
	border: 1px solid !important;
	border-radius: 6px !important;
	font-size: 14px !important;
	background: #fff !important;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
	height: 40px;
	width: 100%;
}

.acf-relationship .filter.-search input::placeholder {
	color: #94a3b8 !important;
	font-style: italic !important;
}

.acf-relationship .filter.-search input:focus {
	border-color: #2271b1 !important;
	outline: none !important;
	box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.15) !important;
}

.acf-relationship .filter.-search::after {
	content: "🔍";
	position: absolute;
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	font-size: 14px;
	opacity: 0.5;
}

.acf-relationship .selection {
	display: flex !important;
	flex-direction: column !important;
	width: 100% !important;
	flex-grow: 1 !important;
	overflow: hidden !important;
}

.acf-relationship:not(.active) .selection,
.acf-relationship.has-selected-product .selection {
	display: none !important;
	border-color: transparent !important;
	box-shadow: none !important;
}

.acf-relationship.active .selection {
	display: flex !important;
	position: relative !important;
	top: 0 !important;
	left: 0 !important;
	width: 100% !important;
	z-index: 999 !important;
	border: 2px solid #2271b1 !important;
	border-top: none !important;
	border-radius: 0 0 8px 8px !important;
	background: #fff !important;
	flex-direction: column !important;
	animation: dropdownFadeIn 0.2s ease forwards;
}

/* ========================================
   IMMAGINI NEI RISULTATI RICERCA
   ======================================== */

.acf-relationship .choices {
	width: 100% !important;
	max-height: 200px !important;
	overflow-y: auto !important;
	background: #fff !important;
	padding-bottom: 4px !important;
}

.acf-relationship .choices .acf-rel-item {
	padding: 10px 12px !important;
	margin: 2px 0 !important;
	border-radius: 6px !important;
	cursor: pointer !important;
	transition: all 0.15s ease !important;
	background: #fff !important;
	font-size: 14px !important;
	color: #334155 !important;
	display: flex !important;
	align-items: center !important;
	gap: 12px !important;
}

.acf-relationship .choices .acf-rel-item:hover {
	background: #f1f5f9 !important;
	color: #2271b1 !important;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
}

/* Thumbnail nella dropdown */
.acf-relationship .choices .acf-rel-item .product-thumbnail {
	flex-shrink: 0;
	width: 50px;
	height: 50px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #f5f5f5;
	border-radius: 6px;
	overflow: hidden;
	border: 1px solid #ddd;
}

.acf-relationship .choices .acf-rel-item .product-thumbnail img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* Loading spinner */
.acf-relationship .choices .acf-rel-item .product-thumbnail.loading {
	animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.5; }
}

/* Placeholder icona */
.acf-relationship .choices .acf-rel-item .product-thumbnail:not(:has(img)):not(.loading) {
	font-size: 24px;
	color: #999;
}

/* Titolo prodotto */
.acf-relationship .choices .acf-rel-item .acf-rel-item-title {
	flex-grow: 1;
	font-size: 14px;
	line-height: 1.4;
	word-break: break-word;
}

/* ========================================
   PRODOTTO SELEZIONATO
   ======================================== */

.acf-relationship .values {
	width: 100% !important;
	padding: 10px 12px !important;
	background: linear-gradient(to bottom, #f8fafc, #f1f5f9) !important;
	border-top: 1px solid #e5e5e5 !important;
	border-radius: 0 0 8px 8px !important;
	min-height: 48px !important;
	position: relative !important;
	padding-right: 30px !important;
}

.acf-relationship .values:after {
	content: '▾';
	position: absolute;
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	font-size: 16px;
	color: #64748b;
	pointer-events: none;
	transition: transform 0.2s ease;
}

.acf-relationship.active .values:after {
	transform: translateY(-50%) rotate(180deg);
}

.acf-relationship .values .acf-rel-item {
	display: flex !important;
	align-items: center !important;
	gap: 10px !important;
	padding: 8px 10px !important;
	background: #f9f9f9 !important;
	border: 1px solid #ddd !important;
	border-radius: 6px !important;
}

/* Immagine prodotto selezionato */
.acf-relationship .values .acf-rel-item .selected-product-thumbnail {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #fff;
	border-radius: 4px;
	overflow: hidden;
	border: 1px solid #ddd;
}

.acf-relationship .values .acf-rel-item .selected-product-thumbnail img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* Placeholder */
.acf-relationship .values .acf-rel-item .selected-product-thumbnail:not(:has(img)) {
	font-size: 20px;
	color: #999;
}

.acf-relationship .values .acf-rel-item .acf-rel-item-title {
	flex-grow: 1;
	font-weight: 500;
	word-break: break-word;
	font-size: 14px;
}

.acf-relationship .values .acf-rel-item .acf-icon {
	margin-left: auto;
	flex-shrink: 0;
}

.acf-repeater .acf-field-relationship {
	overflow: visible !important;
}

/* ---------- ANIMAZIONE ---------- */
@keyframes dropdownFadeIn {
	from {
		opacity: 0;
		transform: translateY(-5px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ========================================
   BOTTONI MODIFICA/RIMUOVI
   ======================================== */

.product-actions-wrapper {
	display: flex;
	gap: 8px;
	margin-top: 10px;
	padding-left: 8px;
	width: 100%;
}

.acf-field-productName .acf-relationship.active .product-actions-wrapper {
	display: none !important;
}

.acf-modifica-prodotto {
	background-color: #f1f5f9 !important;
	border: 1px solid #cbd5e1 !important;
	color: #475569 !important;
	line-height: 1;
	height: 28px;
	padding: 8px 12px;
	font-size: 13px;
}

.acf-modifica-prodotto:hover {
	background-color: #e2e8f0 !important;
}

.acf-rimuovi-prodotto {
	background-color: #fef2f2 !important;
	border: 1px solid #fecaca !important;
	color: #dc2626 !important;
	line-height: 1;
	height: 28px;
	padding: 8px 12px;
	font-size: 13px;
}

.acf-rimuovi-prodotto:hover {
	background-color: #fee2e2 !important;
}

.product-actions-wrapper .dashicons {
	margin-right: 4px;
	font-size: 14px;
	height: 14px;
	width: 14px;
	vertical-align: text-top;
}

/* ========================================
   SCROLL MIGLIORATO
   ======================================== */

.acf-relationship .list {
	max-height: 400px !important;
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: #c1c1c1 #f5f5f5;
}

.acf-relationship .list::-webkit-scrollbar {
	width: 8px;
}

.acf-relationship .list::-webkit-scrollbar-track {
	background: #f5f5f5;
}

.acf-relationship .list::-webkit-scrollbar-thumb {
	background: #c1c1c1;
	border-radius: 4px;
}

.acf-relationship .list::-webkit-scrollbar-thumb:hover {
	background: #a8a8a8;
}

/* ========================================
   📱 RESPONSIVE MOBILE
   ======================================== */

@media (max-width: 782px) {
	
	/* ===== LAYOUT GENERALE ===== */
	.acf-field[data-name="productRepeater"] .acf-row {
		padding: 12px 8px !important;
	}
	
	.acf-field[data-name="productRepeater"] .acf-row > td {
		padding: 8px 4px !important;
	}
	
	/* ===== LARGHEZZE CAMPI MOBILE ===== */
	.acf-field[data-name="productRepeater"] .acf-field[data-name="productName"] {
		width: 100% !important;
		margin-bottom: 12px;
	}
	
	.acf-field[data-name="productRepeater"] .acf-field[data-name="numberOfPieces"] {
		width: 70px !important;
	}
	
	/* ========================================
   MODIFICA MIRATA PER PREZZO MOBILE
   ======================================== */

@media (max-width: 782px) {
    /* Assicuriamoci che la cella della tabella non strozzi il contenuto */
    .acf-field[data-name="productRepeater"] .acf-row > td.acf-field[data-name="singleProductPrice"] {
        width: auto !important; /* Permette alla cella di respirare */
        min-width: 110px !important; /* Spazio vitale minimo per € + cifre */
    }

    .acf-field[data-name="singleProductPrice"] input {
        font-size: 14px !important;
        padding-left: 22px !important; /* Leggermente meno spazio per l'icona € */
        padding-right: 5px !important;
        text-align: right;
        width: 100% !important;
        display: block;
    }

    /* Se il prezzo dovesse ancora essere tagliato, forziamo l'overflow visibile */
    .acf-field[data-name="singleProductPrice"] .acf-input {
        overflow: visible !important;
    }
}

/* OTTIMIZZAZIONE PER INPUT NUMERICI (Evita freccette browser che rubano spazio) */
.acf-field[data-name="singleProductPrice"] input[type=number]::-webkit-inner-spin-button, 
.acf-field[data-name="singleProductPrice"] input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}
	
	/* ===== QT. ACQUISTATA ===== */
	.acf-field[data-name="productRepeater"] .acf-field[data-name="qty_acquistata"] {
		width: 70px !important;
	}
	
	.acf-field[data-name="qty_acquistata"] input {
		font-size: 14px !important;
		padding: 6px 4px !important;
		height: 38px !important;
	}
	
	/* ===== CHECKBOX ===== */
	.acf-field[data-name="productRepeater"] .acf-field[data-name="productBook"],
	.acf-field[data-name="productRepeater"] .acf-field[data-name="productSold"] {
		width: 65px !important;
		min-width: 65px !important;
	}
	
	.acf-field[data-name="productBook"] .acf-input,
	.acf-field[data-name="productSold"] .acf-input {
		height: 38px !important;
		padding: 6px !important;
	}
	
	.acf-field[data-name="productBook"] input[type="checkbox"],
	.acf-field[data-name="productSold"] input[type="checkbox"] {
		width: 20px !important;
		height: 20px !important;
	}
	
	/* ===== IMMAGINE ===== */
	.acf-field[data-name="productRepeater"] .acf-field[data-name="productImage"] {
		width: 120px !important;
	}
	
	.acf-field[data-name="productImage"] .image-wrap img {
		max-height: 35px !important;
	}
	
	/* ===== SELECT PRODOTTO CON IMMAGINE ===== */
	
	/* Thumbnail nella dropdown */
	.acf-relationship .choices .acf-rel-item .product-thumbnail {
		width: 45px !important;
		height: 45px !important;
	}
	
	/* Prodotto selezionato */
	.acf-relationship .values .acf-rel-item .selected-product-thumbnail {
		width: 35px !important;
		height: 35px !important;
	}
	
	/* Testo più piccolo */
	.acf-relationship .choices .acf-rel-item .acf-rel-item-title,
	.acf-relationship .values .acf-rel-item .acf-rel-item-title {
		font-size: 13px !important;
		line-height: 1.3 !important;
	}
	
	/* Input search */
	.acf-relationship .filter.-search input {
		font-size: 13px !important;
		height: 38px !important;
		padding: 6px 12px 6px 6px !important;
	}
	
	/* Bottoni Modifica/Rimuovi */
	.product-actions-wrapper {
		flex-direction: column;
		gap: 6px;
	}
	
	.acf-modifica-prodotto,
	.acf-rimuovi-prodotto {
		width: 100%;
		padding: 8px 10px !important;
		font-size: 12px !important;
		height: auto !important;
	}
	
	.product-actions-wrapper .dashicons {
		font-size: 13px !important;
		width: 13px !important;
		height: 13px !important;
	}
}

/* ========================================
   📱 MOBILE EXTRA PICCOLI (< 600px)
   ======================================== */

@media (max-width: 600px) {
	
	/* Stack verticale per tutti i campi */
	.acf-field[data-name="productRepeater"] .acf-row {
		display: flex !important;
		flex-direction: column !important;
	}
	
	.acf-field[data-name="productRepeater"] .acf-row > td {
		width: 100% !important;
		display: block !important;
		margin-bottom: 8px;
	}
	
	/* Tutti i campi a larghezza piena */
	.acf-field[data-name="productRepeater"] .acf-field[data-name="numberOfPieces"],
	.acf-field[data-name="productRepeater"] .acf-field[data-name="singleProductPrice"],
	.acf-field[data-name="productRepeater"] .acf-field[data-name="qty_acquistata"],
	.acf-field[data-name="productRepeater"] .acf-field[data-name="productBook"],
	.acf-field[data-name="productRepeater"] .acf-field[data-name="productSold"],
	.acf-field[data-name="productRepeater"] .acf-field[data-name="productImage"] {
		width: 100% !important;
		max-width: 100% !important;
	}
	
	/* Input più grandi per touch */
	.acf-field[data-name="numberOfPieces"] input,
	.acf-field[data-name="singleProductPrice"] input,
	.acf-field[data-name="qty_acquistata"] input {
		height: 44px !important;
		font-size: 16px !important;
	}
	
	/* Dropdown più alta */
	.acf-relationship .choices {
		max-height: 250px !important;
	}
	
	.acf-relationship .choices .acf-rel-item {
		padding: 12px !important;
	}
}

/* ========================================
   📱 FIX MOBILE — mostra campi dopo selezione prodotto
   Quando un prodotto è selezionato (.has-selected-product)
   forza la visibilità di tutti i campi della riga
   ======================================== */
@media (max-width: 782px) {
    /* Riga con prodotto selezionato — mostra tutti i campi */
    .acf-field[data-name="productRepeater"] .acf-row:has(.acf-relationship.has-selected-product) > td.acf-field {
        display: table-cell !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Fallback per browser che non supportano :has() */
    .acf-field[data-name="productRepeater"] .acf-row > td.acf-field[data-name="numberOfPieces"],
    .acf-field[data-name="productRepeater"] .acf-row > td.acf-field[data-name="singleProductPrice"],
    .acf-field[data-name="productRepeater"] .acf-row > td.acf-field[data-name="qty_acquistata"],
    .acf-field[data-name="productRepeater"] .acf-row > td.acf-field[data-name="productBook"],
    .acf-field[data-name="productRepeater"] .acf-row > td.acf-field[data-name="productSold"],
    .acf-field[data-name="productRepeater"] .acf-row > td.acf-field[data-name="productImage"] {
        display: table-cell !important;
        visibility: visible !important;
    }
}
