/**
 * Card Collection - Presentation de collection
 *
 * Format physique de reference : 64 x 89 mm
 * Ratio hauteur / largeur = 89 / 64 = 1.390625
 * On l'exprime en aspect-ratio 64 / 89 pour que toutes les pochettes
 * gardent exactement les proportions d'une vraie carte.
 *
 * Ce fichier est independant du theme : il n'utilise que des classes
 * prefixees .cc- et des variables CSS avec valeurs de repli.
 *
 * @copyright (c) 2024, Verturin
 * @license GNU General Public License, version 2 (GPL-2.0)
 */

/* =============================================================
 * VARIABLES
 * ============================================================= */

.cc-collection {
	--cc-ratio: 64 / 89;          /* format carte 64 x 89 mm */
	--cc-gap: 18px;
	--cc-radius: 10px;
	--cc-card-min: 150px;

	--cc-ink: #1c1f26;
	--cc-muted: #6b7280;
	--cc-line: rgba(0, 0, 0, .10);
	--cc-surface: rgba(255, 255, 255, .70);
	--cc-shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.08);
	--cc-shadow-hover: 0 4px 10px rgba(0,0,0,.10), 0 18px 40px rgba(0,0,0,.16);

	--cc-common: #94a3b8;
	--cc-rare: #3b82f6;
	--cc-ultra: #a855f7;
	--cc-legendary: #f59e0b;

	color: var(--cc-ink);
}

/* Adaptation automatique aux themes sombres */
@media (prefers-color-scheme: dark) {
	.cc-collection {
		--cc-ink: #e5e7eb;
		--cc-muted: #9ca3af;
		--cc-line: rgba(255, 255, 255, .12);
		--cc-surface: rgba(255, 255, 255, .04);
	}
}

.cc-collection *,
.cc-collection *::before,
.cc-collection *::after {
	box-sizing: border-box;
}

/* =============================================================
 * EN-TETE ET STATISTIQUES
 * ============================================================= */

.cc-header {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 16px;
	padding: 0 0 18px;
	margin: 0 0 22px;
	border-bottom: 1px solid var(--cc-line);
}

.cc-header-title {
	margin: 0;
	font-size: 1.6em;
	font-weight: 700;
	letter-spacing: -.01em;
}

.cc-header-owner {
	display: block;
	margin-top: 4px;
	font-size: .58em;
	font-weight: 400;
	color: var(--cc-muted);
}

.cc-stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
	gap: 10px;
	margin: 0 0 22px;
	padding: 0;
	list-style: none;
}

.cc-stat {
	padding: 12px 14px;
	background: var(--cc-surface);
	border: 1px solid var(--cc-line);
	border-radius: var(--cc-radius);
	text-align: center;
}

.cc-stat-value {
	display: block;
	font-size: 1.5em;
	font-weight: 700;
	line-height: 1.1;
	font-variant-numeric: tabular-nums;
}

.cc-stat-label {
	display: block;
	margin-top: 3px;
	font-size: .74em;
	text-transform: uppercase;
	letter-spacing: .05em;
	color: var(--cc-muted);
}

/* Barre de progression du catalogue */
.cc-progress {
	margin: 0 0 24px;
}

.cc-progress-head {
	display: flex;
	justify-content: space-between;
	margin-bottom: 6px;
	font-size: .85em;
	color: var(--cc-muted);
}

.cc-progress-track {
	height: 8px;
	background: var(--cc-line);
	border-radius: 999px;
	overflow: hidden;
}

.cc-progress-fill {
	height: 100%;
	border-radius: 999px;
	background: linear-gradient(90deg, var(--cc-rare), var(--cc-ultra));
	transition: width .5s ease;
}

/* =============================================================
 * BARRE D'OUTILS / MODES D'AFFICHAGE
 * ============================================================= */

.cc-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin: 0 0 22px;
}

.cc-viewswitch {
	display: inline-flex;
	padding: 3px;
	background: var(--cc-line);
	border-radius: 999px;
}

.cc-viewswitch a {
	padding: 6px 14px;
	border-radius: 999px;
	font-size: .85em;
	font-weight: 600;
	text-decoration: none;
	color: var(--cc-muted);
	transition: background .15s ease, color .15s ease;
}

.cc-viewswitch a:hover {
	color: var(--cc-ink);
}

