/**
 * Foliora: the sidebar and its widgets (Customizer > Foliora Options >
 * Sidebar). Loaded only where a sidebar shows. Where it sits is set by the
 * page it is on: single.css (beside a post or page) and posts.css (beside a
 * post list). Widgets: Appearance > Widgets > Sidebar.
 *
 * @package Foliora
 */

.foliora-sidebar {
	min-width: 0;
}

@media (min-width: 992px) {
	/* Customizer > Sidebar > Keep in view while scrolling. sidebar.js works
	   out the offset: below the sticky header when the sidebar fits on the
	   screen, otherwise a negative offset so it stops with its last widget
	   in view. */
	.foliora-sidebar.is-sticky {
		position: sticky;
		top: var(--foliora-sidebar-top, calc(var(--foliora-sticky-h, 0px) + 24px));
	}

	body.admin-bar .foliora-sidebar.is-sticky {
		top: var(--foliora-sidebar-top, calc(var(--foliora-sticky-h, 0px) + 56px));
	}
}

/* Widgets: each one is a card with a thin accent line on top, a centred
   small-caps title band and a padded body. Resets the template's sidebar
   card (style.css: .widget) and section padding (default.css); widgets
   are <section> elements. */
.foliora-sidebar {
	--foliora-widget-pad: 28px;
}

.foliora-sidebar .widget {
	position: static;
	overflow: visible;
	margin: 0;
	padding: 0 var(--foliora-widget-pad) var(--foliora-widget-pad);
	border: 1px solid var(--foliora-line);
	border-top: 2px solid var(--foliora-accent);
	/* Less rounded than the post cards, so the accent reads as a line. */
	border-radius: calc(12px * var(--foliora-corner-scale, 1));
	background: var(--foliora-bg);
	box-shadow: none;
}

/* Blocks bring their own bottom margins; the card's padding is the space. */
.foliora-sidebar .widget > :last-child,
.foliora-sidebar .widget > :last-child > :last-child {
	margin-bottom: 0;
}

.foliora-sidebar .widget + .widget {
	margin-top: 32px;
}

/* A widget without a title still gets room at the top. */
.foliora-sidebar .widget:not(:has(.widget-title, .wp-block-heading, .wp-block-search__label:not(.screen-reader-text))) {
	padding-top: var(--foliora-widget-pad);
}

/* Title band: full card width, a line below. Classic widgets use
   .widget-title; block widgets use a heading block (or the search label).
   A Group's first heading counts too: classic themes wrap the Group's
   blocks in .wp-block-group__inner-container (WordPress's default widgets,
   "Recent Posts", "Archives", are built like this). */
.foliora-sidebar .widget-title,
.foliora-sidebar .widget > .wp-block-heading,
.foliora-sidebar .widget > .wp-block-group > .wp-block-heading:first-child,
.foliora-sidebar .widget > .wp-block-group > .wp-block-group__inner-container > .wp-block-heading:first-child,
.foliora-sidebar .wp-block-search__label {
	display: block;
	width: auto !important; /* The search block's own CSS sets 100%. */
	margin: 0 calc(var(--foliora-widget-pad) * -1) 24px;
	padding: 18px var(--foliora-widget-pad) 17px;
	border-bottom: 1px solid var(--foliora-line);
	font-family: var(--foliora-font-heading);
	font-size: 12px !important;
	line-height: 1.4;
	font-weight: 600;
	letter-spacing: 0.14em;
	text-align: center;
	text-transform: uppercase;
	color: var(--foliora-text);
}

/* In the block widget editor a heading added on its own is a separate
   widget: it becomes the top of a card and the widget below its body.
   "On its own" ignores the Customizer preview's edit button, which the
   preview adds inside every widget. */
.foliora-sidebar .widget:has(> .wp-block-heading):not(:has(> :not(.wp-block-heading, .customize-partial-edit-shortcut))) {
	padding-bottom: 0;
	border-bottom: 0;
	border-bottom-left-radius: 0;
	border-bottom-right-radius: 0;
}

.foliora-sidebar .widget:has(> .wp-block-heading):not(:has(> :not(.wp-block-heading, .customize-partial-edit-shortcut))) > .wp-block-heading {
	margin-bottom: 0;
}

.foliora-sidebar .widget:has(> .wp-block-heading):not(:has(> :not(.wp-block-heading, .customize-partial-edit-shortcut))) + .widget {
	margin-top: 0;
	padding-top: 24px; /* Same as below a built-in title. */
	border-top: 0;
	border-top-left-radius: 0;
	border-top-right-radius: 0;
}

.foliora-sidebar .widget p {
	margin: 0 0 12px;
	font-size: calc(15px * var(--foliora-text-scale, 1));
	line-height: calc(1.7 + var(--foliora-leading-adjust, 0));
	color: var(--foliora-body);
}

.foliora-sidebar .widget p:last-child {
	margin-bottom: 0;
}

.foliora-sidebar a {
	padding-bottom: 0;
	background-image: none;
	color: var(--foliora-text);
	text-decoration: none;
	transition: color 0.2s ease;
}

.foliora-sidebar a:hover {
	color: var(--foliora-link);
}

.foliora-sidebar a:focus-visible {
	outline: 3px solid var(--foliora-link);
	outline-offset: 3px;
}

/* Lists (categories, archives, latest posts, pages, menus): rows with
   dividers. The template makes every "ul li" inline-block with a grey
   !important colour. */
