/**
 * Marketplace Hub — modern UI components.
 * Buttons, cards, inputs, badges, alerts, tables, tabs, stats, toasts.
 */

/* -------------------------------------------------------------- Buttons */

.mh-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--mh-space-2);
	padding: 0.625rem 1rem;
	border-radius: var(--mh-radius-md);
	border: 1px solid transparent;
	background: var(--mh-bg-elevated);
	color: var(--mh-text);
	font-size: var(--mh-text-sm);
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	text-decoration: none;
	transition: background var(--mh-duration) var(--mh-ease),
		border-color var(--mh-duration) var(--mh-ease),
		transform var(--mh-duration-fast) var(--mh-ease),
		box-shadow var(--mh-duration) var(--mh-ease);
	white-space: nowrap;
	min-height: 40px;
}

.mh-btn:focus-visible {
	outline: 2px solid var(--mh-primary);
	outline-offset: 2px;
}

.mh-btn:hover {
	background: var(--mh-bg-hover);
}

.mh-btn:active {
	transform: translateY(1px);
}

.mh-btn[disabled],
.mh-btn[aria-disabled="true"] {
	opacity: 0.5;
	cursor: not-allowed;
}

.mh-btn--primary {
	background: var(--mh-primary);
	color: var(--mh-primary-text);
}

.mh-btn--primary:hover {
	background: var(--mh-primary-hover);
}

.mh-btn--ghost {
	background: transparent;
	border-color: var(--mh-border);
}

.mh-btn--ghost:hover {
	background: var(--mh-bg-hover);
	border-color: var(--mh-border-strong);
}

.mh-btn--danger {
	background: var(--mh-danger);
	color: #fff;
}

.mh-btn--danger:hover {
	background: #dc2626;
}

.mh-btn--sm {
	padding: 0.375rem 0.75rem;
	font-size: var(--mh-text-xs);
	min-height: 32px;
}

.mh-btn--lg {
	padding: 0.875rem 1.5rem;
	font-size: var(--mh-text-base);
	min-height: 48px;
}

.mh-btn--block {
	width: 100%;
}

.mh-btn__icon {
	display: inline-flex;
	width: 1.125em;
	height: 1.125em;
	flex: 0 0 auto;
}

/* ---------------------------------------------------------------- Cards */

.mh-card {
	background: var(--mh-bg-elevated);
	border: 1px solid var(--mh-border);
	border-radius: var(--mh-radius-lg);
	box-shadow: var(--mh-shadow-xs);
	overflow: hidden;
	transition: box-shadow var(--mh-duration) var(--mh-ease),
		transform var(--mh-duration) var(--mh-ease),
		border-color var(--mh-duration) var(--mh-ease);
}

.mh-card--interactive:hover {
	box-shadow: var(--mh-shadow-md);
	transform: translateY(-2px);
	border-color: var(--mh-border-strong);
}

.mh-card__header {
	padding: var(--mh-space-5);
	border-bottom: 1px solid var(--mh-border);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--mh-space-4);
}

.mh-card__title {
	margin: 0;
	font-size: var(--mh-text-lg);
	font-weight: 700;
	letter-spacing: -0.01em;
}

.mh-card__body {
	padding: var(--mh-space-5);
}

.mh-card__footer {
	padding: var(--mh-space-4) var(--mh-space-5);
	border-top: 1px solid var(--mh-border);
	background: var(--mh-bg-sunken);
}

/* ---------------------------------------------------------------- Stats */

.mh-stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: var(--mh-space-4);
	margin-bottom: var(--mh-space-6);
}

.mh-stat {
	background: var(--mh-bg-elevated);
	border: 1px solid var(--mh-border);
	border-radius: var(--mh-radius-lg);
	padding: var(--mh-space-5);
	display: flex;
	flex-direction: column;
	gap: var(--mh-space-2);
	position: relative;
	overflow: hidden;
}

.mh-stat::after {
	content: "";
	position: absolute;
	inset: 0 auto 0 0;
	width: 3px;
	background: var(--mh-primary);
	opacity: 0;
	transition: opacity var(--mh-duration) var(--mh-ease);
}

.mh-stat:hover::after {
	opacity: 1;
}

