/*
 * The reusable pieces: cards, buttons, badges, topic rows, category list.
 *
 * Every one of these is used by more than one template, which is the bar for living here
 * rather than in a per-view stylesheet.
 */

/* ── Cards ──────────────────────────────────────────────────────────────────── */

.slf-card {
	background: var(--slf-surface);
	border: 1px solid var(--slf-border);
	border-radius: var(--slf-radius-lg);
	box-shadow: var(--slf-shadow);
}

.slf-card__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--slf-space-3);
	padding: var(--slf-space-4) var(--slf-space-5);
	border-bottom: 1px solid var(--slf-border);
}

.slf-card__title {
	margin: 0;
	font-size: var(--slf-text-lg);
}

.slf-card__body {
	padding: var(--slf-space-4) var(--slf-space-5);
}

.slf-card__footer {
	padding: var(--slf-space-3) var(--slf-space-5);
	border-top: 1px solid var(--slf-border);
	text-align: center;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */

.slf-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--slf-space-2);
	/*
	 * 44px is the WCAG 2.5.5 target size, and on a forum whose traffic is overwhelmingly
	 * mobile it is also just the difference between voting and mis-voting.
	 */
	min-height: 44px;
	padding: var(--slf-space-2) var(--slf-space-4);
	border: 1px solid transparent;
	border-radius: var(--slf-radius);
	background: var(--slf-surface-2);
	color: var(--slf-text);
	font-size: var(--slf-text-sm);
	font-weight: 600;
	text-decoration: none;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}

.slf-btn:hover {
	background: var(--slf-surface-3);
	color: var(--slf-text);
}

.slf-btn--primary {
	background: var(--slf-accent);
	color: var(--slf-on-accent);
}

.slf-btn--primary:hover {
	background: var(--slf-accent-hover);
	color: var(--slf-on-accent);
}

.slf-btn--outline {
	background: transparent;
	border-color: var(--slf-border-strong);
}

.slf-btn--block {
	width: 100%;
}

.slf-btn--icon {
	min-width: 44px;
	padding: var(--slf-space-2);
}

/*
 * The theme toggle shows the theme it switches *to*, never the one you're already in:
 * a moon while reading light, a sun while reading dark. Both icons are in the markup and
 * CSS picks one, so the correct glyph is painted with the first frame — deciding it in
 * JavaScript would mean shipping a button that briefly shows the wrong thing.
 *
 * The `:not([data-theme="light"])` guard mirrors tokens.css: an explicit light choice on a
 * dark-mode machine has to win here too, or the icon would contradict the page.
 */
.slf-theme-toggle__light {
	display: none;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .slf-theme-toggle__dark {
		display: none;
	}

	:root:not([data-theme="light"]) .slf-theme-toggle__light {
		display: block;
	}
}

:root[data-theme="dark"] .slf-theme-toggle__dark {
	display: none;
}

:root[data-theme="dark"] .slf-theme-toggle__light {
	display: block;
}

:root[data-theme="light"] .slf-theme-toggle__dark {
	display: block;
}

:root[data-theme="light"] .slf-theme-toggle__light {
	display: none;
}

/* ── Badges ─────────────────────────────────────────────────────────────────── */

.slf-badge {
	display: inline-flex;
	align-items: center;
	gap: var(--slf-space-1);
	padding: 2px var(--slf-space-2);
	border-radius: var(--slf-radius-pill);
	font-size: var(--slf-text-xs);
	font-weight: 700;
	line-height: 1.6;
}

/*
 * The urgent label (F-07). AC 57 is explicit that it must not obscure the title on a
 * phone, so it is an inline-flex sibling in the heading's flow rather than an absolutely
 * positioned corner ribbon — it can push the title down, never cover it.
 */
.slf-badge--urgent {
	background: var(--slf-urgent-soft);
	color: var(--slf-urgent);
}

.slf-badge--solved {
	background: var(--slf-accent-soft);
	color: var(--slf-solved);
}

.slf-badge--verified {
	background: var(--slf-accent-soft);
	color: var(--slf-accent-text);
}

/* ── Category list (the mockup's left sidebar) ──────────────────────────────── */

.slf-categories {
	margin: 0;
	padding: var(--slf-space-2);
	list-style: none;
}

.slf-categories__link {
	display: flex;
	align-items: center;
	gap: var(--slf-space-3);
	padding: var(--slf-space-3);
	border-radius: var(--slf-radius);
	color: var(--slf-text-2);
	text-decoration: none;
}

