/*
 * Ferndale Intranet: base.
 *
 * Element rules are wrapped in :where() (zero specificity), so every plugin
 * rule wins over them (04 §3 rows 13–14). Theme components use fi- classes.
 * Colours come from role tokens only (tokens.css).
 */

/* ------------------------------------------------------------------
 * Reset and page.
 * ------------------------------------------------------------------ */
*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
	scroll-behavior: smooth;
	scroll-padding-top: calc(var(--fi-header-h) + 1rem);
}

body {
	margin: 0;
	background-color: var(--fi-page-bg);
	color: var(--fi-text);
	font-family: var(--fi-font);
	font-size: 1.0625rem;
	line-height: 1.7;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
}

:where(img, svg, video, canvas) {
	max-width: 100%;
}

:where(img) {
	height: auto;
}

:where(a) {
	color: var(--fi-link);
}

:where(a:hover) {
	color: var(--fi-link-hover);
}

:where(h1, h2, h3, h4, h5, h6) {
	color: var(--fi-heading);
	font-family: var(--fi-font);
	line-height: 1.2;
}

:where(button, input, select, textarea, optgroup) {
	font: inherit;
	letter-spacing: inherit;
}

:where(button, [role="button"], summary, label[for]) {
	cursor: pointer;
}

:where(hr) {
	height: 1px;
	border: 0;
	background: var(--fi-border);
}

/* Focus: always visible for keyboard users. Dark surfaces set --fi-ring
 * to gold (--fi-focus-on-dark); light surfaces use --fi-focus. */
:focus-visible {
	outline: 3px solid var(--fi-ring, var(--fi-focus));
	outline-offset: 2px;
}

:where(.site-main):focus {
	outline: none;
}

::selection {
	background: var(--fi-accent);
	color: var(--fi-on-accent);
}

/* ------------------------------------------------------------------
 * Icons (Phosphor, inc/icons.php).
 * ------------------------------------------------------------------ */
.fi-icon {
	display: inline-block;
	flex: none;
	vertical-align: middle;
}

/* The soft second layer of duotone icons; a container can colour it. */
.fi-icon .icon-duo {
	fill: var(--fi-icon-duo, currentColor);
	opacity: var(--fi-icon-duo-opacity, 0.2);
}

/* ------------------------------------------------------------------
 * Accessibility helpers.
 * ------------------------------------------------------------------ */
.screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	border: 0;
	white-space: nowrap;
	word-wrap: normal !important;
}

.screen-reader-text:focus {
	z-index: var(--fi-z-skip);
	display: block;
	width: auto;
	height: auto;
	padding: 1rem 1.25rem;
	clip: auto !important;
	clip-path: none;
	background: var(--fi-card-bg);
	color: var(--fi-primary);
}

.skip-link {
	position: absolute;
	top: -10rem;
	left: 1rem;
	z-index: var(--fi-z-skip);
	padding: 0.85rem 1.25rem;
	border-radius: var(--fi-radius-control);
	background: var(--fi-current);
	color: var(--fi-heading);
	font-weight: 800;
	text-decoration: none;
	box-shadow: var(--fi-shadow);
}

.skip-link:focus {
	top: 1rem;
	outline-color: var(--fi-heading);
}

#top {
	position: absolute;
	top: 0;
}

/* ------------------------------------------------------------------
 * Buttons: 10px radius, weight 700, at least 44px tall (04 §3 row 7).
 * .fi-btn is the theme's class. Unclassed <button> and submit inputs get
 * the same look at zero specificity, so classed plugin buttons keep theirs.
 * ------------------------------------------------------------------ */
.fi-btn,
.wp-block-button__link,
.wp-element-button,
:where(button:not([class]), input:is([type="submit"], [type="button"], [type="reset"]):not([class])) {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	min-height: 2.75rem;
	padding: 0.7rem 1.3rem;
	border: 2px solid transparent;
	border-radius: var(--fi-radius-control);
	background-color: var(--fi-primary);
	color: var(--fi-on-primary);
	font-family: var(--fi-font);
	font-size: 1rem;
	font-weight: 700;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	cursor: pointer;
	transition: background-color var(--fi-duration) ease, color var(--fi-duration) ease, border-color var(--fi-duration) ease, box-shadow var(--fi-duration) ease;
}

