/**
 * Componente: Tabla (.vdp-table)
 * Patrón compositivo inspirado en shadcn/ui Table (base-nova).
 * @see https://ui.shadcn.com/docs/components/base/table
 *
 * Table → .vdp-table-wrap > .vdp-table
 * TableHeader → thead.vdp-table__header
 * TableBody → tbody.vdp-table__body
 * TableFooter → tfoot.vdp-table__footer
 * TableRow → tr.vdp-table__row
 * TableHead → th.vdp-table__head
 * TableCell → td.vdp-table__cell
 * TableCaption → caption.vdp-table__caption
 */

/* Table container — overflow horizontal */
.vdp-table-wrap,
.vdp-table__wrap {
	position: relative;
	width: 100%;
	overflow-x: auto;
}

.vdp-table {
	width: 100%;
	border-collapse: collapse;
	caption-side: bottom;
	font-size: var(--vdp-text-body-sm);
	line-height: var(--vdp-lh-body);
	color: var(--vdp-ink);
}

.vdp-table caption,
.vdp-table__caption {
	caption-side: bottom;
	margin-top: var(--vdp-space-4);
	padding: 0;
	font-size: var(--vdp-text-body-sm);
	color: var(--vdp-muted);
	text-align: left;
}

/* Header row */
.vdp-table thead tr,
.vdp-table__header .vdp-table__row {
	border-bottom: 1px solid var(--vdp-line);
}

/* Body rows */
.vdp-table tbody tr,
.vdp-table__body .vdp-table__row {
	border-bottom: 1px solid var(--vdp-line);
}

.vdp-table tbody tr:last-child,
.vdp-table__body .vdp-table__row:last-child {
	border-bottom: 0;
}

/* Sin hover en filas — patrón canónico (Mi cuenta y design system) */
.vdp-table tbody tr:hover,
.vdp-table__body .vdp-table__row:hover,
.vdp-table--account tbody tr:hover,
.vdp-table--account .vdp-table__body .vdp-table__row:hover,
.vdp-table--orders tbody tr:hover,
.vdp-table--orders .vdp-table__body .vdp-table__row:hover {
	background: var(--vdp-paper, transparent);
}

.vdp-table tbody tr:hover :is(td, th, .vdp-table__cell),
.vdp-table__body .vdp-table__row:hover :is(td, th, .vdp-table__cell),
.vdp-table--account tbody tr:hover :is(td, th, .vdp-table__cell),
.vdp-table--orders tbody tr:hover :is(td, th, .vdp-table__cell) {
	background: var(--vdp-paper, transparent);
}

.vdp-table tbody tr.is-selected,
.vdp-table tbody tr[aria-selected="true"],
.vdp-table__body .vdp-table__row.is-selected,
.vdp-table__body .vdp-table__row[aria-selected="true"] {
	background: color-mix(in srgb, var(--vdp-soft) 50%, transparent);
}

/* Footer */
.vdp-table tfoot,
.vdp-table__footer {
	border-top: 1px solid var(--vdp-line);
	background: color-mix(in srgb, var(--vdp-soft) 50%, transparent);
	font-weight: var(--vdp-weight-medium);
}

.vdp-table tfoot tr:last-child,
.vdp-table__footer .vdp-table__row:last-child {
	border-bottom: 0;
}

/* Head cells */
.vdp-table th,
.vdp-table__head {
	height: 40px;
	padding: 0 8px;
	text-align: left;
	vertical-align: middle;
	font-size: var(--vdp-text-body-sm);
	font-weight: var(--vdp-weight-medium);
	letter-spacing: normal;
	text-transform: none;
	color: var(--vdp-ink);
	background: transparent;
	border: 0;
	white-space: nowrap;
}

/* Body cells */
.vdp-table td,
.vdp-table__cell {
	padding: 8px;
	text-align: left;
	vertical-align: middle;
	border: 0;
	white-space: normal;
	overflow-wrap: anywhere;
	word-break: break-word;
	min-width: 0;
}

.vdp-table__head--numeric,
.vdp-table__cell--numeric,
.vdp-table th.vdp-table__col--numeric,
.vdp-table td.vdp-table__col--numeric {
	text-align: right;
}

.vdp-table__cell--medium,
.vdp-table td.vdp-table__cell--medium {
	font-weight: var(--vdp-weight-medium);
}

.vdp-table__col--actions,
.vdp-table__head--actions,
.vdp-table__cell--actions {
	width: auto;
	min-width: 148px;
	text-align: right;
	white-space: nowrap;
}

.vdp-table__actions {
	display: inline-flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: flex-end;
	gap: 8px;
}

/* Fila destacada (nivel actual, etc.) */
.vdp-table__row--current,
.vdp-level-table__row--current {
	background: color-mix(in srgb, var(--vdp-soft) 50%, transparent);
}

/* Enlaces en celdas — granate (design system) */
.vdp-table__cell a:not(.vdp-btn) {
	color: var(--vdp-wine);
	font-weight: var(--vdp-weight-medium);
	text-decoration: none;
}

.vdp-table__cell a:not(.vdp-btn):hover,
.vdp-table__cell a:not(.vdp-btn):focus-visible {
	color: var(--vdp-wine-2);
}