.cc-viewswitch a.is-active {
	background: #fff;
	color: var(--cc-ink);
	box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

@media (prefers-color-scheme: dark) {
	.cc-viewswitch a.is-active {
		background: rgba(255,255,255,.14);
	}
}

.cc-sort {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: .88em;
	color: var(--cc-muted);
}

.cc-sort select {
	padding: 5px 10px;
	border: 1px solid var(--cc-line);
	border-radius: 6px;
	background: var(--cc-surface);
	color: inherit;
	font: inherit;
}

/* =============================================================
 * VUE GRILLE
 * ============================================================= */

.cc-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(var(--cc-card-min), 1fr));
	gap: var(--cc-gap);
	margin: 0 0 28px;
	padding: 0;
	list-style: none;
}

/* La pochette : c'est elle qui impose le format 64 x 89 mm */
.cc-card {
	position: relative;
	display: block;
	aspect-ratio: var(--cc-ratio);
	border-radius: var(--cc-radius);
	overflow: hidden;
	background: var(--cc-line);
	box-shadow: var(--cc-shadow);
	text-decoration: none;
	color: inherit;
	transition: transform .18s ease, box-shadow .18s ease;
}

.cc-card:hover,
.cc-card:focus-visible {
	transform: translateY(-4px);
	box-shadow: var(--cc-shadow-hover);
}

.cc-card img {
	width: 100%;
	height: 100%;
	object-fit: cover;   /* le recadrage est deja fait a l'import */
	display: block;
}

/* Carte sans visuel */
.cc-card-empty {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	padding: 10px;
	font-size: .78em;
	text-align: center;
	color: var(--cc-muted);
	background: repeating-linear-gradient(
		45deg,
		transparent, transparent 8px,
		rgba(0,0,0,.03) 8px, rgba(0,0,0,.03) 16px
	);
}

/* Bandeau d'information au survol */
.cc-card-info {
	position: absolute;
	inset: auto 0 0 0;
	padding: 22px 10px 9px;
	background: linear-gradient(to top, rgba(0,0,0,.88), rgba(0,0,0,0));
	color: #fff;
	transform: translateY(100%);
	transition: transform .2s ease;
}

.cc-card:hover .cc-card-info,
.cc-card:focus-visible .cc-card-info {
	transform: translateY(0);
}

.cc-card-name {
	display: block;
	font-size: .86em;
	font-weight: 700;
	line-height: 1.25;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.cc-card-meta {
	display: block;
	margin-top: 1px;
	font-size: .74em;
	opacity: .82;
}

/* Sur ecran tactile, pas de survol : on affiche en permanence */
@media (hover: none) {
	.cc-card-info {
		transform: translateY(0);
		padding-top: 26px;
	}
}

/* Pastille de quantite */
.cc-qty {
	position: absolute;
	top: 8px;
	right: 8px;
	min-width: 24px;
	height: 24px;
	padding: 0 7px;
	border-radius: 999px;
	background: rgba(17,24,39,.86);
	color: #fff;
	font-size: .76em;
	font-weight: 700;
	line-height: 24px;
	text-align: center;
	backdrop-filter: blur(4px);
}

/* Liseré de rareté */
.cc-card::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	border: 2px solid transparent;
	pointer-events: none;
}

.cc-card[data-rarity="rare"]::after       { border-color: var(--cc-rare); }
.cc-card[data-rarity="ultra_rare"]::after { border-color: var(--cc-ultra); }
.cc-card[data-rarity="legendary"]::after  {
	border-color: var(--cc-legendary);
	box-shadow: inset 0 0 18px rgba(245,158,11,.35);
}

/* Marqueurs sticker / echange */
.cc-flag {
	position: absolute;
	top: 8px;
	left: 8px;
	padding: 3px 8px;
	border-radius: 999px;
	font-size: .68em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: #fff;
	backdrop-filter: blur(4px);
}

.cc-flag-sticker { background: rgba(139,92,246,.92); }
.cc-flag-trade   { background: rgba(16,185,129,.92); top: auto; bottom: 8px; }

/* =============================================================
 * VUE CLASSEUR (pages de 9 pochettes, comme un vrai binder)
 * ============================================================= */

.cc-binder {
	margin: 0 0 28px;
}

.cc-binder-page {
	position: relative;
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 14px;
	max-width: 640px;
	margin: 0 auto 26px;
	padding: 22px 20px;
	border-radius: 14px;
	background:
		linear-gradient(135deg, rgba(255,255,255,.55), rgba(255,255,255,.15)),
		var(--cc-surface);
	border: 1px solid var(--cc-line);
	box-shadow: var(--cc-shadow);
}

