/*
 * Sidebar presets.
 *
 * Twenty-three widget treatments and twenty title treatments, all of them built
 * from the tokens the rest of the theme already uses. That is the whole trick:
 * nothing here names a colour. A preset says "surface", "line", "accent", and
 * dark mode, the customiser's palette and a child theme's overrides all keep
 * working without a single one of them being mentioned below.
 *
 * Direction is handled the same way. Every inline offset is written as
 * `inline-start` or `inline-end`, so an Arabic site mirrors these without an
 * RTL stylesheet needing to know they exist. Where a border genuinely means
 * "the left edge of the screen" rather than "the start of the line" — the
 * border-left and border-right presets, which a customer picked by side — the
 * physical property is used on purpose and noted.
 *
 * Every preset is a class on the sidebar, not on each widget, so a widget added
 * tomorrow inherits the treatment without being told about it.
 */

/* ---------------------------------------------------------------- shared -- */

.chr-sidebar__inner > .widget,
.chr-sidebar__inner > section.widget {
	margin-block-end: var(--chr-widget-gap, 32px);
	position: relative;
}

.chr-sidebar__inner > .widget:last-child {
	margin-block-end: 0;
}

/* The presets that draw a container share these, so a change of padding or
   radius is made once rather than twenty-three times. */
.chr-sidebar[class*="chr-sidebar--"] {
	--chr-widget-pad: 22px;
	--chr-widget-radius: 10px;
	--chr-widget-line: var(--chr-border, rgba(128, 128, 128, .22));
}

/* ------------------------------------------------------------- presets --- */

/* Classic — a rule under the title and nothing else. What a newspaper site
   looked like before anybody thought to put a card round it. */
.chr-sidebar--classic .widget {
	padding-block-end: var(--chr-widget-pad);
	border-block-end: 1px solid var(--chr-widget-line);
}

.chr-sidebar--classic .widget:last-child {
	border-block-end: 0;
	padding-block-end: 0;
}

/* Minimal — space alone. */
.chr-sidebar--minimal .widget {
	padding: 0;
	background: none;
	border: 0;
}

/* Modern — a soft surface with a hairline. */
.chr-sidebar--modern .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border: 1px solid var(--chr-widget-line);
	border-radius: var(--chr-widget-radius);
}

/* Elevated — the same, lifted. */
.chr-sidebar--elevated .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border-radius: var(--chr-widget-radius);
	box-shadow: 0 6px 18px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .06);
}

/* Glass — a translucent pane. `backdrop-filter` is progressive: without it the
   background alpha alone still reads as a panel rather than as nothing. */
.chr-sidebar--glass .widget,
.chr-sidebar--soft-glass .widget {
	padding: var(--chr-widget-pad);
	border-radius: var(--chr-widget-radius);
	border: 1px solid rgba(255, 255, 255, .18);
	background: rgba(255, 255, 255, .10);
}

@supports (backdrop-filter: blur(1px)) {
	.chr-sidebar--glass .widget {
		backdrop-filter: blur(14px) saturate(140%);
	}

	.chr-sidebar--soft-glass .widget {
		backdrop-filter: blur(6px) saturate(120%);
	}
}

.chr-sidebar--soft-glass .widget {
	background: rgba(255, 255, 255, .06);
	border-color: rgba(255, 255, 255, .10);
}

/* Card — surface, radius, a quiet shadow. */
.chr-sidebar--card .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border-radius: var(--chr-widget-radius);
	box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}

/* The four edge treatments. Left and right are physical on purpose: somebody
   choosing "border left" chose a side of the screen, and mirroring it in
   Arabic would be answering a question they did not ask. Top and bottom have
   no such ambiguity. */
.chr-sidebar--border-left .widget,
.chr-sidebar--border-right .widget,
.chr-sidebar--border-top .widget,
.chr-sidebar--border-bottom .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border-radius: 4px;
}

