/**
 * LightMega — Frontend styles (desktop)
 *
 * G7: desktop layout — full-width panel with a category sidebar (left) and a
 * product grid (right), replicating the client-approved Oudimmo mockup v4.
 * Loaded ONLY when a mega menu item is actually rendered (conditional enqueue,
 * G2); never globally. Mobile (accordion / slide-in) lands in G8; the desktop
 * panel is simply hidden below the breakpoint here.
 *
 * Design tokens are scoped to .lightmega-panel (not :root) so they never leak
 * into the theme and stay easy to override (basis for Pro theming).
 *
 * @package LightMega
 */

/* ─────────────────────────────────────────────────────────────
   Design tokens (scoped) + local reset

   Two families live here.

   FIXED tokens are internal: the plugin's palette and fonts. Not configurable
   in v1.

   CONFIGURABLE tokens map 1:1 onto LightMega_Settings parameters. The value
   declared here IS the product default, which is what makes the customization
   layer cost nothing: the panel's inline style attribute only ever carries the
   values that DIFFER from these, so a merchant who customizes nothing gets no
   attribute at all. Never move them to :root — scoping them to the element is
   what keeps them travelling with the panel when the JS portals it into <body>,
   and what stops them leaking into the theme.
   ───────────────────────────────────────────────────────────── */
