/*
 * we- framework
 * ------------------------------------------------------------------
 * Lightweight, reusable layout and component classes for the NCA Theme.
 * Every value comes from a CSS custom property generated by the global
 * style controller (Appearance → NCA Theme Options), so presets and
 * dark mode restyle these classes automatically.
 *
 * Breakpoints (mobile-first): 640px (sm), 900px (md), 1200px (lg).
 * Full reference with examples: docs/FRAMEWORK.md
 */

/* ---------- 1. Derived tokens (do not edit; change the options instead) ---------- */
:root {
	/* Fallbacks so the framework works even before options are saved. */
	--we-color-primary: #1f4d3a;
	--we-color-secondary: #5e8b6a;
	--we-color-accent: #1f6f87;
	--we-color-background: #f3f6f2;
	--we-color-surface: #e6ece4;
	--we-color-card: #fff;
	--we-color-text: #2a332e;
	--we-color-heading: #13261c;
	--we-color-link: #1d6646;
	--we-color-link-hover: #13261c;
	--we-color-button-bg: #1f4d3a;
	--we-color-button-text: #fff;
	--we-color-button-hover-bg: #163a2b;
	--we-color-button-hover-text: #fff;
	--we-color-border: #d3dcd2;
	--we-color-alert: #b3261e;
	--we-color-focus: #1f6f87;
	--we-font-heading: system-ui, sans-serif;
	--we-font-body: system-ui, sans-serif;
	--we-font-nav: var(--we-font-body);
	--we-font-button: var(--we-font-body);
	--we-container-width: 1200px;
	--we-content-width: 740px;
	--we-section-space: 5rem;
	--we-grid-gap: 28px;
	--we-card-padding: 24px;
	--we-radius: 10px;
	--we-button-radius: 6px;
	--we-transition: 200ms;

	/* Derived — computed from the tokens above, so they follow presets and dark mode. */
	--we-color-muted: color-mix(in srgb, var(--we-color-text) 74%, var(--we-color-background));
	--we-color-primary-soft: color-mix(in srgb, var(--we-color-primary) 10%, var(--we-color-card));
	--we-color-accent-soft: color-mix(in srgb, var(--we-color-accent) 12%, var(--we-color-card));
	--we-color-alert-soft: color-mix(in srgb, var(--we-color-alert) 10%, var(--we-color-card));
	--we-gutter: clamp(16px, 4vw, 32px);
	--we-space-1: 0.25rem;
	--we-space-2: 0.5rem;
	--we-space-3: 0.75rem;
	--we-space-4: 1rem;
	--we-space-5: 1.5rem;
	--we-space-6: 2rem;
	--we-space-7: 3rem;
	--we-space-8: 4rem;
	--we-font-size-sm: 0.875rem;
	--we-font-size-xs: 0.8125rem;
	--we-font-size-lead: clamp(1.0625rem, 1rem + 0.35vw, 1.25rem);
}

/* ---------- 2. Containers & sections ---------- */
.we-container {
	width: 100%;
	max-width: calc(var(--we-container-width) + var(--we-gutter) * 2);
	margin-inline: auto;
	padding-inline: var(--we-gutter);
}
.we-container--narrow { max-width: calc(var(--we-content-width) + var(--we-gutter) * 2); }
.we-container--wide { max-width: calc(var(--we-container-width) + 240px + var(--we-gutter) * 2); }
.we-container--full { max-width: none; }

.we-section { padding-block: var(--we-section-space); }
.we-section--tight { padding-block: calc(var(--we-section-space) * 0.6); }
.we-section--flush-top { padding-top: 0; }
.we-section--flush-bottom { padding-bottom: 0; }
.we-section--surface { background: var(--we-color-surface); }
.we-section--card { background: var(--we-color-card); }
.we-section--primary {
	background: var(--we-color-primary);
	color: color-mix(in srgb, var(--we-color-card) 88%, var(--we-color-primary));
	--we-color-heading: var(--we-color-card);
	--we-color-link: var(--we-color-card);
	--we-color-link-hover: var(--we-color-card);
	--we-color-muted: color-mix(in srgb, var(--we-color-card) 72%, var(--we-color-primary));
	--we-color-border: color-mix(in srgb, var(--we-color-card) 22%, var(--we-color-primary));
}
:root[data-theme="dark"] .we-section--primary {
	background: var(--we-color-surface);
	color: var(--we-color-text);
	--we-color-heading: var(--we-color-primary);
	--we-color-link: var(--we-color-primary);
	--we-color-muted: color-mix(in srgb, var(--we-color-text) 74%, var(--we-color-surface));
	--we-color-border: var(--we-color-card);
}

/* ---------- 3. Row & columns (flex) ---------- */
/* <div class="we-row"><div class="we-col-3">…</div>…</div>
   we-col-N = 1/N of the row on desktop. Columns stack on phones;
   3–6 column rows show 2 per line on tablets. */