.mh-stat__label {
	display: flex;
	align-items: center;
	gap: var(--mh-space-2);
	font-size: var(--mh-text-xs);
	font-weight: 600;
	color: var(--mh-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.06em;
}

.mh-stat__value {
	font-size: var(--mh-text-3xl);
	font-weight: 800;
	letter-spacing: -0.02em;
	color: var(--mh-text);
	font-variant-numeric: tabular-nums;
}

.mh-stat__delta {
	font-size: var(--mh-text-xs);
	color: var(--mh-text-muted);
}

.mh-stat__delta--up {
	color: var(--mh-success);
}

.mh-stat__delta--down {
	color: var(--mh-danger);
}

/* --------------------------------------------------------------- Inputs */

.mh-field {
	display: flex;
	flex-direction: column;
	gap: var(--mh-space-2);
	margin-bottom: var(--mh-space-4);
}

.mh-field__label {
	font-size: var(--mh-text-sm);
	font-weight: 600;
	color: var(--mh-text);
	display: flex;
	align-items: center;
	gap: var(--mh-space-1);
}

.mh-field__required {
	color: var(--mh-danger);
}

.mh-field__hint {
	font-size: var(--mh-text-xs);
	color: var(--mh-text-muted);
	margin: 0;
}

.mh-input,
.mh-select,
.mh-textarea {
	width: 100%;
	padding: 0.625rem 0.875rem;
	border: 1px solid var(--mh-border-strong);
	border-radius: var(--mh-radius-md);
	background: var(--mh-bg-elevated);
	color: var(--mh-text);
	font-family: inherit;
	font-size: var(--mh-text-sm);
	line-height: 1.5;
	transition: border-color var(--mh-duration) var(--mh-ease),
		box-shadow var(--mh-duration) var(--mh-ease),
		background var(--mh-duration) var(--mh-ease);
}

.mh-input::placeholder,
.mh-textarea::placeholder {
	color: var(--mh-text-subtle);
}

.mh-input:focus,
.mh-select:focus,
.mh-textarea:focus {
	outline: none;
	border-color: var(--mh-primary);
	box-shadow: 0 0 0 3px var(--mh-primary-soft);
}

.mh-input[aria-invalid="true"],
.mh-select[aria-invalid="true"],
.mh-textarea[aria-invalid="true"] {
	border-color: var(--mh-danger);
	box-shadow: 0 0 0 3px var(--mh-danger-soft);
}

.mh-textarea {
	min-height: 120px;
	resize: vertical;
}

.mh-select {
	appearance: none;
	background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.875rem center;
	padding-right: 2.5rem;
}

/* Checkbox / radio */
.mh-check {
	display: flex;
	align-items: flex-start;
	gap: var(--mh-space-3);
	padding: var(--mh-space-3);
	border-radius: var(--mh-radius-md);
	cursor: pointer;
	transition: background var(--mh-duration) var(--mh-ease);
}

.mh-check:hover {
	background: var(--mh-bg-hover);
}

.mh-check input[type="checkbox"],
.mh-check input[type="radio"] {
	margin: 0;
	width: 1.125rem;
	height: 1.125rem;
	accent-color: var(--mh-primary);
	flex: 0 0 auto;
}

/* Switch */
.mh-switch {
	display: inline-flex;
	align-items: center;
	gap: var(--mh-space-3);
	cursor: pointer;
}

.mh-switch input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.mh-switch__track {
	position: relative;
	width: 2.5rem;
	height: 1.5rem;
	border-radius: var(--mh-radius-full);
	background: var(--mh-border-strong);
	transition: background var(--mh-duration) var(--mh-ease);
}

.mh-switch__thumb {
	position: absolute;
	top: 2px;
	left: 2px;
	width: 1.25rem;
	height: 1.25rem;
	border-radius: 50%;
	background: #fff;
	box-shadow: var(--mh-shadow-sm);
	transition: transform var(--mh-duration) var(--mh-ease);
}

.mh-switch input:checked + .mh-switch__track {
	background: var(--mh-primary);
}

.mh-switch input:checked + .mh-switch__track .mh-switch__thumb {
	transform: translateX(1rem);
}

.mh-switch input:focus-visible + .mh-switch__track {
	outline: 2px solid var(--mh-primary);
	outline-offset: 2px;
}

/* --------------------------------------------------------------- Badges */

.mh-badge {
	display: inline-flex;
	align-items: center;
	gap: var(--mh-space-1);
	padding: 0.25rem 0.625rem;
	border-radius: var(--mh-radius-full);
	font-size: var(--mh-text-xs);
	font-weight: 600;
	line-height: 1.4;
	background: var(--mh-bg-sunken);
	color: var(--mh-text-muted);
	white-space: nowrap;
}

.mh-badge--success {
	background: var(--mh-success-soft);
	color: var(--mh-success);
}

.mh-badge--warning {
	background: var(--mh-warning-soft);
	color: #b45309;
}

.mh-badge--danger {
	background: var(--mh-danger-soft);
	color: var(--mh-danger);
}

.mh-badge--primary {
	background: var(--mh-primary-soft);
	color: var(--mh-primary);
}

.mh-badge__dot {
	width: 0.5rem;
	height: 0.5rem;
	border-radius: 50%;
	background: currentColor;
}

/* --------------------------------------------------------------- Alerts */

.mh-alert {
	display: flex;
	gap: var(--mh-space-3);
	padding: var(--mh-space-4);
	border-radius: var(--mh-radius-md);
	border: 1px solid var(--mh-border);
	background: var(--mh-bg-elevated);
	margin-bottom: var(--mh-space-4);
	font-size: var(--mh-text-sm);
}

.mh-alert--success {
	background: var(--mh-success-soft);
	border-color: color-mix(in srgb, var(--mh-success) 30%, transparent);
	color: #065f46;
}

.mh-alert--warning {
	background: var(--mh-warning-soft);
	border-color: color-mix(in srgb, var(--mh-warning) 30%, transparent);
	color: #92400e;
}

.mh-alert--danger {
	background: var(--mh-danger-soft);
	border-color: color-mix(in srgb, var(--mh-danger) 30%, transparent);
	color: #991b1b;
}

.mh-alert--info {
	background: var(--mh-primary-soft);
	border-color: color-mix(in srgb, var(--mh-primary) 30%, transparent);
	color: #3730a3;
}

.mh-alert__icon {
	flex: 0 0 auto;
	width: 1.25rem;
	height: 1.25rem;
}

.mh-alert__content {
	flex: 1 1 auto;
}

.mh-alert__title {
	font-weight: 700;
	margin: 0 0 var(--mh-space-1);
}

/* --------------------------------------------------------------- Tables */

.mh-table-wrap {
	background: var(--mh-bg-elevated);
	border: 1px solid var(--mh-border);
	border-radius: var(--mh-radius-lg);
	overflow: hidden;
	box-shadow: var(--mh-shadow-xs);
}

.mh-table {
	width: 100%;
	border-collapse: collapse;
	font-size: var(--mh-text-sm);
}

.mh-table thead th {
	text-align: left;
	padding: var(--mh-space-3) var(--mh-space-5);
	font-size: var(--mh-text-xs);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--mh-text-muted);
	background: var(--mh-bg-sunken);
	border-bottom: 1px solid var(--mh-border);
	white-space: nowrap;
}