.foliora-sidebar .widget ul,
.foliora-sidebar .widget ol {
	margin: 0;
	padding: 0;
	list-style: none;
}

.foliora-sidebar .widget li {
	display: block;
	margin: 0;
	padding: 13px 0;
	border-bottom: 1px solid var(--foliora-line);
	font-size: calc(15px * var(--foliora-text-scale, 1));
	line-height: 1.5;
	color: var(--foliora-muted) !important;
}

.foliora-sidebar .widget li::before {
	display: none;
}

.foliora-sidebar .widget li:first-child {
	padding-top: 0;
}

.foliora-sidebar .widget li:last-child {
	padding-bottom: 0;
	border-bottom: 0;
}

.foliora-sidebar .widget li li {
	padding: 10px 0 0 18px;
	border: 0;
}

.foliora-sidebar .widget li a {
	font-weight: 500;
}

/* Categories and archives: a small ring before the name, the post count
   pushed to the right ("Travel ... (10)"). */
.foliora-sidebar :is(.wp-block-categories, .wp-block-archives, .widget_categories, .widget_archive) li {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0 8px;
	font-size: 13px;
}

.foliora-sidebar :is(.wp-block-categories, .wp-block-archives, .widget_categories, .widget_archive) li > a {
	display: inline-flex;
	flex: 1;
	align-items: baseline;
	gap: 12px;
	font-size: calc(15px * var(--foliora-text-scale, 1));
}

.foliora-sidebar :is(.wp-block-categories, .wp-block-archives, .widget_categories, .widget_archive) li > a::before {
	content: "";
	flex: none;
	width: 6px;
	height: 6px;
	border: 1.5px solid var(--foliora-accent);
	border-radius: 50%;
	transform: translateY(-1px);
}

.foliora-sidebar :is(.wp-block-categories, .wp-block-archives, .widget_categories, .widget_archive) li > ul {
	flex-basis: 100%;
}

/* Dates under a title (classic Recent Posts, Latest Comments). The Latest
   Posts block is styled in blocks.css. */
.foliora-sidebar .post-date,
.foliora-sidebar .wp-block-latest-comments__comment-date {
	display: block;
	margin-top: 3px;
	font-size: 13px;
	color: var(--foliora-muted);
}

.foliora-sidebar .widget img {
	max-width: 100%;
	height: auto;
	border-radius: calc(8px * var(--foliora-corner-scale, 1));
}

/* Gallery and image grids (like an Instagram-style block of photos). */
/* WordPress sizes each photo from its gap variable, so the variable must
   match the real gap or the last photo of a row wraps (4 columns showed as
   3). Photos keep one size: a short last row does not stretch to fill. */
.foliora-sidebar .wp-block-gallery {
	--wp--style--gallery-gap-default: 8px;
	gap: 8px;
}

.foliora-sidebar .wp-block-gallery.has-nested-images figure.wp-block-image {
	flex-grow: 0;
}

.foliora-sidebar .wp-block-gallery .wp-block-image img {
	aspect-ratio: 1 / 1;
	object-fit: cover;
}

/* Tag cloud: chips. */
.foliora-sidebar .wp-block-tag-cloud,
.foliora-sidebar .tagcloud {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0;
}

.foliora-sidebar .wp-block-tag-cloud a,
.foliora-sidebar .tagcloud a {
	display: inline-flex;
	align-items: center;
	height: 32px;
	margin: 0;
	padding: 0 14px;
	border: 1px solid var(--foliora-line-strong);
	border-radius: 999px;
	font-size: 13px !important;
	font-weight: 500;
}

.foliora-sidebar .wp-block-tag-cloud a:hover,
.foliora-sidebar .tagcloud a:hover {
	border-color: var(--foliora-accent);
}

/* Search block. */
.foliora-sidebar .wp-block-search__inside-wrapper {
	display: flex;
	gap: 8px;
}

.foliora-sidebar .wp-block-search__input {
	flex: 1;
	min-width: 0;
	height: 46px;
	margin: 0; /* The template gives every input a 15px bottom margin. */
	padding: 0 14px;
	border: 1px solid var(--foliora-field);
	border-radius: calc(10px * var(--foliora-corner-scale, 1));
	background: var(--foliora-bg);
	font-size: 15px;
	color: var(--foliora-text);
}

.foliora-sidebar .wp-block-search__button {
	height: 46px;
	margin: 0;
	padding: 0 18px;
	border: 0;
	border-radius: calc(10px * var(--foliora-corner-scale, 1));
	background: var(--foliora-accent);
	color: var(--foliora-on-accent);
	font-family: var(--foliora-font-heading);
	font-size: 14px;
	font-weight: 600;
}

@media (min-width: 992px) and (max-width: 1199px) {
	.foliora-sidebar {
		--foliora-widget-pad: 22px;
	}
}

/* Customizer preview only: shown while the sidebar has no widgets. */
.foliora-sidebar__placeholder {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin: 0;
	padding: 28px 24px;
	border: 1px dashed var(--foliora-line-strong);
	border-radius: var(--foliora-card-radius);
	background: var(--foliora-surface);
	font-size: 14px;
	line-height: 1.5;
	color: var(--foliora-muted);
}

.foliora-sidebar__placeholder strong {
	font-family: var(--foliora-font-heading);
	font-size: 16px;
	color: var(--foliora-text);
}
