/**
 * Sidebar and widget component (04-content-areas/10-sidebar-system.md §4,
 * 04-content-areas/11-widget-system.md §5).
 *
 * Enqueued by Kivora\Assets\Manager only when a widget area actually renders
 * on the current request (04-css-architecture.md §5).
 */

.kivora-sidebar {
	display: flex;
	flex-direction: column;
	gap: var(--kivora-spacing-md);
}

/*
 * Sticky sidebar (10-sidebar-system.md §8). Scoped to the breakpoint where
 * the sidebar is its own column — sticky on a stacked mobile layout would
 * pin the widgets over the content.
 */
@media (min-width: 782px) {
	.kivora-sidebar--sticky {
		position: sticky;
		top: var(--kivora-spacing-md);
		max-height: calc(100vh - var(--kivora-spacing-xl));
		overflow-y: auto;

		/* Room for the focus ring, which the scroll container would clip. */
		padding-inline: 0.25rem;
	}

	/*
	 * Under a sticky header the sidebar has to stick below it: at the plain
	 * offset its top ~2rem sat behind the header, focused widgets included.
	 */
	body:has(.kivora-site-header--sticky) .kivora-sidebar--sticky {
		top: calc(var(--kivora-header-height) + var(--kivora-spacing-md));
		max-height: calc(100vh - var(--kivora-header-height) - var(--kivora-spacing-xl));
	}
}

/* Widget container: separated by spacing plus a subtle rule (§5). */
.kivora-widget {
	padding-block-end: var(--kivora-spacing-md);
	border-block-end: 1px solid color-mix(in srgb, var(--kivora-color-border-muted) 30%, transparent);
}

.kivora-widget:last-child {
	padding-block-end: 0;
	border-block-end: 0;
}

.kivora-widget__title {
	margin-block: 0 var(--kivora-spacing-xs);
	font-size: var(--kivora-font-size-base);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	overflow-wrap: break-word;
}

/*
 * Block-widget headings (Recent Posts, Archives…) arrive as plain h2s at
 * full heading size, which shouts in a 300px column. Set to the h5 step —
 * the same scale as card titles — while keeping the h2 level for the
 * document outline. Classic-widget titles above keep their small-caps label
 * style; this only tames oversized block headings.
 */
.kivora-sidebar .widget_block h2.wp-block-heading {
	font-size: var(--kivora-font-size-h5);
	line-height: 1.3;
	overflow-wrap: break-word;
}

/*
 * Widget content — recent-post links, long URLs, tag soup — must wrap like
 * everything else, or one 85-character post title scrolls the page sideways
 * from inside the sidebar.
 */
.kivora-widget {
	overflow-wrap: break-word;
}

/*
 * Tag cloud as pills: bordered, softly rounded, wrapping with a comfortable
 * gap instead of a ragged inline run.
 */
.widget_tag_cloud .tagcloud {
	display: flex;
	flex-wrap: wrap;
	gap: var(--kivora-spacing-xs);
}

.widget_tag_cloud .tagcloud a {
	padding: 0.125rem var(--kivora-spacing-xs);
	border: var(--kivora-border-width) solid color-mix(in srgb, var(--kivora-color-border-muted) 50%, transparent);
	border-radius: var(--kivora-radius-pill);
	text-decoration: none;
}

.widget_tag_cloud .tagcloud a:hover,
.widget_tag_cloud .tagcloud a:focus-visible {
	border-color: var(--kivora-color-primary);
	color: var(--kivora-color-primary);
}

/* The search block's label sits tight against its field without this. */
.kivora-sidebar .wp-block-search__label,
.kivora-footer-widgets .wp-block-search__label {
	display: block;
	margin-block-end: var(--kivora-spacing-xs);
}

.kivora-widget ul,
.kivora-widget ol {
	margin: 0;
	padding: 0;
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: var(--kivora-spacing-xs);
}

.kivora-widget li ul,
.kivora-widget li ol {
	margin-block-start: var(--kivora-spacing-xs);
	padding-inline-start: var(--kivora-spacing-sm);
}

/*
 * Only list links (recent posts, categories, menus, archives) drop the
 * underline: each one is a whole list item, so it reads as a link by its
 * position. A link inside a Text or paragraph widget keeps the theme.json
 * underline — styled like the prose around it, it was identifiable by
 * nothing at all (WCAG 1.4.1).
 */
.kivora-widget li > a {
	color: var(--kivora-color-foreground);
	text-decoration: none;
}

.kivora-widget li > a:hover,
.kivora-widget li > a:focus-visible {
	color: var(--kivora-color-primary);
	text-decoration: underline;
}

.kivora-widget img {
	height: auto;
}

/* Optional before/after content areas (11-widget-system.md §4). */
.kivora-widget-area {
	display: flex;
	flex-direction: column;
	gap: var(--kivora-spacing-md);
	margin-block: var(--kivora-spacing-md);
}
