/**
 * Roxy frontend styles.
 *
 * Single stylesheet for every shortcode and generated block on the front end.
 * Inherits theme.json tokens with sensible fallbacks so the output blends with
 * any theme. Selectors use :where() so a theme can override anything without
 * fighting !important.
 *
 * Class contract:
 *   .roxyapi-card           Outer container for one rendered reading.
 *   .roxyapi-card-header    Title + meta strip.
 *   .roxyapi-card-title     Reading name (e.g. "Pumpkin", "Aries").
 *   .roxyapi-card-meta      Small inline meta line (date, letter, etc).
 *   .roxyapi-card-lede      Primary prose paragraph (meaning, message).
 *   .roxyapi-section        Sub-block with its own heading.
 *   .roxyapi-section-title  Heading for a section.
 *   .roxyapi-fields         dl grid of scalar key/value pairs.
 *   .roxyapi-field          One row inside .roxyapi-fields.
 *   .roxyapi-table          Semantic table for uniform object lists.
 *   .roxyapi-list           ul for lists of scalars or mixed items.
 *   .roxyapi-details        Collapsed section for long nested content.
 */

/*
 * Theme-overridable design tokens. Themes can override any of these on
 * `:root` (or a wrapping selector) to restyle every Roxy card without
 * touching the primitive rules below. Defaults are intentionally subtle
 * so the cards feel native on a wide range of light themes; dark themes
 * pick up the right contrast through the `currentColor`-relative mixes.
 */
:where(.roxyapi-card, .roxyapi-form-wrap) {
	--roxyapi-radius: var(--wp--custom--border--radius, 12px);
	--roxyapi-pad-y: var(--wp--preset--spacing--40, 1.5rem);
	--roxyapi-pad-x: var(--wp--preset--spacing--50, 1.75rem);
	--roxyapi-border: color-mix(in srgb, currentcolor 10%, transparent);
	--roxyapi-surface: color-mix(in srgb, currentcolor 2%, transparent);
	--roxyapi-shadow:
		0 1px 2px color-mix(in srgb, currentcolor 6%, transparent),
		0 8px 24px -12px color-mix(in srgb, currentcolor 18%, transparent);
}

:where(.roxyapi-card) {
	display: block;
	max-width: 100%;
	margin-block: var(--wp--preset--spacing--40, 1.5rem);
	padding: var(--roxyapi-pad-y) var(--roxyapi-pad-x);
	border: 1px solid var(--roxyapi-border);
	border-radius: var(--roxyapi-radius);
	background: var(--roxyapi-surface);
	box-shadow: var(--roxyapi-shadow);
	color: var(--wp--preset--color--foreground, currentColor);
	font-size: var(--wp--preset--font-size--medium, 1rem);
	line-height: 1.6;
}

:where(.roxyapi-card-header) {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	margin-block-end: 1rem;
	padding-block-end: 1rem;
	border-block-end: 1px solid var(--roxyapi-border);
}

/*
 * Header layouts adapt to whether an image landed in the header. With an
 * image we lay it next to the title; without one we keep the simple stack.
 */
:where(.roxyapi-card-header:has(.roxyapi-image)) {
	flex-direction: row;
	align-items: flex-start;
	gap: 1rem;
}

:where(.roxyapi-card-header:has(.roxyapi-image) .roxyapi-image) {
	flex-shrink: 0;
	margin-block-end: 0;
}

:where(.roxyapi-card-title) {
	margin: 0;
	font-family: var(--wp--preset--font-family--heading, inherit);
	font-size: var(--wp--preset--font-size--x-large, 1.75rem);
	font-weight: 700;
	letter-spacing: -0.015em;
	line-height: 1.15;
	color: var(--roxy-accent, var(--wp--preset--color--foreground, currentcolor));
}

:where(.roxyapi-section .roxyapi-card-title) {
	font-size: var(--wp--preset--font-size--medium, 1.125rem);
	font-weight: 600;
}

