:root {
	--color-bg: #f5f3ef;
	--color-surface: #ffffff;
	--color-surface-alt: #fcfaf7;
	--color-text: #000000;
	--color-text-dim: #3d3a35;
	--color-border: #d9d4cc;
	--color-accent: #f7cf46;
	--color-danger: #d93838;
	--color-link: #0a58ca;
	--space-1: 0.25rem;
	--space-2: 0.5rem;
	--space-3: 0.75rem;
	--space-4: 1rem;
	--space-5: 1.5rem;
	--space-6: 2rem;
	--space-7: 3rem;
	--space-8: 4rem;
	--radius-sm: 0.5rem;
	--radius-lg: 0.75rem;
	--radius-pill: 999px;
	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
	--shadow-md: 0 4px 6px rgba(0, 0, 0, 0.08);
	--shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.1);
	--transition-fast: 120ms ease;
	--transition-smooth: 200ms ease-out;
	--action-bar-height: 60px;
}

@media (prefers-color-scheme: dark) {
	:root {
		--color-bg: #121212;
		--color-surface: #1c1c1b;
		--color-surface-alt: #222221;
		--color-text: #ffffff;
		--color-text-dim: #c7c3ba;
		--color-border: #2c2c2b;
		--color-link: #6ea8fe;
		--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
		--shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
		--shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.5);
	}

	.button--primary:hover {
		background: #f4c935;
		filter: brightness(0.95);
	}

	.login-form {
		box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
	}

	.card__preview::after {
		background: linear-gradient(transparent, var(--color-surface));
	}
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	/* https://qwtel.com/posts/software/the-monospaced-system-ui-css-font-stack */
	font-family:
		ui-monospace,
		Menlo, Monaco,
		"Cascadia Mono", "Segoe UI Mono",
		"Roboto Mono",
		"Oxygen Mono",
		"Ubuntu Mono",
		"Fira Mono",
		"Droid Sans Mono",
		"Consolas", "Courier New", monospace;
	background: var(--color-bg);
	color: var(--color-text);
	line-height: 1.5;
	font-size: 1rem;
}

