/* Smooth scrolling for anchor links */
html {
	scroll-behavior: smooth;
}

/* Docs uses Inter for readability */
aside,
.docs-content {
	font-family: var(--font-readable);
}

/* Dark mode scrollbars */
.dark ::-webkit-scrollbar {
	width: 10px;
	height: 10px;
}

.dark ::-webkit-scrollbar-track {
	background: transparent;
}

.dark ::-webkit-scrollbar-thumb {
	background: #27272a;
	border-radius: 5px;
}

.dark ::-webkit-scrollbar-thumb:hover {
	background: #3f3f46;
}

/* Sidebar scrollbar - slightly lighter and thinner */
.dark aside ::-webkit-scrollbar {
	width: 6px;
}

.dark aside ::-webkit-scrollbar-thumb {
	background: #3f3f46;
}

.dark aside ::-webkit-scrollbar-thumb:hover {
	background: #52525b;
}

/* Light mode scrollbars */
:root:not(.dark) ::-webkit-scrollbar {
	width: 10px;
	height: 10px;
}

:root:not(.dark) ::-webkit-scrollbar-track {
	background: transparent;
}

:root:not(.dark) ::-webkit-scrollbar-thumb {
	background: #d4d4d8;
	border-radius: 5px;
}

:root:not(.dark) ::-webkit-scrollbar-thumb:hover {
	background: #a1a1aa;
}

/* Sidebar scrollbar - slightly darker and thinner in light mode */
:root:not(.dark) aside ::-webkit-scrollbar {
	width: 6px;
}

:root:not(.dark) aside ::-webkit-scrollbar-thumb {
	background: #d4d4d8;
}

:root:not(.dark) aside ::-webkit-scrollbar-thumb:hover {
	background: #a1a1aa;
}

/* Hide header logo on docs pages - sidebar has its own logo */
body:has(.docs-main) .nav a[href="/"]:not(.nav-link) {
	visibility: hidden;
}

/* Hide sidebar logo on mobile - it's redundant */
@media (max-width: 1000px) {
	.sidebar .logo-j,
	.sidebar .logotext {
		display: none;
	}
}

/* Light mode: white background for theme toggle button */
:root:not(.dark) .theme-toggle {
	background: #ffffff !important;
}

/* Nav items - need class:active support */
.nav-item {
	display: block;
	padding: 0.25rem 1.25rem 0.25rem 1.75rem;
	color: var(--text-secondary);
	font-size: 0.8125rem;
	font-weight: 450;
	text-decoration: none;
	transition: all 0.15s ease;
	border-left: 2px solid transparent;
}

.nav-item:hover {
	color: var(--text-primary);
	background: var(--bg-hover);
}

.nav-item.active,
.nav-item[aria-current="page"] {
	color: var(--accent);
	border-left-color: var(--accent);
	background: var(--accent-subtle);
}

.sidebar-section-toggle {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: 0.5rem 1.25rem;
	border: 0;
	background: transparent;
	color: var(--text-secondary);
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	cursor: pointer;
	transition: color 150ms ease;
}

.sidebar-section-toggle:hover {
	color: var(--text-primary);
}

.sidebar-chevron {
	transition: transform 200ms ease;
}

.sidebar-chevron.open {
	transform: rotate(90deg);
}

/* Sidebar filter.
 *
 * A filtered-out row leaves the flow entirely rather than fading, so the rows
 * that survive close up with no gap and nothing below them jumps. Both classes
 * are toggled by a class: directive, and they live here beside .nav-item
 * because the row that wears one is written inside a <for> body. */
.nav-item.nav-hidden {
	display: none;
}

.sidebar-section-hidden {
	display: none;
}

.sidebar-no-matches {
	padding: 0.5rem 1.75rem;
	color: var(--text-tertiary);
	font-size: 0.8125rem;
	font-style: italic;
}

/* Scroll offset for anchor links to account for fixed navbar */
.docs-content h2,
.docs-content h3 {
	scroll-margin-top: 5rem;
}

/* Docs content typography */
.docs-content h1 {
	font-size: 2.25rem;
	font-weight: 700;
	letter-spacing: -0.02em;
	line-height: 1.2;
	margin-bottom: 1rem;
}

