/*
 * Member Invoice Details — front end.
 *
 * Buttons use core's .wp-element-button, so the theme's button styles do the
 * visual work. Everything else is built from the theme's palette and spacing
 * presets (theme.json), falling back to currentColor and system colours —
 * never fixed values. The section deliberately does not reuse Restrict Content
 * Pro's container classes: some themes rebuild those with JavaScript.
 */

/* ---------------------------------------------------------------- tokens */

/*
 * Theme palettes rarely include an error colour (ASPA's third accent is
 * yellow), so errors use a red that reads on white. Themes can override it.
 */
.nwmid-section,
.nwmid-dialog,
.nwmid-inline-editor {
	--nwmid-accent: var(--wp--preset--color--accent, currentColor);
	--nwmid-on-accent: var(--wp--preset--color--base, Canvas);
	--nwmid-error: var(--nwmid-theme-error, #b32d2e);
}

/* ---------------------------------------------------------------- section */

/*
 * A card matching Restrict Content Pro's own form sections, built from the
 * theme's tokens (borderline, base, accent, spacing) with neutral fallbacks.
 */
.nwmid-section {
	background: var(--wp--preset--color--base, transparent);
	border: 1px solid var(--wp--preset--color--borderline, color-mix(in srgb, currentColor 16%, transparent));
	border-radius: 8px;
	margin: 0 0 var(--wp--preset--spacing--20, 1.5rem);
	min-width: 0;
	padding: var(--wp--preset--spacing--20, 1.5rem);
}

.nwmid-heading {
	border-bottom: 1px solid var(--wp--preset--color--borderline, color-mix(in srgb, currentColor 16%, transparent));
	font-size: var(--wp--preset--font-size--medium, 1.15em);
	font-weight: 600;
	margin: 0 0 var(--wp--preset--spacing--20, 1.25rem);
	padding: 0 0 var(--wp--preset--spacing--10, 0.85rem);
}

.nwmid-help {
	color: var(--wp--preset--color--contrast-2, color-mix(in srgb, currentColor 70%, transparent));
	display: block;
	font-size: var(--wp--preset--font-size--x-small, 0.85em);
	font-weight: 400;
	line-height: 1.5;
	margin: 0.35em 0 0;
}

.nwmid-intro {
	margin: 0 0 1em;
}

.nwmid-toggle {
	align-items: start;
	column-gap: 0.65em;
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	margin: 0;
}

.nwmid-toggle input[type="checkbox"] {
	/* Themes pad every input; a checkbox needs none of it, or it stretches sideways. */
	appearance: none;
	aspect-ratio: 1;
	max-height: 1.2em;
	max-width: 1.2em;
	min-height: 1.2em;
	min-width: 1.2em;
	padding: 0;
	background: var(--wp--preset--color--base, Canvas);
	border: 1.5px solid color-mix(in srgb, currentColor 45%, transparent);
	border-radius: 4px;
	box-sizing: border-box;
	cursor: pointer;
	display: grid;
	flex: none;
	height: 1.2em;
	margin: 0.15em 0 0;
	place-content: center;
	transition: background-color 0.15s, border-color 0.15s;
	width: 1.2em;
}

/* The tick: a rotated L drawn with borders, in the theme's background colour. */
.nwmid-toggle input[type="checkbox"]::before {
	border: solid var(--nwmid-on-accent);
	border-width: 0 2px 2px 0;
	content: "";
	height: 0.55em;
	margin-top: -0.12em;
	transform: rotate(45deg) scale(0);
	transition: transform 0.12s;
	width: 0.28em;
}

.nwmid-toggle input[type="checkbox"]:checked {
	background: var(--nwmid-accent);
	border-color: var(--nwmid-accent);
}

.nwmid-toggle input[type="checkbox"]:checked::before {
	transform: rotate(45deg) scale(1);
}

.nwmid-toggle input[type="checkbox"]:hover {
	border-color: var(--nwmid-accent);
}

.nwmid-toggle input[type="checkbox"]:focus-visible {
	outline: 2px solid var(--nwmid-accent);
	outline-offset: 2px;
}

.nwmid-section .nwmid-toggle-label {
	cursor: pointer;
	font-weight: 500;
	margin: 0;
}

.nwmid-toggle-help {
	grid-column: 2;
}

.nwmid-fields {
	margin-top: var(--wp--preset--spacing--20, 1.25em);
}

.nwmid-js .nwmid-fields[hidden] {
	display: none;
}

.nwmid-required-note {
	margin: 0 0 1em;
}

.nwmid-field {
	margin: 0 0 var(--wp--preset--spacing--20, 1.1em);
}

.nwmid-field > label {
	color: var(--wp--preset--color--contrast, inherit);
	display: block;
	font-size: var(--wp--preset--font-size--small, 0.95em);
	font-weight: 500;
	margin-bottom: var(--wp--preset--spacing--10, 0.45rem);
}

.nwmid-section input[type="text"],
.nwmid-section select,
.nwmid-section textarea {
	background-color: var(--wp--preset--color--base, Field);
	border: 1px solid var(--wp--preset--color--borderline, color-mix(in srgb, currentColor 22%, transparent));
	border-radius: 6px;
	box-sizing: border-box;
	color: inherit;
	font: inherit;
	font-size: var(--wp--preset--font-size--small, 1em);
	max-width: 100%;
	min-height: 2.875rem;
	padding: 0.5rem 1rem;
	transition: border-color 0.2s, box-shadow 0.2s;
	width: 100%;
}

.nwmid-section textarea {
	line-height: 1.5;
	min-height: 6rem;
	padding: 0.75rem 1rem;
}

.nwmid-section input[type="text"]:hover,
.nwmid-section select:hover,
.nwmid-section textarea:hover {
	border-color: var(--wp--preset--color--accent, currentColor);
}

.nwmid-section input[type="text"]:focus,
.nwmid-section select:focus,
.nwmid-section textarea:focus {
	border-color: var(--wp--preset--color--accent, currentColor);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--wp--preset--color--accent, currentColor) 18%, transparent);
	outline: none;
}