/* Skip to main content link for keyboard users */
.skip-link {
	position: absolute;
	top: -100px;
	left: 0;
	background: var(--color-accent);
	color: #000;
	padding: var(--space-3) var(--space-4);
	font-weight: 600;
	text-decoration: none;
	z-index: 1000;
	border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus {
	top: 0;
}

button,
input,
textarea,
select {
	font: inherit;
	color: inherit;
}

button {
	cursor: pointer;
}

:focus-visible {
	outline: 0;
	box-shadow: 0 0 0 3px rgba(247, 207, 70, 0.4);
}

h1,
h2,
h3,
h4 {
	font-weight: 600;
	line-height: 1.3;
	margin: 0;
}

h1 {
	font-size: 2rem;
	margin-bottom: var(--space-6);
	letter-spacing: -0.02em;
}

h2 {
	font-size: 1.5rem;
	margin-bottom: var(--space-4);
}

h3 {
	font-size: 1.25rem;
	margin-bottom: var(--space-3);
}

p {
	margin: 0 0 var(--space-4) 0;
	line-height: 1.6;
}

.layout {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
}

.layout__inner {
	flex: 1;
}

/* Roomier top/bottom breathing space with a little overscroll (1.6) */
[data-route="yaks"] .layout__inner {
	padding-top: var(--space-6);
	padding-bottom: var(--space-8);
}

.container {
	max-width: 1200px;
	margin: 0 auto;
	padding: 0 var(--space-5);
}

@media (min-width: 768px) {
	.container {
		padding: 0 var(--space-6);
	}
}

.header {
	position: sticky;
	top: 0;
	background: rgba(245, 243, 239, 0.95);
	backdrop-filter: blur(10px);
	border-bottom: 1px solid var(--color-border);
	padding: var(--space-4) 0;
	z-index: 100;
}

@media (prefers-color-scheme: dark) {
	.header {
		background: rgba(18, 18, 18, 0.95);
	}
}

.header__bar {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.header__center {
	flex: 1;
	text-align: center;
	font-weight: 600;
}

.brand {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	text-decoration: none;
	color: var(--color-text);
	font-weight: 600;
}

.brand__logo {
	width: 2rem;
	height: 2rem;
	background: var(--color-accent);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.8rem;
	font-weight: 700;
	color: #000;
}

.nav__list {
	list-style: none;
	display: flex;
	gap: var(--space-3);
	margin: 0;
	padding: 0;
}

.nav__link {
	text-decoration: none;
	color: var(--color-text-dim);
	padding: var(--space-2) var(--space-3);
	border-radius: var(--radius-pill);
	transition: background var(--transition-fast);
}

.nav__link:hover {
	background: var(--color-surface-alt);
	color: var(--color-text);
}

.nav__link--active {
	background: var(--color-accent);
	color: #000;
	font-weight: 600;
}

.nav__item {
	color: var(--color-text);
	font-weight: 600;
}

.button {
	display: inline-flex;
	align-items: center;
	padding: var(--space-2) var(--space-4);
	background: var(--color-surface);
	color: var(--color-text);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-pill);
	text-decoration: none;
	font-weight: 500;
	transition:
		background var(--transition-smooth),
		border-color var(--transition-smooth),
		box-shadow var(--transition-smooth);
}

.button:hover {
	background: var(--color-surface-alt);
	border-color: var(--color-text-dim);
}

.button--primary {
	background: var(--color-accent);
	color: #000;
	border-color: var(--color-accent);
	font-weight: 600;
}

.button--primary:hover {
	background: #f4c935;
	border-color: #f4c935;
}

.button--sm {
	padding: var(--space-2) var(--space-3);
	font-size: 0.85rem;
	font-weight: 500;
}

.button--secondary {
	background: var(--color-surface-alt);
	color: var(--color-text);
	border-color: var(--color-border);
}

.button--secondary:hover {
	background: var(--color-surface);
	border-color: var(--color-text-dim);
}

.button--secondary.active {
	background: var(--color-accent);
	color: #000;
	border-color: var(--color-accent);
}

.button--danger {
	background: var(--color-danger);
	color: #fff;
	border-color: var(--color-danger);
}

.button--danger:hover {
	background: #c0392b;
	border-color: #c0392b;
}

/* Low-key destructive action: reads as an outline until hovered (item 2) */
.button--danger-ghost {
	background: transparent;
	color: var(--color-danger);
	border-color: var(--color-border);
	font-weight: 500;
	opacity: 0.75;
}

.button--danger-ghost:hover {
	background: var(--color-danger);
	border-color: var(--color-danger);
	color: #fff;
	opacity: 1;
}

.button--full {
	width: 100%;
	justify-content: center;
}

.cards {
	display: grid;
	gap: var(--space-5);
	/* At most three columns so a lone card never stretches full width (1.1) */
	grid-template-columns: 1fr;
	margin-top: var(--space-6);
}

@media (min-width: 640px) {
	.cards {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (min-width: 960px) {
	.cards {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

.card {
	display: flex;
	flex-direction: column;
	padding: var(--space-5);
	background: var(--color-surface);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-sm);
	transition:
		transform var(--transition-smooth),
		box-shadow var(--transition-smooth);
	text-decoration: none;
	color: inherit;
	position: relative;
	overflow: hidden;
}

/* Word-count meter: accent fill spans (words / 500) of the card width (1.2) */
.card__meter {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 4px;
	background: linear-gradient(
		to right,
		var(--card-accent-color, var(--color-border)) calc(var(--card-fill, 0) * 100%),
		var(--color-border) calc(var(--card-fill, 0) * 100%)
	);
}

.card:hover {
	transform: translateY(-2px);
	box-shadow: var(--shadow-lg);
}

.card__body {
	flex: 1;
	margin-top: var(--space-2);
	margin-bottom: var(--space-3);
	color: var(--color-text-dim);
}

/* Compact rendered Djot preview: small type, headers bold but not enlarged (1.5) */
.card__preview {
	position: relative;
	max-height: 8rem;
	overflow: hidden;
	font-size: 0.8rem;
	line-height: 1.5;
	white-space: normal;
}

.card__preview::after {
	content: "";
	position: absolute;
	inset: auto 0 0 0;
	height: 2rem;
	background: linear-gradient(transparent, var(--color-surface));
}

.card__preview > :first-child {
	margin-top: 0;
}

.card__preview .card__h {
	font-size: 1em;
	font-weight: 700;
	margin: 0.5em 0 0.2em;
	color: var(--color-text);
	line-height: 1.3;
}

.card__preview p {
	margin: 0 0 0.4em;
}

.card__preview ul,
.card__preview ol {
	margin: 0.2em 0;
	padding-left: 1.2em;
}

.card__preview pre {
	margin: 0.3em 0;
	padding: 0.4em 0.6em;
	background: var(--color-surface-alt);
	border-radius: var(--radius-sm);
	overflow: hidden;
}

.card__preview code {
	font-size: 0.9em;
}

.card__preview img {
	max-width: 100%;
	height: auto;
}

.card__tags {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2) var(--space-3);
	margin-bottom: var(--space-2);
}

.card__tag {
	color: var(--color-text-dim);
	font-size: 0.72rem;
}

.card__tag::before {
	content: "#";
	opacity: 0.5;
}

/* Links inside a card preview are demoted to non-clickable styled text: the
   whole card is the click target, so a nested <a> would be invalid markup. */
.card__link {
	color: var(--color-text);
	text-decoration: underline dotted;
	text-underline-offset: 2px;
}

/* Boardgame-style footer: a bracketed category token on the left, mono stats on
   the right, ruled off from the body above. */
.card__meta {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-3);
	padding-top: var(--space-3);
	border-top: 1px solid var(--color-border);
	font-size: 0.72rem;
}

.card__chip {
	display: inline-flex;
	align-items: center;
	gap: 0.45em;
	padding: 0.15em 0.55em;
	border: 1px solid var(--color-border);
	border-radius: 3px;
	background: var(--color-surface-alt);
	color: var(--color-text);
	font-weight: 600;
	text-transform: lowercase;
	white-space: nowrap;
}

.card__chip::before {
	content: "";
	width: 0.55em;
	height: 0.55em;
	border-radius: 2px;
	background: var(--card-accent-color, var(--color-border));
}

.card__stats {
	display: flex;
	flex-wrap: wrap;
	gap: 0.2em 0.7em;
	justify-content: flex-end;
	color: var(--color-text-dim);
}

.card__stat {
	white-space: nowrap;
}

.card__stat--links {
	font-variant-numeric: tabular-nums;
}

.card__actions {
	display: flex;
	gap: var(--space-2);
	flex-wrap: wrap;
}

.login-form {
	max-width: 420px;
	margin: var(--space-8) auto;
	display: grid;
	gap: var(--space-5);
	padding: var(--space-7);
	background: var(--color-surface);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-md);
}

.login-form__group {
	display: grid;
	gap: var(--space-2);
}

.login-form__label {
	font-size: 0.8rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--color-text-dim);
}