.docs-content h2 {
	font-size: 1.5rem;
	font-weight: 600;
	letter-spacing: -0.01em;
	margin-top: 3rem;
	margin-bottom: 1rem;
	padding-bottom: 0.5rem;
	border-bottom: 1px solid var(--border);
}

.docs-content h3 {
	font-size: 1.25rem;
	font-weight: 600;
	margin-top: 2rem;
	margin-bottom: 0.75rem;
}

.docs-content p {
	color: var(--text-secondary);
	margin-bottom: 1rem;
	line-height: 1.75;
}

.docs-content .lead {
	font-size: 1.125rem;
	color: var(--text-secondary);
	line-height: 1.7;
	margin-bottom: 2rem;
}

.docs-content pre {
	background: var(--bg-code);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: 1rem 1.25rem;
	padding-top: 2.5rem;
	overflow-x: auto;
	margin: 1.5rem 0;
	position: relative;
}

.docs-content pre::before {
	content: 'code';
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	padding: 0.5rem 1rem;
	background: var(--bg-code-header);
	border-bottom: 1px solid var(--border);
	font-size: 0.75rem;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-tertiary);
	font-family: var(--font-readable);
}

/* Hide default "code" label when inside CodeBlock (which has its own "source" header) */
.docs-content .code-block pre {
	padding-top: 1rem;
	margin: 0;
	border: none;
	border-radius: 0;
}

.docs-content .code-block pre::before {
	display: none;
}

.docs-content pre code {
	background: none;
	padding: 0;
	font-size: 0.875rem;
	line-height: 1.65;
	color: var(--text-secondary);
}

.docs-content ul,
.docs-content ol {
	margin: 1rem 0 1.5rem 1.5rem;
	color: var(--text-secondary);
	line-height: 1.7;
}

.docs-content ul {
	list-style: disc;
}

.docs-content ol {
	list-style: decimal;
}

/* Live examples need list styles too (nested components) */
.live-example-content ul {
	list-style: disc;
	padding-left: 1.5rem;
}

.live-example-content ol {
	list-style: decimal;
	padding-left: 1.5rem;
}

.docs-content li {
	margin-bottom: 0.5rem;
}

.docs-content li::marker {
	color: var(--text-tertiary);
}

/* Tables */
.docs-content table {
	width: 100%;
	border-collapse: collapse;
	margin: 1.5rem 0;
	font-size: 0.875rem;
}

.docs-content th,
.docs-content td {
	text-align: left;
	padding: 0.75rem 1rem;
	border-bottom: 1px solid var(--border);
}

.docs-content th {
	font-weight: 600;
	color: var(--text-primary);
	background: var(--bg-tertiary);
}

.docs-content td {
	color: var(--text-secondary);
}

.docs-content tr:last-child td {
	border-bottom: none;
}

.docs-content tbody tr:hover {
	background: var(--bg-hover);
}

.docs-content a {
	color: var(--accent);
	text-decoration: none;
}

.docs-content a:hover:not(.next-link) {
	text-decoration: underline;
}

/* Callouts

   Two shapes are in use: an icon one (svg.callout-icon + div.callout-content)
   and a bare one that puts inline text straight into .callout. So the row
   layout has to be opt-in - a blanket `display: flex` turns every <strong>
   and <code> of a bare callout into its own flex column. */
.callout {
	padding: 0.9rem 1.15rem;
	border-radius: var(--radius-md);
	border: 1px solid;
	border-left-width: 3px;
	margin: 1.5rem 0;
	color: var(--text-secondary);
	line-height: 1.7;
}

.callout:has(> .callout-icon) {
	display: flex;
	gap: 0.75rem;
}

.callout strong {
	color: var(--text-primary);
	font-weight: 600;
}

/* Callout text already sits on a tinted panel, so the default inline-code
   chip would stack a second background on top of it. */
.callout code {
	background: color-mix(in srgb, var(--text-primary) 8%, transparent);
}

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

.callout > :last-child {
	margin-bottom: 0;
}

.callout-icon {
	flex-shrink: 0;
	width: 20px;
	height: 20px;
	/* Nudge onto the first line's optical centre rather than its box top. */
	margin-top: 0.2em;
}