.lightmega-panel {
	/* ── Fixed ── */
	--lm-accent: #c8961e;
	/* Declared, not yet consumed — NOT leftovers to clean up. --lm-accent-hover is
	   the footer button's hover state (G10c); --lm-accent-light is held for the
	   same palette. Kept in the accent family on purpose: a --lm-gold-* sitting
	   next to --lm-accent reads as a second colour when there is only one. */
	--lm-accent-hover: #a87a10;
	--lm-accent-light: #f0c84a;
	--lm-dark: #1a1a1a;
	--lm-white: #ffffff;
	--lm-off: #f7f5f0;
	--lm-border: #e0dbd0;
	--lm-muted: #777;
	--lm-text: #2c2c2c;
	/* Reserved column for the sidebar count. Internal, not a setting: it is used
	   TWICE — as the count's floor and as the description's right inset — and a
	   single declaration is what stops the two from drifting apart. */
	--lm-sidebar-count-width: 26px;

	/* ── Configurable (LightMega_Settings) ── */
	--lm-panel-bg: #ffffff;
	--lm-panel-height: 75vh;
	--lm-panel-max-width: none;
	--lm-panel-radius: 8px;
	--lm-sidebar-width: 290px;
	--lm-sidebar-font-size: 13px;
	--lm-sidebar-desc-font-size: 11px;
	/* Its own colour, NOT --lm-muted: a sidebar description is navigation, a card
	   subtitle is product copy. Sharing a token would mean one cannot be darkened
	   without moving the other two that use it (count, card subtitle). */
	--lm-sidebar-desc-color: #595959;
	--lm-sidebar-radius: 8px;
	--lm-card-min-width: 190px;
	--lm-card-radius: 8px;
	--lm-card-image-ratio: 4 / 3;

	/* Fonts are referenced, never bundled (WP.org privacy + performance): if
	   the theme already serves Montserrat/Lato they are used, else a clean
	   system fallback keeps the panel light. */
	--lm-font-head: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
	--lm-font-body: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.lightmega-panel,
.lightmega-panel * {
	box-sizing: border-box;
}

/* ─────────────────────────────────────────────────────────────
   Panel shell + open state
   ───────────────────────────────────────────────────────────── */
/* The panel is portaled to <body> by JS at init, so position:fixed is relative
   to the viewport (immune to ancestor transform/filter). It therefore no longer
   positions against .lightmega-item, and opening is driven by a class the JS
   toggles on the panel itself — not by :hover on the menu item. */
.lightmega-panel {
	display: none;
	position: fixed;
	left: 0;
	right: 0;
	top: 0; /* refined to the menu item's bottom edge by JS */
	height: var(--lm-panel-height);
	z-index: 9999;
	flex-direction: column;
	overflow: hidden;
	background: var(--lm-panel-bg);
	color: var(--lm-text);
	font-family: var(--lm-font-body);
	text-align: left;
	box-shadow: 0 8px 48px rgba(0, 0, 0, 0.25);
	/* Only the bottom corners, always: a panel that drops from the site header is
	   flush with it, so rounding its top edge would cut a notch out of the bar.
	   One setting, applied to the two corners it can sensibly affect. */
	border-radius: 0 0 var(--lm-panel-radius) var(--lm-panel-radius);
}

/* Boxed layouts: the shell stays full-bleed (it never breaks a theme), while the
   CONTENT can be constrained and centred. Applied to the panel's only two
   children rather than a new wrapper — no extra DOM.

   `width: 100%` is load-bearing, do not drop it: an auto margin on a flex item's
   cross axis SUPPRESSES align-items:stretch, so `margin-inline: auto` alone would
   shrink both children to their content width. With an explicit width there is no
   free space to absorb while max-width is `none` (the default), so the margins
   resolve to zero and layout is unchanged; set a max-width and the same margins
   centre the content. */
.lightmega-panel__header,
.lightmega-panel__body {
	max-width: var(--lm-panel-max-width);
	margin-inline: auto;
	width: 100%;
}

/* Open state, toggled by JS on hover / focus / tap (see lightmega-frontend.js).
   CSS cannot drive this: the panel is detached from its menu item (portaled to
   <body>), so a descendant selector on the item would never match it. */
.lightmega-panel.is-open {
	display: flex;
}

/* Shared dark overlay (created and toggled by JS, appended to <body> so it is
   never trapped in the theme header's stacking context). */
.lightmega-overlay {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	top: 0; /* refined to the panel's top edge by JS, so the header stays clear */
	z-index: 9990;
	background: rgba(0, 0, 0, 0.5);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s ease;
}

.lightmega-overlay.is-visible {
	opacity: 1;
	visibility: visible;
}

/* ─────────────────────────────────────────────────────────────
   Header (dark bar: heading · count · close)
   ───────────────────────────────────────────────────────────── */
.lightmega-panel__header {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	gap: 16px;
	height: 58px;
	padding: 0 28px;
	background: var(--lm-dark);
	border-bottom: 3px solid var(--lm-accent);
}

.lightmega-panel__titles {
	margin-right: auto;
	min-width: 0;
}

.lightmega-panel__heading {
	margin: 0;
	font-family: var(--lm-font-head);
	font-size: 15px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: #fff;
}

.lightmega-panel__count {
	flex-shrink: 0;
	background: var(--lm-accent);
	color: #fff;
	font-family: var(--lm-font-head);
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.05em;
	padding: 3px 12px;
	border-radius: 20px;
	white-space: nowrap;
}

.lightmega-panel__close {
	/* Pin to a perfect circle, defended against theme <button> styles (Astra Pro
	   adds padding / min-width / line-height that otherwise deform this into an
	   oval). Fixed square box + zeroed padding + aspect-ratio belt-and-braces. */
	flex: 0 0 auto;
	box-sizing: border-box;
	width: 34px;
	height: 34px;
	min-width: 34px;
	min-height: 34px;
	padding: 0;
	aspect-ratio: 1 / 1;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	border: 1.5px solid rgba(255, 255, 255, 0.25);
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
	transition: background 0.15s;
}

.lightmega-panel__close:hover,
.lightmega-panel__close:focus-visible {
	background: rgba(255, 255, 255, 0.28);
	outline: none;
}

/* ─────────────────────────────────────────────────────────────
   Body: sidebar + grid
   ───────────────────────────────────────────────────────────── */
.lightmega-panel__body {
	flex: 1;
	display: flex;
	overflow: hidden;
}

/* ─── Left: category sidebar ─── */
.lightmega-panel__sidebar {
	width: var(--lm-sidebar-width);
	flex-shrink: 0;
	overflow-y: auto;
	padding: 8px 0;
	background: #f2efe9;
	border-right: 1px solid var(--lm-border);
	scrollbar-width: thin;
	scrollbar-color: var(--lm-accent) #e0dbd0;
	/* Mirror of the panel radius, and the mirror is deliberate: the sidebar meets
	   the panel's bottom edge, so only its TOP corners can be rounded. */
	border-radius: var(--lm-sidebar-radius) var(--lm-sidebar-radius) 0 0;
}

.lightmega-panel__sidebar::-webkit-scrollbar {
	width: 4px;
}

.lightmega-panel__sidebar::-webkit-scrollbar-thumb {
	background: var(--lm-accent);
	border-radius: 3px;
}

.lightmega-cat {
	display: flex;
	/* The description (G10b) is a third child that takes a full row of its own, so
	   the entry has to be able to wrap.

	   WHAT WRAP ACTUALLY CHANGES (it is not a no-op, and calling it one is what
	   let a regression through): when the line overflows, a nowrap container
	   SHRINKS its flexible items, while a wrap container BREAKS THE LINE first —
	   line breaking runs before shrinking. With the label sized from its content,
	   a long category name therefore stopped shrinking and pushed the count onto a
	   line of its own, left-aligned by justify-content. That happened with or
	   without a description. See .lightmega-cat__label for the fix.

	   align-items applies PER FLEX LINE, so on line 1 (label + count) it decides
	   where the count sits against the label. flex-start anchors it to the label's
	   FIRST line, which is what a two-line category name needs — and what the
	   client's "category title aligned to the top" actually meant. Uniform across
	   the sidebar, never conditional on a description, or entries would disagree. */
	flex-wrap: wrap;
	align-items: flex-start;
	justify-content: space-between;
	gap: 2px 10px;
	width: 100%;
	padding: 11px 18px;
	border: 0;
	border-left: 3px solid transparent;
	background: none;
	font-family: var(--lm-font-head);
	font-size: var(--lm-sidebar-font-size);
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: #444;
	text-align: left;
	text-decoration: none; /* the entry is an <a> (B1) — never underline it */
	cursor: pointer;
	transition: background 0.15s, color 0.15s, border-color 0.15s;
}

/* A row without a destination URL renders as an inert <span> (B1): it still
   previews its section on hover/focus, but it is not clickable, so it must not
   masquerade as a link. */
span.lightmega-cat {
	cursor: default;
}

.lightmega-cat:hover,
.lightmega-cat:focus-visible,
.lightmega-cat.is-active {
	/* TODO (accent_color, G11): this is --lm-accent at 8% written by hand. CSS
	   cannot derive an alpha from a hex custom property, so the day the accent
	   becomes configurable this tint will NOT follow it. Fix by storing the
	   accent as RGB components and composing rgb(var(--lm-accent-rgb) / 8%). */
	background: rgba(200, 150, 30, 0.08);
	color: var(--lm-accent);
	border-left-color: var(--lm-accent);
	outline: none;
}

/* `flex: 1 1 0` is what keeps the count on the label's line under flex-wrap.
   With a content-based basis the label claims its preferred width, the line
   overflows, and a WRAPPING container resolves that by breaking rather than
   shrinking — so the count dropped below. A zero basis means the label defends no
   preferred width: the line always fits, and the label then grows into whatever
   space the count leaves. Text wrapping inside the label is unchanged, because the
   width it ends up with is the same one shrinking used to produce.
   `min-width: 0` removes the automatic min-content floor, so a single very long
   word cannot re-create the overflow that starts the whole chain. */
.lightmega-cat__label {
	flex: 1 1 0;
	min-width: 0;
	line-height: 1.3;
}

/* Row description (G10b). `flex: 0 0 100%` is what pushes it onto its own line
   under name + count — no wrapper element needed.
   The four resets are not cosmetic: .lightmega-cat styles a short uppercase nav
   label (uppercase, letter-spaced, semibold, display font), and a sentence
   inheriting that is unreadable. The explicit colour also stops the entry's hover
   rule from turning the description gold along with the name.
   The clamp is the real length guarantee — MAX_DESCRIPTION caps what is STORED,
   but how much fits depends on --lm-sidebar-width, which is configurable. */
.lightmega-cat__desc {
	flex: 0 0 100%;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	font-family: var(--lm-font-body);
	font-size: var(--lm-sidebar-desc-font-size);
	font-weight: 400;
	line-height: 1.4;
	letter-spacing: normal;
	text-transform: none;
	color: var(--lm-sidebar-desc-color);
	/* Stop short of the count's column instead of running under it, so the sidebar
	   reads as two columns. Paired with the count's min-width below: both come from
	   the same token, so the reserved width and the inset cannot disagree. */
	padding-right: calc(var(--lm-sidebar-count-width) + 10px);
}

.lightmega-cat__count {
	flex-shrink: 0;
	/* A floor, not a fixed width: it makes the reserved column exact rather than
	   estimated, and lines up one- and two-digit counts down the sidebar. Counts of
	   three digits or more simply grow past it. */
	min-width: var(--lm-sidebar-count-width);
	text-align: center;
	background: var(--lm-border);
	color: var(--lm-muted);
	font-size: 9px;
	font-weight: 700;
	padding: 1px 6px;
	border-radius: 8px;
	transition: background 0.15s, color 0.15s;
}

.lightmega-cat:hover .lightmega-cat__count,
.lightmega-cat:focus-visible .lightmega-cat__count,
.lightmega-cat.is-active .lightmega-cat__count {
	background: var(--lm-accent);
	color: #fff;
}

/* ─── Right: product grid ─── */
.lightmega-panel__grid {
	flex: 1;
	overflow-y: auto;
	padding: 22px 26px 36px;
	scrollbar-width: thin;
	scrollbar-color: var(--lm-accent) #ddd;
}

.lightmega-panel__grid::-webkit-scrollbar {
	width: 4px;
}

.lightmega-panel__grid::-webkit-scrollbar-thumb {
	background: var(--lm-accent);
	border-radius: 3px;
}

.lightmega-section {
	display: none;
}

.lightmega-section.is-active {
	display: block;
}

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

/* ─────────────────────────────────────────────────────────────
   Product card
   ───────────────────────────────────────────────────────────── */
.lightmega-card {
	position: relative;
	margin: 0;
	padding: 0;
	list-style: none;
	/* Height floor for the lone-card case: a row with a single short card has no
	   taller neighbour for the grid's align-items:stretch to match, so without a
	   floor it renders shorter than sibling rows.
	   G10d NOTE: this no longer binds anywhere in the supported range. It was sized
	   against a 100px fixed media box; now the media is ratio-sized, so at the
	   narrowest allowed card (140px) it is already ~105px tall and the natural card
	   height clears 200px on its own. Kept because removing it would be a behaviour
	   change with nothing to gain — but do not read it as the current floor. */
	min-height: 200px;
}

.lightmega-card__link {
	display: block;
	position: relative;
	height: 100%;
	background: var(--lm-white);
	border: 1.5px solid var(--lm-border);
	border-radius: var(--lm-card-radius);
	overflow: hidden;
	color: inherit;
	text-decoration: none;
	transition: transform 0.22s, box-shadow 0.22s, border-color 0.22s, background 0.22s;
}

.lightmega-card__link:hover,
.lightmega-card__link:focus-visible {
	transform: translateY(-4px);
	/* TODO (accent_color, G11): hardcoded --lm-accent at 18% — see the note on
	   .lightmega-cat:hover; it will not follow a configurable accent. */
	box-shadow: 0 12px 32px rgba(200, 150, 30, 0.18);
	border-color: var(--lm-accent);
	background: #fffdf5;
	outline: none;
}

/* Media: positioning context for the top-right badges.
   The height comes from the RATIO, not from a fixed value: it is computed from the
   box's width during layout, before the image loads, so the space is reserved just
   as the old fixed height reserved it — the zero-CLS promise is unchanged, and the
   ratio also gives Lighthouse the explicit sizing signal it looks for. What DOES
   change is that the media now grows with the card instead of staying 100px while
   the card widens. */
.lightmega-card__media {
	position: relative;
	display: block;
	width: 100%;
	aspect-ratio: var(--lm-card-image-ratio);
	overflow: hidden;
	background: #e4e0d8;
}

.lightmega-card__image {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	object-fit: cover;
	transition: transform 0.35s;
}

.lightmega-card__link:hover .lightmega-card__image,
.lightmega-card__link:focus-visible .lightmega-card__image {
	transform: scale(1.07);
}

/* Hover "go" affordance — purely DECORATIVE. Anchored to the card link and placed
   BOTTOM-RIGHT (below the description), leaving the top-right corner free for the
   badges (up to 3 in Pro). A filled gold disc with a white arrow gives clear
   contrast on the white/cream card, where the old white disc used to blend in.
   Pure ::after — zero extra DOM — and pointer-events:none so it never becomes a
   second click target: the whole card is already the product link. */
.lightmega-card__link::after {
	content: "\2192"; /* → */
	position: absolute;
	right: 9px;
	bottom: 9px;
	width: 22px;
	height: 22px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: var(--lm-accent);
	color: var(--lm-white);
	font-family: var(--lm-font-head);
	font-size: 11px;
	font-weight: 700;
	line-height: 1;
	/* TODO (accent_color, G11): hardcoded --lm-accent at 35% — see the note on
	   .lightmega-cat:hover; it will not follow a configurable accent. */
	box-shadow: 0 2px 6px rgba(200, 150, 30, 0.35);
	opacity: 0;
	transform: translateY(3px);
	pointer-events: none;
	transition: opacity 0.18s, transform 0.18s;
}

.lightmega-card__link:hover::after,
.lightmega-card__link:focus-visible::after {
	opacity: 1;
	transform: translateY(0);
}

/* The extra bottom padding reserves a clear strip for the hover "go" arrow
   (::after, bottom-right). The arrow's box reaches ~31px up from the card's
   bottom edge; a 32px bottom padding keeps the last line of text — title OR
   description, whichever ends lowest — just above it, so the arrow never
   overlaps the words (reported on the live site). B1/B2. */
.lightmega-card__body {
	display: block;
	padding: 9px 11px 32px;
}

.lightmega-card__title {
	display: block;
	font-family: var(--lm-font-head);
	font-size: 13px;
	font-weight: 700;
	line-height: 1.3;
	color: var(--lm-dark);
	margin-bottom: 4px;
	transition: color 0.18s;
}

.lightmega-card__link:hover .lightmega-card__title,
.lightmega-card__link:focus-visible .lightmega-card__title {
	color: var(--lm-accent);
}

/* Descriptions only: clamp to 3 lines so the text block height is uniform across
   cards (the subtitle is already truncated server-side in G5c; this evens out the
   visual height). Titles are deliberately NOT clamped — Oudimmo product names
   carry the model (AKUPAN, ADAMANT FireSafe, EXIST ART) and must read in full. */
.lightmega-card__subtitle {
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
	font-size: 11.5px;
	font-weight: 300;
	line-height: 1.5;
	color: var(--lm-muted);
}

/* ─────────────────────────────────────────────────────────────
   Badges (FREE: fixed top-right)
   ───────────────────────────────────────────────────────────── */
/* The width cap belongs HERE, not on the badge. This box is absolutely positioned
   with only `right`, so its width is shrink-to-fit — a max-width on the badge would
   resolve against a parent that is itself sized by its content. Capping the
   container against the media box (its containing block) is what actually bounds
   the row; 14px is the two 7px offsets. */
.lightmega-badges {
	position: absolute;
	display: flex;
	gap: 4px;
	max-width: calc(100% - 14px);
	z-index: 2;
}

.lightmega-badges--tr {
	top: 7px;
	right: 7px;
}

.lightmega-badge {
	font-family: var(--lm-font-head);
	font-size: 8px;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	padding: 2px 6px;
	border-radius: 3px;
	color: #fff;
	/* nowrap stays — a badge reads as one token, never two lines. The ellipsis is
	   the structural guarantee behind MAX_BADGE_TEXT: 20 characters fit a 190px
	   card and overflow a 140px one, and card_min_width is configurable, so the
	   character count alone can promise nothing.
	   All three declarations are required together: text-overflow needs overflow
	   hidden, and a flex item will not shrink below its content width without
	   min-width: 0 — leave that out and the ellipsis never appears. */
	white-space: nowrap;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Fixed FREE badge set: new | sale | eco | premium (+ default fallback). */
.lightmega-badge--new {
	background: var(--lm-accent);
}

.lightmega-badge--sale {
	background: #c0392b;
}

.lightmega-badge--eco {
	background: #27ae60;
}

.lightmega-badge--premium {
	background: var(--lm-dark);
}

.lightmega-badge--default {
	background: var(--lm-muted);
}

/* ─────────────────────────────────────────────────────────────
   Reduced motion: honor the user preference (a11y + perf)
   ───────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
	.lightmega-panel *,
	.lightmega-overlay {
		transition: none !important;
	}

	.lightmega-card__link:hover,
	.lightmega-card__link:focus-visible {
		transform: none;
	}

	.lightmega-card__link:hover .lightmega-card__image,
	.lightmega-card__link:focus-visible .lightmega-card__image {
		transform: none;
	}
}

/* ─────────────────────────────────────────────────────────────
   Responsive: hide the desktop panel below the breakpoint.
   The real mobile experience (accordion / slide-in) is G8.
   ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
	.lightmega-panel {
		display: none !important;
	}

	.lightmega-overlay {
		display: none !important;
	}
}