.login-form__control {
	padding: var(--space-3) var(--space-4);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	background: var(--color-surface);
	color: var(--color-text);
	font: inherit;
	transition:
		border-color var(--transition-smooth),
		box-shadow var(--transition-smooth);
}

.login-form__control:focus {
	border-color: var(--color-accent);
	box-shadow: 0 0 0 3px rgba(247, 207, 70, 0.1);
}

.alert {
	padding: var(--space-4);
	background: var(--color-surface-alt);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	font-size: 0.9rem;
}

.alert--warn {
	background: #fff8e0;
	border-color: var(--color-accent);
	color: #3a3100;
}

.form {
	max-width: 600px;
	margin: 0 auto;
	display: grid;
	gap: var(--space-4);
}

.form__group {
	display: grid;
	gap: var(--space-2);
}

.form__label {
	font-size: 0.8rem;
	font-weight: 600;
	text-transform: uppercase;
	color: var(--color-text-dim);
}

.form__select,
.form__input {
	padding: var(--space-3);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	background: var(--color-surface);
	color: var(--color-text);
	font: inherit;
	transition: border-color var(--transition-fast);
}

.form__select:focus,
.form__input:focus {
	border-color: var(--color-accent);
}

.combobox {
	position: relative;
}

.combobox__list {
	position: absolute;
	top: calc(100% + var(--space-1));
	left: 0;
	right: 0;
	z-index: 20;
	max-height: 240px;
	overflow-y: auto;
	margin: 0;
	padding: var(--space-1);
	list-style: none;
	background: var(--color-surface);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-md);
}

.combobox__option {
	padding: var(--space-2) var(--space-3);
	border-radius: var(--radius-sm);
	cursor: pointer;
	font-size: 0.9rem;
}

.combobox__option:hover {
	background: var(--color-surface-alt);
}

.combobox__option--active {
	background: var(--color-accent);
	color: #000;
}

.form__actions {
	display: flex;
	gap: var(--space-2);
	flex-wrap: wrap;
}

code {
	background: var(--color-surface-alt);
	padding: 0.2em 0.4em;
	border-radius: 0.25rem;
}

pre {
	background: var(--color-surface-alt);
	padding: var(--space-4);
	border-radius: var(--radius-sm);
	overflow-x: auto;
	line-height: 1.4;
}

pre code {
	padding: 0;
	background: none;
}

/* ============================================================================
   EDITOR COMPONENT STYLES

   The editor uses a complex flex layout system with three view modes:
   1. "editoronly" - Shows only CodeJar editor (default on mobile)
   2. "sidebyside" - 50/50 split: editor on left, preview on right (default desktop)
   3. "previewonly" - Shows only rendered Djot preview

   CRITICAL LAYOUT RULES:
   - Form wrapper MUST be a flex container (min-height: 0 fixes overflow in nested flex)
   - Each mode uses different flex/width values to show/hide editor and preview
   - Mobile breakpoint at 768px changes behavior (see @media queries at bottom)

   Related files:
   - yak_shears/static/js/editor.js (setViewMode function)
   - yak_shears/_templates/yak/edit.html.jinja (HTML structure)
   ============================================================================ */

.editor__header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: var(--space-4);
}

/* View Mode Toggle - appears in metadata panel */
.view-toggle {
	display: flex;
	gap: var(--space-2);
	background: var(--color-surface-alt);
	padding: var(--space-2);
	border-radius: var(--radius-pill);
	border: 1px solid var(--color-border);
}

.view-toggle .button {
	background: transparent;
	color: var(--color-text-dim);
	border: none;
	font-weight: 500;
}

.view-toggle .button:hover {
	background: var(--color-surface);
	color: var(--color-text);
}

.view-toggle .button.active {
	background: var(--color-accent);
	color: #000;
	font-weight: 600;
}

/* Main editor container - holds form (with editor) and preview */
.editor-container {
	display: flex;
	gap: var(--space-4);
	/* Comfortable centered reading width so ultrawide screens leave gutters (2.6) */
	width: 100%;
	max-width: 1200px;
	margin: 0 auto;
	padding: var(--space-4);
	flex: 1;
	min-height: 0; /* Critical: allows overflow scrolling in flex children */
	overflow: hidden;
}

/* Form wrapper needs to be a flex item to participate in layout */
/* min-height: 0 is REQUIRED for nested flex children to respect overflow */
.editor-container form {
	display: flex;
	flex: 1;
	min-height: 0; /* Without this, nested .editor won't scroll properly */
}

/* ============================================================================
   VIEW MODE 1: Editor-only (mobile default)
   Shows: CodeJar editor only
   Hides: Preview pane
   ============================================================================ */
.editor-container.editoronly form {
	width: 100%;
}

.editor-container.editoronly .editor {
	flex: 1;
	width: 100%;
}

.editor-container.editoronly .preview {
	display: none;
}

/* ============================================================================
   VIEW MODE 2: Preview-only
   Shows: Rendered Djot preview only
   Hides: CodeJar editor and form
   ============================================================================ */