.nwmid-section .error,
.nwmid-section [aria-invalid="true"] {
	border-color: var(--nwmid-error);
}

.nwmid-error {
	color: var(--nwmid-error);
	display: block;
	font-size: var(--wp--preset--font-size--x-small, 0.85em);
	font-weight: 500;
	margin-top: 0.35em;
}

.nwmid-optional {
	color: var(--wp--preset--color--contrast-2, color-mix(in srgb, currentColor 65%, transparent));
	font-weight: 400;
}

.nwmid-section .required {
	color: var(--wp--preset--color--accent, currentColor);
	margin-left: 0.15em;
}

.nwmid-address-head {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: 0.75em 1em;
	justify-content: space-between;
	margin: 0.25em 0 1em;
}

.nwmid-subheading {
	display: block;
	font-weight: 500;
}

.nwmid-status:empty {
	display: none;
}

.nwmid-status {
	font-size: var(--wp--preset--font-size--x-small, 0.85em);
	margin: -0.5em 0 1em;
}

.nwmid-grid {
	column-gap: var(--wp--preset--spacing--20, 1em);
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.nwmid-reminder {
	background: color-mix(in srgb, var(--wp--preset--color--accent, currentColor) 7%, transparent);
	border-radius: 6px;
	font-size: var(--wp--preset--font-size--x-small, 0.875em);
	margin: 0;
	padding: 0.75em 1em;
}

/* ---------------------------------------------------------------- buttons */

.nwmid-button {
	cursor: pointer;
	white-space: nowrap;
}

.nwmid-button:has(.nwmid-icon) {
	align-items: center;
	display: inline-flex;
	gap: 0.45em;
}

.nwmid-icon {
	flex: none;
	height: 1.15em;
	width: 1.15em;
}

.nwmid-button-wrap {
	display: inline-block;
}

/* Actions that sit beside a heading or a receipt link are smaller. */
.nwmid-address-head .nwmid-button,
.nwmid-actions-cell .nwmid-button {
	font-size: var(--wp--preset--font-size--x-small, 0.875em);
	padding: 0.6em 1.2em;
}

/* ---------------------------------------------------------- account page */

.nwmid-actions-cell {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5em;
}

.nwmid-actions-cell .nwmid-button-wrap-full {
	align-self: stretch;
	display: flex;
	width: 100%;
}

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

/* Readable even where the theme doesn't style Restrict Content Pro's messages. */
.nwmid-notice {
	background: color-mix(in srgb, var(--wp--preset--color--accent, currentColor) 8%, transparent);
	border-radius: 6px;
	margin: 0 0 1.25em;
	padding: 0.8em 1em;
}

.nwmid-notice p {
	margin: 0;
}

.nwmid-notice a {
	color: inherit;
	font-weight: 600;
	text-decoration: underline;
}

.nwmid-noscript ul {
	margin: 0.5em 0 0;
}

.nwmid-table-wrap {
	overflow-x: auto;
}

.nwmid-invoice-table {
	width: 100%;
}

.nwmid-invoice-table th {
	white-space: nowrap;
}

/* ---------------------------------------------------------------- editors */

.nwmid-editor-title {
	margin: 0;
}

.nwmid-editor-subtitle {
	margin: 0.2em 0 0;
}

.nwmid-editor .nwmid-section {
	background: none;
	border: 0;
	margin: var(--wp--preset--spacing--20, 1.25em) 0 0;
	padding: 0;
}

.nwmid-editor-actions {
	align-items: center;
	display: flex;
	flex-wrap: wrap;
	gap: 0.75em;
	margin-top: var(--wp--preset--spacing--20, 1.25em);
}

.nwmid-inline-editor {
	border: 1px solid var(--wp--preset--color--borderline, color-mix(in srgb, currentColor 18%, transparent));
	border-radius: 8px;
	margin: 0 0 1.5em;
	padding: var(--wp--preset--spacing--20, 1.25em);
}

/* ---------------------------------------------------------------- dialog */

/*
 * Fixed header and footer with a scrolling body, so Save is always in reach
 * and it's obvious there's more form below. Shadows on the header and footer
 * appear only while there's content hidden past them (set by frontend.js).
 */
.nwmid-dialog {
	background: var(--wp--preset--color--base, Canvas);
	border: 0;
	border-radius: 12px;
	box-shadow: 0 1.5rem 4rem color-mix(in srgb, CanvasText 22%, transparent);
	color: var(--wp--preset--color--contrast, CanvasText);
	max-height: min(800px, calc(100vh - 3rem));
	max-height: min(800px, calc(100dvh - 3rem));
	overflow: hidden;
	padding: 0;
	width: min(40rem, calc(100vw - 2rem));
}

.nwmid-dialog[open] {
	display: flex;
	flex-direction: column;
}

.nwmid-dialog::backdrop {
	background: color-mix(in srgb, CanvasText 45%, transparent);
}

.nwmid-dialog-form {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	margin: 0;
	min-height: 0;
}

.nwmid-dialog-header,
.nwmid-dialog-footer {
	flex: none;
	padding-left: 1.5rem;
	padding-right: 1.5rem;
	position: relative;
	transition: box-shadow 0.2s;
	z-index: 1;
}

.nwmid-dialog-header {
	align-items: center;
	border-bottom: 1px solid var(--wp--preset--color--borderline, color-mix(in srgb, currentColor 14%, transparent));
	display: flex;
	gap: 1em;
	justify-content: space-between;
	padding-bottom: 0.85rem;
	padding-top: 1rem;
}

.nwmid-dialog-heading {
	min-width: 0;
}

.nwmid-dialog .nwmid-editor-title {
	font-size: var(--wp--preset--font-size--medium, 1.2rem);
	line-height: 1.3;
}

/* Dialog buttons sit in a compact bar, so they're smaller than page buttons. */
.nwmid-dialog-footer .nwmid-button {
	font-size: var(--wp--preset--font-size--x-small, 0.875rem);
	line-height: 1.4;
	min-height: 0;
	padding: 0.6em 1.4em;
}

.nwmid-dialog-footer {
	border-top: 1px solid var(--wp--preset--color--borderline, color-mix(in srgb, currentColor 14%, transparent));
	justify-content: flex-end;
	margin-top: 0;
	padding-bottom: 0.85rem;
	padding-top: 0.85rem;
}

.nwmid-dialog[data-nwmid-above] .nwmid-dialog-header {
	box-shadow: 0 6px 12px -8px color-mix(in srgb, CanvasText 35%, transparent);
}

.nwmid-dialog[data-nwmid-below] .nwmid-dialog-footer {
	box-shadow: 0 -6px 12px -8px color-mix(in srgb, CanvasText 35%, transparent);
}

.nwmid-dialog-body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 0 1.5rem 1.25rem;
	scrollbar-gutter: stable;
}

