/**
 * Jany Chat Widget styles.
 * Self-scoped to avoid theme conflicts. Uses CSS variables set from settings.
 */

/* v1.19.0 — Rating 👍/👎 sotto messaggi bot */
.jany-rating {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 4px 0 8px 8px;
	font-size: 12px;
	color: #666;
}
.jany-rating-q { margin-right: 4px; }
.jany-rating-up, .jany-rating-down {
	background: transparent;
	border: 1px solid #ddd;
	border-radius: 4px;
	padding: 2px 8px;
	cursor: pointer;
	font-size: 14px;
	transition: background 0.15s, transform 0.15s;
}
.jany-rating-up:hover { background: #e8fbe8; transform: scale(1.1); }
.jany-rating-down:hover { background: #fde8e8; transform: scale(1.1); }
.jany-rating-up:disabled, .jany-rating-down:disabled {
	opacity: 0.4; cursor: default; transform: none;
}
.jany-rating-thanks { font-style: italic; color: #2a8a2a; }

#jany-chat-root {
	--jany-primary: #465140;
	--jany-accent: #FBB72E;
	--jany-neutral: #999999;
	--jany-bg: #ffffff;
	--jany-text: #222222;
	--jany-user-bg: #465140;
	--jany-user-text: #ffffff;
	--jany-bot-bg: #f3f4ef;
	--jany-bot-text: #222222;
	--jany-shadow: 0 12px 36px rgba(0, 0, 0, 0.18);
	--jany-radius: 14px;
	--jany-font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-family: var(--jany-font);
}

#jany-chat-root * {
	box-sizing: border-box;
}

.jany-launcher {
	position: fixed;
	/* v1.26.1 — Desktop: pallino launcher rialzato (era 22px) per essere
	   più visibile in zona "occhio" del cliente. Mobile resta a 14px nella
	   media query in fondo al file. */
	bottom: 130px;
	width: 64px;
	height: 64px;
	border-radius: 50%;
	background: var(--jany-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	box-shadow: var(--jany-shadow);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 28px;
	z-index: 2147483646;
	transition: transform 0.2s ease;
}

.jany-launcher[data-position="bottom-right"] { right: 22px; }
.jany-launcher[data-position="bottom-left"]  { left: 22px; }

.jany-launcher:hover { transform: scale(1.05); }

.jany-badge {
	position: absolute;
	top: -4px;
	right: -4px;
	background: var(--jany-accent);
	color: #222;
	font-size: 11px;
	font-weight: 700;
	border-radius: 10px;
	padding: 2px 6px;
	min-width: 18px;
	text-align: center;
}

.jany-panel {
	position: fixed;
	/* v1.26.1 — Pannello chat alzato in coerenza col launcher (130 + 64
	   altezza launcher + 16 gap = 210px). Mobile resta gestito dalla media
	   query in fondo al file. */
	bottom: 210px;
	width: 370px;
	max-width: calc(100vw - 20px);
	height: min(560px, calc(100vh - 140px));
	background: var(--jany-bg);
	border-radius: var(--jany-radius);
	box-shadow: var(--jany-shadow);
	display: none;
	flex-direction: column;
	overflow: hidden;
	z-index: 2147483647;
	font-size: 14px;
	color: var(--jany-text);
}

.jany-panel[data-position="bottom-right"] { right: 22px; }
.jany-panel[data-position="bottom-left"]  { left: 22px; }

.jany-panel.is-open { display: flex; }

.jany-header {
	background: var(--jany-primary);
	color: #fff;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	gap: 10px;
}

.jany-flag-stripe {
	display: flex;
	height: 4px;
	width: 100%;
}
.jany-flag-stripe span {
	flex: 1;
	height: 100%;
}
.jany-flag-stripe span:nth-child(1) { background: #008C45; } /* green */
.jany-flag-stripe span:nth-child(2) { background: #F4F9FF; } /* white */
.jany-flag-stripe span:nth-child(3) { background: #CD212A; } /* red */

.jany-flag {
	display: inline-block;
	margin-left: 6px;
	font-size: 14px;
	vertical-align: middle;
	opacity: 0.92;
}

.jany-italian .jany-header-name {
	letter-spacing: 0.2px;
}

.jany-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: #fff;
	color: var(--jany-primary);
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	font-size: 16px;
	overflow: hidden;
}
.jany-avatar img { width: 100%; height: 100%; object-fit: cover; }

.jany-header-title { flex: 1; min-width: 0; }
.jany-header-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.jany-header-sub  { font-size: 11px; opacity: 0.85; line-height: 1.3; margin-top: 2px; }

.jany-close {
	background: transparent;
	border: none;
	color: #fff;
	cursor: pointer;
	font-size: 22px;
	padding: 8px 12px;
	line-height: 1;
	opacity: 0.85;
	min-width: 44px;
	min-height: 44px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 6px;
	-webkit-tap-highlight-color: rgba(255, 255, 255, 0.2);
}
.jany-close:hover,
.jany-close:active { opacity: 1; background: rgba(255, 255, 255, 0.12); }

.jany-messages {
	flex: 1;
	overflow-y: auto;
	padding: 14px;
	background: #fafbfa;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.jany-msg { max-width: 82%; padding: 9px 12px; border-radius: 12px; line-height: 1.45; word-wrap: break-word; }
.jany-msg-bot  { background: var(--jany-bot-bg); color: var(--jany-bot-text); align-self: flex-start; border-bottom-left-radius: 4px; }
.jany-msg-user { background: var(--jany-user-bg); color: var(--jany-user-text); align-self: flex-end; border-bottom-right-radius: 4px; }
.jany-msg-bot strong { font-weight: 600; color: var(--jany-primary); }
.jany-msg-bot em { font-style: italic; color: #555; }
.jany-msg-bot .jany-md-list {
	margin: 6px 0 4px 0;
	padding-left: 18px;
	list-style: disc outside;
}
.jany-msg-bot .jany-md-list li {
	margin: 3px 0;
	line-height: 1.4;
}
.jany-msg-bot { max-width: 90%; }
.jany-msg-typing { background: var(--jany-bot-bg); align-self: flex-start; padding: 12px 14px; border-radius: 12px; }
.jany-msg-typing .dot { display: inline-block; width: 6px; height: 6px; margin: 0 2px; background: var(--jany-neutral); border-radius: 50%; animation: janyBlink 1.3s infinite; }
.jany-msg-typing .dot:nth-child(2) { animation-delay: 0.2s; }
.jany-msg-typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes janyBlink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

.jany-footer {
	padding: 10px 12px;
	border-top: 1px solid #eee;
	background: #fff;
}
/* v1.28.17 — layout footer: textarea a tutta larghezza sopra, bottoni in row sotto.
   Prima la textarea era flex:1 dentro .jany-input-wrap con 📎 a sx + ▶ a dx.
   Ora la textarea occupa tutta la riga, sotto c'è .jany-input-actions con i bottoni. */
.jany-input-wrap { display: flex; gap: 8px; align-items: flex-end; } /* legacy, non più usato dal markup principale */
.jany-input {
	display: block;
	width: 100%;
	box-sizing: border-box;
	border: 1px solid #ddd;
	border-radius: 20px;
	padding: 9px 14px;
	resize: none;
	max-height: 120px;
	min-height: 40px;
	font-family: inherit;
	outline: none;
}
.jany-input-actions {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-top: 8px;
}
/* v1.22.8 — Anti-zoom iOS Safari con !important + tripla specificità.
   Il tema WordPress di Pizza Base ha un CSS textarea con font-size 14px
   che vince sulla nostra .jany-input via !important — quindi iOS vedeva
   ancora 14px e zoomava. Qui forziamo 16px in 3 modi diversi così niente
   può sovrascrivere. 16.5px (non 16) per assoluta sicurezza su iOS edge cases. */
#jany-chat-root .jany-input,
#jany-chat-root textarea.jany-input,
textarea.jany-input {
	font-size: 16.5px !important;
	line-height: 1.4 !important;
}
.jany-input:focus { border-color: var(--jany-primary); }

.jany-send {
	background: var(--jany-primary);
	color: #fff;
	border: none;
	border-radius: 50%;
	width: 40px;
	height: 40px;
	/* v1.22.5 — flex shorthand impedisce che il bottone Invia si comprima a 0
	   quando la textarea cresce e occupa tutta la riga (bug osservato su mobile
	   fullscreen). flex-shrink: 0 + width fissa garantisce sempre 40x40 px. */
	flex: 0 0 40px;
	cursor: pointer;
	font-size: 16px;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity 0.2s;
}
.jany-send:disabled { opacity: 0.5; cursor: not-allowed; }

.jany-disclaimer {
	font-size: 10px;
	color: var(--jany-neutral);
	text-align: center;
	margin-top: 6px;
	line-height: 1.3;
}
.jany-disclaimer a { color: var(--jany-neutral); text-decoration: underline; }

.jany-counter {
	font-size: 10px;
	color: var(--jany-neutral);
	font-variant-numeric: tabular-nums;
	/* v1.28.17 — counter ora dentro .jany-input-actions (row con 📎 e ▶).
	   Mettiamo flex:1 con text-align center così resta centrato tra i 2 bottoni,
	   senza forzare la sua larghezza. */
	flex: 1;
	text-align: center;
}
.jany-counter.jany-counter-max { color: #9b1c1c; font-weight: 600; }

/* ==========================================================================
 * v1.28.24 — Product link button
 * I link Markdown [text](url) generati da Claude per le pagine prodotto
 * vengono renderizzati come bottoni inline-block primari invece che come
 * link inline. Su feedback Luigi: i clienti devono avere un CTA chiaro
 * per andare alla pagina prodotto, non un link sottolineato che si perde
 * nel testo.
 * ========================================================================== */
.jany-product-btn {
	display: inline-block;
	background: var(--jany-primary, #465140);
	color: #fff !important;
	padding: 8px 16px;
	border-radius: 20px;
	font-size: 13px;
	font-weight: 600;
	text-decoration: none !important;
	margin-top: 6px;
	line-height: 1.3;
	border: none;
	cursor: pointer;
	transition: background 0.15s, transform 0.1s;
	box-shadow: 0 1px 2px rgba(0,0,0,0.08);
	white-space: nowrap;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
}
.jany-product-btn:hover {
	background: var(--jany-accent, #5a6a4f);
	transform: translateY(-1px);
	box-shadow: 0 2px 4px rgba(0,0,0,0.12);
}
.jany-product-btn:active {
	transform: translateY(0);
	box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
/* Quando il bottone è dentro una <li> (formato Markdown lista con bottone inline),
   riduci leggermente padding per non rompere il layout della riga. */
.jany-md-list .jany-product-btn {
	padding: 4px 10px;
	font-size: 12px;
	margin-left: 6px;
}
/* v1.28.25 — Variante per URL bare auto-linkificati (testo plain con https://...).
   Stile leggermente più scuro/sobrio per distinguerli dai CTA prodotto principali. */
.jany-product-btn-bare {
	background: #6a7560 !important;
	font-weight: 500;
	font-size: 12px;
	padding: 5px 12px;
}
.jany-product-btn-bare:hover {
	background: #555f4d !important;
}
/* v1.28.39 — Container per bottoni link spostati alla fine del messaggio.
 * Tutti i .jany-product-btn vengono estratti dal testo inline e accorpati
 * qui sotto la spiegazione, per non interrompere il flusso di lettura.
 * Flex con wrap per layout responsive su msg multi-link.
 */
.jany-btn-row {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 10px;
	padding-top: 8px;
	border-top: 1px dashed rgba(0,0,0,0.08);
}
.jany-btn-row .jany-product-btn {
	margin-top: 0; /* override margin-top default che dava spazio inline */
}

/* Suggested follow-up chips rendered below the latest bot message. */
.jany-suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 4px 0 10px 0;
	padding: 0 2px;
}
.jany-chip {
	background: #fff;
	border: 1px solid var(--jany-primary);
	color: var(--jany-primary);
	border-radius: 999px;
	padding: 6px 12px;
	font-size: 12px;
	line-height: 1.2;
	font-family: inherit;
	cursor: pointer;
	max-width: 100%;
	white-space: normal;
	text-align: left;
	transition: background 0.15s ease, color 0.15s ease;
}
.jany-chip:hover:not(:disabled) {
	background: var(--jany-primary);
	color: #fff;
}
.jany-chip:disabled { opacity: 0.5; cursor: default; }

.jany-error {
	background: #fde8e8;
	color: #9b1c1c;
	border-radius: 8px;
	padding: 8px 12px;
	font-size: 12px;
	margin: 4px 0;
}

/* v1.22.7+ → v1.22.10 — Mobile UI: bolla compatta in basso a destra.
   Niente più: fullscreen 100dvh, env(safe-area-*), fixed dismiss button.
   Header + footer sempre visibili per costruzione. Funziona ovunque, no
   edge case Safari iOS.
   v1.22.10: ridotta del 20% (80vw × 64vh, era 95vw × 80vh) come richiesto
   per lasciare più sito visibile dietro il pannello. */
@media (max-width: 480px) {
	.jany-panel {
		width: 80vw;
		max-width: 80vw;
		height: 64vh;
		max-height: 64vh;
		bottom: 90px;
		/* v1.22.11 — centrata orizzontalmente sullo schermo invece che
		   ancorata a destra. Transform translateX(-50%) la centra
		   indipendentemente dalla larghezza configurata. */
		left: 50% !important;
		right: auto !important;
		transform: translateX(-50%);
		border-radius: 14px;
	}
	.jany-launcher {
		bottom: 14px;
		right: 14px !important;
		left: auto !important;
	}
	/* X close grande e ben tappabile (48px area Apple HIG). */
	.jany-close {
		font-size: 26px;
		min-width: 48px;
		min-height: 48px;
	}
	/* Mobile dismiss button non serve più (header X sempre visibile). */
	.jany-mobile-dismiss { display: none !important; }
}

@media (min-width: 481px) {
	.jany-mobile-dismiss { display: none; }
}

/* ==========================================================================
 * v1.27.8 — Email gate (form richiesta email all'apertura chat)
 * ========================================================================== */
.jany-email-gate {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 28px 24px;
	text-align: center;
	background: linear-gradient(to bottom, #fafafa 0%, #fff 100%);
}
.jany-email-gate-icon {
	font-size: 42px;
	margin-bottom: 10px;
}
.jany-email-gate-title {
	font-size: 17px;
	font-weight: 600;
	color: var(--jany-primary, #465140);
	margin-bottom: 8px;
	line-height: 1.3;
}
.jany-email-gate-desc {
	font-size: 13px;
	color: #666;
	margin-bottom: 18px;
	line-height: 1.5;
	max-width: 320px;
}
.jany-email-gate-input {
	width: 100%;
	max-width: 320px;
	padding: 11px 14px;
	font-size: 15px;
	border: 1.5px solid #ccd0d4;
	border-radius: 8px;
	outline: none;
	transition: border-color 0.15s;
	margin-bottom: 10px;
	box-sizing: border-box;
}
.jany-email-gate-input:focus {
	border-color: var(--jany-primary, #465140);
}
.jany-email-gate-error {
	color: #b91c1c;
	font-size: 12.5px;
	margin-bottom: 10px;
	max-width: 320px;
}
.jany-email-gate-submit {
	width: 100%;
	max-width: 320px;
	padding: 12px 18px;
	background: var(--jany-primary, #465140);
	color: #fff;
	font-size: 15px;
	font-weight: 600;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	transition: opacity 0.15s;
}
.jany-email-gate-submit:hover { opacity: 0.92; }
.jany-email-gate-submit:active { opacity: 0.82; }

/* ==========================================================================
 * v1.28.1 — Attachments (allegati foto/PDF)
 * ========================================================================== */
.jany-attach {
	background: transparent;
	border: none;
	color: #666;
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	padding: 0;
	flex-shrink: 0;
	transition: color 0.15s;
}
.jany-attach:hover { color: var(--jany-primary, #465140); }
.jany-attach:disabled { opacity: 0.5; cursor: not-allowed; }

.jany-attachment-chip {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 10px;
	margin: 0 8px 6px 8px;
	background: #f0f3f0;
	border: 1px solid #d0d5d0;
	border-radius: 8px;
	font-size: 13px;
}
.jany-chip-icon { font-size: 18px; flex-shrink: 0; }
.jany-chip-name {
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: #333;
}
.jany-chip-remove {
	background: transparent;
	border: none;
	color: #999;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
	padding: 0 4px;
	flex-shrink: 0;
}
.jany-chip-remove:hover { color: #b91c1c; }

/* Allegati renderizzati nella bolla user (immagini + PDF) */
.jany-attach-thumb {
	max-width: 220px;
	max-height: 220px;
	border-radius: 6px;
	display: block;
	margin-bottom: 6px;
	cursor: zoom-in;
}
.jany-attach-pdf {
	display: inline-block;
	padding: 6px 10px;
	background: rgba(255,255,255,0.15);
	border-radius: 6px;
	color: inherit;
	text-decoration: none;
	font-size: 13px;
	margin-bottom: 6px;
}
.jany-attach-pdf:hover { background: rgba(255,255,255,0.25); }
.jany-attach-text { margin-top: 4px; }