.editor-container.previewonly .preview {
	flex: 1;
	width: 100%;
}

.editor-container.previewonly form,
.editor-container.previewonly .editor {
	display: none;
}

/* ============================================================================
   VIEW MODE 3: Side-by-side (desktop default)
   Shows: 50/50 split with editor on left, preview on right
   Note: min-width: 0 prevents flex items from overflowing container
   ============================================================================ */
.editor-container.sidebyside form {
	flex: 1;
	width: 50%;
	min-width: 0; /* Prevents flex item from growing beyond 50% */
}

.editor-container.sidebyside .editor {
	flex: 1;
	width: 100%;
}

.editor-container.sidebyside .preview {
	flex: 1;
	width: 50%;
	min-width: 0; /* Prevents flex item from growing beyond 50% */
}

/* ============================================================================
   CodeJar Editor Element
   The actual contenteditable div where users type
   ============================================================================ */
.editor {
	background: var(--color-surface);
	border-radius: var(--radius-sm);
	border: 2px solid var(--color-border);
	line-height: 1.6;
	min-height: 300px;
	padding: var(--space-4);
	/* Sublime-style room to scroll the last line up past the fold (2.1) */
	padding-bottom: var(--editor-overscroll, 45vh);
	/* Default is unwrapped; the wrap toggle adds .wrap (2.5) */
	white-space: pre;
	overflow: auto;
	flex: 1;
	font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
	font-size: 0.9375rem;
}

/* Word-wrap toggle (2.5): .wrap re-wraps preview code blocks. The editor's
   own white-space is set inline by editor.js because CodeJar owns that style. */
.editor-container.wrap .preview-content pre,
.editor-container.wrap .preview-content pre code {
	white-space: pre-wrap;
	word-break: break-word;
}

/* The highlighter wraps Djot code blocks in <pre><code> inside the editor; a
   nested <pre> keeps the UA default white-space: pre, so the inline pre-wrap on
   .editor never reaches it. Re-wrap those blocks when the wrap toggle is on. */
.editor-container.wrap .editor pre,
.editor-container.wrap .editor pre code {
	white-space: pre-wrap;
	overflow-wrap: break-word;
	word-break: break-word;
}

.editor:focus {
	outline: none;
	border-color: var(--color-accent);
	box-shadow: 0 0 0 3px rgba(247, 207, 70, 0.2); /* Accent color with 20% opacity */
}

/* ============================================================================
   Djot Preview Pane
   Shows rendered HTML from Djot parser (via editor.js:renderPreview)
   ============================================================================ */
.preview {
	background: #fff;
	border-radius: var(--radius-sm);
	border: 1px solid var(--color-border);
	padding: var(--space-5);
	min-height: 300px;
	overflow-y: auto;
	box-shadow: var(--shadow-sm);
}

@media (prefers-color-scheme: dark) {
	.preview {
		background: var(--color-surface);
	}
}

.preview-content {
	line-height: 1.7;
	font-size: 1rem;
	color: var(--color-text);
}

.preview-content h1,
.preview-content h2,
.preview-content h3 {
	margin-top: 1.5em;
	margin-bottom: 0.5em;
	line-height: 1.3;
}

.preview-content h1:first-child,
.preview-content h2:first-child,
.preview-content h3:first-child {
	margin-top: 0;
}

.preview-content p {
	margin: 0 0 1em 0;
}

/* Themed link color; without it, rendered links fell back to the UA dark blue,
   which is unreadable on the dark surface. */
.preview-content a {
	color: var(--color-link);
	text-decoration: underline;
	text-underline-offset: 2px;
}

.preview-content a:hover {
	text-decoration-thickness: 2px;
}

.preview-content code {
	background: var(--color-surface-alt);
	padding: 0.125em 0.375em;
	border-radius: var(--radius-sm);
	font-size: 0.875em;
}

.preview-content pre {
	background: var(--color-surface-alt);
	padding: var(--space-4);
	border-radius: var(--radius-sm);
	overflow-x: auto;
	margin: 1em 0;
}

.preview-content pre code {
	background: none;
	padding: 0;
}

/* Attached photos/videos: thumbnails in preview, click/play loads full media. */
.preview-media {
	display: block;
	max-width: 100%;
	height: auto;
	margin: 1em 0;
	border-radius: var(--radius-sm);
	border: 1px solid var(--color-border);
	background: var(--color-surface-alt);
}

.preview-media--video {
	width: 100%;
	max-height: 70vh;
	object-fit: contain;
}

.preview-media__link {
	display: inline-block;
}

.preview-media__link:hover .preview-media--image {
	border-color: var(--color-link);
}

/* ============================================================================
   Fixed Bottom Action Bar
   Contains Save button, Menu button, and status indicator
   Fixed position ensures it's always visible during scrolling
   ============================================================================ */
.editor__actions {
	display: flex;
	gap: var(--space-3);
	align-items: center;
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: rgba(245, 243, 239, 0.95); /* Semi-transparent light theme */
	backdrop-filter: blur(10px); /* Blur content behind the bar */
	padding: var(--space-4);
	border-top: 1px solid var(--color-border);
	box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
	z-index: 10; /* Above editor content, below modals */
}

@media (prefers-color-scheme: dark) {
	.editor__actions {
		background: rgba(18, 18, 18, 0.95); /* Semi-transparent dark theme */
	}
}