.fi-btn:hover,
.wp-block-button__link:hover,
.wp-element-button:hover,
:where(button:not([class]), input:is([type="submit"], [type="button"], [type="reset"]):not([class])):hover {
	background-color: var(--fi-primary-hover);
	color: var(--fi-on-primary);
	text-decoration: none;
}

.fi-btn:disabled,
.fi-btn[aria-disabled="true"],
:where(button:not([class]), input:is([type="submit"], [type="button"], [type="reset"]):not([class])):disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

.fi-btn--secondary,
.is-style-outline > .wp-block-button__link,
.wp-block-button__link.is-style-outline {
	border-color: var(--fi-primary);
	background-color: transparent;
	color: var(--fi-primary);
}

.fi-btn--secondary:hover,
.is-style-outline > .wp-block-button__link:hover {
	background-color: var(--fi-primary);
	color: var(--fi-on-primary);
}

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

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

.fi-btn--success {
	background-color: var(--fi-success);
	color: var(--fi-on-primary);
}

.fi-btn--success:hover {
	background-color: var(--fi-success-hover);
}

.fi-btn--danger {
	background-color: var(--fi-danger);
	color: var(--fi-on-primary);
}

.fi-btn--danger:hover {
	background-color: var(--fi-danger-hover);
}

.fi-btn--ghost-light {
	border-color: var(--fi-on-dark-border);
	background-color: transparent;
	color: var(--fi-header-text);
}

.fi-btn--ghost-light:hover {
	background-color: var(--fi-on-dark-hover);
	color: var(--fi-header-text);
}

.fi-btn--sm {
	min-height: 2.25rem;
	padding: 0.45rem 0.9rem;
	font-size: 0.9375rem;
}

.fi-btn--lg {
	min-height: 3.25rem;
	padding: 0.85rem 1.6rem;
	font-size: 1.0625rem;
}

/* ------------------------------------------------------------------
 * The one form-control spec (04 §3 row 6), for every input, select and
 * textarea in the theme and the plugins. Zero specificity: plugin
 * stylesheets map their controls onto it with the same tokens.
 * Colours are explicit so a dark OS never repaints the controls.
 * ------------------------------------------------------------------ */
:where(input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="reset"], [type="file"], [type="range"], [type="color"], [type="image"], [type="hidden"]), select, textarea),
.fi-control {
	min-height: 2.75rem;
	max-width: 100%;
	padding: 0.6rem 0.85rem;
	border: 1px solid var(--fi-control-border);
	border-radius: var(--fi-radius-control);
	background-color: var(--fi-control-bg);
	color: var(--fi-text);
	line-height: 1.4;
	transition: border-color var(--fi-duration) ease, box-shadow var(--fi-duration) ease;
}

:where(textarea),
textarea.fi-control {
	min-height: 6rem;
}

:where(select) option,
:where(select) optgroup {
	background-color: var(--fi-control-bg);
	color: var(--fi-text);
}

:where(input, textarea)::placeholder {
	color: var(--fi-placeholder);
	opacity: 1;
}

:where(input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="reset"], [type="file"], [type="range"], [type="color"], [type="image"], [type="hidden"]), select, textarea):focus-visible,
.fi-control:focus-visible {
	border-color: var(--fi-primary);
	outline: 3px solid var(--fi-focus);
	outline-offset: 1px;
}

:where(input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="reset"], [type="file"], [type="range"], [type="color"], [type="image"], [type="hidden"]), select, textarea):disabled,
.fi-control:disabled {
	background-color: var(--fi-surface-2);
	color: var(--fi-muted);
	cursor: not-allowed;
}

/* Checkboxes and radios are drawn by the theme (not the browser), so a
 * dark OS can't turn them into dark filled squares and circles on the light
 * content (decision 15). Zero specificity: plugin rules still win, and
 * plugins that hide the input behind their own box keep doing so. Focus
 * uses the global :focus-visible ring. */
:where(input[type="checkbox"], input[type="radio"]) {
	-webkit-appearance: none;
	appearance: none;
	display: inline-grid;
	place-content: center;
	flex: none;
	width: 1.125rem;
	height: 1.125rem;
	margin: 0 0.3em 0 0;
	padding: 0;
	border: 1px solid var(--fi-control-border);
	border-radius: 4px;
	background-color: var(--fi-control-bg);
	color: var(--fi-on-primary);
	vertical-align: middle; /* Not baseline: the tick or dot would move the box. */
	cursor: pointer;
}

