/**
 * Collection Category Sidebar — front-end styles.
 *
 * Renders a hierarchical, accordion-style tree of product categories on
 * the /new/ + /sale/ archives. Visually mirrors .ims-subcategory-nav so
 * collection pages feel consistent with the existing parent-category
 * archive layout. Width is driven by --ims-filter-sidebar-width set in
 * assets/css/product-listing.css.
 *
 * @package IMS_by_Soul_Country
 */

.ims-collection-sidebar {
	background: var(--ims-bg-white, #ffffff);
	border: 1px solid var(--color-border, #e5e7eb);
	border-radius: 8px;
	overflow: hidden;
	position: sticky;
	top: 2rem;
}

.ims-collection-sidebar__header {
	padding: 1rem 1.25rem;
	background: var(--ims-bg-white, #ffffff);
	border-bottom: 1px solid var(--color-border, #e5e7eb);
}

.ims-collection-sidebar__title {
	font-size: 1rem;
	font-weight: 600;
	color: var(--color-dark, #1f2937);
	margin: 0;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

/* ==========================================================================
   Tree
   ========================================================================== */

.ims-collection-sidebar__list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.ims-collection-sidebar__list--root > .ims-collection-sidebar__item {
	border-bottom: none;
}

/* Each row is a flex container holding [link, optional toggle]. */
.ims-collection-sidebar__row {
	display: flex;
	align-items: stretch;
	gap: 0.25rem;
}

.ims-collection-sidebar__link {
	flex: 1;
	min-width: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.625rem 0.75rem 0.625rem 1.25rem;
	color: var(--color-dark, #1f2937);
	text-decoration: none;
	font-size: 0.875rem;
	line-height: 1.3;
	transition: background-color 0.15s ease, color 0.15s ease;
	min-height: 2.5rem;
}

.ims-collection-sidebar__link:hover,
.ims-collection-sidebar__link:focus-visible {
	background: var(--color-bg-light, #f3f4f6);
	color: var(--color-cta, #2563eb);
	text-decoration: none;
}

/* Active state — bold + accent stripe down the left edge of the row. */
.ims-collection-sidebar__item.is-active > .ims-collection-sidebar__row > .ims-collection-sidebar__link {
	background: var(--color-bg-light, #f3f4f6);
	color: var(--color-cta, #1f2937);
	font-weight: 600;
	box-shadow: inset 3px 0 0 0 var(--color-cta, #2563eb);
}

/* Subtle indicator that this branch contains the active leaf. */
.ims-collection-sidebar__item.is-on-active-branch > .ims-collection-sidebar__row > .ims-collection-sidebar__link {
	color: var(--color-dark, #1f2937);
	font-weight: 500;
}

.ims-collection-sidebar__name {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ims-collection-sidebar__count {
	color: var(--color-muted, #6b7280);
	font-size: 0.8125rem;
	font-variant-numeric: tabular-nums;
	flex-shrink: 0;
}

.ims-collection-sidebar__item.is-active > .ims-collection-sidebar__row > .ims-collection-sidebar__link .ims-collection-sidebar__count {
	color: inherit;
}

/* "All categories" row sits visually flush like the rest, with a subtle
   tonal background to flag it as the un-filtered fallback. */
.ims-collection-sidebar__item--all {
	background: var(--color-bg-light, #f9fafb);
}

/* ==========================================================================
   Expand/collapse chevron
   ========================================================================== */

.ims-collection-sidebar__toggle {
	flex: 0 0 auto;
	width: 2.25rem;
	display: flex;
	align-items: center;
	justify-content: center;
	background: transparent;
	border: none;
	color: var(--color-muted, #6b7280);
	cursor: pointer;
	padding: 0;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.ims-collection-sidebar__toggle:hover,
.ims-collection-sidebar__toggle:focus-visible {
	background: var(--color-bg-light, #f3f4f6);
	color: var(--color-cta, #2563eb);
	outline: none;
}

.ims-collection-sidebar__toggle svg {
	transition: transform 0.18s ease;
}

.ims-collection-sidebar__item.is-expanded > .ims-collection-sidebar__row > .ims-collection-sidebar__toggle svg {
	transform: rotate(180deg);
}

/* ==========================================================================
   Children container — collapsed by default, expanded via .is-expanded.
   ========================================================================== */

.ims-collection-sidebar__children {
	list-style: none;
	margin: 0;
	padding: 0;
	display: none;
	background: var(--color-bg-light, #fafafa);
}

.ims-collection-sidebar__item.is-expanded > .ims-collection-sidebar__children {
	display: block;
}

/* Indent each level by ~0.75rem so the hierarchy reads at a glance.
   Applied via classes on the <li> rather than nested CSS so depths beyond
   2 keep getting the right left padding without explosion. */
.ims-collection-sidebar__item.is-depth-1 > .ims-collection-sidebar__row > .ims-collection-sidebar__link { padding-left: 2rem;    }
.ims-collection-sidebar__item.is-depth-2 > .ims-collection-sidebar__row > .ims-collection-sidebar__link { padding-left: 2.75rem; }
.ims-collection-sidebar__item.is-depth-3 > .ims-collection-sidebar__row > .ims-collection-sidebar__link { padding-left: 3.5rem;  }
.ims-collection-sidebar__item.is-depth-4 > .ims-collection-sidebar__row > .ims-collection-sidebar__link { padding-left: 4.25rem; }

/* ==========================================================================
   Empty state + responsive
   ========================================================================== */

.ims-collection-sidebar__empty {
	padding: 1rem 1.25rem;
	margin: 0;
	color: var(--color-muted, #6b7280);
	font-size: 0.875rem;
	font-style: italic;
}

@media ( max-width: 900px ) {
	.ims-collection-sidebar {
		position: static;
		margin-bottom: 1.5rem;
	}
}

/* ==========================================================================
   Full-path hover tooltip
   --------------------------------------------------------------------------
   Lives directly under <body>, escapes the sidebar's overflow:hidden /
   sticky-positioning context, and is positioned by JS using
   getBoundingClientRect (`position: fixed` so the coordinates map straight
   to viewport pixels). Hidden by default; only revealed when JS sets
   `.is-visible`.
   ========================================================================== */

.ims-collection-sidebar-tip {
	position: fixed;
	top: 0;
	left: -9999px;
	z-index: 10000;
	max-width: min(420px, 70vw);
	padding: 0.5rem 0.75rem;
	background: var(--color-dark, #1f2937);
	color: #ffffff;
	font-size: 0.8125rem;
	line-height: 1.4;
	font-weight: 500;
	border-radius: 6px;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
	pointer-events: none;
	opacity: 0;
	transform: translateX(-4px);
	transition: opacity 0.12s ease, transform 0.12s ease;
	white-space: normal;
	overflow-wrap: anywhere;
}

.ims-collection-sidebar-tip.is-visible {
	opacity: 1;
	transform: translateX(0);
}

.ims-collection-sidebar-tip.is-flipped {
	transform: translateX(4px);
}

.ims-collection-sidebar-tip.is-flipped.is-visible {
	transform: translateX(0);
}

/* Caret pointing at the row. Drawn as a CSS arrow using border tricks.
   Sits on the left edge by default, on the right edge when flipped. */
.ims-collection-sidebar-tip::before {
	content: '';
	position: absolute;
	top: 50%;
	width: 0;
	height: 0;
	transform: translateY(-50%);
	border-style: solid;
}

.ims-collection-sidebar-tip:not(.is-flipped)::before {
	left: -6px;
	border-width: 6px 6px 6px 0;
	border-color: transparent var(--color-dark, #1f2937) transparent transparent;
}

.ims-collection-sidebar-tip.is-flipped::before {
	right: -6px;
	border-width: 6px 0 6px 6px;
	border-color: transparent transparent transparent var(--color-dark, #1f2937);
}

@media ( max-width: 900px ) {
	/* Touch devices don't really do hover; skip the tooltip entirely. */
	.ims-collection-sidebar-tip {
		display: none !important;
	}
}

/* ==========================================================================
   Slide-out drawer
   --------------------------------------------------------------------------
   On every viewport the category list collapses behind a fixed vertical
   "Categories" tab on the left edge. Clicking the tab slides the panel in
   from the left over the listing; picking a category animates it back out.

   The panel markup is the same <aside class="ims-collection-sidebar"> — JS
   relocates it to <body>, adds .ims-cat-drawer-panel, and injects the tab +
   backdrop. Two-class selectors below intentionally out-specify the base
   .ims-collection-sidebar rules (sticky/static positioning) so the drawer
   wins regardless of source order.
   ========================================================================== */

/* Vertical tab pinned to the left edge — the only thing visible at rest. */
.ims-cat-drawer-tab {
	position: fixed;
	left: 0;
	top: 50%;
	transform: translateY(-50%);
	z-index: 9997;
	writing-mode: vertical-rl;
	text-orientation: mixed;
	background: var(--color-dark, #1f2937);
	color: #ffffff;
	border: none;
	border-radius: 0 6px 6px 0;
	padding: 0.875rem 0.5rem;
	font-size: 0.8125rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	cursor: pointer;
	box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
	transition: background-color 0.2s ease;
}

.ims-cat-drawer-tab:hover,
.ims-cat-drawer-tab:focus-visible {
	background: var(--color-cta, #111827);
	outline: none;
}

.ims-cat-drawer-tab.is-hidden {
	display: none;
}

/* Collection-themed tab: red on the Sale archive, green on the New archive
   (matching the SALE! / +NEW nav buttons and product badges). */
.ims-cat-drawer-tab--sale {
	background: #DC2626;
}

.ims-cat-drawer-tab--sale:hover,
.ims-cat-drawer-tab--sale:focus-visible {
	background: #B91C1C;
}

.ims-cat-drawer-tab--new {
	background: #16A34A;
}

.ims-cat-drawer-tab--new:hover,
.ims-cat-drawer-tab--new:focus-visible {
	background: #15803D;
}

/* Dimmed backdrop behind the open panel; click to dismiss. */
.ims-cat-drawer-overlay {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.4);
	z-index: 9998;
}

.ims-cat-drawer-overlay.is-visible {
	display: block;
}

/* The panel itself — off-screen left by default, slides in on .is-open. */
.ims-collection-sidebar.ims-cat-drawer-panel {
	position: fixed;
	top: 0;
	left: 0;
	height: 100%;
	width: 360px;
	max-width: 90vw;
	margin: 0;
	z-index: 9999;
	border: none;
	border-radius: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
	transform: translateX(-100%);
	transition: transform 0.3s ease;
}

.ims-collection-sidebar.ims-cat-drawer-panel.is-open {
	transform: translateX(0);
}

/* Inside the drawer the panel is wide enough to show the full name, so let
   the labels wrap instead of truncating with an ellipsis. */
.ims-cat-drawer-panel .ims-collection-sidebar__name {
	white-space: normal;
	overflow: visible;
	text-overflow: clip;
}

/* Header becomes a flex row so the injected close button sits opposite the
   title. */
.ims-cat-drawer-panel .ims-collection-sidebar__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	position: sticky;
	top: 0;
	z-index: 1;
}

.ims-cat-drawer-close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	flex-shrink: 0;
	border: none;
	background: var(--color-bg-light, #f3f4f6);
	border-radius: 6px;
	color: var(--color-dark, #1f2937);
	cursor: pointer;
	padding: 0;
	transition: background-color 0.2s ease;
}

.ims-cat-drawer-close:hover,
.ims-cat-drawer-close:focus-visible {
	background: var(--color-border, #e5e7eb);
	outline: none;
}

.ims-cat-drawer-close svg {
	width: 18px;
	height: 18px;
}

/* Lock background scroll while the drawer is open. */
body.ims-cat-drawer-open {
	overflow: hidden;
}

/* On phones the panel covers the full width of the browser. */
@media ( max-width: 768px ) {
	.ims-collection-sidebar.ims-cat-drawer-panel {
		width: 100vw;
		max-width: 100vw;
	}
}
