/*
 * Statistiques d'une édition : bloc btf/statistiques et aperçu de l'admin.
 * D'après styles.css de l'appli BTFStats, limité au conteneur .btf-stats et aux couleurs du thème btf.
 */

.btf-stats {
	--s-fond: #f3f4f6;
	--s-surface: #ffffff;
	--s-barre: var(--wp--preset--color--dark, #161616);
	--s-liste: var(--wp--preset--color--dark-alt, #222222);
	--s-liste-survol: #2e2e2e;
	--s-liste-texte: #ececec;
	--s-liste-discret: var(--wp--preset--color--muted-dark, #999999);
	--s-accent: var(--wp--preset--color--primary-text, #2b78a8);
	--s-accent-clair: var(--wp--preset--color--primary, #53a1ce);
	--s-vol: #2b78a8;
	--s-marche: #c25e05;
	--s-sommet: #7e3fbf;
	--s-vario: #0f7a55;
	--s-texte: var(--wp--preset--color--text, #333333);
	--s-discret: var(--wp--preset--color--muted, #666666);
	--s-bordure: #e2e5e9;
	--s-rayon: 3px;
	--s-ombre: 0 1px 3px rgba(0, 0, 0, .1);
	--s-hauteur: calc(100vh - var(--btf-header-h, 0px) - var(--wp-admin--admin-bar--height, 0px));

	display: flex;
	flex-direction: column;
	height: var(--s-hauteur);
	min-height: 480px;
	background: var(--s-fond);
	color: var(--s-texte);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
	text-align: left;
}

/*
 * Sur le site, le pied de page remonte sous la dernière section de la diagonale (--btf-diagonale) et le thème
 * réserve en bas de cette section la diagonale + un espacement. Ici, la réserve se limite à la diagonale
 * (le fond gris passe sous la coupe) et le bloc grandit d'autant : les statistiques restent plein écran.
 * Sélecteur renforcé et !important : la règle du thème (main > .wp-block-post-content > :last-child) l'est aussi.
 */
.wp-block-btf-statistiques.btf-stats.btf-stats {
	height: calc(var(--s-hauteur) + var(--btf-diagonale, 0px));
	padding-bottom: var(--btf-diagonale, 0px) !important;
}

.btf-stats[hidden],
.btf-stats [hidden] {
	display: none !important;
}

.btf-stats *,
.btf-stats *::before,
.btf-stats *::after {
	box-sizing: border-box;
}

.btf-stats button {
	font: inherit;
	color: inherit;
}

.btf-stats :focus-visible {
	outline: 2px solid var(--s-accent-clair);
	outline-offset: 2px;
}

/* Barre du haut */
.btf-stats__barre {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 12px;
	padding: 10px 16px;
	background: var(--s-barre);
	color: #ffffff;
}

.btf-stats__titre {
	margin-right: 8px;
	font-size: 15px;
	font-weight: 700;
	font-style: italic;
	text-transform: uppercase;
	letter-spacing: .02em;
}

.btf-stats__bouton {
	padding: 6px 14px;
	border: 1px solid #3a3a3a;
	border-radius: var(--s-rayon);
	background: transparent;
	color: #dddddd !important;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
}

.btf-stats__bouton:hover {
	border-color: var(--s-accent-clair);
	color: #ffffff !important;
}

.btf-stats__bouton[aria-pressed="true"] {
	border-color: var(--s-accent-clair);
	background: var(--s-accent-clair);
	color: #000000 !important;
}

.btf-stats__avertissement {
	margin-left: auto;
	color: var(--s-liste-discret);
	font-size: 12px;
}

/* Corps : liste des pilotes à gauche, contenu à droite */
.btf-stats__corps {
	display: flex;
	flex: 1;
	min-height: 0;
}

.btf-stats__pilotes {
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
	width: 250px;
	background: var(--s-liste);
}

.btf-stats__recherche {
	margin: 10px;
	padding: 8px 10px;
	border: 1px solid #3a3a3a;
	border-radius: var(--s-rayon);
	background: #161616;
	color: var(--s-liste-texte);
	font: inherit;
	font-size: 14px;
}

.btf-stats__recherche::placeholder {
	color: #8a8a8a;
}

.btf-stats__liste {
	flex: 1;
	overflow-y: auto;
	padding: 0 6px 10px;
	scrollbar-color: #444444 transparent;
	scrollbar-width: thin;
}

.btf-stats__vide {
	margin: 8px 10px;
	color: var(--s-liste-discret);
}

.btf-stats .pilot-item {
	display: block;
	width: 100%;
	margin-bottom: 2px;
	padding: 8px 10px;
	border: 0;
	border-radius: var(--s-rayon);
	background: transparent;
	text-align: left;
	cursor: pointer;
}

.btf-stats .pilot-item:hover {
	background: var(--s-liste-survol);
}

.btf-stats .pilot-item.active {
	background: var(--s-accent);
}

.btf-stats .pilot-item-name {
	display: block;
	overflow: hidden;
	margin-bottom: 4px;
	color: var(--s-liste-texte);
	font-size: 14px;
	font-weight: 600;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.btf-stats .pilot-item-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.btf-stats .pilot-item-meta span {
	padding: 1px 5px;
	border-radius: 2px;
	font-size: 12px;
}

.btf-stats .tag-air { background: #1c3446; color: #9fd0ee; }
.btf-stats .tag-flights { background: #183528; color: #8ee0b6; }
.btf-stats .tag-alt { background: #3d2610; color: #f6c08a; }
.btf-stats .pilot-item.active .pilot-item-meta span { background: rgba(0, 0, 0, .25); color: #ffffff; }

.btf-stats__contenu {
	flex: 1;
	min-width: 0;
	overflow-y: auto;
	padding: 24px;
}

.btf-stats__erreur {
	margin: 40px 0;
	color: var(--wp--preset--color--danger, #e02020);
}

/* Fiche pilote */
.btf-stats .pilot-header {
	margin-bottom: 20px;
}

.btf-stats .pilot-header h2 {
	margin: 0;
	font-size: 26px;
	font-weight: 700;
	font-style: italic;
	line-height: 1.1;
	text-transform: uppercase;
}

.btf-stats .pilot-header .meta {
	margin-top: 4px;
	color: var(--s-discret);
	font-size: 13px;
}

.btf-stats .cards {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	margin-bottom: 24px;
}

.btf-stats .stat-card {
	flex: 1;
	min-width: 110px;
	padding: 14px 16px;
	border-radius: var(--s-rayon);
	background: var(--s-surface);
	box-shadow: var(--s-ombre);
}

.btf-stats .stat-value {
	color: var(--s-texte);
	font-size: 22px;
	font-weight: 700;
	line-height: 1;
	white-space: nowrap;
}

.btf-stats .stat-label {
	margin-top: 4px;
	color: var(--s-discret);
	font-size: 12px;
	letter-spacing: .03em;
	text-transform: uppercase;
}

.btf-stats .stat-card.fly .stat-value { color: var(--s-vol); }
.btf-stats .stat-card.hike .stat-value { color: var(--s-marche); }
.btf-stats .stat-card.peak .stat-value { color: var(--s-sommet); }
.btf-stats .stat-card.vario .stat-value { color: var(--s-vario); }

.btf-stats .section-title {
	margin: 0 0 12px;
	font-size: 16px;
	font-weight: 700;
	font-style: italic;
	text-transform: uppercase;
}

.btf-stats .table-wrap + .section-title {
	margin-top: 28px;
}

/* Graphique */
.btf-stats .chart-wrap {
	margin-bottom: 12px;
	padding: 12px;
	border-radius: var(--s-rayon);
	background: var(--s-surface);
	box-shadow: var(--s-ombre);
}

.btf-stats .cards-jour {
	margin-bottom: 28px;
}

.btf-stats .chart-title {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-bottom: 8px;
	color: var(--s-discret);
	font-size: 14px;
	font-weight: 600;
}

.btf-stats .chart-title::first-letter {
	text-transform: uppercase;
}

.btf-stats .zoom-hint {
	padding: 0;
	border: 0;
	background: none;
	color: var(--s-accent) !important;
	font-size: 12px;
	font-weight: 400;
	cursor: pointer;
}

.btf-stats .phase-legend {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 16px;
	margin-bottom: 10px;
	color: var(--s-discret);
	font-size: 12px;
}

.btf-stats .phase-legend span {
	display: flex;
	align-items: center;
	gap: 5px;
}

.btf-stats .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.btf-stats .dot-fly { background: #2b78a8; }
.btf-stats .dot-hike { background: #e8740c; }
.btf-stats .dot-ground { background: #94a3b8; }
.btf-stats .vline { display: inline-block; width: 2px; height: 12px; }
.btf-stats .vline-takeoff { background: #e02020; }
.btf-stats .vline-landing { background: #4f46e5; }

.btf-stats canvas.alt-chart {
	display: block;
	width: 100%;
	height: 180px;
	touch-action: none;
}

.btf-stats .chart-tooltip {
	position: fixed;
	z-index: 100;
	padding: 8px;
	border-radius: var(--s-rayon);
	background: #161616;
	color: #f1f1f1;
	font-size: 12px;
	line-height: 1.5;
	pointer-events: none;
}

/* Tableaux */
.btf-stats .table-wrap {
	overflow-x: auto;
	border-radius: var(--s-rayon);
	background: var(--s-surface);
	box-shadow: var(--s-ombre);
}

.btf-stats table {
	width: 100%;
	margin: 0;
	border-collapse: collapse;
	font-size: 14px;
}

.btf-stats th {
	padding: 10px 12px;
	border-bottom: 1px solid var(--s-bordure);
	background: #f8f9fa;
	color: var(--s-discret);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: .03em;
	text-align: left;
	text-transform: uppercase;
	white-space: nowrap;
}

.btf-stats th button {
	padding: 0;
	border: 0;
	background: none;
	color: inherit !important;
	font-size: inherit;
	font-weight: inherit;
	letter-spacing: inherit;
	text-transform: inherit;
	cursor: pointer;
}

.btf-stats th .sort-icon {
	margin-left: 4px;
	opacity: .35;
}

.btf-stats th.sorted .sort-icon {
	opacity: 1;
}

.btf-stats td {
	padding: 9px 12px;
	border-bottom: 1px solid var(--s-bordure);
	white-space: nowrap;
}

.btf-stats tr:last-child td {
	border-bottom: 0;
}

.btf-stats tbody tr:hover td {
	background: #f8f9fa;
}

.btf-stats .td-fly { color: var(--s-vol); font-weight: 600; }
.btf-stats .td-hike { color: var(--s-marche); font-weight: 600; }
.btf-stats .td-vario { color: var(--s-vario); font-weight: 600; }
.btf-stats .td-alt { color: var(--s-sommet); font-weight: 600; }

.btf-stats .pilot-link {
	padding: 0;
	border: 0;
	background: none;
	color: var(--s-accent) !important;
	font-weight: 600;
	text-align: left;
	cursor: pointer;
}

.btf-stats .pilot-link:hover {
	text-decoration: underline;
}

/* Résumé de la course */
.btf-stats .race-summary {
	margin-bottom: 28px;
}

.btf-stats .race-summary .cards {
	margin-bottom: 0;
}

.btf-stats .race-summary .stat-card {
	min-width: 90px;
	padding: 10px 12px;
}

.btf-stats .race-summary .stat-value {
	font-size: 17px;
}

.btf-stats .summary-group-label {
	margin: 14px 0 8px;
	color: var(--s-discret);
	font-size: 12px;
	font-weight: 700;
	letter-spacing: .03em;
	text-transform: uppercase;
}

/* Chargement */
.btf-stats .loader-wrap {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	height: 300px;
	color: var(--s-discret);
}

.btf-stats .spinner {
	width: 36px;
	height: 36px;
	border: 3px solid var(--s-bordure);
	border-top-color: var(--s-accent);
	border-radius: 50%;
	animation: btf-stats-rotation .7s linear infinite;
}

@keyframes btf-stats-rotation {
	to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
	.btf-stats .spinner { animation-duration: 2s; }
}

/* Message quand l'édition n'a pas encore de statistiques */
.btf-stats-attente {
	padding: var(--wp--preset--spacing--50, 48px) 16px;
	text-align: center;
}

/* Mobile : liste au-dessus, page qui défile normalement */
@media (max-width: 768px) {
	.btf-stats,
	.wp-block-btf-statistiques.btf-stats.btf-stats {
		height: auto;
		min-height: 0;
	}

	.btf-stats__barre {
		padding: 8px 12px;
	}

	.btf-stats__avertissement {
		flex-basis: 100%;
		margin-left: 0;
	}

	.btf-stats__corps {
		flex-direction: column;
	}

	.btf-stats__pilotes {
		width: 100%;
		max-height: 34vh;
	}

	.btf-stats__contenu {
		overflow: visible;
		padding: 16px 12px;
		scroll-margin-top: calc(var(--btf-header-h, 0px) + 8px);
	}

	.btf-stats .cards {
		gap: 8px;
	}

	.btf-stats .stat-card {
		min-width: 90px;
		padding: 10px 12px;
	}

	.btf-stats .stat-value {
		font-size: 18px;
	}

	.btf-stats .pilot-header h2 {
		font-size: 22px;
	}
}
