// 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

// ============================================================
// TOKENS
// ============================================================

:host {
	--spring: cubic-bezier(0.34, 1.56, 0.64, 1);
	--ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

// ============================================================
// STATES
// ============================================================

.loading-wrap {
	display: flex;
	justify-content: center;
	padding: 64px 0;
}

.empty-wrap {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 64px 32px;
	text-align: center;
}

.empty-icon {
	width: 72px;
	height: 72px;
	border-radius: 22px;
	background: var(--ion-color-light, #f4f5f8);
	display: flex;
	align-items: center;
	justify-content: center;
	margin-bottom: 16px;

	ion-icon {
		font-size: 34px;
		color: var(--ion-color-medium);
	}
}

.empty-title {
	font-size: 17px;
	font-weight: 700;
	color: var(--ion-color-dark);
	margin: 0 0 6px;
	letter-spacing: -0.2px;
}

.empty-sub {
	font-size: 13px;
	color: var(--ion-color-medium);
	margin: 0;
	line-height: 1.5;
}

// ============================================================
// SEARCH ZONE (stessa fascia colorata della home)
// ============================================================

.search-zone {
	background: var(--app-brand);
	padding: calc(env(safe-area-inset-top, 0px) + 12px) 8px 10px;
}

.search-row {
	display: flex;
	align-items: center;
	gap: 4px;
}

.search-input {
	flex: 1;
	--background: rgba(255, 255, 255, 0.16);
	--color: var(--app-on-brand);
	--placeholder-color: rgba(var(--app-on-brand-rgb), 0.6);
	--icon-color: rgba(var(--app-on-brand-rgb), 0.6);
	--clear-button-color: rgba(var(--app-on-brand-rgb), 0.7);
	--border-radius: 12px;
	--box-shadow: none;
	--padding-top: 0;
	--padding-bottom: 0;
	padding-top: 0;
	padding-bottom: 0;
}

.result-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 4px 4px 0;
}

.result-count {
	font-size: 11px;
	color: rgba(var(--app-on-brand-rgb), 0.75);
	font-weight: 500;
}

.clear-btn {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	background: none;
	border: none;
	color: rgba(var(--app-on-brand-rgb), 0.9);
	font-size: 11px;
	font-weight: 600;
	cursor: pointer;
	padding: 2px 6px;

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

// ============================================================
// CONVERSATION LIST
// ============================================================

.conv-list {
	padding: 8px 0;
}

.conv-item {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 12px 16px;
	cursor: pointer;
	transition: background 0.12s ease;
	position: relative;

	&:active {
		background: rgba(var(--ion-color-primary-rgb), 0.04);
	}

	&::after {
		content: '';
		position: absolute;
		bottom: 0;
		left: 76px;
		right: 0;
		height: 1px;
		background: rgba(0, 0, 0, 0.05);
	}

	&:last-child::after {
		display: none;
	}

	&.has-unread {
		background: rgba(var(--ion-color-primary-rgb), 0.025);
	}
}

// ============================================================
// AVATAR
// ============================================================

.conv-avatar {
	width: 50px;
	height: 50px;
	border-radius: 16px;
	background: var(--ion-color-primary);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	position: relative;

	&.is-company {
		background: var(--ion-color-secondary, var(--app-brand-2));

		.avatar-initials {
			color: var(--ion-color-secondary-contrast, #fff);
		}
	}
}

.avatar-initials {
	font-size: 16px;
	font-weight: 800;
	color: var(--app-on-brand, #fff);
	letter-spacing: -0.5px;
}

.avatar-company-dot {
	position: absolute;
	bottom: -3px;
	right: -3px;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: var(--app-brand);
	border: 2px solid var(--ion-background-color, #fff);
	display: flex;
	align-items: center;
	justify-content: center;

	ion-icon {
		font-size: 9px;
		color: var(--app-on-brand, #fff);
	}
}

// ============================================================
// BODY
// ============================================================

.conv-body {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.conv-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}

.conv-name {
	font-size: 15px;
	font-weight: 700;
	color: var(--ion-color-dark, #1c1c1e);
	letter-spacing: -0.2px;
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.conv-time {
	font-size: 11px;
	color: var(--ion-color-medium);
	flex-shrink: 0;
}

.conv-bottom {
	display: flex;
	align-items: center;
	gap: 8px;
}

.conv-preview {
	font-size: 13px;
	color: var(--ion-color-medium);
	margin: 0;
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;

	&.is-unread {
		color: var(--ion-color-dark-shade);
		font-weight: 600;
	}
}

.unread-pill {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	border-radius: 10px;
	background: var(--ion-color-primary);
	color: var(--app-on-brand, #fff);
	font-size: 11px;
	font-weight: 800;
	padding: 0 5px;
	flex-shrink: 0;
}

.conv-arrow {
	font-size: 14px;
	color: var(--ion-color-medium-shade);
	flex-shrink: 0;
}

// ============================================================
// CONTACTS PERMISSION MODAL
// ============================================================

.ctc-content {
	--background: var(--app-brand-2, #0c1a2e);
}

.ctc-shell {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 20px 24px 16px;
}

.ctc-icon-wrap {
	position: relative;
	width: 96px;
	height: 96px;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-bottom: 16px;
}

@keyframes ctc-ring-pulse {
	0%   { transform: scale(1);   opacity: 0.55; }
	70%  { transform: scale(1.9); opacity: 0; }
	100% { transform: scale(1.9); opacity: 0; }
}

.ctc-ring {
	position: absolute;
	inset: 0;
	border-radius: 50%;
	border: 1.5px solid rgba(var(--app-brand-rgb), 0.5);
}

@media (prefers-reduced-motion: no-preference) {
	.ctc-ring {
		animation: ctc-ring-pulse 2.4s ease-out infinite;
	}

	.ctc-ring-1 { animation-delay: 0s; }
	.ctc-ring-2 { animation-delay: 0.7s; }
	.ctc-ring-3 { animation-delay: 1.4s; }
}

.ctc-glow {
	position: absolute;
	inset: 20px;
	border-radius: 50%;
	background: radial-gradient(circle, rgba(var(--app-brand-rgb), 0.25) 0%, transparent 70%);
}

.ctc-icon {
	position: relative;
	z-index: 2;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: linear-gradient(145deg, var(--app-brand-3), var(--app-brand));
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 0 0 4px rgba(var(--app-brand-rgb), 0.2), 0 8px 32px rgba(var(--app-brand-rgb), 0.4);

	ion-icon {
		font-size: 26px;
		color: var(--app-on-brand, #fff);
	}
}

.ctc-headline {
	font-size: 22px !important;
	font-weight: 700;
	color: #f1f5f9;
	text-align: center;
	line-height: 1.25;
	margin: 0 0 8px;
	letter-spacing: -0.3px;

	em {
		font-style: normal;
		font-weight: 800;
		color: color-mix(in srgb, var(--app-brand-3) 65%, #fff);
	}
}

.ctc-sub {
	font-size: 13px !important;
	color: rgba(241, 245, 249, 0.6);
	text-align: center;
	line-height: 1.5;
	margin: 0 0 16px;
	max-width: 280px;
}

.ctc-features {
	width: 100%;
	display: flex;
	flex-direction: column;
	background: rgba(255, 255, 255, 0.05);
	border-radius: 14px;
	overflow: hidden;
	margin-bottom: 16px;
}

.ctc-feature {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 9px 14px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.06);

	&:last-child {
		border-bottom: none;
	}
}

.ctc-feat-icon {
	width: 32px;
	height: 32px;
	border-radius: 9px;
	background: rgba(var(--app-brand-rgb), 0.14);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;

	ion-icon {
		font-size: 18px;
		color: color-mix(in srgb, var(--app-brand-3) 65%, #fff);
	}
}

.ctc-feat-text {
	display: flex;
	flex-direction: column;
	gap: 1px;
}

.ctc-feat-title {
	font-size: 13px;
	font-weight: 600;
	color: #f1f5f9;
}

.ctc-feat-desc {
	font-size: 11px;
	color: rgba(241, 245, 249, 0.5);
}

.ctc-actions {
	width: 100%;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.ctc-btn-primary {
	width: 100%;
	height: 46px;
	border-radius: 14px;
	border: none;
	background: linear-gradient(135deg, var(--app-brand-3) 0%, var(--app-brand) 100%);
	color: var(--app-on-brand, #fff);
	font-size: 15px;
	font-weight: 700;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	cursor: pointer;
	box-shadow: 0 4px 20px rgba(var(--app-brand-rgb), 0.45);
	transition: opacity 0.15s, transform 0.1s;

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

	.ctc-btn-spinner {
		width: 16px;
		height: 16px;
		color: var(--app-on-brand, #fff);
	}

	&:active {
		opacity: 0.88;
		transform: scale(0.98);
	}
}

.ctc-btn-skip {
	width: 100%;
	height: 36px;
	border-radius: 10px;
	border: none;
	background: transparent;
	color: rgba(241, 245, 249, 0.65);
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
	letter-spacing: 0.2px;
	transition: color 0.15s;

	&:active {
		color: rgba(241, 245, 249, 0.9);
	}
}