:where(input[type="radio"]) {
	border-radius: 50%;
}

:where(input[type="checkbox"]:checked, input[type="radio"]:checked, input[type="checkbox"]:indeterminate) {
	border-color: var(--fi-primary);
	background-color: var(--fi-primary);
}

:where(input[type="checkbox"]:not(:checked, :disabled):hover, input[type="radio"]:not(:checked, :disabled):hover) {
	border-color: var(--fi-primary);
}

:where(input[type="checkbox"]:checked)::before {
	content: "";
	width: 0.75rem;
	height: 0.75rem;
	background: currentColor;
	-webkit-mask: var(--fi-icon-check) center / contain no-repeat;
	mask: var(--fi-icon-check) center / contain no-repeat;
}

:where(input[type="checkbox"]:indeterminate)::before {
	content: "";
	width: 0.6rem;
	height: 2px;
	border-radius: 1px;
	background: currentColor;
	-webkit-mask: none;
	mask: none;
}

:where(input[type="radio"]:checked)::before {
	content: "";
	width: 0.45rem;
	height: 0.45rem;
	border-radius: 50%;
	background: currentColor;
}

:where(input[type="checkbox"]:disabled, input[type="radio"]:disabled) {
	opacity: 0.55;
	cursor: not-allowed;
}

:where(input[type="file"]) {
	max-width: 100%;
	color: var(--fi-text);
}

:where(input[type="file"])::file-selector-button {
	margin-inline-end: 0.75rem;
	padding: 0.5rem 0.9rem;
	border: 1px solid var(--fi-primary);
	border-radius: var(--fi-radius-control);
	background: var(--fi-card-bg);
	color: var(--fi-primary);
	font: inherit;
	font-weight: 700;
	cursor: pointer;
	transition: background-color var(--fi-duration) ease;
}

:where(input[type="file"])::file-selector-button:hover {
	background: var(--fi-tint);
}

:where(input[type="range"], progress) {
	accent-color: var(--fi-primary);
	background-color: transparent;
}

.fi-label {
	display: block;
	margin-bottom: 0.35rem;
	color: var(--fi-heading);
	font-weight: 700;
}

.fi-help {
	margin-top: 0.35rem;
	color: var(--fi-muted);
	font-size: 0.9375rem;
}

.fi-error-text {
	margin-top: 0.35rem;
	color: var(--fi-danger);
	font-size: 0.9375rem;
	font-weight: 600;
}

/* ------------------------------------------------------------------
 * Tables (.fi-table; content tables share the look in content.css).
 * ------------------------------------------------------------------ */
.fi-table-wrap {
	overflow-x: auto;
	border: 1px solid var(--fi-border);
	border-radius: var(--fi-radius);
	background: var(--fi-card-bg);
	-webkit-overflow-scrolling: touch;
}

.fi-table {
	width: 100%;
	border-collapse: collapse;
	background: var(--fi-card-bg);
	color: var(--fi-text);
	font-size: 0.9375rem;
	line-height: 1.55;
}

.fi-table :is(th, td) {
	padding: 0.75rem 1rem;
	border: 0;
	border-top: 1px solid var(--fi-border);
	text-align: start;
	vertical-align: top;
}

.fi-table thead :is(th, td) {
	border-top: 0;
	background: var(--fi-primary);
	color: var(--fi-on-primary);
	font-weight: 700;
}

.fi-table tbody tr:nth-child(even) > :is(td, th) {
	background: var(--fi-row-alt);
}

.fi-table tbody th {
	color: var(--fi-heading);
	font-weight: 700;
}

/* ------------------------------------------------------------------
 * Notices, badges, cards and panels.
 * ------------------------------------------------------------------ */
.fi-notice {
	padding: 0.9rem 1.1rem;
	border: 1px solid var(--fi-border);
	border-inline-start: 4px solid var(--fi-info);
	border-radius: var(--fi-radius);
	background: var(--fi-info-tint);
	color: var(--fi-text);
	line-height: 1.55;
}

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

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