.we-row {
	display: flex;
	flex-wrap: wrap;
	gap: var(--we-grid-gap);
}
.we-row > [class*="we-col"] { flex: 1 1 100%; min-width: 0; }
.we-row--center { align-items: center; }
.we-row--stretch { align-items: stretch; }
.we-row--reverse { flex-direction: row-reverse; }

@media (min-width: 640px) {
	.we-row > .we-col-3,
	.we-row > .we-col-4,
	.we-row > .we-col-5,
	.we-row > .we-col-6 { flex-basis: calc((100% - var(--we-grid-gap)) / 2); flex-grow: 0; }
}
@media (min-width: 900px) {
	.we-row > .we-col { flex: 1 1 0; }
	.we-row > .we-col-2 { flex: 0 0 calc((100% - var(--we-grid-gap)) / 2); }
	.we-row > .we-col-3 { flex: 0 0 calc((100% - var(--we-grid-gap) * 2) / 3); }
	.we-row > .we-col-4 { flex: 0 0 calc((100% - var(--we-grid-gap) * 3) / 4); }
	.we-row > .we-col-5 { flex: 0 0 calc((100% - var(--we-grid-gap) * 4) / 5); }
	.we-row > .we-col-6 { flex: 0 0 calc((100% - var(--we-grid-gap) * 5) / 6); }
	.we-row > .we-col-wide { flex: 0 0 calc((100% - var(--we-grid-gap)) * 0.58); }
	.we-row > .we-col-narrow { flex: 0 0 calc((100% - var(--we-grid-gap)) * 0.42); }
}