/* Anneaux du classeur sur le bord gauche */
.cc-binder-page::before {
	content: "";
	position: absolute;
	top: 26px;
	bottom: 26px;
	left: 7px;
	width: 6px;
	border-radius: 3px;
	background: repeating-linear-gradient(
		to bottom,
		var(--cc-line) 0, var(--cc-line) 14px,
		transparent 14px, transparent 34px
	);
}

.cc-binder-label {
	max-width: 640px;
	margin: 0 auto 8px;
	font-size: .82em;
	font-weight: 600;
	letter-spacing: .05em;
	text-transform: uppercase;
	color: var(--cc-muted);
	text-align: center;
}

/* Pochette vide du classeur */
.cc-sleeve-empty {
	aspect-ratio: var(--cc-ratio);
	border: 2px dashed var(--cc-line);
	border-radius: var(--cc-radius);
	background: rgba(0,0,0,.015);
}

@media (max-width: 560px) {
	.cc-binder-page {
		grid-template-columns: repeat(3, 1fr);
		gap: 8px;
		padding: 14px 12px;
	}

	.cc-binder-page::before {
		display: none;
	}
}

/* =============================================================
 * VUE LISTE
 * ============================================================= */

.cc-list {
	margin: 0 0 28px;
	padding: 0;
	list-style: none;
	border: 1px solid var(--cc-line);
	border-radius: var(--cc-radius);
	overflow: hidden;
}

.cc-list li + li {
	border-top: 1px solid var(--cc-line);
}

.cc-row {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 10px 14px;
	text-decoration: none;
	color: inherit;
	transition: background .15s ease;
}

.cc-row:hover {
	background: var(--cc-surface);
}

.cc-row-thumb {
	flex: 0 0 auto;
	width: 44px;
	aspect-ratio: var(--cc-ratio);
	border-radius: 4px;
	overflow: hidden;
	background: var(--cc-line);
}

.cc-row-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.cc-row-main {
	flex: 1 1 auto;
	min-width: 0;
}

