/**
 * KH Link System — Scoped Frontend Styles
 * All rules namespaced under .khls-wrapper — no global theme overrides.
 */

.khls-wrapper {
	--khls-radius: 20px;
	--khls-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
	--khls-glow: 0 0 32px rgba(99, 102, 241, 0.22);
	--khls-text: #ffffff;
	--khls-text-muted: #cbd5e1;
	--khls-text-soft: #94a3b8;
	--khls-border: rgba(255, 255, 255, 0.1);
	--khls-gradient: linear-gradient(135deg, var(--kh-primary, #6366f1), var(--kh-secondary, #8b5cf6), var(--kh-accent, #22d3ee));

	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	margin: 1.5rem 0;
	padding: clamp(1rem, 2.5vw, 2rem);
	background: var(--kh-bg, #0f172a);
	color: var(--khls-text);
	border-radius: var(--khls-radius);
	font-family: inherit;
	line-height: 1.6;
	position: relative;
	overflow: hidden;
	clear: both;
}

.khls-wrapper *,
.khls-wrapper *::before,
.khls-wrapper *::after {
	box-sizing: border-box;
}

.khls-wrapper h2,
.khls-wrapper h3,
.khls-wrapper p,
.khls-wrapper span,
.khls-wrapper a,
.khls-wrapper button {
	font-family: inherit;
}

.khls-sr-only {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal;
}

.khls-message {
	margin: 0 0 1rem;
	padding: 0.75rem 1rem;
	border-radius: 10px;
	font-size: 0.875rem;
	font-weight: 600;
}

.khls-message--error {
	background: rgba(239, 68, 68, 0.15);
	border: 1px solid rgba(239, 68, 68, 0.35);
	color: #fecaca;
}

.khls-message--info {
	background: rgba(59, 130, 246, 0.12);
	border: 1px solid rgba(59, 130, 246, 0.3);
	color: #bfdbfe;
}

/* Hero */
.khls-hero {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 1.5rem;
	align-items: center;
	margin-bottom: 1.5rem;
	padding: clamp(1rem, 2vw, 1.75rem);
	background: rgba(17, 24, 39, 0.85);
	border: 1px solid var(--khls-border);
	border-radius: calc(var(--khls-radius) - 4px);
}

.khls-hero__title {
	margin: 0 0 0.5rem;
	font-size: clamp(1.5rem, 3vw, 2.25rem);
	font-weight: 800;
	color: var(--khls-text);
	line-height: 1.2;
}

@supports (-webkit-background-clip: text) {
	.khls-hero__title {
		background: var(--khls-gradient);
		-webkit-background-clip: text;
		background-clip: text;
		-webkit-text-fill-color: transparent;
	}
}

.khls-hero__subtitle {
	margin: 0 0 1rem;
	color: var(--khls-text-muted);
	font-size: clamp(0.9375rem, 1.8vw, 1.0625rem);
	max-width: 52ch;
}

.khls-hero__cta {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.75rem 1.25rem;
	background: var(--khls-gradient);
	color: #ffffff;
	text-decoration: none;
	border-radius: 999px;
	font-weight: 700;
	font-size: 0.9375rem;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.khls-hero__cta:hover,
.khls-hero__cta:focus-visible {
	color: #ffffff;
	transform: translateY(-2px);
	box-shadow: var(--khls-glow);
}

.khls-hero__visual {
	position: relative;
	width: 100px;
	height: 100px;
}

.khls-hero__orb {
	position: absolute;
	border-radius: 50%;
	filter: blur(18px);
}

.khls-hero__orb--1 { width: 70px; height: 70px; background: var(--kh-primary, #6366f1); top: 0; right: 0; opacity: 0.55; }
.khls-hero__orb--2 { width: 50px; height: 50px; background: var(--kh-accent, #22d3ee); bottom: 0; left: 0; opacity: 0.45; }
.khls-hero__orb--3 { width: 36px; height: 36px; background: var(--kh-secondary, #8b5cf6); top: 40%; left: 40%; opacity: 0.5; }

/* Stats */
.khls-stats {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 0.875rem;
	margin-bottom: 1.5rem;
}

.khls-stat {
	background: var(--kh-card, #111827);
	border: 1px solid var(--khls-border);
	border-radius: 14px;
	padding: 1rem;
	text-align: center;
	min-width: 0;
}

.khls-stat__value {
	display: block;
	font-size: 1.375rem;
	font-weight: 800;
	color: var(--kh-accent, #22d3ee);
	margin-bottom: 0.25rem;
	word-break: break-word;
}

.khls-stat__label {
	display: block;
	font-size: 0.75rem;
	color: var(--khls-text-soft);
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

/* Toolbar */
.khls-toolbar {
	display: flex;
	flex-wrap: wrap;
	gap: 0.875rem;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 1.25rem;
}

.khls-filters {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	max-width: 100%;
}

.khls-filter {
	background: rgba(255, 255, 255, 0.05);
	border: 1px solid var(--khls-border);
	color: var(--khls-text-muted);
	padding: 0.5rem 0.875rem;
	border-radius: 999px;
	cursor: pointer;
	font-size: 0.8125rem;
	font-weight: 600;
	transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.khls-filter:hover,
.khls-filter:focus-visible {
	color: var(--khls-text);
	border-color: rgba(99, 102, 241, 0.45);
	outline: none;
}

.khls-filter.is-active {
	background: var(--khls-gradient);
	border-color: transparent;
	color: #ffffff;
}

.khls-search {
	position: relative;
	flex: 1 1 220px;
	max-width: 340px;
	min-width: 0;
}

.khls-search i {
	position: absolute;
	left: 0.875rem;
	top: 50%;
	transform: translateY(-50%);
	color: var(--khls-text-soft);
	pointer-events: none;
}

.khls-search__input {
	width: 100%;
	padding: 0.625rem 0.875rem 0.625rem 2.5rem;
	background: var(--kh-card, #111827);
	border: 1px solid var(--khls-border);
	border-radius: 999px;
	color: var(--khls-text);
	font-size: 0.875rem;
	outline: none;
}

.khls-search__input::placeholder {
	color: var(--khls-text-soft);
}

.khls-search__input:focus {
	border-color: var(--kh-primary, #6366f1);
	box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

/* Grid */
.khls-grid-wrap {
	position: relative;
	min-height: 80px;
}

.khls-loader {
	display: none;
	position: absolute;
	inset: 0;
	align-items: center;
	justify-content: center;
	background: rgba(15, 23, 42, 0.75);
	border-radius: 14px;
	z-index: 5;
	font-weight: 600;
	color: var(--kh-accent, #22d3ee);
}

.khls-loader[hidden] {
	display: none;
}

.khls-wrapper.is-loading .khls-loader {
	display: flex;
}

.khls-grid {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 1rem;
	width: 100%;
}

.khls-empty {
	grid-column: 1 / -1;
	text-align: center;
	padding: 2rem 1rem;
	color: var(--khls-text-muted);
	background: var(--kh-card, #111827);
	border-radius: 14px;
	border: 1px dashed var(--khls-border);
}

/* Cards */
.khls-card {
	position: relative;
	background: var(--kh-card, #111827);
	border: 1px solid var(--khls-border);
	border-radius: var(--khls-radius);
	transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
	min-width: 0;
	overflow: hidden;
}

.khls-card::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	padding: 1px;
	background: var(--khls-gradient);
	-webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
	mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
	-webkit-mask-composite: xor;
	mask-composite: exclude;
	opacity: 0.25;
	pointer-events: none;
}

.khls-card:hover {
	transform: translateY(-6px);
	box-shadow: var(--khls-shadow), var(--khls-glow);
	border-color: rgba(99, 102, 241, 0.35);
}

.khls-card--featured {
	border-color: rgba(34, 211, 238, 0.35);
}

.khls-card__inner {
	padding: 1.25rem;
	display: flex;
	flex-direction: column;
	gap: 0.875rem;
	height: 100%;
}

.khls-badge {
	display: inline-flex;
	align-self: flex-start;
	padding: 0.2rem 0.55rem;
	border-radius: 999px;
	font-size: 0.625rem;
	font-weight: 800;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: #ffffff;
}

.khls-badge--new { background: #16a34a; }
.khls-badge--popular { background: #ea580c; }
.khls-badge--vip { background: #ca8a04; color: #111827; }
.khls-badge--trend { background: #db2777; }
.khls-badge--recommended { background: #4f46e5; }

.khls-card__header {
	display: flex;
	gap: 0.875rem;
	align-items: flex-start;
	min-width: 0;
}

.khls-card__thumb {
	width: 52px;
	height: 52px;
	border-radius: 12px;
	overflow: hidden;
	flex-shrink: 0;
}

.khls-card__thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.khls-card__icon {
	width: 52px;
	height: 52px;
	border-radius: 12px;
	background: rgba(99, 102, 241, 0.18);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	font-size: 1.375rem;
	color: var(--kh-accent, #22d3ee);
}

.khls-card__meta {
	min-width: 0;
	flex: 1;
}

.khls-card__category {
	display: block;
	font-size: 0.6875rem;
	color: var(--kh-accent, #22d3ee);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	margin-bottom: 0.2rem;
}

.khls-card__title {
	margin: 0;
	font-size: 1rem;
	font-weight: 700;
	color: var(--khls-text);
	line-height: 1.35;
	word-break: break-word;
}

.khls-card__desc {
	margin: 0;
	font-size: 0.8125rem;
	color: var(--khls-text-muted);
	word-break: break-word;
}

.khls-card__footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.625rem;
	margin-top: auto;
	flex-wrap: wrap;
}

.khls-card__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.45rem;
	padding: 0.625rem 1rem;
	background: rgba(255, 255, 255, 0.07);
	border: 1px solid var(--khls-border);
	border-radius: 10px;
	color: var(--khls-text);
	text-decoration: none;
	font-size: 0.8125rem;
	font-weight: 600;
	transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
	flex: 1 1 auto;
	min-width: 0;
}

.khls-card__btn:hover,
.khls-card__btn:focus-visible {
	background: var(--khls-gradient);
	border-color: transparent;
	color: #ffffff;
}

.khls-card__clicks {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	font-size: 0.75rem;
	color: var(--khls-text-soft);
	white-space: nowrap;
}

/* CTA */
.khls-cta {
	margin-top: 1.75rem;
	padding: clamp(1.5rem, 3vw, 2.25rem);
	background: rgba(99, 102, 241, 0.12);
	border: 1px solid rgba(99, 102, 241, 0.28);
	border-radius: var(--khls-radius);
	text-align: center;
}

.khls-cta__title {
	margin: 0 0 0.625rem;
	font-size: clamp(1.25rem, 2.5vw, 1.75rem);
	font-weight: 800;
	color: var(--khls-text);
}

.khls-cta__subtitle {
	margin: 0 0 1.25rem;
	color: var(--khls-text-muted);
	max-width: 56ch;
	margin-inline: auto;
}

.khls-cta__btn {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.875rem 1.75rem;
	background: var(--khls-gradient);
	color: #ffffff;
	text-decoration: none;
	border-radius: 999px;
	font-weight: 700;
	font-size: 0.9375rem;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.khls-cta__btn:hover,
.khls-cta__btn:focus-visible {
	color: #ffffff;
	transform: translateY(-2px);
	box-shadow: var(--khls-glow);
}

/* Style variants */
.khls-wrapper--minimal .khls-card::before { display: none; }

.khls-wrapper--glass .khls-card {
	background: rgba(17, 24, 39, 0.65);
	backdrop-filter: blur(10px);
}

/* Link reset inside wrapper only */
.khls-wrapper a.khls-card__btn,
.khls-wrapper a.khls-hero__cta,
.khls-wrapper a.khls-cta__btn {
	text-decoration: none;
}

/* Responsive — desktop 4, tablet 2, mobile 1 */
@media (max-width: 1024px) {
	.khls-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.khls-stats {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.khls-hero {
		grid-template-columns: 1fr;
	}

	.khls-hero__visual {
		display: none;
	}
}

@media (max-width: 640px) {
	.khls-wrapper {
		margin: 1rem 0;
		padding: 0.875rem;
		border-radius: 16px;
	}

	.khls-grid {
		grid-template-columns: minmax(0, 1fr);
	}

	.khls-stats {
		grid-template-columns: minmax(0, 1fr);
	}

	.khls-toolbar {
		flex-direction: column;
		align-items: stretch;
	}

	.khls-search {
		max-width: none;
		flex-basis: auto;
	}

	.khls-filters {
		flex-wrap: nowrap;
		overflow-x: auto;
		padding-bottom: 0.25rem;
		-webkit-overflow-scrolling: touch;
	}

	.khls-filter {
		flex-shrink: 0;
	}
}
