// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

/* ============================================================================
 * Login — allineato al design system MyTown (landing di riferimento)
 * Heading Plus Jakarta Sans 800, body Inter, sfondo azzurrino tenue,
 * bordi hairline azzurri, raggi 12px, bottone pill con gradiente brand.
 * I token MyTown (navy/blu, #F3F8FE, #E1E9F4) coincidono col tema `cna`:
 * mappandoli su --ion-color-* la pagina resta adattiva anche per edil.
 * Niente ion-card: form diretto sullo sfondo. Solo layer visivo.
 * ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@600;700;800&display=swap');

:host {
	--font-display: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
	--mt-line: rgba(var(--app-brand-rgb), 0.16); /* ≈ #E1E9F4 su cna */
	--mt-grad: linear-gradient(120deg, var(--ion-color-secondary), var(--ion-color-primary));
	/* Colore brand per testo/icone su sfondo chiaro: il primary va bene sul blu
	 * cna, ma sul giallo edil sarebbe illeggibile → override nel blocco edil. */
	--mt-accent: var(--ion-color-primary);
}

/* Torna alla bacheca (solo MyTown, app pubblica) */
.login-back-bacheca {
	position: absolute;
	top: max(14px, env(safe-area-inset-top));
	left: 14px;
	z-index: 20;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 8px 14px 8px 10px;
	border: 1px solid var(--mt-line);
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.9);
	backdrop-filter: blur(6px);
	color: var(--mt-accent);
	font-family: var(--font-display);
	font-size: 13px;
	font-weight: 700;
	cursor: pointer;

	ion-icon {
		font-size: 18px;
	}

	&:active {
		transform: scale(0.97);
	}
}

/* --- Tema edil (giallo): primary illeggibile come testo/fill chiaro -------- *
 * Bottone primario pieno giallo→oro con testo scuro (come il portale); accenti
 * di testo/icona su chiaro in ambra scura leggibile (#713f12, accento yellow). */
:host-context([app-theme='edil']) {
	--mt-grad: linear-gradient(120deg, var(--ion-color-primary-shade), var(--ion-color-primary));
	--mt-accent: #713f12;
}

:host-context([app-theme='edil']) ion-button[color='primary'] {
	--color: var(--app-on-brand);
}

/* --- Sfondo: tinta azzurra tenue + cerchi morbidi (eco hero MyTown) ------- */
ion-content.login {
	--background: var(--ion-color-light);
}

.login > div {
	min-height: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 40px 20px;
	position: relative;
	overflow: hidden;
	background: var(--ion-color-light);
}

.login > div::before {
	content: '';
	position: absolute;
	width: 460px;
	height: 460px;
	border-radius: 50%;
	top: -200px;
	right: -180px;
	background: rgba(var(--app-brand-rgb), 0.10);
	pointer-events: none;
}

.login > div::after {
	content: '';
	position: absolute;
	width: 320px;
	height: 320px;
	border-radius: 50%;
	bottom: -150px;
	left: -120px;
	background: rgba(var(--app-brand-rgb), 0.07);
	pointer-events: none;
}

.flex-baseline {
	display: flex;
	justify-content: center;
	align-items: center;
	position: relative;
	z-index: 1;
}