:where(.roxyapi-card-meta) {
	margin: 0;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	color: color-mix(in srgb, currentcolor 65%, transparent);
}

:where(.roxyapi-card-subtitle) {
	margin: 0;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	font-weight: 500;
	letter-spacing: 0.02em;
	color: color-mix(in srgb, currentcolor 70%, transparent);
}

:where(.roxyapi-card-disclaimer) {
	margin: var(--wp--preset--spacing--30, 1rem) 0 0;
	padding-block-start: 0.5rem;
	border-block-start:
		1px dashed
		color-mix(in srgb, currentcolor 14%, transparent);
	font-size: var(--wp--preset--font-size--small, 0.8125rem);
	font-style: italic;
	color: color-mix(in srgb, currentcolor 60%, transparent);
}

:where(.roxyapi-credit) {
	margin: var(--wp--preset--spacing--30, 1rem) 0 0;
	font-size: var(--wp--preset--font-size--small, 0.8125rem);
	text-align: end;
	color: color-mix(in srgb, currentcolor 55%, transparent);
}

:where(.roxyapi-credit-link) {
	color: inherit;
	text-decoration: none;
	border-block-end:
		1px dotted
		color-mix(in srgb, currentcolor 40%, transparent);
}

:where(.roxyapi-credit-link:hover) {
	color: var(--wp--preset--color--foreground, currentColor);
	border-block-end-color: currentcolor;
}

/*
 * Lede + quote fill the card width. The card itself sets the readable
 * column via its own padding + theme content-width; an extra max-inline
 * cap here just leaves empty space on the right of every reading.
 */
:where(.roxyapi-card-lede) {
	margin-block: 0 var(--wp--preset--spacing--30, 1rem);
	font-size: var(--wp--preset--font-size--medium, 1.0625rem);
	line-height: 1.6;
}

:where(.roxyapi-quote) {
	margin: 0 0 var(--wp--preset--spacing--30, 1rem);
	padding: 0.5rem 1rem;
	border-inline-start:
		3px solid
		color-mix(in srgb, currentcolor 30%, transparent);
	font-style: italic;
	font-size: var(--wp--preset--font-size--medium, 1.0625rem);
	color: color-mix(in srgb, currentcolor 80%, transparent);
}

:where(.roxyapi-card-header > .roxyapi-image) {
	display: block;
	max-inline-size: min(280px, 100%);
	block-size: auto;
	margin-block-end: 0.75rem;
	border-radius: var(--wp--custom--border--radius, 6px);
	object-fit: cover;
}

:where(.roxyapi-image) {
	max-inline-size: 100%;
	block-size: auto;
	border-radius: var(--wp--custom--border--radius, 6px);
}

:where(.roxyapi-table .roxyapi-image) {
	max-block-size: 48px;
	max-inline-size: 48px;
	object-fit: cover;
}

:where(.roxyapi-link) {
	color: inherit;
	text-decoration: underline;
	text-decoration-color: color-mix(in srgb, currentcolor 40%, transparent);
	text-underline-offset: 2px;
	word-break: break-word;
}

:where(.roxyapi-link:hover) {
	text-decoration-color: currentcolor;
}

:where(.roxyapi-section) {
	display: block;
	margin-block: var(--wp--preset--spacing--40, 1.5rem) 0;
}

:where(.roxyapi-section + .roxyapi-section),
:where(.roxyapi-fields + .roxyapi-section),
:where(.roxyapi-table + .roxyapi-section) {
	padding-block-start: var(--wp--preset--spacing--30, 1rem);
	border-block-start:
		1px solid
		var(--roxyapi-border, color-mix(in srgb, currentColor 10%, transparent));
}