/* ---------- 4. Grid ---------- */
.we-grid { display: grid; gap: var(--we-grid-gap); grid-template-columns: minmax(0, 1fr); }
.we-grid--auto { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
@media (min-width: 640px) {
	.we-grid--2, .we-grid--3, .we-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
	.we-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
	.we-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
	.we-span-2 { grid-column: span 2; }
	.we-span-full { grid-column: 1 / -1; }
}

/* ---------- 5. Flex & stack utilities ---------- */
.we-flex { display: flex; gap: var(--we-space-4); align-items: center; }
.we-flex--wrap { flex-wrap: wrap; }
.we-flex--between { justify-content: space-between; }
.we-flex--center { justify-content: center; }
.we-flex--start { align-items: flex-start; }
.we-flex--column { flex-direction: column; align-items: stretch; }

.we-stack > * { margin-block: 0; }
.we-stack > * + * { margin-top: var(--we-stack-space, var(--we-space-4)); }
.we-stack--sm { --we-stack-space: var(--we-space-2); }
.we-stack--lg { --we-stack-space: var(--we-space-6); }

/* Spacer element: <div class="we-space"></div> */
.we-space { display: block; height: var(--we-grid-gap); }
.we-space--sm { height: var(--we-space-3); }
.we-space--lg { height: calc(var(--we-grid-gap) * 2); }

/* ---------- 6. Typography helpers ---------- */
.we-eyebrow {
	font-family: var(--we-font-body);
	font-size: var(--we-font-size-sm);
	font-weight: 600;
	color: var(--we-color-accent);
	margin: 0 0 var(--we-space-2);
}
.we-lead { font-size: var(--we-font-size-lead); color: var(--we-color-muted); max-width: 62ch; }
.we-muted { color: var(--we-color-muted); }
.we-small { font-size: var(--we-font-size-sm); }
.we-text-center { text-align: center; }
.we-text-center .we-lead { margin-inline: auto; }
.we-measure { max-width: 66ch; }

.we-section-header { display: flex; flex-wrap: wrap; gap: var(--we-space-4) var(--we-space-6); align-items: end; justify-content: space-between; margin-bottom: var(--we-space-7); }
.we-section-header__text { max-width: 46rem; }
.we-section-header__title { margin: 0; }
.we-section-header__lead { margin: var(--we-space-3) 0 0; font-size: var(--we-font-size-lead); color: var(--we-color-muted); }
.we-section-header--center { justify-content: center; text-align: center; }
.we-section-header--center .we-section-header__text { margin-inline: auto; }

/* ---------- 7. Buttons ---------- */
.we-button,
.wp-element-button,
.wp-block-button__link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5em;
	padding: var(--we-button-padding-y, 12px) var(--we-button-padding-x, 22px);
	border: var(--we-border-width, 1px) solid transparent;
	border-radius: var(--we-button-radius);
	background: var(--we-color-button-bg);
	color: var(--we-color-button-text);
	font-family: var(--we-font-button);
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	cursor: pointer;
	transition: background-color var(--we-transition), color var(--we-transition), border-color var(--we-transition), transform var(--we-transition);
}
.we-button:hover,
.we-button:focus-visible,
.wp-element-button:hover,
.wp-block-button__link:hover {
	background: var(--we-color-button-hover-bg);
	color: var(--we-color-button-hover-text);
	transform: var(--we-button-hover-transform, none);
	text-decoration: none;
}
.we-button .we-icon { width: 1.15em; height: 1.15em; flex: none; }
.we-button--secondary { background: transparent; color: var(--we-color-primary); border-color: currentColor; }
.we-button--secondary:hover, .we-button--secondary:focus-visible { background: var(--we-color-primary-soft); color: var(--we-color-primary); }
.we-button--ghost { background: transparent; color: var(--we-color-heading); }
.we-button--ghost:hover, .we-button--ghost:focus-visible { background: var(--we-color-primary-soft); color: var(--we-color-heading); }
.we-button--alert { background: var(--we-color-alert); color: #fff; }
.we-button--alert:hover, .we-button--alert:focus-visible { background: color-mix(in srgb, var(--we-color-alert) 84%, #000); color: #fff; }
.we-button--light { background: var(--we-color-card); color: var(--we-color-primary); }
.we-button--light:hover, .we-button--light:focus-visible { background: color-mix(in srgb, var(--we-color-card) 88%, var(--we-color-primary)); color: var(--we-color-primary); }
.we-button--link { background: none; padding: 0; border: 0; color: var(--we-color-link); text-decoration: underline; text-underline-offset: 0.2em; }
.we-button--link:hover, .we-button--link:focus-visible { background: none; color: var(--we-color-link-hover); transform: none; }
.we-button--sm { padding: 8px 14px; font-size: var(--we-font-size-sm); }
.we-button--lg { padding: calc(var(--we-button-padding-y, 12px) + 4px) calc(var(--we-button-padding-x, 22px) + 6px); font-size: 1rem; }
.we-button--block { width: 100%; }
.we-button-group { display: flex; flex-wrap: wrap; gap: var(--we-space-3); align-items: center; }

/* ---------- 8. Cards ---------- */
.we-card {
	position: relative;
	display: flex;
	flex-direction: column;
	background: var(--we-color-card);
	border: var(--we-border-width, 1px) solid var(--we-color-border);
	border-radius: var(--we-radius);
	box-shadow: var(--we-shadow, none);
	overflow: hidden;
	height: 100%;
	transition: transform var(--we-transition), box-shadow var(--we-transition), border-color var(--we-transition);
}
.we-card__media { aspect-ratio: 3 / 2; background: var(--we-color-surface); overflow: hidden; }
.we-card__media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.we-card__body { padding: var(--we-card-padding); display: flex; flex-direction: column; gap: var(--we-space-3); flex: 1; }
.we-card__body > * { margin: 0; }
.we-card__title { font-size: 1.1875rem; line-height: 1.3; }
.we-card__title a { color: inherit; text-decoration: none; }
.we-card__text { color: var(--we-color-muted); font-size: 0.9688rem; }
.we-card__footer { margin-top: auto; padding-top: var(--we-space-2); }
.we-card--plain { border: 0; box-shadow: none; background: transparent; }
.we-card--plain .we-card__body { padding-inline: 0; }
.we-card--padded { padding: var(--we-card-padding); }

/* Whole card clickable: put .we-card--link on the card and the stretched link on the title. */
.we-card--link .we-card__title a::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.we-card--link:hover,
.we-card--link:focus-within {
	transform: var(--we-card-hover-transform, none);
	box-shadow: var(--we-card-hover-shadow, var(--we-shadow));
	border-color: var(--we-card-hover-border, var(--we-color-border));
}
.we-card--link:focus-within .we-card__title a { text-decoration: underline; }

/* ---------- 9. Chips & badges ---------- */
.we-chips { display: flex; flex-wrap: wrap; gap: var(--we-space-2); list-style: none; margin: 0; padding: 0; }
.we-chip {
	display: inline-block;
	padding: 3px 10px;
	border-radius: 999px;
	background: var(--we-color-primary-soft);
	color: var(--we-color-primary);
	font-size: var(--we-font-size-xs);
	font-weight: 600;
	text-decoration: none;
	position: relative;
	z-index: 2;
}
a.we-chip:hover { background: var(--we-color-primary); color: var(--we-color-card); }

/* ---------- 10. Forms ---------- */
.we-field { display: flex; flex-direction: column; gap: var(--we-space-2); }
.we-label { font-weight: 600; font-size: var(--we-font-size-sm); color: var(--we-color-heading); }
.we-input,
.we-select,
.we-textarea {
	width: 100%;
	min-height: 46px;
	padding: 10px 14px;
	border: 1px solid var(--we-color-border);
	border-radius: calc(var(--we-radius) * 0.6);
	background: var(--we-color-card);
	color: var(--we-color-text);
	font: inherit;
	font-size: 1rem;
	transition: border-color var(--we-transition), box-shadow var(--we-transition);
}
.we-textarea { min-height: 140px; resize: vertical; }
.we-input:hover, .we-select:hover, .we-textarea:hover { border-color: color-mix(in srgb, var(--we-color-border) 50%, var(--we-color-text)); }
.we-input:focus, .we-select:focus, .we-textarea:focus { outline: none; border-color: var(--we-color-focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--we-color-focus) 30%, transparent); }
.we-help { font-size: var(--we-font-size-xs); color: var(--we-color-muted); margin: 0; }
.we-checkbox { display: flex; gap: var(--we-space-3); align-items: flex-start; font-size: var(--we-font-size-sm); }
.we-checkbox input { margin-top: 0.25em; width: 1.1em; height: 1.1em; accent-color: var(--we-color-primary); flex: none; }

/* ---------- 11. Notices ---------- */
.we-notice { padding: var(--we-space-4) var(--we-space-5); border-radius: calc(var(--we-radius) * 0.6); border-left: 4px solid var(--we-color-accent); background: var(--we-color-accent-soft); color: var(--we-color-text); }
.we-notice--success { border-color: var(--we-color-primary); background: var(--we-color-primary-soft); }
.we-notice--error, .we-notice--alert { border-color: var(--we-color-alert); background: var(--we-color-alert-soft); }
.we-notice > :last-child { margin-bottom: 0; }

/* ---------- 12. Media & lists ---------- */
.we-media { border-radius: var(--we-radius); overflow: hidden; background: var(--we-color-surface); }
.we-media img { display: block; width: 100%; height: 100%; object-fit: cover; }
.we-ratio-16x9 { aspect-ratio: 16 / 9; }
.we-ratio-4x3 { aspect-ratio: 4 / 3; }
.we-ratio-1x1 { aspect-ratio: 1; }
.we-ratio-4x5 { aspect-ratio: 4 / 5; }

.we-list-check { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--we-space-3); }
.we-list-check li { position: relative; padding-left: 1.75em; }
.we-list-check li::before { content: ""; position: absolute; left: 0; top: 0.45em; width: 0.9em; height: 0.5em; border-left: 2px solid var(--we-color-primary); border-bottom: 2px solid var(--we-color-primary); transform: rotate(-45deg); }

.we-icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.2em; }
.we-icon-badge { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: calc(var(--we-radius) * 0.8); background: var(--we-color-primary-soft); color: var(--we-color-primary); }
.we-icon-badge .we-icon { width: 26px; height: 26px; }