/* Save status indicator text */
.editor__status {
	font-size: 0.8rem;
	padding: var(--space-2);
	border-radius: var(--radius-sm);
}

/* "Saved" status gets green background */
.editor__status.saved {
	background: #e8f5e8;
	color: #2e7d32;
}

/* "Error saving!" status gets red background */
.editor__status.error {
	background: #ffebee;
	color: var(--color-danger);
}

/* Syntax highlighting for editor content (applied by highlight.js) */
/* TODO: Pick more appropriate colors for these tokens */
.editor .heading {
	font-weight: 600;
}
.editor .quote {
	color: var(--color-text-dim);
}
.editor .checkbox.checked {
	color: var(--color-text-dim);
}
.editor .checkbox.unchecked {
	color: var(--color-text-dim);
}

.page-info {
	font-size: 0.95rem;
	color: var(--color-text-dim);
	margin-bottom: var(--space-5);
}

.sort-controls {
	display: flex;
	gap: var(--space-2);
	flex-wrap: wrap;
	align-items: center;
	margin-bottom: var(--space-4);
}

.sort-controls__label {
	font-size: 0.8rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--color-text-dim);
}

.filter-controls {
	display: flex;
	gap: var(--space-2);
	flex-wrap: wrap;
	align-items: center;
	margin-bottom: var(--space-5);
}

.filter-controls__label {
	font-size: 0.8rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--color-text-dim);
}

.pagination {
	display: flex;
	justify-content: center;
	gap: var(--space-2);
	flex-wrap: wrap;
	margin-top: var(--space-5);
}

.pagination__link {
	padding: var(--space-2) var(--space-3);
	text-decoration: none;
	border-radius: var(--radius-pill);
	font-weight: 500;
	transition: background var(--transition-fast);
	color: var(--color-text);
}

.pagination__link--active {
	background: var(--color-accent);
	color: #000;
	font-weight: 600;
}

.pagination__link:hover:not(.pagination__link--active) {
	background: var(--color-surface-alt);
}

.text-center {
	text-align: center;
}

.text-sm {
	font-size: 0.8rem;
}

.font-semibold {
	font-weight: 600;
}

.upper {
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

/* Search Modal Styles */
.search-modal {
	position: fixed;
	top: 3rem;
	left: 0;
	width: 100vw;
	height: calc(100vh - 3rem);
	background: var(--color-surface);
	display: flex;
	flex-direction: column;
	z-index: 1000;
}

.search-input-container {
	padding: var(--space-4);
	border-bottom: 1px solid var(--color-border);
}

.search-input {
	width: 100%;
	padding: var(--space-3);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	background: var(--color-surface);
	color: var(--color-text);
	font: inherit;
	font-size: 1.1rem;
}

.search-input:focus {
	border-color: var(--color-accent);
	outline: none;
}

.search-content {
	flex: 1;
	display: flex;
	overflow: hidden;
}

.search-results-sidebar {
	width: 50%;
	border-right: 1px solid var(--color-border);
	display: flex;
	flex-direction: column;
}

.search-results-count {
	padding: var(--space-3);
	background: var(--color-surface-alt);
	border-bottom: 1px solid var(--color-border);
	font-size: 0.9rem;
	color: var(--color-text-dim);
	font-weight: 600;
}

.search-results-list {
	flex: 1;
	overflow-y: auto;
}

.search-result {
	padding: var(--space-3);
	border-bottom: 1px solid var(--color-border);
	cursor: pointer;
	transition: background var(--transition-fast);
}

.search-result:hover,
.search-result.selected {
	background: var(--color-surface-alt);
}

.search-result__first-line {
	font-weight: 600;
	font-size: 0.9rem;
	margin-bottom: var(--space-2);
}

.search-result__path {
	font-size: 0.8rem;
	color: var(--color-text-dim);
}

.search-preview {
	width: 50%;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--color-bg);
}

/* The previewPane (#search-preview-content) fills the pane as a flex column so
   the rendered body scrolls and the Open bar stays pinned to the bottom (3.3). */
.search-preview > .search-preview-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.search-preview__body {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: var(--space-5);
}

/* Full-width action bar to open the note in the editor (3.3) */
.search-preview__open {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.6em;
	padding: var(--space-4);
	background: var(--color-accent);
	color: #000;
	font-weight: 600;
	text-decoration: none;
	border-top: 1px solid var(--color-border);
	transition: filter var(--transition-fast);
}

.search-preview__open:hover {
	filter: brightness(0.96);
}

.search-preview__hint {
	font-size: 0.82em;
	font-weight: 500;
	opacity: 0.65;
}

/* Search-in-progress indicator (3.1): an indeterminate bar under the input */
.search-progress {
	height: 2px;
	margin-top: var(--space-3);
	overflow: hidden;
	background: var(--color-border);
	border-radius: var(--radius-pill);
}

.search-progress::before {
	content: "";
	display: block;
	height: 100%;
	width: 40%;
	background: var(--color-accent);
	border-radius: inherit;
	animation: search-progress-slide 1s ease-in-out infinite;
}

@keyframes search-progress-slide {
	0% {
		transform: translateX(-100%);
	}
	100% {
		transform: translateX(350%);
	}
}

/* htmx indicator visibility (opacity toggled while the request is in flight) */
.htmx-indicator {
	opacity: 0;
	transition: opacity 120ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
	opacity: 1;
}