:where(.roxyapi-section-title) {
	margin: 0 0 0.6rem;
	font-family: var(--wp--preset--font-family--heading, inherit);
	font-size: var(--wp--preset--font-size--medium, 1.0625rem);
	font-weight: 600;
	letter-spacing: -0.005em;
	color: var(--wp--preset--color--foreground, currentColor);
}

/*
 * Field grid: two columns on roomy screens (label / value), single
 * stacked column on narrow viewports so long values do not crush the
 * label cell. `display: contents` on the wrapping .roxyapi-field lets
 * the dt/dd participate in the parent grid directly.
 */
:where(.roxyapi-fields) {
	display: grid;
	grid-template-columns: minmax(8rem, max-content) 1fr;
	gap: 0.6rem 1.5rem;
	margin: 0;
	padding: 0;
}

@media (max-width: 480px) {

	:where(.roxyapi-fields) {
		grid-template-columns: 1fr;
		gap: 0.15rem 0;
	}

	:where(.roxyapi-fields dt) {
		margin-block-start: 0.55rem;
	}

	:where(.roxyapi-fields dt:first-of-type) {
		margin-block-start: 0;
	}
}

:where(.roxyapi-field) {
	display: contents;
}

:where(.roxyapi-fields dt) {
	font-weight: 500;
	color: color-mix(in srgb, currentcolor 65%, transparent);
}

:where(.roxyapi-fields dd) {
	margin: 0;
	color: var(--wp--preset--color--foreground, currentColor);
}

/*
 * Tables get rounded corners + soft zebra stripes + sticky header. A
 * horizontal scroll wrapper kicks in below ~480px so wide tables stay
 * readable on phones without breaking the card layout.
 */