.cc-row-name {
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.cc-row-meta {
	font-size: .82em;
	color: var(--cc-muted);
}

.cc-row-aside {
	flex: 0 0 auto;
	font-size: .84em;
	font-variant-numeric: tabular-nums;
	color: var(--cc-muted);
}

/* =============================================================
 * PROGRESSION PAR SERIE
 * ============================================================= */

.cc-series {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
	gap: 14px;
	margin: 0 0 28px;
	padding: 0;
	list-style: none;
}

.cc-series-item {
	padding: 14px 16px;
	background: var(--cc-surface);
	border: 1px solid var(--cc-line);
	border-radius: var(--cc-radius);
}

.cc-series-name {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	margin-bottom: 8px;
	font-size: .92em;
	font-weight: 600;
}

.cc-series-count {
	font-variant-numeric: tabular-nums;
	color: var(--cc-muted);
	font-weight: 400;
}

.cc-series-item.is-complete .cc-progress-fill {
	background: linear-gradient(90deg, #10b981, #34d399);
}

/* =============================================================
 * ETAT VIDE
 * ============================================================= */

.cc-empty {
	padding: 48px 24px;
	text-align: center;
	border: 2px dashed var(--cc-line);
	border-radius: 14px;
	color: var(--cc-muted);
}

.cc-empty-title {
	margin: 0 0 6px;
	font-size: 1.1em;
	font-weight: 600;
	color: var(--cc-ink);
}

/* =============================================================
 * BADGES DE RARETE (reutilisables hors collection)
 * ============================================================= */

.cc-rarity {
	display: inline-block;
	padding: 2px 8px;
	border-radius: 999px;
	font-size: .7em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: #fff;
}

.cc-rarity-common     { background: var(--cc-common); }
.cc-rarity-rare       { background: var(--cc-rare); }
.cc-rarity-ultra_rare { background: var(--cc-ultra); }
.cc-rarity-legendary  { background: var(--cc-legendary); }

/* =============================================================
 * IMPRESSION : sortie a l'echelle reelle 64 x 89 mm
 * ============================================================= */

@media print {
	.cc-toolbar,
	.cc-viewswitch,
	.cc-sort,
	.cc-progress,
	.cc-stats {
		display: none !important;
	}

	.cc-grid,
	.cc-binder-page {
		display: grid;
		grid-template-columns: repeat(3, 64mm);
		gap: 4mm;
		justify-content: center;
		padding: 0;
		border: 0;
		box-shadow: none;
		background: none;
		page-break-after: always;
	}

	.cc-binder-page::before {
		display: none;
	}

	/* Dimensions physiques exactes */
	.cc-card {
		width: 64mm;
		height: 89mm;
		aspect-ratio: auto;
		box-shadow: none;
		border: .2mm solid #999;
		break-inside: avoid;
	}

	.cc-card-info,
	.cc-qty,
	.cc-flag {
		display: none !important;
	}
}

/* =============================================================
 * ACCESSIBILITE
 * ============================================================= */

@media (prefers-reduced-motion: reduce) {
	.cc-card,
	.cc-card-info,
	.cc-progress-fill,
	.cc-row {
		transition: none;
	}
}

.cc-collection a:focus-visible {
	outline: 2px solid var(--cc-rare);
	outline-offset: 2px;
}

/* =============================================================
 * FORMULAIRE DE SAISIE
 * ============================================================= */

.cc-alert {
	margin: 0 0 18px;
	padding: 12px 16px;
	border-radius: 8px;
	border-left: 4px solid;
	font-size: .92em;
}

.cc-alert-info    { background: rgba(59,130,246,.08);  border-color: #3b82f6; }
.cc-alert-warning { background: rgba(245,158,11,.10);  border-color: #f59e0b; }
.cc-alert-error   { background: rgba(239,68,68,.10);   border-color: #ef4444; }

/* Apercu de l'image choisie, au format carte */
.cc-preview {
	margin-top: 10px;
	width: 120px;
	aspect-ratio: var(--cc-ratio, 64 / 89);
	border-radius: 8px;
	overflow: hidden;
	border: 1px solid var(--cc-line, rgba(0,0,0,.1));
	background: var(--cc-line, rgba(0,0,0,.1));
}

.cc-preview img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* Doublons proposes */
.cc-dup-list {
	margin: 0 0 22px;
	padding: 0;
	list-style: none;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 12px;
}

.cc-dup {
	display: flex;
	gap: 12px;
	padding: 12px;
	border: 1px solid var(--cc-line, rgba(0,0,0,.1));
	border-radius: 10px;
	background: var(--cc-surface, rgba(255,255,255,.7));
}

.cc-dup-thumb {
	flex: 0 0 auto;
	width: 58px;
	aspect-ratio: var(--cc-ratio, 64 / 89);
	border-radius: 5px;
	overflow: hidden;
	background: var(--cc-line, rgba(0,0,0,.1));
}

.cc-dup-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.cc-dup-info { min-width: 0; }

.cc-dup-name {
	display: block;
	font-weight: 600;
	margin-bottom: 3px;
}

.cc-dup-reason {
	margin: 5px 0;
	font-size: .8em;
	font-weight: 600;
	color: #b45309;
}

/* Suggestions pendant la saisie */
.cc-search-results {
	margin-top: 8px;
	padding: 10px 12px;
	border: 1px solid var(--cc-line, rgba(0,0,0,.1));
	border-radius: 8px;
	background: rgba(245,158,11,.06);
}

.cc-search-title {
	margin: 0 0 8px;
	font-size: .84em;
	font-weight: 700;
	color: #b45309;
}

.cc-search-results ul {
	margin: 0;
	padding: 0;
	list-style: none;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.cc-search-results li a {
	display: flex;
	align-items: center;
	gap: 7px;
	padding: 5px 9px;
	border-radius: 6px;
	background: rgba(255,255,255,.85);
	font-size: .82em;
	text-decoration: none;
}

.cc-search-results li img {
	width: 22px;
	aspect-ratio: var(--cc-ratio, 64 / 89);
	object-fit: cover;
	border-radius: 3px;
}

/* Actions de gestion sur la fiche carte */
.cc-manage {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin: 18px 0;
	padding-top: 16px;
	border-top: 1px solid var(--cc-line, rgba(0,0,0,.1));
}

/* Crayon de modification en vue liste */
.cc-row-edit {
	display: inline-block;
	margin-left: 10px;
	padding: 2px 7px;
	border-radius: 5px;
	background: var(--cc-line, rgba(0,0,0,.1));
	text-decoration: none;
	font-size: 1.05em;
	line-height: 1.4;
}

.cc-row-edit:hover {
	background: var(--cc-rare, #3b82f6);
	color: #fff;
}

/* =============================================================
 * FILTRES DU CATALOGUE
 * ============================================================= */

.cc-filters {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0 0 22px;
	padding: 14px 16px;
	background: var(--cc-surface, rgba(255,255,255,.7));
	border: 1px solid var(--cc-line, rgba(0,0,0,.1));
	border-radius: var(--cc-radius, 10px);
}

.cc-filters input,
.cc-filters select {
	flex: 1 1 130px;
	min-width: 0;
	padding: 7px 11px;
	border: 1px solid var(--cc-line, rgba(0,0,0,.1));
	border-radius: 6px;
	background: #fff;
	color: inherit;
	font: inherit;
}

@media (prefers-color-scheme: dark) {
	.cc-filters input,
	.cc-filters select,
	.cc-picker {
		background: rgba(255,255,255,.06);
	}
}

/* Pastille "déjà possédée" au catalogue */
.cc-qty-owned {
	background: rgba(16,185,129,.92);
	font-size: .82em;
}

/* Badge de priorité en mancoliste */
.cc-flag-priority { top: auto; bottom: 8px; left: 8px; }

.cc-priority-urgent { background: rgba(239,68,68,.92); }
.cc-priority-high   { background: rgba(245,158,11,.92); }
.cc-priority-medium { background: rgba(59,130,246,.92); }
.cc-priority-low    { background: rgba(107,114,128,.92); }

/* =============================================================
 * FICHE CARTE
 * ============================================================= */

.cc-detail-list {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 6px 18px;
	margin: 0 0 20px;
}

.cc-detail-list dt {
	font-weight: 600;
	color: var(--cc-muted, #6b7280);
	white-space: nowrap;
}

.cc-detail-list dd { margin: 0; }

/* Numéro unique permanent */
.cc-uid {
	display: inline-block;
	padding: 2px 9px;
	border-radius: 5px;
	background: #1f2937;
	color: #fff;
	font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
	font-size: .88em;
	letter-spacing: .06em;
}

/* Bloc "exemplaires possédés" */
.cc-owned {
	margin: 20px 0;
	padding: 16px;
	border-radius: var(--cc-radius, 10px);
	background: var(--cc-surface, rgba(255,255,255,.7));
	border: 1px solid var(--cc-line, rgba(0,0,0,.1));
}

.cc-owned-form {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
}

.cc-owned-form input[type="number"] {
	width: 88px;
	padding: 7px 10px;
	border: 1px solid var(--cc-line, rgba(0,0,0,.1));
	border-radius: 6px;
	background: #fff;
	font: inherit;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.cc-owned-trade {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: .9em;
}

.cc-owned-help {
	margin: 10px 0 0;
	font-size: .84em;
	color: var(--cc-muted, #6b7280);
}

/* Liste déroulante des séries existantes */
.cc-picker {
	display: block;
	margin-bottom: 7px;
	padding: 6px 10px;
	border: 1px solid var(--cc-line, rgba(0,0,0,.1));
	border-radius: 6px;
	background: #fff;
	font: inherit;
	max-width: 420px;
}

/* Image conservée après re-affichage du formulaire */
.cc-kept {
	color: #059669;
	font-weight: 600;
}

/* =============================================================
 * CARTES NON POSSEDEES : VISIBLES MAIS ATTENUEES
 *
 * Le visuel reste identifiable, mais desature et eclairci : on
 * comprend au premier coup d'oeil ce qui manque a la collection.
 * Des que la carte est possedee, elle reprend son rendu normal.
 * ============================================================= */

.cc-card[data-owned="0"] img,
.cc-sheet-card[data-owned="0"] img {
	opacity: .38;
	filter: grayscale(72%) contrast(88%);
	transition: opacity .2s ease, filter .2s ease;
}

/* Au survol, on revele le visuel : utile pour identifier la carte */
.cc-card[data-owned="0"]:hover img,
.cc-card[data-owned="0"]:focus-visible img,
.cc-sheet-card[data-owned="0"]:hover img {
	opacity: .78;
	filter: grayscale(28%);
}

/* Voile leger par-dessus, pour renforcer la distinction */
.cc-card[data-owned="0"]::before,
.cc-sheet-card[data-owned="0"]::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	background: rgba(255, 255, 255, .30);
	pointer-events: none;
}

@media (prefers-color-scheme: dark) {
	.cc-card[data-owned="0"]::before,
	.cc-sheet-card[data-owned="0"]::before {
		background: rgba(0, 0, 0, .34);
	}
}

/* Le liseré de rareté s'efface aussi quand la carte manque */
.cc-card[data-owned="0"]::after {
	opacity: .35;
}