.nwmid-dialog-body:focus {
	outline: none;
}

.nwmid-dialog-close {
	align-items: center;
	background: none;
	border: 0;
	border-radius: 50%;
	color: color-mix(in srgb, currentColor 50%, transparent);
	cursor: pointer;
	display: inline-flex;
	flex: none;
	height: 2rem;
	justify-content: center;
	margin-right: -0.5rem;
	padding: 0;
	transition: color 0.2s;
	width: 2rem;
}

.nwmid-dialog-close svg {
	display: block;
	transition: transform 0.25s ease;
}

.nwmid-dialog-close:hover,
.nwmid-dialog-close:focus-visible {
	color: var(--nwmid-accent);
}

.nwmid-dialog-close:hover svg,
.nwmid-dialog-close:focus-visible svg {
	transform: rotate(90deg);
}

.nwmid-dialog-close:focus-visible {
	outline: 2px solid var(--nwmid-accent);
	outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
	.nwmid-dialog-close svg {
		transition: none;
	}
}

body:has(.nwmid-dialog[open]) {
	overflow: hidden;
}

/* ---------------------------------------------------------------- small */

@media (max-width: 600px) {
	.nwmid-grid {
		grid-template-columns: minmax(0, 1fr);
	}

	/* Phones: use nearly the whole screen. */
	.nwmid-dialog {
		max-height: calc(100vh - 1rem);
		max-height: calc(100dvh - 1rem);
		width: calc(100vw - 1rem);
	}

	.nwmid-dialog-header,
	.nwmid-dialog-footer {
		padding-left: 1rem;
		padding-right: 1rem;
	}

	.nwmid-dialog-body {
		padding-left: 1rem;
		padding-right: 1rem;
	}

	.nwmid-editor-actions .nwmid-button-primary {
		flex: 1 1 auto;
	}

	/* Keep Save and Cancel on one row so the form keeps the space. */
	.nwmid-dialog-footer {
		flex-wrap: nowrap;
	}

	.nwmid-dialog-footer .nwmid-button {
		padding-left: 1em;
		padding-right: 1em;
	}

	.nwmid-invoice-table thead {
		display: none;
	}

	.nwmid-invoice-table tr {
		border-bottom: 1px solid color-mix(in srgb, currentColor 18%, transparent);
		display: block;
		padding: 0.6em 0;
	}

	.nwmid-invoice-table td {
		border: 0;
		display: block;
		padding: 0.15em 0;
	}

	.nwmid-invoice-table td[data-th]::before {
		content: attr(data-th) ": ";
		font-weight: 600;
	}
}