/* ---------- 13. Tables ---------- */
.we-table-wrap { overflow-x: auto; border: 1px solid var(--we-color-border); border-radius: var(--we-radius); background: var(--we-color-card); }
.we-table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.we-table th, .we-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--we-color-border); vertical-align: top; }
.we-table thead th { font-size: var(--we-font-size-xs); font-weight: 700; color: var(--we-color-muted); background: var(--we-color-surface); }
.we-table tbody tr:last-child td { border-bottom: 0; }

/* Stacked table on phones: add data-label to each td. */
@media (max-width: 760px) {
	.we-table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
	.we-table--stack, .we-table--stack tbody, .we-table--stack tr, .we-table--stack td { display: block; width: 100%; }
	.we-table--stack tr { padding: var(--we-space-3) 0; border-bottom: 1px solid var(--we-color-border); }
	.we-table--stack td { border: 0; padding: 4px 16px; display: grid; grid-template-columns: 8.5rem 1fr; gap: var(--we-space-3); }
	.we-table--stack td::before { content: attr(data-label); font-weight: 600; color: var(--we-color-muted); font-size: var(--we-font-size-xs); }
}

/* ---------- 14. Visibility ---------- */
.screen-reader-text,
.we-visually-hidden {
	border: 0; clip: rect(1px, 1px, 1px, 1px); clip-path: inset(50%); height: 1px; margin: -1px;
	overflow: hidden; padding: 0; position: absolute !important; width: 1px; word-wrap: normal !important;
}
.screen-reader-text:focus { clip: auto !important; clip-path: none; height: auto; width: auto; z-index: 100000; }
@media (max-width: 639px) { .we-hide-mobile { display: none !important; } }
@media (min-width: 900px) { .we-hide-desktop { display: none !important; } }

/* Dark mode: the alert colour is light, so its text must be dark. */
:root[data-theme="dark"] .we-button--alert,
:root[data-theme="dark"] .we-button--alert:hover,
:root[data-theme="dark"] .we-button--alert:focus-visible { color: var(--we-color-background); }
:root[data-theme="dark"] .we-button--alert:hover { background: color-mix(in srgb, var(--we-color-alert) 85%, #fff); }