:where(.roxyapi-section:has(> .roxyapi-table)) {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

:where(.roxyapi-table) {
	inline-size: 100%;
	border-collapse: separate;
	border-spacing: 0;
	font-size: var(--wp--preset--font-size--small, 0.9375rem);
	margin-block-start: 0.5rem;
	border:
		1px solid
		var(--roxyapi-border, color-mix(in srgb, currentColor 10%, transparent));
	border-radius: var(--roxyapi-radius, 8px);
	overflow: hidden;
}

:where(.roxyapi-table th),
:where(.roxyapi-table td) {
	padding: 0.55rem 0.75rem;
	text-align: start;
	vertical-align: top;
}

:where(.roxyapi-table thead tr) {
	background: color-mix(in srgb, currentcolor 4%, transparent);
}

:where(.roxyapi-table th) {
	font-weight: 600;
	font-size: 0.8125rem;
	letter-spacing: 0.01em;
	color: color-mix(in srgb, currentcolor 75%, transparent);
	border-block-end:
		1px solid
		var(--roxyapi-border, color-mix(in srgb, currentColor 10%, transparent));
}

:where(.roxyapi-table tbody tr) {
	border-block-end: 1px solid color-mix(in srgb, currentcolor 6%, transparent);
}

:where(.roxyapi-table tbody tr:nth-child(even)) {
	background: color-mix(in srgb, currentcolor 1.5%, transparent);
}

:where(.roxyapi-table tbody tr:last-child) {
	border-block-end: 0;
}

/*
 * Badge: surfaces a boolean-true `is_*` / `has_*` field as a small chip
 * instead of a raw "1". Reads as the property the field describes.
 */
:where(.roxyapi-badge) {
	display: inline-flex;
	align-items: center;
	padding: 0.1rem 0.55rem;
	border-radius: 999px;
	background: color-mix(in srgb, var(--roxy-accent, currentcolor) 12%, transparent);
	color: var(--roxy-accent, var(--wp--preset--color--foreground, currentcolor));
	font-size: 0.8125rem;
	font-weight: 600;
	letter-spacing: 0.01em;
	line-height: 1.4;
}

:where(.roxyapi-list) {
	margin: 0;
	padding-inline-start: 1.25rem;
}

:where(.roxyapi-list li + li) {
	margin-block-start: 0.25rem;
}

:where(.roxyapi-details) {
	margin-block: 0.5rem 0;
	border-block-start:
		1px solid
		color-mix(in srgb, currentcolor 10%, transparent);
	padding-block-start: 0.5rem;
}

:where(.roxyapi-details > summary) {
	cursor: pointer;
	font-weight: 600;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	padding-block: 0.25rem;
	list-style: none;
}

:where(.roxyapi-details > summary)::-webkit-details-marker {
	display: none;
}

:where(.roxyapi-details > summary)::before {
	content: "\2192";
	display: inline-block;
	margin-inline-end: 0.4rem;
	transition: transform 0.15s ease;
	color: color-mix(in srgb, currentcolor 60%, transparent);
}

:where(.roxyapi-details[open] > summary)::before {
	transform: rotate(90deg);
}

:where(.roxyapi-error) {
	display: block;
	padding: 0.75rem 1rem;
	border: 1px solid color-mix(in srgb, currentcolor 12%, transparent);
	border-inline-start-width: 4px;
	border-inline-start-color: color-mix(in srgb, var(--roxy-danger-fg, #b91c1c) 70%, currentColor);
	border-radius: var(--wp--custom--border--radius, 6px);
	background: color-mix(in srgb, #fee2e2 30%, transparent);
	color: var(--wp--preset--color--foreground, currentColor);
	font-size: var(--wp--preset--font-size--small, 0.9375rem);
}

:where(.roxyapi-error-admin) {
	display: block;
	margin-block-start: 0.4rem;
	font-size: 0.8125rem;
	font-style: italic;
	color: color-mix(in srgb, currentcolor 65%, transparent);
}

:where(.roxyapi-form-wrap) {
	display: block;
	margin-block: var(--wp--preset--spacing--40, 1.25rem);
}

:where(.roxyapi-form) {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--30, 1rem);
	padding:
		var(--wp--preset--spacing--40, 1.25rem)
		var(--wp--preset--spacing--50, 1.5rem);
	border: 1px solid color-mix(in srgb, currentcolor 12%, transparent);
	border-radius: var(--wp--custom--border--radius, 8px);
	background: color-mix(in srgb, currentcolor 3%, transparent);
}

:where(.roxyapi-form-title) {
	margin: 0;
	font-size: var(--wp--preset--font-size--large, 1.5rem);
	font-weight: 600;
	letter-spacing: -0.01em;
}

:where(.roxyapi-form-lede) {
	margin: 0;
	color: color-mix(in srgb, currentcolor 70%, transparent);
}

:where(.roxyapi-form-section) {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
	gap: 0.75rem 1rem;
	padding: var(--wp--preset--spacing--30, 1rem);
	border: 1px solid color-mix(in srgb, currentcolor 10%, transparent);
	border-radius: var(--wp--custom--border--radius, 6px);
	margin: 0;
}

:where(.roxyapi-form-section > legend) {
	padding-inline: 0.4rem;
	font-weight: 600;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: color-mix(in srgb, currentcolor 70%, transparent);
}

:where(.roxyapi-form-field) {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	margin: 0;
}

:where(.roxyapi-form-field > label) {
	font-weight: 600;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
}

:where(.roxyapi-form-required) {
	color: var(--roxy-danger-fg, #b91c1c);
}

:where(.roxyapi-form-field input),
:where(.roxyapi-form-field select) {
	inline-size: 100%;
	padding: 0.5rem 0.65rem;
	font-size: var(--wp--preset--font-size--medium, 1rem);
	border: 1px solid color-mix(in srgb, currentcolor 18%, transparent);
	border-radius: var(--wp--custom--border--radius, 6px);
	background: color-mix(in srgb, currentcolor 1%, transparent);
	color: inherit;
}

:where(.roxyapi-form-field input:focus),
:where(.roxyapi-form-field select:focus) {
	outline: 2px solid color-mix(in srgb, currentcolor 35%, transparent);
	outline-offset: 1px;
}

:where(.roxyapi-form-field.has-error input),
:where(.roxyapi-form-field.has-error select) {
	border-color: color-mix(in srgb, var(--roxy-danger-fg, #b91c1c) 70%, currentColor);
}

:where(.roxyapi-form-error) {
	font-size: 0.8125rem;
	color: var(--roxy-danger-fg, #b91c1c);
}

:where(.roxyapi-form-help) {
	font-size: 0.8125rem;
	color: color-mix(in srgb, currentcolor 60%, transparent);
}

:where(.roxyapi-form-consent) {
	margin: 0;
	padding: 0.75rem;
	background: color-mix(in srgb, currentcolor 4%, transparent);
	border: 1px solid color-mix(in srgb, currentcolor 12%, transparent);
	border-radius: var(--wp--custom--border--radius, 6px);
}

:where(.roxyapi-form-consent-label) {
	display: flex;
	gap: 0.5rem;
	align-items: flex-start;
	cursor: pointer;
	font-size: var(--wp--preset--font-size--small, 0.9375rem);
	line-height: 1.5;
}

:where(.roxyapi-form-consent-label > input[type="checkbox"]) {
	margin-block-start: 0.25rem;
	flex-shrink: 0;
}

:where(.roxyapi-form-consent.has-error) {
	border-color: color-mix(in srgb, var(--roxy-danger-fg, #b91c1c) 70%, currentColor);
}

:where(.roxyapi-form-actions) {
	margin: 0;
}

:where(.roxyapi-form-submit) {
	cursor: pointer;
	padding: 0.6rem 1.2rem;
	font-weight: 600;
	font-size: var(--wp--preset--font-size--medium, 1rem);
	border: 0;
	border-radius: var(--wp--custom--border--radius, 6px);
	background: var(--roxy-accent, var(--wp--preset--color--foreground, #111));
	color: var(--wp--preset--color--background, #fff);
}

:where(.roxyapi-form-submit:hover) {
	opacity: 0.9;
}

:where(.roxyapi-form-geocode) {
	grid-column: 1 / -1;
	position: relative;
}

:where(.roxyapi-geocode-listbox) {
	position: absolute;
	inset-inline-start: 0;
	inset-inline-end: 0;
	top: 100%;
	z-index: 10;
	margin: 0.25rem 0 0;
	padding: 0.25rem 0;
	max-block-size: 16rem;
	overflow-y: auto;
	list-style: none;
	background: var(--wp--preset--color--background, #fff);
	color: var(--wp--preset--color--foreground, #111);
	border: 1px solid color-mix(in srgb, currentcolor 18%, transparent);
	border-radius: var(--wp--custom--border--radius, 6px);
	box-shadow: 0 6px 24px color-mix(in srgb, currentcolor 12%, transparent);
}

:where(.roxyapi-geocode-listbox[hidden]) {
	display: none;
}

:where(.roxyapi-geocode-option) {
	padding: 0.5rem 0.75rem;
	font-size: var(--wp--preset--font-size--small, 0.9375rem);
	cursor: pointer;
}

:where(.roxyapi-geocode-option:hover),
:where(.roxyapi-geocode-option[aria-selected="true"]) {
	background: color-mix(in srgb, currentcolor 8%, transparent);
}

:where(.roxyapi-geocode-status) {
	display: block;
	margin-block-start: 0.25rem;
	font-size: 0.8125rem;
	color: color-mix(in srgb, currentcolor 60%, transparent);
}

/* Web-component progressive enhancement. The server-rendered fallback shows
   until the custom element upgrades, then the upgraded element takes over. */
.roxyapi-component:not(:defined) .roxyapi-component-fallback {
	display: block;
}

.roxyapi-component:defined .roxyapi-component-fallback {
	display: none;
}

.roxyapi-component:not(:defined) {
	display: block;
}