.search-empty {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: var(--space-8);
}

.empty-state {
	text-align: center;
	max-width: 500px;
}

.empty-state__icon {
	font-size: 4rem;
	margin-bottom: var(--space-5);
	opacity: 0.4;
}

.empty-state__title {
	font-size: 1.5rem;
	font-weight: 600;
	margin-bottom: var(--space-3);
	color: var(--color-text);
}

.empty-state__message {
	font-size: 1rem;
	color: var(--color-text-dim);
	margin-bottom: var(--space-6);
	line-height: 1.6;
}

.empty-state__hints {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	padding: var(--space-4);
	background: var(--color-surface-alt);
	border-radius: var(--radius-sm);
	border: 1px solid var(--color-border);
}

.empty-state__hint {
	font-size: 0.9rem;
	color: var(--color-text-dim);
	margin: 0;
	text-align: left;
}

.empty-state__hint strong {
	color: var(--color-text);
}

.empty-state-container {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 400px;
	padding: var(--space-8);
}

/* Loading states */
.htmx-request {
	opacity: 0.6;
	transition: opacity var(--transition-smooth);
	pointer-events: none;
}

@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@keyframes slideDown {
	from {
		opacity: 0;
		transform: translateY(-10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Subtle page animations */
.card {
	animation: fadeIn 0.3s ease-out;
}

.card:nth-child(1) {
	animation-delay: 0ms;
}
.card:nth-child(2) {
	animation-delay: 50ms;
}
.card:nth-child(3) {
	animation-delay: 100ms;
}
.card:nth-child(4) {
	animation-delay: 150ms;
}
.card:nth-child(5) {
	animation-delay: 200ms;
}
.card:nth-child(6) {
	animation-delay: 250ms;
}

.empty-state {
	animation: fadeIn 0.4s ease-out;
}

.alert {
	animation: slideDown 0.3s ease-out;
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}

	.card {
		animation: none;
	}

	.empty-state {
		animation: none;
	}

	.alert {
		animation: none;
	}
}

/* Highlight matches */
.search-highlight {
	background: var(--color-accent);
	color: #000;
	padding: 0.1em 0.2em;
	border-radius: 0.2em;
}

/* Search Preview Modal */
.search-preview-modal {
	position: fixed;
	top: 0;
	left: 0;
	width: 100vw;
	height: 100vh;
	z-index: 2000;
	display: flex;
	align-items: center;
	justify-content: center;
}

.search-preview-modal__overlay {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.5);
}

.search-preview-modal__content {
	position: relative;
	background: var(--color-surface);
	border-radius: var(--radius-sm);
	border: 1px solid var(--color-border);
	max-width: 90vw;
	max-height: 90vh;
	width: 800px;
	height: 600px;
	display: flex;
	flex-direction: column;
	box-shadow: var(--shadow-md);
}

.search-preview-modal__close {
	position: absolute;
	top: var(--space-2);
	right: var(--space-2);
	background: none;
	border: none;
	font-size: 1.5rem;
	cursor: pointer;
	color: var(--color-text-dim);
	padding: var(--space-2);
	border-radius: var(--radius-sm);
	transition: background var(--transition-fast);
	z-index: 1;
}

.search-preview-modal__close:hover {
	background: var(--color-surface-alt);
}

.search-preview-modal .search-preview-content {
	flex: 1;
	padding: var(--space-4);
	overflow-y: auto;
	padding-top: var(--space-6);
}

/* ============================================================================
   RESPONSIVE BREAKPOINT: Mobile (max-width: 768px)
   Major layout changes for smaller screens:
   - Search: Stack sidebar + preview vertically, hide preview by default
   - Editor: Force column layout for all view modes
   - Metadata panel: Unpin if pinned, show as full-screen modal

   IMPORTANT: This 768px breakpoint is referenced in editor.js as MOBILE_BREAKPOINT
   ============================================================================ */
@media (max-width: 768px) {
	/* Search page adjustments */
	.search-content {
		flex-direction: column;
	}

	.search-results-sidebar {
		width: 100%;
		height: 100%;
		border-right: none;
		border-bottom: none;
	}

	.search-preview {
		display: none; /* Show via modal instead (see search.js) */
	}

	/* Force vertical stacking for editor on mobile */
	.editor-container {
		flex-direction: column;
	}

	/* Override all view modes to stack vertically */
	.editor-container.editoronly,
	.editor-container.previewonly,
	.editor-container.sidebyside {
		flex-direction: column;
	}

	.editor-container form {
		width: 100%;
	}

	.editor-container .editor,
	.editor-container .preview {
		width: 100%;
		min-height: 200px; /* Shorter than desktop 300px */
	}
}

/* ============================================================================
   METADATA/PROPERTIES PANEL

   A sidebar that shows yak metadata, backlinks, and controls

   BEHAVIOR BY SCREEN SIZE:
   - Desktop (>768px): Can be toggled or pinned. When pinned, becomes part of grid.
   - Mobile (≤768px): Always shows as slide-in modal over content (cannot be pinned)

   STATES:
   - Hidden: transform: translateX(100%) - off-screen to the right
   - Visible: transform: translateX(0) - slides in from right
   - Pinned (desktop only): position: relative, part of grid layout

   Controlled by: editor.js (toggleMetadataPanel, togglePanelPin functions)
   ============================================================================ */

/* Main layout container - uses CSS Grid */
.editor-layout {
	display: grid;
	grid-template-columns: 1fr; /* Default: single column (panel hidden) */
	gap: 0;
	min-height: calc(100vh - var(--header-height, 60px));
	transition: grid-template-columns 0.3s ease-in-out;
	position: relative;
	overflow: hidden;
}

/* When pinned, the panel stays a fixed right rail (not a grid track) so it does
   not squeeze the centered editor on screens wider than its max-width (2.6). */
.editor-layout.panel-pinned {
	grid-template-columns: 1fr;
}

/* Reserve the rail width so the editor/preview can use the rest, then drop the
   centered reading cap while pinned so they actually claim that freed space (2.6). */
@media (min-width: 769px) {
	.editor-layout.panel-pinned .editor-main {
		padding-right: 320px;
	}

	.editor-layout.panel-pinned .editor-container {
		max-width: none;
	}
}

/* Main editor area (left side or full width when panel hidden) */
.editor-main {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 0; /* Critical for nested flex overflow */
	flex: 1;
	padding-bottom: calc(var(--action-bar-height) + var(--space-3)); /* Space for fixed action bar */
}

/* The metadata panel itself - starts off-screen */
.metadata-panel {
	background: var(--color-surface);
	border-left: 1px solid var(--color-border);
	padding: var(--space-4);
	overflow-y: auto;
	max-height: calc(100vh - var(--header-height, 60px));
	transition: transform 0.3s ease-in-out;
	position: fixed; /* Floats over content by default */
	top: var(--header-height, 60px);
	right: 0;
	bottom: 0;
	width: 320px;
	z-index: 100; /* Above editor, below backdrop */
	transform: translateX(100%); /* Hidden: off-screen to the right */
}

/* Visible state - slides in from right */
.metadata-panel.visible {
	transform: translateX(0);
}

/* Pinned state - stays fixed on the right, persistent (no slide, no backdrop) */
.editor-layout.panel-pinned .metadata-panel {
	transform: none;
}

/* Terminal-style title bar - full-bleed strip with a category-colored accent */
.panel-titlebar {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) var(--space-4);
	padding: var(--space-2) var(--space-3);
	background: var(--color-surface-alt);
	border-bottom: 1px solid var(--color-border);
	font-size: 0.78rem;
}

