/**
 * CSS Frontend per Elementor Table Widget
 * Stili moderni e puliti con possibilità di personalizzazione tramite widget settings
 */

/* Wrapper principale */
.etw-table-wrapper {
	position: relative;
	width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	/* Scrollbar moderna e pulita */
	scrollbar-width: thin;
	scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.etw-table-wrapper::-webkit-scrollbar {
	height: 8px;
}

.etw-table-wrapper::-webkit-scrollbar-track {
	background: transparent;
}

.etw-table-wrapper::-webkit-scrollbar-thumb {
	background-color: rgba(0, 0, 0, 0.2);
	border-radius: 4px;
}

.etw-table-wrapper::-webkit-scrollbar-thumb:hover {
	background-color: rgba(0, 0, 0, 0.3);
}

/* Wrapper con sticky header - gestione speciale per desktop e mobile */
.etw-sticky-header.etw-table-wrapper {
	position: relative;
	/* Su desktop: rimuovi overflow-x per permettere a sticky di funzionare */
	/* Il JavaScript gestirà l'overflow su mobile quando necessario */
	overflow-y: visible !important;
	/* Crea un nuovo contesto di stacking per lo sticky */
	transform: translateZ(0);
	-webkit-transform: translateZ(0);
	/* Assicura che il wrapper non interferisca con lo sticky */
	contain: layout style;
}

/* Su desktop, forza overflow-x visible per sticky */
@media (min-width: 769px) {
	.etw-sticky-header.etw-table-wrapper {
		overflow-x: visible !important;
	}
}

/* Su mobile, quando sticky è attivo e c'è overflow-x necessario, usa JavaScript sticky */
@media (max-width: 768px) {
	.etw-sticky-header.etw-table-wrapper.etw-mobile-js-sticky .etw-table thead th {
		position: fixed !important;
		top: 0 !important;
		left: 0;
		right: 0;
		width: 100%;
	}
	
	.etw-sticky-header.etw-table-wrapper.etw-mobile-js-sticky .etw-table thead {
		position: relative;
	}
}

/* Tabella base - Stile moderno e pulito */
.etw-table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	margin: 0;
	background-color: #fff;
	position: relative;
	border-radius: 8px;
	overflow: hidden;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.etw-table th,
.etw-table td {
	padding: 16px 20px;
	text-align: left;
	border: none;
	border-bottom: 1px solid rgba(0, 0, 0, 0.06);
	vertical-align: middle;
	transition: background-color 0.15s ease, color 0.15s ease;
}

/* Rimuovi bordo dall'ultima riga */
.etw-table tbody tr:last-child td {
	border-bottom: none;
}

/* Header moderno */
.etw-table th {
	font-weight: 600;
	background-color: #f8f9fa;
	color: #212529;
	text-transform: none;
	letter-spacing: 0.01em;
	font-size: 0.95em;
	padding: 18px 20px;
}

/* Hover effect sulle righe */
.etw-table tbody tr {
	transition: background-color 0.15s ease;
}

.etw-table tbody tr:hover {
	background-color: rgba(0, 0, 0, 0.02);
}

/* Sticky Header - Funziona quando si scrolla la pagina */
.etw-sticky-header .etw-table {
	position: relative;
}

.etw-sticky-header .etw-table thead {
	position: relative;
	z-index: 1;
	display: table-header-group;
}

.etw-sticky-header .etw-table thead th {
	position: -webkit-sticky !important; /* Safari */
	position: sticky !important;
	top: 0 !important;
	z-index: 100 !important;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
	/* Il background verrà gestito dal JavaScript per rispettare gli stili di Elementor */
	/* Forza il background a rimanere visibile */
	background-clip: padding-box;
	will-change: transform;
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
	/* Assicura che il background sia sempre presente */
	background-image: none !important;
}

/* Assicura che il background sia sempre visibile durante lo scroll */
.etw-sticky-header .etw-table thead th::before {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: inherit;
	z-index: -1;
	pointer-events: none;
	opacity: 1;
}

/* Override overflow per genitori quando sticky è attivo */
.etw-sticky-parent-override {
	overflow-x: visible !important;
	overflow-y: visible !important;
}

/* Sticky Column */
.etw-sticky-column .etw-table th.etw-sticky-cell,
.etw-sticky-column .etw-table td.etw-sticky-cell {
	position: sticky;
	left: 0;
	z-index: 5;
	background-color: inherit;
	box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
}

.etw-sticky-column .etw-table thead th.etw-sticky-cell {
	z-index: 15;
}

/* Combinazione Sticky Header + Column */
.etw-sticky-header.etw-sticky-column .etw-table thead th.etw-sticky-cell {
	z-index: 20;
}

/* Responsive - Scroll Orizzontale (default) */
.etw-mobile-scroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.etw-mobile-scroll .etw-table {
	min-width: 100%;
	white-space: nowrap;
}

/* Responsive - Stack Verticale */
@media (max-width: 768px) {
	.etw-mobile-stack .etw-table {
		border-radius: 8px;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
	}
	
	.etw-mobile-stack .etw-table,
	.etw-mobile-stack .etw-table thead,
	.etw-mobile-stack .etw-table tbody,
	.etw-mobile-stack .etw-table th,
	.etw-mobile-stack .etw-table td,
	.etw-mobile-stack .etw-table tr {
		display: block;
		width: 100%;
	}

	.etw-mobile-stack .etw-table thead {
		display: none;
	}

	.etw-mobile-stack .etw-table tr {
		margin-bottom: 12px;
		border: 1px solid rgba(0, 0, 0, 0.08);
		border-radius: 8px;
		padding: 0;
		background-color: #fff;
		box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
		overflow: hidden;
	}

	.etw-mobile-stack .etw-table td {
		border: none;
		border-bottom: 1px solid rgba(0, 0, 0, 0.06);
		padding: 14px 16px;
		text-align: left !important;
		position: relative;
		padding-left: 50% !important;
	}

	.etw-mobile-stack .etw-table td:before {
		content: attr(data-label);
		position: absolute;
		left: 16px;
		width: 45%;
		padding-right: 10px;
		white-space: nowrap;
		font-weight: 600;
		color: #495057;
		font-size: 0.9em;
	}

	.etw-mobile-stack .etw-table td:last-child {
		border-bottom: none;
	}
}

/* Responsive - Collassa Colonne */
@media (max-width: 768px) {
	.etw-mobile-collapse .etw-table {
		display: block;
		width: 100%;
		border-radius: 8px;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
	}

	.etw-mobile-collapse .etw-table thead {
		display: none;
	}

	.etw-mobile-collapse .etw-table tbody {
		display: block;
		width: 100%;
	}

	.etw-mobile-collapse .etw-table tr {
		display: block;
		margin-bottom: 12px;
		border: 1px solid rgba(0, 0, 0, 0.08);
		border-radius: 8px;
		background-color: #fff;
		box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
		overflow: hidden;
	}

	.etw-mobile-collapse .etw-table td {
		display: block;
		width: 100% !important;
		border: none;
		border-bottom: 1px solid rgba(0, 0, 0, 0.06);
		padding: 14px 16px;
		text-align: left !important;
	}

	.etw-mobile-collapse .etw-table td:last-child {
		border-bottom: none;
	}

	.etw-mobile-collapse .etw-table td:before {
		content: attr(data-label) ': ';
		font-weight: 600;
		display: inline-block;
		margin-right: 8px;
		color: #495057;
		font-size: 0.9em;
	}
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
	.etw-table th,
	.etw-table td {
		padding: 14px 18px;
		font-size: 0.95em;
	}
}

/* Print styles */
@media print {
	.etw-table-wrapper {
		overflow: visible;
	}

	.etw-table {
		page-break-inside: auto;
		box-shadow: none;
		border: 1px solid #000;
	}

	.etw-table tr {
		page-break-inside: avoid;
		page-break-after: auto;
	}

	.etw-table thead {
		display: table-header-group;
	}

	.etw-table tfoot {
		display: table-footer-group;
	}
}

/* Righe alternate */
.etw-table tbody tr:nth-child(even) td {
	/* Colore sarà sovrascritto dalle impostazioni del widget se abilitato */
}

/* Smooth transitions migliorate */
.etw-table th,
.etw-table td {
	transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

/* Focus states per accessibilità migliorati */
.etw-table th:focus,
.etw-table td:focus {
	outline: 2px solid #0073aa;
	outline-offset: -2px;
	border-radius: 2px;
}

/* Icone nelle celle */
.etw-cell-icon-wrapper {
	display: inline-flex;
	align-items: center;
	vertical-align: middle;
}

.etw-cell-icon-wrapper svg,
.etw-cell-icon-wrapper i {
	display: inline-block;
	vertical-align: middle;
}

/* Wrapper interno per scroll su mobile */
.etw-table-scroll-inner {
	scrollbar-width: thin;
	scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.etw-table-scroll-inner::-webkit-scrollbar {
	height: 6px;
}

.etw-table-scroll-inner::-webkit-scrollbar-track {
	background: transparent;
}

.etw-table-scroll-inner::-webkit-scrollbar-thumb {
	background-color: rgba(0, 0, 0, 0.2);
	border-radius: 3px;
}

.etw-table-scroll-inner::-webkit-scrollbar-thumb:hover {
	background-color: rgba(0, 0, 0, 0.3);
}