.chr-sidebar--border-left .widget {
	border-left: 3px solid var(--chr-accent, #8f660e);
}

.chr-sidebar--border-right .widget {
	border-right: 3px solid var(--chr-accent, #8f660e);
}

.chr-sidebar--border-top .widget {
	border-block-start: 3px solid var(--chr-accent, #8f660e);
}

.chr-sidebar--border-bottom .widget {
	border-block-end: 3px solid var(--chr-accent, #8f660e);
}

/* Flat — a filled block with no border and no radius. */
.chr-sidebar--flat .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-bg-alt, rgba(128, 128, 128, .06));
	border-radius: 0;
}

/* Magazine — a heavy rule above, tight leading, editorial. */
.chr-sidebar--magazine .widget {
	padding-block-start: 14px;
	border-block-start: 4px solid var(--chr-text, currentColor);
}

/* Newspaper — a double rule, the way a printed section head is set. */
.chr-sidebar--newspaper .widget {
	padding-block: 10px 18px;
	border-block-start: 3px double var(--chr-text, currentColor);
	border-block-end: 1px solid var(--chr-widget-line);
}

/* Premium — surface, a fine border, and an accent hairline along the top. */
.chr-sidebar--premium .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border: 1px solid var(--chr-widget-line);
	border-radius: var(--chr-widget-radius);
	box-shadow: 0 10px 30px rgba(0, 0, 0, .07);
	position: relative;
	overflow: hidden;
}

.chr-sidebar--premium .widget::before {
	content: "";
	position: absolute;
	inset-block-start: 0;
	inset-inline: 0;
	height: 3px;
	background: linear-gradient(90deg, var(--chr-accent, #8f660e), transparent);
}

/* Rounded — the card, softened. */
.chr-sidebar--rounded .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border: 1px solid var(--chr-widget-line);
	border-radius: 20px;
}

/* Shadow and soft shadow — no border, depth only. */
.chr-sidebar--shadow .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border-radius: var(--chr-widget-radius);
	box-shadow: 0 12px 28px rgba(0, 0, 0, .14);
}

.chr-sidebar--soft-shadow .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border-radius: var(--chr-widget-radius);
	box-shadow: 0 4px 20px rgba(0, 0, 0, .05);
}

/* Outline — border only, no fill. */
.chr-sidebar--outline .widget {
	padding: var(--chr-widget-pad);
	background: none;
	border: 2px solid var(--chr-widget-line);
	border-radius: var(--chr-widget-radius);
}