.panel-titlebar__tab {
	display: inline-flex;
	align-items: center;
	gap: 0.45em;
	font-weight: 600;
	color: var(--color-text);
}

.panel-titlebar__mark {
	width: 0.6em;
	height: 0.6em;
	border-radius: 2px;
	background: var(--panel-accent, var(--color-accent));
}

.panel-titlebar__tri {
	color: var(--panel-accent, var(--color-accent));
	margin-right: auto;
	line-height: 1;
}

/* Filename + category row */
.panel-file {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--space-2);
	margin-bottom: var(--space-5);
	padding-bottom: var(--space-3);
	border-bottom: 1px solid var(--color-border);
}

.panel-file__name {
	font-weight: 600;
	font-size: 0.85rem;
	color: var(--color-text);
	word-break: break-all;
}

.panel-file__category {
	font-size: 0.72rem;
	color: var(--color-text-dim);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	white-space: nowrap;
}

/* Pin Button - only functional on desktop */
.panel-pin {
	flex-shrink: 0;
	width: 32px;
	height: 32px;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: transparent;
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	color: var(--color-text-dim);
	cursor: pointer;
	transition: all var(--transition-fast);
}

.panel-pin:hover {
	background: var(--color-surface-alt);
	color: var(--color-text);
}

/* Pinned state - button appears pressed */
.panel-pin[aria-pressed="true"] {
	background: var(--color-accent);
	border-color: var(--color-accent);
	color: #000;
}

/* Backdrop - dimmed overlay when panel is visible but not pinned */
.metadata-backdrop {
	position: fixed;
	inset: 0;
	top: var(--header-height, 60px);
	background: rgba(0, 0, 0, 0.3); /* 30% black overlay */
	opacity: 0;
	pointer-events: none; /* Doesn't block clicks when invisible */
	transition: opacity 0.3s ease;
	z-index: 90; /* Below panel, above editor */
}

.metadata-backdrop.visible {
	opacity: 1;
	pointer-events: auto; /* Captures clicks to dismiss panel */
}

/* Hide backdrop when pinned (panel is part of layout, not overlay) */
.editor-layout.panel-pinned ~ .metadata-backdrop {
	display: none;
}

/* View toggle in panel - flat segmented control, labels centered (2.3) */
.metadata-panel .view-toggle {
	display: flex;
	gap: 2px;
	background: var(--color-surface-alt);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	padding: 2px;
}

.metadata-panel .view-toggle .button {
	flex: 1;
	justify-content: center; /* Center the label within the filled area (2.3) */
	text-align: center;
	border-radius: calc(var(--radius-sm) - 2px);
	padding: var(--space-2) var(--space-1);
	font-size: 0.78rem;
}

/* Word-wrap toggle button (2.5) */
.wrap-toggle {
	padding: var(--space-2) var(--space-5);
	font-size: 0.78rem;
	border-radius: var(--radius-sm);
}

.wrap-toggle.active {
	background: var(--color-accent);
	color: #000;
	border-color: var(--color-accent);
	font-weight: 600;
}

.metadata-section {
	margin-bottom: var(--space-6);
}