.fi-notice--success {
	border-inline-start-color: var(--fi-success);
	background: var(--fi-success-tint);
}

.fi-notice--warning {
	border-inline-start-color: var(--fi-warning-line);
	background: var(--fi-warning-tint);
}

.fi-notice--danger {
	border-inline-start-color: var(--fi-danger);
	background: var(--fi-danger-tint);
}

.fi-notice__title {
	display: block;
	margin-bottom: 0.25rem;
	color: var(--fi-heading);
	font-weight: 750;
}

.fi-notice--danger .fi-notice__title {
	color: var(--fi-danger);
}

.fi-notice--warning .fi-notice__title {
	color: var(--fi-warning-text);
}

.fi-badge {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	padding: 0.15rem 0.6rem;
	border-radius: var(--fi-radius-pill);
	background: var(--fi-surface-2);
	color: var(--fi-primary);
	font-size: 0.8125rem;
	font-weight: 750;
	line-height: 1.5;
	white-space: nowrap;
}

.fi-badge--accent {
	background: var(--fi-accent);
	color: var(--fi-on-accent);
}

.fi-badge--success {
	background: var(--fi-success-tint);
	color: var(--fi-success);
}

.fi-badge--warning {
	background: var(--fi-warning-tint);
	color: var(--fi-warning-text);
}

.fi-badge--danger {
	background: var(--fi-danger-tint);
	color: var(--fi-danger);
}

.fi-card {
	padding: clamp(1.25rem, 1rem + 1vw, 1.75rem);
	border: 1px solid var(--fi-border);
	border-top: 4px solid var(--fi-card-accent);
	border-radius: var(--fi-radius-lg);
	background: var(--fi-card-bg);
	box-shadow: var(--fi-shadow);
}

.fi-panel {
	padding: 1rem 1.25rem;
	border-radius: var(--fi-radius);
	background: var(--fi-surface);
}

/* ------------------------------------------------------------------
 * Details / accordions (.fi-details; content details share the look).
 * ------------------------------------------------------------------ */
.fi-details {
	border: 1px solid var(--fi-border);
	border-radius: var(--fi-radius);
	background: var(--fi-card-bg);
}

.fi-details > summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	min-height: 3rem;
	padding: 0.75rem 1rem;
	color: var(--fi-heading);
	font-weight: 700;
	list-style: none;
}

.fi-details > summary::-webkit-details-marker {
	display: none;
}

.fi-details > summary::after {
	content: "+";
	flex: none;
	color: var(--fi-primary);
	font-size: 1.35rem;
	font-weight: 600;
	line-height: 1;
}

.fi-details[open] > summary::after {
	content: "\2212";
}

.fi-details > :not(summary) {
	margin: 0;
	padding: 0 1rem 1rem;
}

/* ------------------------------------------------------------------
 * Motion, forced colours and print.
 * ------------------------------------------------------------------ */
/* Reduced motion: the theme's own components only. Plugin markup is left
 * alone, so plugin progress spinners and loaders keep showing that work is
 * going on; each plugin group honours reduced motion for its plugin. */
@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}

	:is(.skip-link, .site-header, .mobile-menu, .fi-title-band, .fi-welcome, .fi-footer, .fi-btn, .fi-result),
	:is(.skip-link, .site-header, .mobile-menu, .fi-title-band, .fi-welcome, .fi-footer, .fi-btn, .fi-result)::before,
	:is(.skip-link, .site-header, .mobile-menu, .fi-title-band, .fi-welcome, .fi-footer, .fi-btn, .fi-result)::after,
	:is(.site-header, .mobile-menu, .fi-title-band, .fi-welcome, .fi-footer) *,
	:is(.site-header, .mobile-menu, .fi-title-band, .fi-welcome, .fi-footer) *::before,
	:is(.site-header, .mobile-menu, .fi-title-band, .fi-welcome, .fi-footer) *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}

@media (forced-colors: active) {
	/* The system draws checkboxes and radios in its own colours. */
	:where(input[type="checkbox"], input[type="radio"]) {
		-webkit-appearance: auto;
		appearance: auto;
	}

	.fi-btn,
	.fi-card,
	.fi-notice,
	.fi-badge {
		border: 1px solid CanvasText;
	}
}
