/**
 * Main menu, header tools (account + cart), «کتاب‌ها» megamenu, edition landing pages and the
 * category index (ADR-032, revised by ADR-033).
 * RTL first: the site is Persian, so `right` is the start side.
 */

.kf-mega-anchor {
	position: relative;
}

/* A chevron marks the item as a panel opener (Blocksy only draws one for real sub-menus).
   It is a real element: Blocksy already owns `.ct-menu-link::after`. */
.kf-mega-caret {
	display: inline-block;
	flex: 0 0 auto; /* Blocksy renders the link as a flex row. */
	align-self: center;
	width: 6px;
	height: 6px;
	margin-inline-start: 7px;
	border-right: 1.5px solid currentColor;
	border-bottom: 1.5px solid currentColor;
	transform: rotate(45deg) translateY(-2px);
	opacity: 0.7;
}

/* The panel is a plain block on tablet/mobile (see the media query at the end). */
/* The panel is as wide as the page, so it cannot hang off the anchor's side: it is pinned to the
   viewport (its top edge is written by navigation.js when the panel opens) and centred. */
.kf-mega {
	position: fixed;
	top: var(--kf-mega-top, 120px);
	right: auto;
	left: 50%;
	transform: translateX(-50%);
	z-index: 120;
	display: none;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	gap: 18px 22px;
	width: min(1240px, 96vw);
	padding: 22px 26px;
	border: 1px solid var(--kf-mega-border, #e6e6ea);
	border-radius: 14px;
	background: var(--kf-mega-bg, #fff);
	box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
	text-align: right;
	direction: rtl;
}

.kf-mega-anchor:hover > .kf-mega,
.kf-mega-anchor:focus-within > .kf-mega,
.kf-mega-anchor.is-open > .kf-mega {
	display: grid;
}

.kf-mega__title {
	margin: 0 0 10px;
	padding-bottom: 6px;
	border-bottom: 1px solid var(--kf-mega-border, #e6e6ea);
	font-size: 0.95rem;
	font-weight: 700;
	color: var(--kf-mega-strong, #123a6b);
}

.kf-mega__title a {
	text-decoration: none;
	color: inherit;
}

.kf-mega__col--shortcuts .kf-mega__list a {
	font-weight: 500;
}

.kf-mega__list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.kf-mega__list li {
	margin: 0 0 6px;
}

.kf-mega__list a {
	display: block;
	padding: 4px 6px;
	border-radius: 8px;
	font-size: 0.95rem;
	text-decoration: none;
	color: inherit;
}

.kf-mega__list a:hover,
.kf-mega__list a:focus {
	background: var(--kf-mega-hover, #f4f4f7);
}

.kf-mega__count {
	flex: none;
	font-size: 0.78rem;
	color: var(--kf-mega-muted, #8b8b96);
}

.kf-mega__all {
	display: inline-block;
	margin-top: 10px;
	font-size: 0.85rem;
	text-decoration: none;
	border-bottom: 1px dashed currentColor;
}

/* Edition landing pages. */
.kf-edition-intro,
.kf-edition-empty {
	margin: 0 0 18px;
	font-size: 1rem;
	line-height: 2;
	color: var(--kf-mega-title, #6b6b76);
}

/* Category index page. */
.kf-category-index__root {
	margin-bottom: 34px;
}

.kf-category-index__root > h2 {
	margin: 0 0 12px;
	padding-bottom: 8px;
	border-bottom: 2px solid var(--kf-mega-border, #e6e6ea);
	font-size: 1.35rem;
}

.kf-category-index__group {
	margin: 0 0 16px;
}

.kf-category-index__group > h3 {
	margin: 0 0 6px;
	font-size: 1.05rem;
}

.kf-category-index__group ul {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 18px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.kf-category-index__count {
	font-size: 0.78rem;
	color: var(--kf-mega-muted, #8b8b96);
}

@media (max-width: 1400px) {
	.kf-mega {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		width: min(900px, 96vw);
	}
}

@media (max-width: 1024px) {
	.kf-mega {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		width: min(720px, 94vw);
	}
}

@media (max-width: 767px) {
	/* Mobile drawer: the panel becomes an accordion in the flow, opened by tapping the item. */
	.kf-mega {
		position: static;
		display: none;
		transform: none;
		left: auto;
		width: 100%;
		grid-template-columns: 1fr;
		gap: 14px;
		padding: 12px 0;
		border: 0;
		box-shadow: none;
	}

	.kf-mega-anchor.is-open > .kf-mega {
		display: grid;
	}

	.kf-mega-anchor:hover > .kf-mega {
		display: none;
	}

	.kf-mega-anchor.is-open:hover > .kf-mega {
		display: grid;
	}

}

/* ---------------------------------------------------------------------------
   Header tools (ADR-033 §1): the account state and the cart total are visible
   in the header on every page, so a signed-in buyer can see they are signed in
   without opening «کتابخانهٔ من».
   --------------------------------------------------------------------------- */

.kf-header-item > a,
.kf-header-item > .kf-header-item__label {
	display: flex;
	align-items: center;
	gap: 7px;
	white-space: nowrap;
}

.kf-header-item__icon {
	flex: 0 0 auto;
	width: 18px;
	height: 18px;
}

.kf-header-item--account > a {
	font-weight: 600;
}

.kf-header-item--login > a {
	padding: 6px 14px;
	border: 1px solid currentColor;
	border-radius: 999px;
	font-weight: 600;
}

.kf-header-item--cart .kf-cart__amount {
	font-variant-numeric: tabular-nums;
}

.kf-header-item--cart .kf-cart__count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: 999px;
	background: var(--kf-mega-strong, #123a6b);
	color: #fff;
	font-size: 0.72rem;
	line-height: 1;
}

.kf-header-item--cart .kf-cart__inner {
	display: flex;
	align-items: center;
	gap: 7px;
}

.kf-header-item--cart .kf-cart__inner.is-empty .kf-cart__count {
	display: none;
}

.kf-header-item .kf-account__name {
	max-width: 12ch;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Account drop-down (reported by the owner 2026-09-17: the list printed open under the header).
   Same open/close model as the megamenu: hover + focus on desktop, tap toggles `.is-open` on touch. */
.kf-account-anchor {
	position: relative;
}

.kf-account-menu {
	position: absolute;
	top: 100%;
	right: 0;
	z-index: 120;
	display: none;
	min-width: 190px;
	margin: 6px 0 0;
	padding: 8px 0;
	list-style: none;
	border: 1px solid var(--kf-mega-border, #e6e6ea);
	border-radius: 12px;
	background: var(--kf-mega-bg, #fff);
	box-shadow: 0 14px 32px rgba(0, 0, 0, 0.12);
	text-align: right;
	direction: rtl;
}

.kf-account-anchor:hover > .kf-account-menu,
.kf-account-anchor:focus-within > .kf-account-menu,
.kf-account-anchor.is-open > .kf-account-menu {
	display: block;
}

.kf-account-menu__item {
	margin: 0;
	padding: 0;
}

.kf-account-menu__item a {
	display: block;
	padding: 8px 16px;
	color: inherit;
	font-size: 0.92rem;
	font-weight: 500;
	white-space: nowrap;
	text-decoration: none;
}

.kf-account-menu__item a:hover,
.kf-account-menu__item a:focus {
	background: var(--kf-mega-hover, #f4f5f8);
	color: var(--kf-mega-strong, #123a6b);
}

.kf-account-menu__item:last-child a {
	border-top: 1px solid var(--kf-mega-border, #e6e6ea);
	margin-top: 4px;
	padding-top: 10px;
}

@media (max-width: 767px) {
	/* Inside the mobile drawer the panel sits in the flow like the megamenu accordion. */
	.kf-account-menu {
		position: static;
		min-width: 0;
		margin: 0;
		padding: 0 12px 6px;
		border: 0;
		border-radius: 0;
		box-shadow: none;
	}

	.kf-account-anchor:hover > .kf-account-menu {
		display: none;
	}

	.kf-account-anchor.is-open > .kf-account-menu,
	.kf-account-anchor.is-open:hover > .kf-account-menu {
		display: block;
	}
}

/* Category banner (ADR-033 §5, ADR-039): the owner uploads one 2.5:1 image per root category.
   .kf-hero: the same treatment for the owner's home / sellers banners placed as image blocks (ADR-039 §5). */
.kf-cat-banner,
.kf-hero {
	margin: 0 0 22px;
	overflow: hidden;
	border-radius: 14px;
	line-height: 0;
	background: #0b1d3a; /* banner series ground colour, shown while the image streams in */
}

.kf-hero a {
	display: block;
	line-height: 0;
}

.kf-cat-banner__img,
.kf-cat-banner img,
.kf-hero img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 2.5 / 1; /* reserve the box before the image arrives: no layout shift */
	object-fit: cover;
	object-position: right center; /* logo + title live in the right half of every banner */
}

/* Phones: a 2.5:1 strip is ~150px tall on a 375px screen and the baked-in text becomes unreadable.
   Show a taller, right-anchored crop instead: the text column stays whole, the illustration is trimmed. */
@media (max-width: 640px) {
	.kf-cat-banner,
	.kf-hero {
		border-radius: 10px;
		margin-bottom: 16px;
	}

	.kf-cat-banner__img,
	.kf-cat-banner img,
	.kf-hero img {
		aspect-ratio: 5 / 3;
	}
}

/* Real call-to-action over the home hero (owner request 2026-09-17: the button was baked into the image before).
   Desktop: sits over the empty dark floor in the bottom-left corner of the 2.5:1 banner. Phones: the left side is
   cropped away, so the button drops below the image as a full-width bar. */
.kf-hero--home {
	position: relative;
	overflow: visible;
	line-height: 0;
}

.kf-hero--home a:first-child {
	overflow: hidden;
	border-radius: 14px;
}

.wp-block-image.kf-hero > .kf-hero__cta {
	position: absolute;
	width: auto; /* beats the block editor's `.alignwide > a { width: 100% }` */
	left: 4.5%;
	bottom: 9%;
	display: inline-block;
	line-height: 1.2;
	padding: 0.85em 1.9em;
	border-radius: 999px;
	background: #ff9f1c; /* the banner's amber "بخوان" tone */
	color: #0b1d3a !important;
	font-size: clamp(14px, 1.25vw, 18px);
	font-weight: 700;
	line-height: 1.2;
	text-decoration: none;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
	transition: transform 0.15s ease, background 0.15s ease;
}

.kf-hero .kf-hero__cta:hover,
.kf-hero .kf-hero__cta:focus-visible {
	background: #ffb347;
	transform: translateY(-2px);
	color: #0b1d3a !important;
}

@media (max-width: 640px) {
	.kf-hero--home a:first-child {
		border-radius: 10px;
	}

	.wp-block-image.kf-hero > .kf-hero__cta {
		position: static;
		display: block;
		margin-top: 10px;
		text-align: center;
		font-size: 16px;
		padding: 0.9em 1em;
		border-radius: 10px;
	}
}

/* Category archives that show a banner: the theme's 250px grey title hero (data-type="type-2") pushed the
   banner below the fold and repeated the name the banner already carries — the owner asked for it to go
   (2026-09-17). The H1 stays in the DOM; the banner's alt text is the category name. */
.kf-cat-has-banner .hero-section[data-type] {
	display: none;
}

.kf-cat-has-banner .kf-cat-banner {
	margin-top: 8px;
}

@media (max-width: 640px) {
	.kf-cat-has-banner .kf-cat-banner {
		margin-top: 4px;
	}
}