/* Compact — everything closer together. */
.chr-sidebar--compact .widget {
	--chr-widget-pad: 14px;

	padding: var(--chr-widget-pad);
	background: var(--chr-surface, #fff);
	border: 1px solid var(--chr-widget-line);
	border-radius: 6px;
	margin-block-end: calc(var(--chr-widget-gap, 32px) * .55);
	font-size: .95em;
}

/* Separated — a gap and a rule, without a container. */
.chr-sidebar--separated .widget + .widget {
	padding-block-start: var(--chr-widget-gap, 32px);
	border-block-start: 1px solid var(--chr-widget-line);
}

/* Gradient accent — a wash from the accent, fading out. */
.chr-sidebar--gradient-accent .widget {
	padding: var(--chr-widget-pad);
	border-radius: var(--chr-widget-radius);
	border: 1px solid var(--chr-widget-line);
	background:
		linear-gradient(160deg, color-mix(in srgb, var(--chr-accent, #8f660e) 12%, transparent), transparent 55%),
		var(--chr-surface, #fff);
}

/* Modern blocks — a filled block with a square accent corner. */
.chr-sidebar--modern-blocks .widget {
	padding: var(--chr-widget-pad);
	background: var(--chr-bg-alt, rgba(128, 128, 128, .06));
	border-radius: 4px;
	position: relative;
	overflow: hidden;
}

.chr-sidebar--modern-blocks .widget::after {
	content: "";
	position: absolute;
	inset-block-start: 0;
	inset-inline-end: 0;
	width: 34px;
	height: 34px;
	background: var(--chr-accent, #8f660e);
	clip-path: polygon(100% 0, 0 0, 100% 100%);
	opacity: .9;
}

/* -------------------------------------------------------- title presets --- */

.chr-sidebar[class*="chr-sidebar--titles-"] .widget-title,
.chr-sidebar[class*="chr-sidebar--titles-"] .widgettitle {
	margin-block: 0 16px;
	position: relative;
}

/* Double underline. */
.chr-sidebar--titles-double-underline .widget-title {
	padding-block-end: 8px;
	border-block-end: 3px double var(--chr-accent, #8f660e);
}

/* Double accent — a short heavy rule over a long light one. */
.chr-sidebar--titles-double-accent .widget-title {
	padding-block-end: 10px;
	border-block-end: 1px solid var(--chr-border, rgba(128, 128, 128, .3));
}

.chr-sidebar--titles-double-accent .widget-title::after {
	content: "";
	position: absolute;
	inset-block-end: -1px;
	inset-inline-start: 0;
	width: 52px;
	height: 3px;
	background: var(--chr-accent, #8f660e);
}

/* The three border treatments. */
.chr-sidebar--titles-left-border .widget-title {
	padding-inline-start: 12px;
	border-inline-start: 4px solid var(--chr-accent, #8f660e);
}

.chr-sidebar--titles-right-border .widget-title {
	padding-inline-end: 12px;
	border-inline-end: 4px solid var(--chr-accent, #8f660e);
	text-align: end;
}

.chr-sidebar--titles-bottom-border .widget-title {
	padding-block-end: 10px;
	border-block-end: 2px solid var(--chr-border, rgba(128, 128, 128, .3));
}

/* Gradient — the rule fades rather than stopping. */
.chr-sidebar--titles-gradient .widget-title {
	padding-block-end: 10px;
}

.chr-sidebar--titles-gradient .widget-title::after {
	content: "";
	position: absolute;
	inset-block-end: 0;
	inset-inline: 0;
	height: 3px;
	background: linear-gradient(to right, var(--chr-accent, #8f660e), transparent);
	border-radius: 3px;
}

/* Capsule and modern capsule. */
.chr-sidebar--titles-capsule .widget-title,
.chr-sidebar--titles-modern-capsule .widget-title {
	display: inline-block;
	padding: 7px 16px;
	border-radius: 999px;
	background: var(--chr-accent, #8f660e);
	color: var(--chr-on-accent, #fff);
}

.chr-sidebar--titles-modern-capsule .widget-title {
	background: color-mix(in srgb, var(--chr-accent, #8f660e) 14%, transparent);
	color: var(--chr-accent, #8f660e);
	border: 1px solid color-mix(in srgb, var(--chr-accent, #8f660e) 35%, transparent);
}

/* Ribbon — a filled band with a folded end. The fold is decorative and is
   drawn with a border rather than a glyph, so a screen reader meets the title
   and nothing else. */
.chr-sidebar--titles-ribbon .widget-title,
.chr-sidebar--titles-premium-ribbon .widget-title {
	display: inline-block;
	padding: 8px 26px 8px 14px;
	background: var(--chr-accent, #8f660e);
	color: var(--chr-on-accent, #fff);
	clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 50%, 100% 100%, 0 100%);
}

.chr-sidebar--titles-premium-ribbon .widget-title {
	background: linear-gradient(90deg, var(--chr-accent, #8f660e), color-mix(in srgb, var(--chr-accent, #8f660e) 60%, #000));
	box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}

/* Minimal — small, spaced, quiet. */
.chr-sidebar--titles-minimal .widget-title {
	font-size: .8em;
	font-weight: 600;
	letter-spacing: .12em;
	text-transform: uppercase;
	opacity: .75;
}

/* Newspaper — a rule above and below, centred. */
.chr-sidebar--titles-newspaper .widget-title {
	padding-block: 8px;
	border-block: 2px solid var(--chr-text, currentColor);
	text-align: center;
	font-weight: 700;
	letter-spacing: .04em;
	text-transform: uppercase;
}

/* Elegant serif. */
.chr-sidebar--titles-elegant-serif .widget-title {
	font-family: var(--chr-font-heading, Georgia, "Times New Roman", serif);
	font-style: italic;
	font-weight: 500;
	padding-block-end: 10px;
	border-block-end: 1px solid var(--chr-border, rgba(128, 128, 128, .3));
}

/* Split accent — the rule runs the width, with a heavier segment behind the
   text itself. */
.chr-sidebar--titles-split-accent .widget-title {
	display: flex;
	align-items: center;
	gap: 12px;
}

.chr-sidebar--titles-split-accent .widget-title::after {
	content: "";
	flex: 1;
	height: 1px;
	background: var(--chr-border, rgba(128, 128, 128, .3));
}

/* Numbered — a counter down the sidebar. The number is generated content, so
   it is decoration to a screen reader and the heading still reads as itself. */
.chr-sidebar[class*="chr-sidebar--titles-numbered"] .chr-sidebar__inner {
	counter-reset: hilaal-widget;
}

.chr-sidebar--titles-numbered .widget {
	counter-increment: hilaal-widget;
}

.chr-sidebar--titles-numbered .widget-title {
	display: flex;
	align-items: baseline;
	gap: 10px;
}

.chr-sidebar--titles-numbered .widget-title::before {
	content: counter(hilaal-widget, decimal-leading-zero);
	font-variant-numeric: tabular-nums;
	font-size: .85em;
	font-weight: 700;
	color: var(--chr-accent, #8f660e);
}

/* Floating label — the title sits on the widget's top edge. Only meaningful
   where the widget has a border to sit on, so it brings its own. */
.chr-sidebar--titles-floating-label .widget {
	padding: 26px var(--chr-widget-pad, 22px) var(--chr-widget-pad, 22px);
	border: 1px solid var(--chr-border, rgba(128, 128, 128, .3));
	border-radius: 10px;
}

.chr-sidebar--titles-floating-label .widget-title {
	position: absolute;
	inset-block-start: -11px;
	inset-inline-start: 16px;
	margin: 0;
	padding: 2px 10px;
	background: var(--chr-bg, #fff);
	font-size: .78em;
	letter-spacing: .08em;
	text-transform: uppercase;
}

/* Section divider — a rule across the sidebar with the title centred on it. */
.chr-sidebar--titles-section-divider .widget-title {
	display: flex;
	align-items: center;
	gap: 14px;
	text-align: center;
}

.chr-sidebar--titles-section-divider .widget-title::before,
.chr-sidebar--titles-section-divider .widget-title::after {
	content: "";
	flex: 1;
	height: 1px;
	background: var(--chr-border, rgba(128, 128, 128, .3));
}

/* ------------------------------------------------------------- dark mode -- */

/*
 * Only the presets that hard-code a light value need saying twice. Everything
 * else is already reading a token that changed underneath it.
 */
@media (prefers-color-scheme: dark) {
	.chr-sidebar--glass .widget,
	.chr-sidebar--soft-glass .widget {
		background: rgba(255, 255, 255, .05);
		border-color: rgba(255, 255, 255, .09);
	}

	.chr-sidebar--elevated .widget,
	.chr-sidebar--shadow .widget,
	.chr-sidebar--premium .widget {
		box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
	}
}

[data-theme="dark"] .chr-sidebar--glass .widget,
[data-theme="dark"] .chr-sidebar--soft-glass .widget {
	background: rgba(255, 255, 255, .05);
	border-color: rgba(255, 255, 255, .09);
}

[data-theme="dark"] .chr-sidebar--elevated .widget,
[data-theme="dark"] .chr-sidebar--shadow .widget,
[data-theme="dark"] .chr-sidebar--premium .widget {
	box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
}

/* ------------------------------------------------------------------ RTL --- */

/*
 * Almost nothing is needed here, which is the point of having written the rest
 * in logical properties. What is left is the handful of places where a shape
 * was cut rather than positioned, and a clip path has no logical form.
 */
[dir="rtl"] .chr-sidebar--titles-ribbon .widget-title,
[dir="rtl"] .chr-sidebar--titles-premium-ribbon .widget-title {
	padding: 8px 14px 8px 26px;
	clip-path: polygon(100% 0, 0 0, 12px 50%, 0 100%, 100% 100%);
}

[dir="rtl"] .chr-sidebar--modern-blocks .widget::after {
	clip-path: polygon(0 0, 100% 0, 0 100%);
}

[dir="rtl"] .chr-sidebar--premium .widget::before {
	background: linear-gradient(270deg, var(--chr-accent, #8f660e), transparent);
}

[dir="rtl"] .chr-sidebar--titles-gradient .widget-title::after {
	background: linear-gradient(to left, var(--chr-accent, #8f660e), transparent);
}

/* ----------------------------------------------------------- responsive --- */

@media (max-width: 782px) {
	/*
	 * Below the breakpoint the sidebar is a full-width band under the content,
	 * where deep padding and heavy shadows read as clutter rather than as
	 * hierarchy. The treatments stay; their weight comes down.
	 */
	.chr-sidebar[class*="chr-sidebar--"] {
		--chr-widget-pad: 16px;
	}

	.chr-sidebar--elevated .widget,
	.chr-sidebar--shadow .widget,
	.chr-sidebar--soft-shadow .widget,
	.chr-sidebar--premium .widget {
		box-shadow: 0 2px 10px rgba(0, 0, 0, .10);
	}

	.chr-sidebar--titles-newspaper .widget-title,
	.chr-sidebar--titles-section-divider .widget-title {
		font-size: .95em;
	}
}

/* --------------------------------------------------------- accessibility -- */

/*
 * A title is a heading whatever it has been dressed as. These make sure the
 * dressing never costs it contrast or a focus outline.
 */
.chr-sidebar[class*="chr-sidebar--titles-"] .widget-title a:focus-visible,
.chr-sidebar[class*="chr-sidebar--"] .widget a:focus-visible {
	outline: 2px solid var(--chr-accent, #8f660e);
	outline-offset: 2px;
}

@media (prefers-contrast: more) {
	/* Glass is the one treatment that cannot survive a contrast preference:
	   translucency is the whole idea, and the whole idea is what has to go. */
	.chr-sidebar--glass .widget,
	.chr-sidebar--soft-glass .widget {
		background: var(--chr-surface, #fff);
		border-color: var(--chr-text, currentColor);
		backdrop-filter: none;
	}

	.chr-sidebar--titles-minimal .widget-title {
		opacity: 1;
	}
}

@media (prefers-reduced-transparency: reduce) {
	.chr-sidebar--glass .widget,
	.chr-sidebar--soft-glass .widget {
		background: var(--chr-surface, #fff);
		backdrop-filter: none;
	}
}