.slf-categories__link:hover {
	background: var(--slf-surface-2);
	color: var(--slf-text);
}

.slf-categories__link[aria-current="page"] {
	background: var(--slf-accent-soft);
	color: var(--slf-text);
	font-weight: 600;
}

/*
 * Each category carries its own accent, set inline from term meta as --slf-cat. The
 * fallback keeps an un-themed term readable instead of transparent.
 */
.slf-categories__icon {
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	flex: 0 0 28px;
	border-radius: 8px;
	background: color-mix(in srgb, var(--slf-cat, var(--slf-accent)) 22%, transparent);
	color: color-mix(in srgb, var(--slf-cat, var(--slf-accent-text)) var(--slf-cat-strength), var(--slf-cat-blend));
}

.slf-categories__name {
	flex: 1 1 auto;
	min-width: 0;
}

.slf-categories__count {
	flex: 0 0 auto;
	font-size: var(--slf-text-sm);
	color: var(--slf-text-muted);
	font-variant-numeric: tabular-nums;
}

/* ── Topic rows ─────────────────────────────────────────────────────────────── */

.slf-topics {
	margin: 0;
	padding: 0;
	list-style: none;
}

.slf-topic {
	display: grid;
	grid-template-columns: 40px minmax(0, 1fr);
	gap: var(--slf-space-3);
	padding: var(--slf-space-4) var(--slf-space-5);
	border-bottom: 1px solid var(--slf-border);
}

.slf-topic:last-child {
	border-bottom: 0;
}

.slf-avatar {
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(--slf-surface-3);
	color: var(--slf-text);
	font-weight: 700;
	text-transform: uppercase;
	overflow: hidden;
}

.slf-topic__title {
	margin: 0 0 var(--slf-space-1);
	font-size: var(--slf-text-base);
	font-weight: 600;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--slf-space-2);
}

.slf-topic__title a {
	color: var(--slf-text);
	text-decoration: none;
}

.slf-topic__title a:hover {
	color: var(--slf-accent-text);
	text-decoration: underline;
}

.slf-topic__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--slf-space-1) var(--slf-space-3);
	font-size: var(--slf-text-sm);
	color: var(--slf-text-muted);
}

/*
 * Blended toward the current theme's text colour so a category is legible on both
 * backgrounds from the one stored value — see --slf-cat-strength in tokens.css.
 */
.slf-topic__category {
	color: color-mix(in srgb, var(--slf-cat, var(--slf-accent-text)) var(--slf-cat-strength), var(--slf-cat-blend));
	text-decoration: none;
}

.slf-topic__category:hover {
	color: var(--slf-text);
	text-decoration: underline;
}

/*
 * On a phone the counts wrap onto a second grid row, and without this they land in the
 * 40px avatar column and stack one per line. Pinning them to the content column keeps
 * them on one line, aligned under the title where they read as part of the topic.
 */
.slf-topic__stats {
	grid-column: 2;
	display: flex;
	gap: var(--slf-space-4);
	margin: var(--slf-space-2) 0 0;
	color: var(--slf-text-muted);
	font-size: var(--slf-text-sm);
}

.slf-topic__stat {
	display: inline-flex;
	align-items: center;
	gap: var(--slf-space-1);
	font-variant-numeric: tabular-nums;
}

/* ── Empty and error states ─────────────────────────────────────────────────── */

.slf-empty {
	padding: var(--slf-space-6) var(--slf-space-5);
	text-align: center;
	color: var(--slf-text-muted);
}

.slf-empty__title {
	color: var(--slf-text);
	margin-bottom: var(--slf-space-2);
}

/* ── Wider screens ──────────────────────────────────────────────────────────── */

@media (min-width: 48em) {
	.slf-topic {
		grid-template-columns: 40px minmax(0, 1fr) auto;
		align-items: start;
	}

	.slf-topic__title {
		font-size: var(--slf-text-lg);
	}

	/*
	 * Wide enough for a third column: the counts move out to the right, as in the mockup,
	 * instead of sitting under the title.
	 */
	.slf-topic__stats {
		grid-column: auto;
		margin: 0;
		padding-left: var(--slf-space-4);
	}
}

/* ── Notification bell ──────────────────────────────────────────────────────── */

.slf-bell {
	position: relative;
	display: inline-grid;
	place-items: center;
	width: 42px;
	height: 42px;
	border: 1px solid var(--slf-border);
	border-radius: var(--slf-radius);
	color: var(--slf-text-2);
	text-decoration: none;
}