.mh-table tbody td {
	padding: var(--mh-space-4) var(--mh-space-5);
	border-bottom: 1px solid var(--mh-border);
	vertical-align: middle;
}

.mh-table tbody tr:last-child td {
	border-bottom: none;
}

.mh-table tbody tr {
	transition: background var(--mh-duration-fast) var(--mh-ease);
}

.mh-table tbody tr:hover {
	background: var(--mh-bg-hover);
}

.mh-table__num {
	font-variant-numeric: tabular-nums;
	text-align: right;
}

/* --------------------------------------------------------------- Tabs */

.mh-tabs {
	display: flex;
	gap: var(--mh-space-1);
	border-bottom: 1px solid var(--mh-border);
	overflow-x: auto;
	scrollbar-width: thin;
	margin-bottom: var(--mh-space-5);
}

.mh-tab {
	position: relative;
	padding: var(--mh-space-3) var(--mh-space-4);
	font-size: var(--mh-text-sm);
	font-weight: 600;
	color: var(--mh-text-muted);
	text-decoration: none;
	white-space: nowrap;
	border-bottom: 2px solid transparent;
	transition: color var(--mh-duration) var(--mh-ease),
		border-color var(--mh-duration) var(--mh-ease);
}

.mh-tab:hover {
	color: var(--mh-text);
}

.mh-tab.is-active {
	color: var(--mh-primary);
	border-bottom-color: var(--mh-primary);
}

/* --------------------------------------------------------------- Empty */

.mh-empty {
	text-align: center;
	padding: var(--mh-space-8) var(--mh-space-5);
	color: var(--mh-text-muted);
}

.mh-empty__icon {
	width: 3rem;
	height: 3rem;
	margin: 0 auto var(--mh-space-4);
	color: var(--mh-text-subtle);
}

.mh-empty__title {
	font-size: var(--mh-text-lg);
	font-weight: 700;
	color: var(--mh-text);
	margin: 0 0 var(--mh-space-2);
}

.mh-empty__text {
	margin: 0 0 var(--mh-space-5);
	max-width: 32rem;
	margin-inline: auto;
}

/* -------------------------------------------------------------- Toasts */

.mh-toasts {
	position: fixed;
	bottom: var(--mh-space-5);
	right: var(--mh-space-5);
	display: flex;
	flex-direction: column;
	gap: var(--mh-space-2);
	z-index: 9999;
	pointer-events: none;
}

.mh-toast {
	background: var(--mh-bg-elevated);
	border: 1px solid var(--mh-border);
	border-left: 3px solid var(--mh-primary);
	border-radius: var(--mh-radius-md);
	box-shadow: var(--mh-shadow-lg);
	padding: var(--mh-space-3) var(--mh-space-4);
	font-size: var(--mh-text-sm);
	max-width: 22rem;
	pointer-events: auto;
	animation: mh-toast-in var(--mh-duration-slow) var(--mh-ease);
}

.mh-toast--success { border-left-color: var(--mh-success); }
.mh-toast--danger  { border-left-color: var(--mh-danger); }
.mh-toast--warning { border-left-color: var(--mh-warning); }

@keyframes mh-toast-in {
	from { opacity: 0; transform: translateX(20px); }
	to   { opacity: 1; transform: translateX(0); }
}

/* ---------------------------------------------------------- Skeletons */

.mh-skeleton {
	background: linear-gradient(
		90deg,
		var(--mh-bg-sunken) 25%,
		var(--mh-bg-hover) 50%,
		var(--mh-bg-sunken) 75%
	);
	background-size: 200% 100%;
	border-radius: var(--mh-radius-sm);
	animation: mh-shimmer 1.5s infinite;
}

@keyframes mh-shimmer {
	from { background-position: 200% 0; }
	to   { background-position: -200% 0; }
}