.metadata-section:last-child {
	margin-bottom: 0;
}

/* Status-bar style section label: "▸ label" with a category-colored marker */
.metadata-section__label {
	display: flex;
	align-items: center;
	gap: 0.5em;
	font-size: 0.72rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--color-text-dim);
	margin: 0 0 var(--space-3) 0;
}

.metadata-section__label::before {
	content: "▸";
	color: var(--panel-accent, var(--color-accent));
	font-size: 0.9em;
}

.metadata-section--danger {
	margin-top: auto;
	padding-top: var(--space-4);
	border-top: 1px solid var(--color-border);
}

.metadata-properties {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

.metadata-property {
	display: flex;
	gap: 0.4em;
	font-size: 0.78rem;
	line-height: 1.5;
}

.metadata-property__key {
	color: var(--color-text-dim);
	white-space: nowrap;
}

.metadata-property__key::after {
	content: " =";
}

.metadata-property__value {
	color: var(--color-text);
	word-break: break-word;
}

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

.backlink-item {
	padding: var(--space-3) 0;
	border-bottom: 1px solid var(--color-border);
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: var(--space-2);
}

.backlink-item:last-child {
	border-bottom: none;
}

.backlink-link {
	color: var(--color-text);
	text-decoration: none;
	font-size: 0.875rem;
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	transition: color var(--transition-fast);
}

.backlink-link:hover {
	color: var(--color-accent);
	text-decoration: underline;
}

.backlink-type {
	font-size: 0.75rem;
	color: var(--color-text-dim);
	background: var(--color-surface-alt);
	padding: 0.125rem 0.5rem;
	border-radius: var(--radius-sm);
}

.metadata-empty {
	color: var(--color-text-dim);
	font-size: 0.875rem;
	font-style: italic;
	margin: 0;
	padding: var(--space-3) 0;
}

.stats-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--space-3);
}

.stat-item {
	background: var(--color-surface-alt);
	padding: var(--space-4);
	border-radius: var(--radius-sm);
	border: 1px solid var(--color-border);
}

.stat-item__label {
	font-size: 0.75rem;
	color: var(--color-text-dim);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	margin-bottom: 0.25rem;
}

.stat-item__value {
	font-size: 1.25rem;
	font-weight: 600;
	color: var(--color-text);
}

/* Responsive: Mobile layout */
@media (max-width: 768px) {
	/* Editor layout - single column, full width */
	.editor-layout {
		display: block;
	}

	.editor-layout.panel-pinned {
		display: block;
	}

	.editor-main {
		min-height: calc(100vh - var(--header-height, 60px) - 60px);
	}

	/* Editor container - full width */
	.editor-container {
		flex-direction: column;
		padding: var(--space-3);
	}

	.editor-container.editoronly,
	.editor-container.previewonly {
		flex-direction: column;
	}

	.editor-container form {
		width: 100%;
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.editor-container .editor {
		width: 100%;
		flex: 1;
		min-height: calc(100vh - var(--header-height, 60px) - 140px);
	}

	.editor-container .preview {
		width: 100%;
		flex: 1;
	}

	/* Metadata panel - bottom sheet */
	.metadata-panel {
		position: fixed;
		top: auto;
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		max-height: 70vh;
		border-left: none;
		border-top: 1px solid var(--color-border);
		border-radius: var(--radius-lg) var(--radius-lg) 0 0;
		transform: translateY(100%);
		z-index: 100;
	}

	.metadata-panel.visible {
		transform: translateY(0);
	}

	/* No pinning on mobile */
	.editor-layout.panel-pinned .metadata-panel {
		position: fixed;
		transform: translateY(0);
	}

	/* Hide pin button on mobile */
	.panel-pin {
		display: none;
	}

	/* Backdrop - full screen on mobile */
	.metadata-backdrop {
		top: 0;
	}

	/* Stats grid - single column */
	.stats-grid {
		grid-template-columns: 1fr;
	}

	/* View toggle - compact */
	.metadata-panel .view-toggle .button {
		padding: var(--space-2) var(--space-1);
		font-size: 0.75rem;
	}
}

/* ============================================================================
   Doctor: attachment integrity report
   ============================================================================ */
.doctor-section {
	margin: var(--space-4) 0 var(--space-6) 0;
}

.doctor-section__title {
	font-size: 1.125rem;
	margin: 0 0 var(--space-2) 0;
	padding-bottom: var(--space-2);
	border-bottom: 1px solid var(--color-border);
}

.doctor-section__hint {
	color: var(--color-text-muted, inherit);
	font-size: 0.875rem;
	margin: 0 0 var(--space-3) 0;
}

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

.doctor-item {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: var(--space-2) var(--space-4);
	padding: var(--space-2) var(--space-3);
	border-left: 3px solid var(--color-border);
	background: var(--color-surface-alt);
	border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
	margin-bottom: var(--space-2);
}

.doctor-item--missing {
	border-left-color: #d9534f;
}

.doctor-item--orphan {
	border-left-color: #d9a441;
}

.doctor-item__ref {
	font-size: 0.875rem;
}

.doctor-item__note {
	font-size: 0.8125rem;
	opacity: 0.85;
}

.doctor-item__size {
	font-size: 0.8125rem;
	opacity: 0.7;
	margin-left: auto;
}

.doctor-empty {
	color: var(--color-text-muted, inherit);
	opacity: 0.75;
	margin: 0;
}