.slf-bell:hover {
	background: var(--slf-surface-2);
	color: var(--slf-text);
}

/*
 * The badge sits half outside the button, which means it must not be what decides the
 * button's box — hence `position: absolute` rather than a flex child. `min-width` with
 * centred text lets "3" and "12" both stay circular-ish without a second rule.
 */
.slf-bell__count {
	position: absolute;
	top: -6px;
	right: -6px;
	min-width: 18px;
	padding: 0 4px;
	border-radius: var(--slf-radius-pill);
	background: var(--slf-urgent);
	color: #fff;
	font-size: var(--slf-text-xs);
	font-weight: 700;
	line-height: 18px;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

/* ── Mentions and quotes ────────────────────────────────────────────────────── */

.slf-mention {
	color: var(--slf-accent-text);
	font-weight: 600;
	text-decoration: none;
}

.slf-mention:hover {
	text-decoration: underline;
}

/*
 * A quote is marked by the bar and the muted colour, not by italics: quoted passages here
 * are often long and in German, and a paragraph of italic text at 16px is materially
 * harder to read — which defeats the point of quoting it.
 */
.slf-quote {
	margin: var(--slf-space-3) 0;
	padding: var(--slf-space-2) var(--slf-space-4);
	border-left: 3px solid var(--slf-border-strong);
	background: var(--slf-surface-2);
	border-radius: 0 var(--slf-radius) var(--slf-radius) 0;
	color: var(--slf-text-2);
}

.slf-quote p:last-child {
	margin-bottom: 0;
}

/* ── Follow / save-search actions ───────────────────────────────────────────── */

.slf-term-actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--slf-space-2);
	margin-bottom: var(--slf-space-4);
}

.slf-term-actions:empty {
	display: none;
}

.slf-btn.is-active {
	border-color: var(--slf-accent);
	color: var(--slf-accent-text);
}

/* ── Notification list ──────────────────────────────────────────────────────── */

.slf-notifications,
.slf-subscriptions {
	margin: 0;
	padding: 0;
	list-style: none;
}

.slf-notifications__item {
	border-top: 1px solid var(--slf-border);
}

.slf-notifications__item:first-child {
	border-top: 0;
}

/*
 * Unread is marked twice — a tinted background and a left bar — because the tint alone is
 * a colour-only distinction, and NF-03 does not allow one.
 */
.slf-notifications__item.is-unread {
	background: var(--slf-accent-soft);
	box-shadow: inset 3px 0 0 var(--slf-accent);
}

.slf-notifications__link {
	display: grid;
	gap: var(--slf-space-1);
	padding: var(--slf-space-4) var(--slf-space-5);
	color: var(--slf-text);
	text-decoration: none;
}

.slf-notifications__link:hover {
	background: var(--slf-surface-2);
}

.slf-notifications__title {
	font-weight: 600;
}

.slf-notifications__excerpt {
	color: var(--slf-text-muted);
	font-size: var(--slf-text-sm);
}

.slf-subscriptions__item {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--slf-space-2);
	padding: var(--slf-space-3) var(--slf-space-5);
	border-top: 1px solid var(--slf-border);
}

.slf-subscriptions__item:first-child {
	border-top: 0;
}

.slf-subscriptions__link {
	color: var(--slf-text);
	font-weight: 600;
	text-decoration: none;
	min-width: 0;
	overflow-wrap: anywhere;
}

.slf-subscriptions__link:hover {
	text-decoration: underline;
}

/* ── Notification preference switches ───────────────────────────────────────── */

/*
 * A real table, because it is one: three columns of the same relationship, and a screen
 * reader needs the row header ("Someone answers my question") read out with each checkbox
 * or the two unlabelled columns are indistinguishable.
 */
.slf-switches {
	width: 100%;
	border-collapse: collapse;
	margin-bottom: var(--slf-space-4);
}

.slf-switches th,
.slf-switches td {
	padding: var(--slf-space-2);
	border-bottom: 1px solid var(--slf-border);
	text-align: left;
	font-weight: 400;
}

.slf-switches thead th {
	font-size: var(--slf-text-sm);
	color: var(--slf-text-muted);
}

.slf-switches td {
	width: 5.5rem;
}

.slf-switch {
	display: inline-flex;
	align-items: center;
	/* The tap target, not the checkbox, is what has to reach 44px (WCAG 2.2). */
	min-width: 44px;
	min-height: 44px;
	cursor: pointer;
}

