/**
* Responsive Tables - Frontend Styles v2
* Approche: Table desktop + Cards mobile (double HTML)
* 
* @package H5X_Responsive_Tables
* @version 1.0.0
*/

/* ==========================================================================
Variables CSS
========================================================================== */

:root {
	/* Couleur principale (surchargée par Elementor) */
	--h5x-primary: #F78500;
	--h5x-background: #80808012;
	--h5x-border: #80808020;
	--h5x-border-light: #F7850077;

	/* Fixes */
	--h5x-text-color: #333;
	--h5x-bg-white: #fff;
	--h5x-card-radius: 8px;
	--h5x-card-gap: 20px;
	--h5x-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
Couleurs dérivées de la couleur primaire
========================================================================== */

.h5x-responsive-table-wrapper {
	--h5x-border-light: color-mix(in srgb, var(--h5x-primary) 25%, #FFF7);
	--h5x-bg-highlight: color-mix(in srgb, var(--h5x-primary) 25%, transparent);
	--h5x-bg-highlight-dark: color-mix(in srgb, var(--h5x-primary) 25%, #00000004);
	--h5x-bg-highlight-hover: color-mix(in srgb, var(--h5x-primary) 25%, #00000007);
	--h5x-bg-highlight-dark-hover: color-mix(in srgb, var(--h5x-primary) 25%, #00000009);
	--h5x-bg-highlight-lighter: color-mix(in srgb, var(--h5x-primary) 3%, #FFFFFF00);
	--h5x-bg-highlight-light: color-mix(in srgb, var(--h5x-primary) 5%, #FFFFFF07);
	--h5x-bg-highlight-light-hover: color-mix(in srgb, var(--h5x-primary) 5%, #FFFFFF14);
}

/* ==========================================================================
Wrapper
========================================================================== */

.h5x-responsive-table-wrapper {
	width: 100%;
	max-width: 100%;
	margin: 0;
	color: var(--h5x-text-color);
	font-family: inherit;
}

/* ==========================================================================
COMMUN (desktop & mobile)
========================================================================== */

.h5x-table-cell p,
.h5x-table-card__value p,
.h5x-table-card__label p {
	margin: 0;
	font-weight: normal;
	font-size: 1em;
}
.h5x-table-cell p :is(strong,a),
.h5x-table-card__value p :is(strong, a),
.h5x-table-card__label p :is(strong, a){
	margin: 0;
	font-weight: bolder;
	font-size: 1.1em;
}


.h5x-table-cell :is(a, a:hover),
.h5x-table-card__value :is(a,a:hover) {
	color: var(--h5x-bg-white);
	background-color: var(--h5x-primary);
	padding: 8px 16px;
	border-radius: 8px;
	margin: 0;
	text-decoration: none;
	display: inline-block;
}
.h5x-table-cell a:hover{
	outline: 2px solid var(--h5x-primary);
}

.badge{
	margin-top: 6px;
	background-color: var(--h5x-bg-white);
	border: 1px solid var(--h5x-primary);
	color: var(--h5x-primary);
	padding: 4px 8px;
	border-radius: 40px;
	font-size: 0.9em;
	font-weight: 600;
	display: inline-block;
}

/* ==========================================================================
DESKTOP TABLE (visible uniquement sur desktop)
========================================================================== */

.h5x-desktop-table {
	display: grid;
	/* --h5x-cols-rest (nb colonnes - 1) est posé en inline par le widget ;
	   --h5x-first-col / --h5x-first-col-max viennent des réglages Style d'Elementor */
	grid-template-columns: var(--h5x-first-col, minmax(auto, var(--h5x-first-col-max, 40%))) repeat(var(--h5x-cols-rest, 3), 1fr);
	width: 100%;
	border-collapse: collapse;
	border-spacing: 0;
	table-layout: auto;
	background: var(--h5x-bg-white);
	margin: 0;
	border-radius: var(--h5x-card-radius);
	overflow: hidden;
	outline: 1px solid var(--h5x-border);
}
.h5x-desktop-table :is(thead,tbody,tr) {
	display: contents;
}

table.h5x-desktop-table tr :is(td,th){
	border-top:1px solid var(--h5x-border);
	border-left: 1px solid var(--h5x-border);
	border-bottom: 0;
	border-right: 0;
}

table.h5x-desktop-table tr :is(td:first-child, th:first-child) {
	border-left: 0;
}
table.h5x-desktop-table tr :is(td:last-child, th:last-child) {
	border-right: 0;
}
table.h5x-desktop-table thead tr:first-child :is(td, th) {
	border-top: 0;
}
table.h5x-desktop-table tr:last-child :is(td,th) {
	border-bottom: 0;
}

.h5x-desktop-table :is(th,td){
	padding: 12px 15px;
	text-align: center;
	vertical-align: top;
}

.h5x-desktop-table :is(th, td).h5x-table-cell--highlight {
	border-top: 1px solid var(--h5x-border-light);
	border-left: 1px solid var(--h5x-border-light);
	border-right: 1px solid var(--h5x-border-light);
}
.h5x-desktop-table :is(th, td).h5x-table-cell--highlight + :is(th, td) {
	border-left: 0;
}

.h5x-desktop-table tr>th:first-child {
	text-align: left;
}

.h5x-desktop-table th {
	font-weight: 600;
}

.h5x-desktop-table tbody > tr:nth-child(odd) > :is(td,th) {
	background-color: var(--h5x-bg-highlight-light);
}
.h5x-desktop-table tbody tr:hover> :is(td, th) {
	background-color: var(--h5x-bg-highlight-lighter);
}
.h5x-desktop-table tbody > tr:nth-child(odd):hover > :is(td, th) {
	background-color: var(--h5x-bg-highlight-light-hover);
}


/* Highlight desktop */
.h5x-desktop-table .h5x-table-cell--highlight,
.h5x-table-row--highlight td {
	background-color: var(--h5x-bg-highlight);
}
.h5x-desktop-table tbody tr:nth-child(odd) .h5x-table-cell--highlight,
.h5x-table-row--highlight:nth-child(odd) td {
	background-color: var(--h5x-bg-highlight-dark);
}

.h5x-desktop-table tr:hover .h5x-table-cell--highlight,
.h5x-table-row--highlight:hover td {
	background-color: var(--h5x-bg-highlight-hover);
}

.h5x-desktop-table tbody tr:nth-child(odd):hover .h5x-table-cell--highlight,
.h5x-table-row--highlight:nth-child(odd):hover td {
	background-color: var(--h5x-bg-highlight-dark-hover);
}

/* Support pour contenu riche */
.h5x-desktop-table .elementor-widget-container {
	width: 100%;
}

.h5x-desktop-table img {
	max-width: 100%;
	height: auto;
}

/* ==========================================================================
MOBILE CARDS (visible uniquement sur mobile)
========================================================================== */

.h5x-mobile-cards {
	display: none;
	flex-direction: column;
	gap: var(--h5x-card-gap);
}

.h5x-table-card {
	border: 1px solid var(--h5x-border);
	border-radius: var(--h5x-card-radius);
	overflow: hidden;
	background: var(--h5x-bg-white);
	box-shadow: var(--h5x-card-shadow);
}

/* Card Header */
.h5x-table-card__header {
	padding: 16px;
	font-weight: 600;
	text-align: center;
	background-color: var(--h5x-bg-highlight);
}

.h5x-table-card__header p {
	margin: 0;
}

/* Card Body */
.h5x-table-card__body {
	padding: 0 16px;
}

.h5x-table-card__row {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	justify-content: space-between;
	align-items: flex-start;
	padding: 12px;
	border-bottom: 1px solid var(--h5x-border);
}

.h5x-table-card__row:last-child {
	border-bottom: none;
	padding-bottom: 16px;
}

/* Row sans label : centrer la valeur */
.h5x-table-card__row--no-label {
	display: block;
	text-align: center;
}

.h5x-table-card__row--no-label .h5x-table-card__value {
	text-align: center;
	width: 100%;
}

.h5x-table-card__label {
	flex: 2;
	font-weight: 600;
	flex-shrink: 0;
	min-width: 120px;
	word-break: break-word;
	min-width: 200px;
}

.h5x-table-card__value {
	flex-grow: 1;
	text-align: right;
	word-break: break-word;
	min-width: fit-content;
}

/* Card highlight */
.h5x-table-card--highlight {
	border: 2px solid var(--h5x-primary);
}
.h5x-table-card--highlight .h5x-table-card__row {
	border-bottom: 1px solid var(--h5x-border-light);
}

/* Tous les headers de cards portent déjà la couleur de mise en avant :
   ceux mis en avant sont un cran plus soutenus */
.h5x-table-card--highlight .h5x-table-card__header,
.h5x-table-card__header--highlight {
	background-color: var(--h5x-bg-highlight-dark-hover);
}

/* Ligne (ou colonne, selon le mode) mise en avant à l'intérieur de chaque card */
.h5x-table-card__row--highlight {
	--h5x-row-bg: var(--h5x-bg-highlight-light);
	position: relative;
	isolation: isolate;
}
/* Fond porté par une seule couche (couleur semi-transparente : pas de superposition) :
   déborde sur le padding latéral (16px) de .h5x-table-card__body
   et sur la bordure (1px) de la ligne précédente */
.h5x-table-card__row--highlight::before {
	content: '';
	position: absolute;
	inset: -1px -16px -1px;
	background-color: var(--h5x-row-bg);
	z-index: -1;
	pointer-events: none;
}
.h5x-table-card__row--highlight:last-child::before {
	bottom: 0;
}
/* Pas de bordure autour d'une ligne mise en avant (ni au-dessus, ni en dessous),
   ni sous la dernière ligne d'une card (y compris dans une card mise en avant) */
.h5x-table-card .h5x-table-card__row--highlight,
.h5x-table-card .h5x-table-card__row:has(+ .h5x-table-card__row--highlight) {
	border-bottom-color: transparent;
}
.h5x-table-card .h5x-table-card__row:last-child {
	border-bottom: none;
}
.h5x-table-card--highlight .h5x-table-card__row--highlight {
	--h5x-row-bg: var(--h5x-bg-highlight);
}

/* Support pour contenu riche dans les cards */
.h5x-table-card__value .elementor-widget-container {
	width: 100%;
}

.h5x-table-card__value img {
	max-width: 100%;
	height: auto;
}

/* ==========================================================================
RESPONSIVE SWITCH (Desktop ↔ Mobile)
========================================================================== */

/* Desktop: afficher table, cacher cards */
@media (min-width: 768px) {
	.h5x-desktop-table {
		display: grid !important;
	}

	.h5x-mobile-cards {
		display: none !important;
	}
}

/* Mobile: cacher table, afficher cards */
@media (max-width: 767px) {
	.h5x-desktop-table {
		display: none !important;
	}

	.h5x-mobile-cards {
		display: flex !important;
	}
}

/* Fallback si problème de media query */
.h5x-mobile-cards {
	display: none;
}

@media screen and (max-width: 767px) {
	.h5x-mobile-cards {
		display: flex !important;
		flex-direction: column !important;
	}
}

/* ==========================================================================
Accessibilité
========================================================================== */

.h5x-desktop-table:focus {
	outline: 2px solid var(--h5x-primary);
	outline-offset: 2px;
}

.h5x-table-card:focus-within {
	outline: 2px solid var(--h5x-primary);
	outline-offset: 2px;
}

/* Support pour les lecteurs d'écran */
.h5x-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border-width: 0;
}

/* ==========================================================================
Print Styles
========================================================================== */

@media print {
	.h5x-desktop-table {
		display: table !important;
		border-collapse: collapse;
		page-break-inside: auto;
	}

	.h5x-mobile-cards {
		display: none !important;
	}

	.h5x-desktop-table th,
	.h5x-desktop-table td {
		border: 1px solid #000;
		padding: 8px;
	}

	.h5x-desktop-table tr {
		page-break-inside: avoid;
		page-break-after: auto;
	}
}

/* ==========================================================================
Support RTL
========================================================================== */

[dir="rtl"] .h5x-desktop-table th,
[dir="rtl"] .h5x-desktop-table td {
	text-align: right;
}

[dir="rtl"] .h5x-table-card__label {
	text-align: right;
}

[dir="rtl"] .h5x-table-card__value {
	text-align: left;
}

@media (max-width: 767px) {
	[dir="rtl"] .h5x-table-card__row {
		flex-direction: row-reverse;
	}
}

/* ==========================================================================
Animations et Transitions
========================================================================== */

.h5x-desktop-table th,
.h5x-desktop-table td {
	transition: background-color 0.2s ease, color 0.2s ease;
}

.h5x-table-card {
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

@media (max-width: 767px) {
	.h5x-table-card:hover {
		transform: translateY(-2px);
		box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	}
}