/* --- Contenitore form (nessuna card) -------------------------------------- */
.card-login,
.card-registration {
	width: 100%;
	margin: auto;
	--background: transparent;
	background: transparent;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	overflow: visible;
	position: relative;
	z-index: 1;
	animation: authRise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.card-login {
	max-width: 400px;
}

.card-registration {
	max-width: 600px;
}

.card-login ion-grid,
.card-registration ion-grid {
	padding: 0 clamp(8px, 4vw, 16px);
}

/* --- Logo ----------------------------------------------------------------- */
.logo-wrap {
	display: flex;
	justify-content: center;
	margin: 0 auto 22px;
}

.login-image-otp {
	max-width: 58%;
	max-height: 70px;
	margin: auto;
	object-fit: contain;
}

/* --- Testi titolo --------------------------------------------------------- */
.login-virifcation-code-text {
	padding-bottom: 2px;
}

.login-virifcation-code-text > h1 {
	font-family: var(--font-display);
	font-weight: 800;
	font-size: 26px;
	line-height: 1.15;
	letter-spacing: -0.02em;
	text-align: center;
	width: 100%;
	display: block;
	color: var(--ion-color-dark);
	margin: 0 0 6px;
}

.login-virifcation-code-text > span {
	text-align: center;
	width: 100%;
	display: block;
	color: var(--ion-color-medium);
	font-size: 14px;
	line-height: 1.5;
}

.login-virifcation-code-text > span strong {
	color: var(--ion-color-dark);
	font-weight: 700;
	word-break: break-word;
}

.login-virifcation-resendcode-text > span {
	margin-top: 8px;
	text-align: center;
	width: 100%;
	display: block;
	color: var(--ion-color-medium);
	font-size: 13px;
}

/* --- Input (compatti: padding ridotto) ------------------------------------ */
.login-mail-container,
.login-tel-container {
	width: 100%;
	margin: 10px 0 0;
	border-radius: 12px;
	border: 1px solid var(--mt-line);
	background: #ffffff;
	box-shadow: 0 1px 2px rgba(10, 42, 102, 0.05);
	transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.login-mail-container:focus-within,
.login-tel-container:focus-within {
	border-color: var(--ion-color-primary);
	box-shadow: 0 0 0 3px rgba(var(--app-brand-rgb), 0.12);
}

.login-tel-country {
	min-height: 26px;
	border: 0 !important;
	border-radius: 0 !important;
	border-right: 1px solid var(--mt-line) !important;
	box-shadow: none !important;
}

.login-mail,
.login-tel {
	--padding-start: 14px;
	--padding-end: 14px;
	--color: var(--ion-color-dark);
	--placeholder-color: var(--ion-color-medium);
	--placeholder-opacity: 0.75;
	min-height: 26px;
	font-size: 14px;
	border-radius: 0 !important;
	border: 0 !important;
	box-shadow: none !important;
}

.log-noborder-input {
	border-radius: 0 !important;
	border: 0 !important;
	box-shadow: none !important;
}

/* --- Codice OTP a 6 cifre ------------------------------------------------- */
.login-verificationcode {
	max-width: calc((45px * 6) + 30px);
	margin: auto;
}

.login-verificationcode > ion-col {
	margin: auto;
	display: block;
}

.login-verificationcode > ion-col > ion-input,
.login-verificationcode > ion-input {
	min-height: 30px;
	letter-spacing: 1ch;
	border-bottom: 2px solid var(--ion-color-primary);
	text-align: center;
	font-size: 1.7em;
	font-weight: 600;
	color: var(--ion-color-dark);
	border-radius: 0 !important;
	border-top: 0 !important;
	border-left: 0 !important;
	border-right: 0 !important;
	box-shadow: none !important;
}

/* --- Separatore hairline -------------------------------------------------- */
.divider {
	height: 1px;
	background: var(--mt-line);
	margin: 20px 0 14px;
}

/* --- Bottoni (pill, gradiente brand, ombra MyTown) ------------------------ */
ion-button {
	text-transform: none;
}

ion-button[color='primary'] {
	--background: var(--mt-grad);
	--background-activated: var(--ion-color-primary-shade);
	--background-hover: var(--ion-color-primary-shade);
	--color: #ffffff;
	--border-radius: 999px;
	--box-shadow: 0 8px 22px rgba(var(--app-brand-rgb), 0.30);
	--padding-top: 15px;
	--padding-bottom: 15px;
	font-family: var(--font-display);
	font-weight: 700;
	font-size: 15px;
	letter-spacing: 0;
	transition: transform 0.15s ease, box-shadow 0.2s ease;
}

ion-button[color='primary']:hover {
	transform: translateY(-2px);
	--box-shadow: 0 14px 30px rgba(var(--app-brand-rgb), 0.40);
}

ion-button[color='primary'].button-disabled {
	--box-shadow: none;
	opacity: 0.5;
}

ion-button[color='medium'] {
	--background: #ffffff;
	--color: var(--ion-color-dark);
	--border-radius: 999px;
	--box-shadow: 0 1px 2px rgba(10, 42, 102, 0.05);
	border: 1px solid var(--mt-line);
	border-radius: 999px;
	font-family: var(--font-display);
	font-weight: 700;
	font-size: 15px;
}

/* --- Link registrazione / reset ------------------------------------------ */
.reg {
	color: var(--mt-accent) !important;
	cursor: pointer;
	font-weight: 700;
	font-family: var(--font-display);
}

.reg:hover {
	text-decoration: underline;
}

/* --- OTP login: badge sicurezza + 6 celle --------------------------------- */
.otp-badge {
	width: 64px;
	height: 64px;
	margin: 0 auto 6px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 18px;
	background: rgba(var(--app-brand-rgb), 0.10);
	color: var(--mt-accent);
}

.otp-badge ion-icon {
	font-size: 32px;
}

.otp-field {
	position: relative;
	max-width: 300px;
	margin: 12px auto 0;
}

/* input reale trasparente sopra le celle: cattura tastiera/incolla, cursore nascosto */
.otp-input {
	position: absolute;
	inset: 0;
	z-index: 2;
	opacity: 0;
	--color: transparent;
	caret-color: transparent;
}

.otp-cells {
	display: flex;
	gap: 8px;
	justify-content: center;
}

.otp-cell {
	flex: 1;
	min-width: 0;
	height: 52px;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 1.5px solid var(--mt-line);
	border-radius: 12px;
	background: #ffffff;
	box-shadow: 0 1px 2px rgba(10, 42, 102, 0.05);
	font-family: var(--font-display);
	font-weight: 700;
	font-size: 22px;
	color: var(--ion-color-dark);
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.otp-cell.is-filled {
	border-color: var(--ion-color-primary);
}

.otp-cell.is-active {
	border-color: var(--ion-color-primary);
	box-shadow: 0 0 0 3px rgba(var(--app-brand-rgb), 0.12);
}

/* --- Registrazione guidata (wizard a fasi) -------------------------------- */
.reg-phase {
	animation: authRise 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* progress a pallini */
.reg-steps {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	margin: 0 auto 20px;
}

.reg-dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--mt-line);
	transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.reg-dot.is-active {
	background: var(--ion-color-primary);
}

.reg-dot.is-current {
	transform: scale(1.35);
	box-shadow: 0 0 0 4px rgba(var(--app-brand-rgb), 0.15);
}

.reg-bar {
	width: 28px;
	height: 2px;
	border-radius: 2px;
	background: var(--mt-line);
	transition: background 0.2s ease;
}

.reg-bar.is-active {
	background: var(--ion-color-primary);
}

/* campo con label sopra (coerente col login) */
.reg-field {
	margin-bottom: 12px;
}

.reg-field .login-mail-container {
	margin: 0;
}

.reg-label {
	display: block;
	font-family: var(--font-display);
	font-weight: 600;
	font-size: 12px;
	color: var(--ion-color-medium);
	margin: 0 0 4px 2px;
}

.login-mail-container.has-error {
	border-color: var(--ion-color-danger);
}

.reg-error {
	display: block;
	color: var(--ion-color-danger);
	font-size: 12px;
	margin: 4px 0 0 2px;
}

/* banner informativo / successo */
.reg-banner {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	border-radius: 12px;
	background: rgba(var(--app-brand-rgb), 0.08);
	color: var(--ion-color-dark);
	font-size: 13px;
	line-height: 1.4;
	margin-bottom: 16px;
}

.reg-banner ion-icon {
	font-size: 20px;
	color: var(--mt-accent);
	flex: none;
}

.reg-banner strong {
	font-weight: 700;
	word-break: break-all;
}

.reg-banner--ok {
	background: rgba(var(--ion-color-success-rgb), 0.12);
}

.reg-banner--ok ion-icon {
	color: var(--ion-color-success);
}

/* link "indietro" / "annulla" */
.reg-back {
	display: block;
	margin: 14px auto 0;
	padding: 4px 8px;
	background: none;
	border: 0;
	color: var(--mt-accent);
	font-family: var(--font-display);
	font-weight: 600;
	font-size: 13px;
	cursor: pointer;
}

.reg-back--cancel {
	color: var(--ion-color-medium);
	margin-top: 18px;
}

.reg-back:hover {
	text-decoration: underline;
}

/* --- Targa contributo Regione Abruzzo (solo MyTown / tema cna) ------------ */
.funding-strip {
	display: none; /* nascosta per default: visibile solo su tema cna (MyTown) */
}

:host-context([app-theme='cna']) .funding-strip {
	display: block;
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	bottom: calc(14px + env(safe-area-inset-bottom, 0px));
	width: 100%;
	max-width: 340px;
	padding: 6px;
	margin: 0;
	background: #ffffff;
	border: 1px solid var(--mt-line);
	border-radius: 12px;
	box-shadow: 0 1px 2px rgba(10, 42, 102, 0.05);
	cursor: pointer;
	transition: transform 0.15s ease, box-shadow 0.2s ease;
}

:host-context([app-theme='cna']) .funding-strip:hover {
	transform: translateX(-50%) translateY(-2px);
	box-shadow: 0 8px 22px rgba(var(--app-brand-rgb), 0.16);
}

:host-context([app-theme='cna']) .funding-strip img {
	display: block;
	width: 100%;
	height: auto;
	border-radius: 8px;
}

/* lascia spazio in basso alla targa così non copre il form (solo MyTown) */
:host-context([app-theme='cna']) .login > div {
	padding-bottom: 150px;
}

.funding-modal-content img {
	width: 100%;
	height: auto;
	display: block;
}

/* --- Resto invariato ------------------------------------------------------ */
ion-list-header {
	justify-content: center;
}

.header-container {
	width: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
}

.header-logo {
	padding: 20px;
	margin: auto;
}

ion-item {
	--background: transparent;
}

.privacylabel {
	white-space: normal;
	overflow: hidden;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
}

/* --- Animazione d'ingresso ------------------------------------------------ */
@keyframes authRise {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.card-login,
	.card-registration {
		animation: none;
	}
}