.slf-switch input {
	width: 20px;
	height: 20px;
	accent-color: var(--slf-accent);
}

/*
 * Below ~30rem three columns do not fit: the event names are sentences, and squeezing them
 * into a third of 320px wraps "Someone answers my question" onto four lines next to two
 * checkboxes floating in whitespace. Each row becomes its own block instead — the event on
 * one line, the two switches beneath it, each captioned from the header text carried in
 * `data-slf-column`.
 *
 * The table semantics are untouched; only the boxes change. The column headers are hidden
 * rather than removed because every checkbox already carries its own full sr-only label
 * ("Send “Someone mentions me” as a push notification"), so nothing a screen reader relies
 * on lives in `thead` alone.
 */
@media (max-width: 30rem) {
	.slf-switches thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	/*
	 * `tbody` has to come out of table layout too. Leaving it as `table-row-group` around
	 * block rows makes the engine generate an anonymous table box per row, which puts the
	 * two switches on separate lines however they are displayed.
	 */
	.slf-switches,
	.slf-switches tbody {
		display: block;
	}

	.slf-switches tr {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: var(--slf-space-2) var(--slf-space-4);
		padding: var(--slf-space-3) 0;
		border-bottom: 1px solid var(--slf-border);
	}

	.slf-switches th,
	.slf-switches td {
		border-bottom: 0;
		padding: 0;
	}

	.slf-switches tbody th {
		flex: 1 0 100%;
	}

	.slf-switches td {
		display: flex;
		align-items: center;
		gap: var(--slf-space-2);
		width: auto;
	}

	.slf-switches td::before {
		content: attr(data-slf-column);
		font-size: var(--slf-text-sm);
		color: var(--slf-text-muted);
	}
}

.slf-card__header--split {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--slf-space-2);
}

/* ── Public profile ─────────────────────────────────────────────────────────── */

.slf-profile {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--slf-space-4);
}

.slf-profile__name {
	margin: 0 0 var(--slf-space-1);
	font-size: var(--slf-text-xl);
}

/* ── Reporting and moderation ──────────────────────────────────────────────────── */

/*
 * The report control is deliberately quiet. It is a safety valve, not a call to action:
 * a "Report" button styled like the reply button gets pressed by people who meant to
 * disagree, and a queue full of disagreements is a queue nobody reads.
 */
.slf-report {
	margin-top: var(--slf-space-3);
}

.slf-report__toggle {
	display: inline-flex;
	align-items: center;
	gap: var(--slf-space-1);
	/* A summary is a click target, so it needs the tap size a button gets. */
	min-height: 44px;
	color: var(--slf-text-muted);
	font-size: var(--slf-text-sm);
	cursor: pointer;
	list-style: none;
}

.slf-report__toggle::-webkit-details-marker {
	display: none;
}

.slf-report__toggle:hover {
	color: var(--slf-text-2);
}

.slf-report__form {
	max-width: 34rem;
	margin-top: var(--slf-space-2);
	padding: var(--slf-space-3);
	border: 1px solid var(--slf-border);
	border-radius: var(--slf-radius);
	background: var(--slf-surface-2);
}

.slf-report__form fieldset {
	margin: 0 0 var(--slf-space-3);
	padding: 0;
	border: 0;
}

.slf-report__form legend {
	margin-bottom: var(--slf-space-2);
	padding: 0;
	font-weight: 600;
}

.slf-choice--radio {
	display: flex;
	align-items: center;
	gap: var(--slf-space-2);
	min-height: 40px;
}

/*
 * The moderator strip. Bordered in the urgent colour so it can never be mistaken for
 * something a reader is meant to press — these buttons are the only ones on the page that
 * change what everyone else sees.
 */
.slf-mod {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--slf-space-2);
	margin-top: var(--slf-space-3);
	padding: var(--slf-space-2) var(--slf-space-3);
	border: 1px dashed var(--slf-urgent);
	border-radius: var(--slf-radius);
}