/* Ordenación */
.vdp-table th[aria-sort],
.vdp-table__head[aria-sort] {
	cursor: pointer;
	user-select: none;
}

.vdp-table th[aria-sort="none"] .vdp-table__sort-icon,
.vdp-table__head[aria-sort="none"] .vdp-table__sort-icon {
	opacity: 0.35;
}

.vdp-table th[aria-sort="ascending"] .vdp-table__sort-icon,
.vdp-table th[aria-sort="descending"] .vdp-table__sort-icon,
.vdp-table__head[aria-sort="ascending"] .vdp-table__sort-icon,
.vdp-table__head[aria-sort="descending"] .vdp-table__sort-icon {
	opacity: 1;
	color: var(--vdp-wine);
}

.vdp-table__sort-icon {
	display: inline-block;
	margin-left: 4px;
	font-size: 10px;
	line-height: 1;
}

/* Columnas numéricas / ledger */
.vdp-table .pos,
.vdp-puntos-table .pos {
	color: var(--vdp-color-positive);
	font-weight: var(--vdp-weight-bold);
}

.vdp-table .neg,
.vdp-puntos-table .neg {
	color: var(--vdp-color-negative);
	font-weight: var(--vdp-weight-bold);
}

/* Legacy grid table (shortcode / admin simple) */
.vdp-puntos-table:not(.vdp-table) {
	width: 100%;
	border-collapse: collapse;
	margin: var(--vdp-space-3) 0;
}

.vdp-puntos-table:not(.vdp-table) th,
.vdp-puntos-table:not(.vdp-table) td {
	border: 1px solid #e0e0e0;
	padding: var(--vdp-space-2) 10px;
	text-align: left;
}

/* Badges en celdas */
.vdp-status,
.vdp-badge {
	display: inline-flex;
	align-items: center;
	border-radius: var(--vdp-radius-lg);
	padding: 5px 9px;
	font-size: var(--vdp-text-eyebrow);
	font-weight: var(--vdp-weight-bold);
	text-transform: uppercase;
	letter-spacing: 0.06em;
	background: #e5ebdd;
	color: #455437;
}

.vdp-status--pending,
.vdp-badge--pending {
	background: var(--vdp-color-warning-bg);
	color: var(--vdp-color-warning);
}

.vdp-status--available,
.vdp-status--done,
.vdp-badge--available,
.vdp-badge--done,
.vdp-status--completed,
.vdp-badge--completed {
	background: #e3e9e1;
	color: #4b624c;
}

.vdp-status--cancelled,
.vdp-status--failed,
.vdp-badge--cancelled,
.vdp-badge--failed {
	background: var(--vdp-color-error-bg);
	color: var(--vdp-color-error);
}

/* Estados tabla: vacío / carga / error */
.vdp-table-state {
	padding: var(--vdp-space-9) var(--vdp-space-4);
	text-align: center;
}

.vdp-table-state--loading .vdp-table-state__spinner {
	display: inline-block;
	width: 28px;
	height: 28px;
	border: 3px solid var(--vdp-line);
	border-top-color: var(--vdp-wine);
	border-radius: 50%;
	animation: vdp-table-spin 0.7s linear infinite;
	margin-bottom: var(--vdp-space-3);
}

@keyframes vdp-table-spin {
	to {
		transform: rotate(360deg);
	}
}

.vdp-table-state__title {
	margin: 0 0 var(--vdp-space-2);
	font-size: 16px;
	font-weight: var(--vdp-weight-bold);
	color: var(--vdp-ink);
}

.vdp-table-state__text {
	margin: 0;
	font-size: var(--vdp-text-body-sm);
	color: var(--vdp-muted);
}

.vdp-table-state--error {
	background: var(--vdp-color-error-bg);
	color: var(--vdp-color-error);
}

.vdp-table-state--error .vdp-table-state__title {
	color: var(--vdp-color-error);
}

/* Paginación */
.vdp-pagination,
.vdp-table__pagination {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--vdp-space-3);
	margin-top: var(--vdp-space-4);
	padding: var(--vdp-space-3) 0;
}

.vdp-pagination__list {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.vdp-pagination__link,
.vdp-pagination__list .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 36px;
	min-height: 36px;
	padding: 0 10px;
	border: 1px solid var(--vdp-line);
	background: var(--vdp-paper);
	color: var(--vdp-ink);
	font-size: var(--vdp-text-body-sm);
	text-decoration: none;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.vdp-pagination__link:hover,
.vdp-pagination__link:focus-visible,
.vdp-pagination__list .page-numbers:hover,
.vdp-pagination__list .page-numbers:focus {
	border-color: var(--vdp-wine);
	color: var(--vdp-wine);
	outline: none;
}

.vdp-pagination__link.is-current,
.vdp-pagination__list .page-numbers.current {
	background: var(--vdp-wine);
	border-color: var(--vdp-wine);
	color: #fff;
}

.vdp-pagination__link[aria-disabled="true"],
.vdp-pagination__list .page-numbers.disabled {
	opacity: 0.5;
	pointer-events: none;
}