.callout-content {
	flex: 1;
	min-width: 0;
}

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

.callout-content > :last-child {
	margin-bottom: 0;
}

.callout-info {
	background: color-mix(in srgb, var(--accent) 8%, transparent);
	border-color: color-mix(in srgb, var(--accent) 22%, transparent);
	border-left-color: var(--accent);
}

.callout-info .callout-icon {
	color: var(--accent);
}

.callout-warning {
	background: color-mix(in srgb, var(--warning) 10%, transparent);
	border-color: color-mix(in srgb, var(--warning) 25%, transparent);
	border-left-color: var(--warning);
}

.callout-warning .callout-icon {
	color: var(--warning);
}

/* ===========================================
   SIDEBAR - Pure CSS Responsive Behavior
   =========================================== */

/* Sidebar base styles */
.sidebar {
	position: fixed;
	top: 0;
	left: 0;
	bottom: 0;
	width: 280px;
	background: var(--bg-secondary);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	z-index: 100;
	transition: transform 0.25s ease;
}

/* Hidden checkbox for mobile toggle */
.sidebar-checkbox {
	display: none;
}

/* Hamburger button - mobile only */
.sidebar-hamburger {
	display: none;
	position: fixed;
	top: 1rem;
	left: 1rem;
	z-index: 101;
	width: 32px;
	height: 32px;
	cursor: pointer;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	gap: 5px;
	background: var(--bg-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	transition: all 0.15s ease;
}

.sidebar-hamburger:hover {
	background: var(--bg-hover);
	border-color: var(--border-hover);
}

.sidebar-hamburger span {
	display: block;
	width: 16px;
	height: 2px;
	background: var(--text-secondary);
	transition: all 0.25s ease;
}

/* Overlay for mobile */
.sidebar-overlay {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	z-index: 99;
	opacity: 0;
	transition: opacity 0.25s ease;
	pointer-events: none;
}

/* The docs column is a flex item (`flex-1` in docs/layout.html), and a flex
   item's default `min-width: auto` floors it at its own min-content width
   instead of at zero. Anything inside that refuses to wrap - a long code line
   in a <pre>, the package-manager tab bar, an unbreakable token - therefore
   pushed the WHOLE column wider than the viewport rather than scrolling inside
   its own box. Measured on /docs/quick-start at a 375px viewport: the column
   came out 583px wide, so every paragraph wrapped to 487px and was clipped at
   the right edge (this is the "no build conf...", "PascalCa..." cut-off).
   `min-width: 0` lets the column shrink to the viewport again; the <pre> and
   .pm-body boxes already carry `overflow-x: auto`, so the wide content scrolls
   inside them where it belongs. Not scoped to a media query on purpose - the
   same floor applies at any width where the content's min-content exceeds the
   space, and at desktop widths the column is far wider than its min-content so
   nothing about the desktop layout changes. */
.docs-main {
	min-width: 0;
}

/* Mobile: ≤1000px */
@media (max-width: 1000px) {
	/* Show hamburger */
	.sidebar-hamburger {
		display: flex;
	}

	/* Sidebar hidden by default, with top padding to match desktop header height */
	.sidebar {
		transform: translateX(-100%);
		padding-top: 2rem;
	}

	/* Main content full width */
	.docs-main {
		margin-left: 0 !important;
	}

	/* `px-12` is 48px a side - a third of a 375px phone spent on margin, which
	   left prose wrapping in a 279px ribbon. 24px matches what the homepage
	   hero drops to at this same breakpoint (`max-[1000px]:px-6`), so the two
	   templates share one mobile gutter. */
	.docs-content {
		padding-left: 1.5rem;
		padding-right: 1.5rem;
	}

	/* A table whose columns cannot fit the phone would otherwise punch out of
	   the column and re-break the page the way the flex floor above did. As a
	   block box the table scrolls inside itself instead. It still lays out at
	   the column width whenever it fits - every table currently in the docs
	   does (widest min-content measured: 179px against 327px available) - so
	   this is a floor, not a change to how today's tables render. */
	.docs-content table {
		display: block;
		overflow-x: auto;
	}

	/* The nav's home logo is already `visibility: hidden` on docs pages (the
	   sidebar carries the brand), and on mobile the sidebar's own logo is
	   hidden too - so the row was reserving 67px for the invisible logo plus
	   the 48px this rule used to keep clear for the hamburger. Measured on
	   /docs/quick-start at 375px, that pushed the theme toggle out to x=395:
	   entirely off the screen and untappable. Nothing is there to see or to
	   clear, so take the box out of the flow. `justify-between` cannot hold the
	   links against the right edge with only one child left, hence the auto
	   margin. Both halves are keyed to `body:has(.docs-main)` because docs.css
	   stays in the document after a client-side navigation away from /docs -
	   the old unguarded rule leaked its 3rem indent onto the homepage nav. */
	body:has(.docs-main) .nav a[href="/"]:not(.nav-link) {
		display: none;
	}

	body:has(.docs-main) .nav-links {
		margin-left: auto;
	}

	/* Show overlay element (still invisible until checked) */
	.sidebar-overlay {
		display: block;
	}

	/* When checkbox is checked: show sidebar */
	.sidebar-checkbox:checked ~ .sidebar,
	.sidebar-checkbox:checked ~ * .sidebar {
		transform: translateX(0);
	}

	/* When checkbox is checked: show overlay */
	.sidebar-checkbox:checked ~ .sidebar-overlay {
		opacity: 1;
		pointer-events: auto;
	}

	/* Animate hamburger to X when open */
	.sidebar-checkbox:checked ~ .sidebar-hamburger span:nth-child(1) {
		transform: rotate(45deg) translate(5px, 5px);
	}

	.sidebar-checkbox:checked ~ .sidebar-hamburger span:nth-child(2) {
		opacity: 0;
	}

	.sidebar-checkbox:checked ~ .sidebar-hamburger span:nth-child(3) {
		transform: rotate(-45deg) translate(5px, -5px);
	}
}

/* Desktop: >1000px - sidebar always visible */
@media (min-width: 1001px) {
	.sidebar {
		transform: translateX(0);
	}

	.docs-main {
		margin-left: 280px;
	}
}

/* Right-hand Table of Contents */
.toc-sidebar {
	display: none;
}

@media (min-width: 1280px) {
	.docs-main {
		display: grid;
		grid-template-columns: minmax(0, 900px) 160px;
		gap: 1.5rem;
		justify-content: center;
		padding-inline: 1.5rem;
	}

	.toc-sidebar {
		display: block;
		position: sticky;
		top: 5rem;
		align-self: start;
		max-height: calc(100vh - 6rem);
		overflow-y: auto;
	}

	.toc-nav {
		padding: 2.5rem 0 1rem 0;
	}

	.toc-title {
		font-size: 0.75rem;
		font-weight: 600;
		text-transform: uppercase;
		letter-spacing: 0.05em;
		color: var(--text-tertiary);
		margin-bottom: 0.75rem;
		padding-left: 0.75rem;
	}

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

	.toc-item {
		margin: 0;
	}

	.toc-item-nested {
		padding-left: 0.75rem;
	}

	.toc-link {
		display: block;
		padding: 0.375rem 0.75rem;
		font-size: 0.8125rem;
		color: var(--text-tertiary);
		text-decoration: none;
		border-left: 2px solid transparent;
		transition: all 0.15s ease;
		line-height: 1.4;
	}

	.toc-link:hover {
		color: var(--text-secondary);
	}

	.toc-link.active {
		color: var(--accent);
		border-left-color: var(--accent);
	}
}

/* Adjust for extra-wide screens */
@media (min-width: 1536px) {
	.docs-main {
		grid-template-columns: minmax(0, 900px) 180px;
		gap: 2rem;
	}
}

/* JSX component demo (docs/advanced/react) -------------------------------- */
/* Plain CSS rather than a scoped <style> block: the markup is produced by a
   JetShake-compiled .tsx component, which carries no JAF scoping class. */

.jsx-demo {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.jsx-counter {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.jsx-counter-label {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.jsx-counter-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.jsx-counter-value {
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.jsx-counter-button,
.jsx-demo-controls button {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
}

.jsx-counter-button:hover,
.jsx-demo-controls button:hover {
  border-color: var(--text-tertiary);
}

.jsx-demo-controls {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.jsx-demo-readout {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}

/* ===========================================
   CALLOUT ICONS (leaf: foundation-callout-icons)
   ===========================================

   One shared definition instead of an inlined <svg> per page. The old
   per-page icons were solid Material glyphs whose "i" collapsed into a
   blob at 20px; these are Lucide-style outline marks (Lucide is ISC,
   derived from MIT Feather) inlined as data URIs, so no icon package is
   added to the site.

   The glyph is painted with `background-color` through a `mask`, so it
   always takes the variant's own theme token and therefore tracks light
   and dark mode with no extra rules.

   Markup contract: a callout opts into the icon row simply by wrapping
   its body in `<div class="callout-content">`. No icon markup is needed.
   The `:not(:has(> .callout-icon))` guard keeps any page that still has a
   hand-inlined `<svg class="callout-icon">` on its own icon rather than
   showing two.  */

.callout {
	/* Lucide "info": circle + stem + dot. */
	--callout-icon-info: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E");
	/* Lucide "triangle-alert": rounded triangle + stem + dot. */
	--callout-icon-warning: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E");
}

/* The icon row is now keyed off .callout-content, since the icon itself is
   no longer an element in the page. */
.callout:has(> .callout-content) {
	display: flex;
	gap: 0.75rem;
}

.callout-info:has(> .callout-content):not(:has(> .callout-icon))::before,
.callout-warning:has(> .callout-content):not(:has(> .callout-icon))::before {
	content: "";
	flex: none;
	width: 20px;
	height: 20px;
	/* Nudge onto the first line's optical centre rather than its box top. */
	margin-top: 0.2em;
	background-color: var(--callout-icon-tint);
	-webkit-mask: var(--callout-icon) center / contain no-repeat;
	mask: var(--callout-icon) center / contain no-repeat;
}

.callout-info {
	--callout-icon: var(--callout-icon-info);
	--callout-icon-tint: var(--accent);
}

.callout-warning {
	--callout-icon: var(--callout-icon-warning);
	--callout-icon-tint: var(--warning);
}

/* ===========================================
   FORM CONTROLS IN LIVE EXAMPLES (leaf: bind-page)
   ===========================================

   Tailwind v4's preflight strips native form chrome
   (`*, ::before, ::after { border: 0 solid; margin: 0; padding: 0 }` plus
   `button, input, select, textarea { background-color: transparent }`),
   and nothing in the site ever put it back. An unstyled field in a docs
   example was therefore a transparent, borderless, zero-padding rectangle
   in both themes: invisible until the UA focus ring appeared, which is
   also what made `bind:` demos read as "laggy" (nothing to anchor the eye
   while the echo landed 1ms later).

   Scoped to `.live-example-content` on purpose: site chrome and the REPL
   style their own controls, and an example that ships its own <style>
   block still wins on specificity where it sets the same properties.

   `color-scheme` is set per theme so the native parts we deliberately do
   not restyle - checkbox and radio glyphs, select popups, number spinners,
   scrollbars - follow the docs theme. The site's dark mode is a `.dark`
   class on <html>, not `prefers-color-scheme`, so both sides are explicit. */

:root.dark {
	color-scheme: dark;
}

:root:not(.dark) {
	color-scheme: light;
}

.live-example-content
	:is(
		input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
		textarea,
		select
	) {
	font: inherit;
	font-size: 0.9rem;
	color: var(--text-primary);
	background: var(--bg-primary);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: 0.35rem 0.6rem;
}

/* A colour input is the one control whose whole surface IS its value. The
   chrome-restoring rule above would paint --bg-primary behind it and then
   push 0.35rem/0.6rem of padding inward, which on a 50x27 control leaves the
   swatch a few pixels tall inside a black box - the value is correct, the
   paint is correct, and the control reads as broken (bug 137's other half:
   a `bind:value` colour picker was reported as "renders black" and the
   binding turned out to be innocent). So it keeps its native swatch and only
   gets a size worth clicking. */
.live-example-content input[type="color"] {
	width: 3rem;
	height: 2rem;
	padding: 0;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: none;
	vertical-align: middle;
	cursor: pointer;
}

.live-example-content :is(input, textarea, select):focus-visible {
	border-color: var(--accent);
	outline: none;
}