.slf-mod__label {
	display: flex;
	align-items: center;
	gap: var(--slf-space-2);
	margin-right: auto;
	color: var(--slf-text-muted);
	font-size: var(--slf-text-sm);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.slf-mod__count {
	padding: 2px 8px;
	border-radius: 999px;
	background: var(--slf-urgent-soft);
	color: var(--slf-urgent);
	text-transform: none;
	letter-spacing: 0;
}

.slf-mod__form {
	display: inline-flex;
}

.slf-btn--danger {
	color: var(--slf-urgent);
}

.slf-btn--danger:hover,
.slf-btn--danger:focus-visible {
	background: var(--slf-urgent-soft);
	color: var(--slf-urgent);
}

.slf-topic-page__foot {
	margin-top: var(--slf-space-4);
	padding-top: var(--slf-space-3);
	border-top: 1px solid var(--slf-border);
}

/* ── Deleting an account ───────────────────────────────────────────────────────── */

.slf-danger-zone {
	border: 1px solid var(--slf-urgent);
	border-radius: var(--slf-radius);
	padding: var(--slf-space-4);
}

.slf-danger-zone h3 {
	margin: 0 0 var(--slf-space-2);
	color: var(--slf-urgent);
}

.slf-danger-zone ul {
	margin: 0 0 var(--slf-space-3);
	padding-left: var(--slf-space-4);
	color: var(--slf-text-2);
}

.slf-danger-zone input[type="text"] {
	max-width: 12rem;
}

/*
 * Narrow screens: the label stops competing with the buttons for the first line. With
 * `margin-right: auto` it otherwise keeps one button beside it and pushes the rest onto
 * lines of their own, which reads as three unrelated controls rather than one strip.
 */
@media (max-width: 34rem) {
	.slf-mod__label {
		flex: 1 0 100%;
		margin-right: 0;
	}
}

/* ── Sharing ───────────────────────────────────────────────────────────────────── */

.slf-share {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--slf-space-2);
}

.slf-share__label {
	color: var(--slf-text-muted);
	font-size: var(--slf-text-sm);
	font-weight: 600;
}

/* ── Advertising ───────────────────────────────────────────────────────────────── */

/*
 * No `min-height`. F-27 AC 130 requires a failed ad script to leave the layout intact, and
 * a reserved box that never fills *is* the damage — most readers here decline consent and
 * would get a permanent empty rectangle. The slot is between blocks rather than inside one,
 * so what it costs when it does load is a shift of the content below it, once.
 */
.slf-ad {
	display: block;
	margin: var(--slf-space-4) 0;
	text-align: center;
}

.slf-ad:empty,
.slf-ad__unit:empty {
	display: none;
	margin: 0;
}

.slf-ad__label {
	display: block;
	margin-bottom: var(--slf-space-1);
	color: var(--slf-text-muted);
	font-size: var(--slf-text-xs);
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

/* ── Consent banner ────────────────────────────────────────────────────────────── */

/*
 * Fixed to the bottom, but only as tall as its text — never a full-screen overlay. A modal
 * consent wall on a page someone reached from a search for "Kündigung Frist" is the thing
 * that makes them leave, and it would also break AC 131's promise about mobile.
 */
.slf-consent {
	position: fixed;
	inset-inline: 0;
	bottom: 0;
	z-index: 60;
	padding: var(--slf-space-3);
	border-top: 1px solid var(--slf-border-strong);
	background: var(--slf-surface);
	box-shadow: var(--slf-shadow);
}

.slf-consent__inner {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--slf-space-3);
	max-width: 68rem;
	margin: 0 auto;
}

.slf-consent__title {
	margin: 0 0 var(--slf-space-1);
	font-size: var(--slf-text-base);
}

.slf-consent__text {
	margin: 0;
	max-width: 52ch;
	color: var(--slf-text-2);
	font-size: var(--slf-text-sm);
}

.slf-consent__actions {
	display: flex;
	gap: var(--slf-space-2);
}

.slf-consent__actions form {
	display: contents;
}

/* ── Static pages and articles ─────────────────────────────────────────────────── */

/*
 * Centred, not just narrowed. `.slf-layout` is a full-width grid, so capping the width
 * alone pins the prose to the left of a wide screen with an empty column beside it — which
 * reads as a broken three-column layout rather than a deliberate one.
 */
.slf-layout--single {
	max-width: 52rem;
	margin-inline: auto;
	width: 100%;
}

.slf-page__title {
	margin: 0 0 var(--slf-space-4);
	font-size: var(--slf-text-2xl);
	line-height: 1.2;
}

.slf-page__image {
	width: 100%;
	height: auto;
	border-radius: var(--slf-radius-lg) var(--slf-radius-lg) 0 0;
}

/* 65-ish characters a line, which is where long prose stops being a wall. */
.slf-prose--page {
	max-width: 65ch;
}

.slf-prose--page h2 {
	margin-top: var(--slf-space-5);
	font-size: var(--slf-text-lg);
}

.slf-prose--page p {
	margin-bottom: var(--slf-space-3);
	line-height: 1.7;
}
