/* Mejoras UX — móvil, estados, búsqueda, adjuntos, onboarding */

/* —— Toasts —— */
.tn-toast-host {
	position: fixed;
	bottom: 20px;
	right: 20px;
	z-index: 99999;
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-width: min(360px, calc(100vw - 32px));
	pointer-events: none;
}

.tn-toast {
	pointer-events: auto;
	padding: 12px 16px;
	border-radius: var(--tn-radius-md, 12px);
	background: var(--tn-text-secondary, #1e293b);
	color: #fff;
	font-size: 0.88rem;
	font-weight: 500;
	box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
	border-left: 4px solid var(--tn-primary-bright, #3498db);
	animation: tn-toast-in 0.22s ease;
}

.tn-toast.is-success {
	border-left-color: #22c55e;
}

.tn-toast.is-error {
	border-left-color: #ef4444;
}

.tn-toast.is-info {
	border-left-color: var(--tn-primary-bright, #3498db);
}

@keyframes tn-toast-in {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* —— Onboarding —— */
.tn-onboarding {
	margin: 8px 10px 6px;
	padding: 12px 14px;
	border-radius: var(--tn-radius-sm, 8px);
	background: rgba(255, 255, 255, 0.12);
	border: 1px solid rgba(255, 255, 255, 0.28);
	color: #fff;
	font-size: 0.78rem;
	line-height: 1.45;
}

.tn-onboarding strong {
	display: block;
	margin-bottom: 4px;
	font-size: 0.82rem;
}

.tn-onboarding-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 10px;
}

.tn-onboarding-actions a,
.tn-onboarding-actions button {
	border: none;
	border-radius: 6px;
	padding: 6px 10px;
	font-size: 0.75rem;
	font-weight: 600;
	cursor: pointer;
	text-decoration: none;
}

.tn-onboarding-actions a {
	background: var(--tn-primary-bright, #3498db);
	color: #fff !important;
}

.tn-onboarding-dismiss {
	background: rgba(255, 255, 255, 0.14) !important;
	color: #fff !important;
}

/* —— Filtros rápidos + densidad —— */
.tn-list-extras {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 8px 10px;
	background: var(--tn-surface-subtle, #f1f5f9);
	border-bottom: 1px solid var(--tn-border, #cbd5e1);
}

.tn-filter-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	flex: 1 1 auto;
}

.tn-filter-chip {
	border: 1px solid var(--tn-border-strong, #94a3b8);
	background: #fff;
	color: var(--tn-text-secondary, #1e293b);
	border-radius: 999px;
	padding: 6px 12px;
	font-size: 0.78rem;
	font-weight: 600;
	cursor: pointer;
	min-height: 32px;
	transition: background var(--tn-transition), border-color var(--tn-transition), color var(--tn-transition);
}

.tn-filter-chip:hover,
.tn-filter-chip.is-active {
	background: var(--tn-primary, #2980b9);
	border-color: var(--tn-primary, #2980b9);
	color: #fff;
}

.tn-density-toggle {
	border: 1px solid var(--tn-border-strong, #94a3b8);
	background: #fff;
	color: var(--tn-text-muted, #475569);
	border-radius: var(--tn-radius-sm, 8px);
	padding: 6px 10px;
	font-size: 0.75rem;
	font-weight: 600;
	cursor: pointer;
	min-height: 32px;
	white-space: nowrap;
}

.tn-density-toggle:hover {
	border-color: var(--tn-primary, #2980b9);
	color: var(--tn-primary, #2980b9);
}

/* —— Búsqueda —— */
.search-input,
.folderSearchInput,
input.folderSearchInput {
	border: 1px solid var(--tn-border-strong, #94a3b8) !important;
	border-radius: var(--tn-radius-sm, 8px) !important;
	background: #fff !important;
	color: var(--tn-text-secondary, #1e293b) !important;
	font-weight: 500;
	min-height: 36px;
}

.search-input:focus,
.folderSearchInput:focus {
	border-color: var(--tn-primary, #2980b9) !important;
	box-shadow: 0 0 0 3px rgba(41, 128, 185, 0.18) !important;
	outline: none !important;
}

.tn-search-mark {
	background: #fef08a;
	color: var(--tn-text-secondary, #1e293b);
	padding: 0 2px;
	border-radius: 2px;
	font-weight: 700;
}

/* —— Lista vacía / error / skeleton —— */
.listEmptyMessage,
.folders-list-error {
	padding: 32px 24px !important;
	text-align: center;
	color: var(--tn-text-muted, #475569) !important;
	font-size: 0.95rem !important;
	line-height: 1.5;
}

.listEmptyMessage::before {
	content: "";
	display: block;
	width: 64px;
	height: 64px;
	margin: 0 auto 16px;
	border-radius: 50%;
	background: var(--tn-surface-subtle, #f1f5f9) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232980b9'%3E%3Cpath d='M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4-8 5-8-5V6l8 5 8-5v2z'/%3E%3C/svg%3E") center / 32px no-repeat;
	border: 2px solid var(--tn-border, #cbd5e1);
}

.tn-list-skeleton {
	padding: 8px 12px;
}

.tn-skeleton-row {
	height: 52px;
	margin-bottom: 8px;
	border-radius: 8px;
	background: linear-gradient(90deg, #e2e8f0 0%, #f1f5f9 50%, #e2e8f0 100%);
	background-size: 200% 100%;
	animation: tn-shimmer 1.2s ease infinite;
}

@keyframes tn-shimmer {
	to {
		background-position: -200% 0;
	}
}

.messageListItem.tn-filter-hidden {
	display: none !important;
}

/* —— Agrupación por fecha —— */
.tn-date-group {
	padding: 8px 14px 4px;
	font-size: 0.72rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--tn-text-muted, #475569);
	background: var(--tn-surface-subtle, #f1f5f9);
	border-bottom: 1px solid var(--tn-border, #cbd5e1);
	position: sticky;
	top: 0;
	z-index: 2;
}

/* —— Avatares —— */
.messageListItem .senderParent img,
.messageListItem .avatar,
.messageView .messageItemHeader img {
	border-radius: 50%;
	object-fit: cover;
	border: 2px solid var(--tn-border, #cbd5e1);
}

.messageListItem .senderParent img {
	width: 28px;
	height: 28px;
	margin-right: 6px;
	vertical-align: middle;
}

/* —— Adjuntos —— */
.messageView .attachmentList a,
#V-PopupsCompose .attachmentList a,
.messageListItem .attachmentParent {
	border-radius: var(--tn-radius-sm, 8px);
}

.messageView .attachmentList li,
#V-PopupsCompose .attachmentList li {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 12px !important;
	margin-bottom: 6px;
	background: var(--tn-surface-subtle, #f1f5f9);
	border: 1px solid var(--tn-border, #cbd5e1);
	border-radius: var(--tn-radius-sm, 8px);
}

.messageView .attachmentList li::before,
#V-PopupsCompose .attachmentList li::before {
	content: "";
	width: 32px;
	height: 32px;
	flex-shrink: 0;
	border-radius: 6px;
	background: var(--tn-primary, #2980b9) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6z'/%3E%3C/svg%3E") center / 18px no-repeat;
}

/* —— Lectura sticky acciones —— */
.messageView .message-fixed-button-toolbar {
	position: sticky;
	top: 0;
	z-index: 5;
	background: rgba(255, 255, 255, 0.96);
	backdrop-filter: blur(8px);
	padding: 10px 12px !important;
	border-bottom: 1px solid var(--tn-border, #cbd5e1);
	box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.messageView .controls-handle {
	min-width: 44px;
	min-height: 44px;
	color: var(--tn-primary, #2980b9) !important;
	font-weight: 700;
}

/* —— Hilos —— */
.messageView .thread-controls {
	border-left: 3px solid var(--tn-primary, #2980b9);
	padding-left: 12px;
	margin-left: 8px;
}

/* —— Sidebar carpetas —— */
.tn-folder-divider {
	height: 0;
	border: none;
	border-top: 1px solid rgba(255, 255, 255, 0.2);
	margin: 8px 12px;
}

#rl-left .b-folders-system .folder-name::before {
	margin-right: 6px;
	opacity: 0.9;
}

/* Iconos de carpetas → app-premium.css (SVG) */

/* —— Compose borrador —— */
#V-PopupsCompose header .saved-text {
	font-weight: 600 !important;
	opacity: 1 !important;
}

.tn-draft-hint {
	font-size: 0.78rem;
	color: rgba(255, 255, 255, 0.92);
	margin-left: 8px;
}

/* —— Logout confirm —— */
.tn-modal-backdrop {
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, 0.55);
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
}

.tn-modal {
	background: #fff;
	border-radius: var(--tn-radius-md, 12px);
	padding: 24px;
	max-width: 400px;
	width: 100%;
	box-shadow: var(--tn-shadow-login);
}

.tn-modal h2 {
	margin: 0 0 8px;
	font-size: 1.1rem;
	color: var(--tn-text-secondary, #1e293b);
}

.tn-modal p {
	margin: 0 0 18px;
	color: var(--tn-text-muted, #475569);
	font-size: 0.9rem;
	line-height: 1.5;
}

.tn-modal-actions {
	display: flex;
	gap: 10px;
	justify-content: flex-end;
}

.tn-modal-actions button {
	border-radius: 8px;
	padding: 10px 16px;
	font-weight: 600;
	cursor: pointer;
	border: 1px solid var(--tn-border-strong, #94a3b8);
	background: #fff;
	color: var(--tn-text-secondary, #1e293b);
}

.tn-modal-actions .tn-modal-confirm {
	background: var(--tn-primary, #2980b9);
	border-color: var(--tn-primary, #2980b9);
	color: #fff;
}

/* —— Login extras —— */
.tn-caps-warning,
.tn-domain-warning {
	display: none;
	margin: 0 0 10px;
	padding: 8px 12px;
	border-radius: 8px;
	font-size: 0.82rem;
	font-weight: 500;
	line-height: 1.4;
}

.tn-caps-warning {
	background: #fef3c7;
	border: 1px solid #fcd34d;
	color: #92400e;
}

.tn-domain-warning {
	background: #fee2e2;
	border: 1px solid #fca5a5;
	color: #991b1b;
}

.tn-caps-warning.is-visible,
.tn-domain-warning.is-visible {
	display: block;
}

#V-Login.LoginView .buttonLogin.is-loading {
	opacity: 0.75;
	pointer-events: none;
	position: relative;
}

#V-Login.LoginView .buttonLogin.is-loading::after {
	content: "";
	position: absolute;
	right: 16px;
	top: 50%;
	width: 18px;
	height: 18px;
	margin-top: -9px;
	border: 2px solid rgba(255, 255, 255, 0.35);
	border-top-color: #fff;
	border-radius: 50%;
	animation: tn-spin 0.7s linear infinite;
}

/* —— Móvil —— */
.tn-mobile-topbar {
	display: none;
	align-items: center;
	gap: 10px;
	padding: 8px 12px;
	background: var(--tn-surface, #fff);
	border-bottom: 1px solid var(--tn-border, #cbd5e1);
}

.tn-mobile-topbar img {
	max-height: 28px;
	max-width: 120px;
	object-fit: contain;
}

.tn-mobile-back {
	display: none;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	border: none;
	background: transparent;
	color: var(--tn-primary, #2980b9);
	font-size: 1.25rem;
	font-weight: 700;
	cursor: pointer;
	border-radius: 8px;
}

.tn-fab-compose {
	display: none;
	position: fixed;
	right: 18px;
	bottom: 18px;
	z-index: 9000;
	width: 56px;
	height: 56px;
	border: none;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--tn-primary-bright, #3498db), var(--tn-primary, #2980b9));
	color: #fff;
	font-size: 1.75rem;
	line-height: 1;
	box-shadow: 0 8px 24px rgba(41, 128, 185, 0.45);
	cursor: pointer;
	transition: transform var(--tn-transition), box-shadow var(--tn-transition);
}

.tn-fab-compose:hover {
	transform: scale(1.05);
}

@media (max-width: 768px) {
	.tn-mobile-topbar {
		display: flex;
	}

	.tn-fab-compose {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tn-account-chip {
		max-width: 42vw;
	}

	.thm-message-list-top-toolbar .btn {
		min-width: 44px;
		min-height: 44px;
	}

	#rl-left .b-folders a {
		min-height: 44px;
		display: flex;
		align-items: center;
	}

	body.tn-message-open .tn-mobile-back {
		display: inline-flex;
	}

	.tn-list-extras {
		padding: 6px 8px;
	}

	.tn-toast-host {
		left: 16px;
		right: 16px;
		bottom: 80px;
	}
}

body.rl-mobile .tn-mobile-topbar,
body.rl-mobile .tn-fab-compose {
	display: flex;
}

body.rl-mobile .tn-fab-compose {
	align-items: center;
	justify-content: center;
}

/* —— Densidad —— */
body.tn-density-compact .messageListItem {
	min-height: 36px !important;
}

body.tn-density-compact .messageListItem .subjectParent {
	font-size: 14px !important;
}

body.tn-density-comfortable .messageListItem {
	min-height: 56px !important;
}

/* —— Agrupación por fecha (atributos, sin nodos extra en KO) —— */
.messageListItem.tn-date-start::before {
	content: attr(data-tn-date-label);
	display: block;
	padding: 8px 14px 4px;
	margin: 0 -8px 4px;
	font-size: 0.72rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--tn-text-muted, #475569);
	background: var(--tn-surface-subtle, #f1f5f9);
	border-bottom: 1px solid var(--tn-border, #cbd5e1);
	position: sticky;
	top: 0;
	z-index: 2;
}

/* —— Búsqueda con overlay seguro —— */
.messageListItem .subjectParent,
.messageListItem .senderParent {
	position: relative;
}

.tn-search-overlay {
	display: none;
	position: absolute;
	inset: 0;
	pointer-events: none;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	color: transparent;
}

.tn-search-overlay.is-active {
	display: block;
}

.tn-search-overlay .tn-search-mark {
	background: #fde68a;
	color: transparent;
	border-radius: 2px;
}

.messageListItem.tn-search-miss {
	opacity: 0.35;
}

.messageListItem.tn-search-hit .subjectParent,
.messageListItem.tn-search-hit .senderParent {
	background: rgba(253, 230, 138, 0.25);
	border-radius: 4px;
}

/* —— Carga carpetas —— */
.tn-folders-loading {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	color: var(--tn-sidebar-muted, #e2e8f0);
	font-size: 0.82rem;
}

.tn-folders-spinner {
	width: 18px;
	height: 18px;
	border: 2px solid rgba(255, 255, 255, 0.2);
	border-top-color: var(--tn-primary-bright, #3498db);
	border-radius: 50%;
	animation: tn-shimmer 0.8s linear infinite;
}

/* —— Accesibilidad —— */
:focus-visible {
	outline: 2px solid var(--tn-primary-bright, #3498db);
	outline-offset: 2px;
}

.tn-filter-chip:focus-visible,
.tn-fab-compose:focus-visible,
.tn-mobile-back:focus-visible {
	outline-offset: 3px;
}
