/*
 * RawNews platform: shared front-end styles for module screens.
 *
 * Forms, steppers, status pills, dashboard tables and the empty / loading /
 * error states, built on the redesign theme's tokens (--rx-*) so module
 * screens follow its light and dark themes without restating a colour.
 * Panels and buttons are the theme's own .rx-panel, .rx-btn and
 * .rx-btn--accent; this file only adds what they lack (disabled and busy
 * states, full-width forms, 44px tap targets).
 *
 * Every token has a fallback, so a screen still reads if it is ever shown
 * without the redesign stylesheet.
 *
 * Accessibility: every control has a visible focus ring that does not rely
 * on colour alone, errors are text as well as red, and every tappable thing
 * is at least 44px tall on touch screens (WCAG 2.5.5).
 */

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

.rnp-page {
	--rnp-gap: 18px;
	--rnp-ok: #15803d;
	--rnp-ok-bg: #e7f6ec;
	--rnp-warn: #a15c00;
	--rnp-warn-bg: #fdf3e2;
	--rnp-info: #1d4ed8;
	--rnp-info-bg: #e8effd;
	--rnp-bad: var(--rx-accent-2, #b8131f);
	--rnp-bad-bg: #fdecee;
	--rnp-focus: 0 0 0 3px rgba(225, 29, 46, 0.3);
	color: var(--rx-ink, #0d1117);
	font-family: var(--rx-sans, system-ui, sans-serif);
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .rnp-page {
		--rnp-ok: #4ade80;
		--rnp-ok-bg: rgba(74, 222, 128, 0.12);
		--rnp-warn: #fbbf24;
		--rnp-warn-bg: rgba(251, 191, 36, 0.12);
		--rnp-info: #93b4ff;
		--rnp-info-bg: rgba(147, 180, 255, 0.12);
		--rnp-bad: #ff8a95;
		--rnp-bad-bg: rgba(255, 59, 75, 0.14);
		--rnp-focus: 0 0 0 3px rgba(255, 59, 75, 0.4);
	}
}

:root[data-theme="dark"] .rnp-page {
	--rnp-ok: #4ade80;
	--rnp-ok-bg: rgba(74, 222, 128, 0.12);
	--rnp-warn: #fbbf24;
	--rnp-warn-bg: rgba(251, 191, 36, 0.12);
	--rnp-info: #93b4ff;
	--rnp-info-bg: rgba(147, 180, 255, 0.12);
	--rnp-bad: #ff8a95;
	--rnp-bad-bg: rgba(255, 59, 75, 0.14);
	--rnp-focus: 0 0 0 3px rgba(255, 59, 75, 0.4);
}

.rnp-page *,
.rnp-page *::before,
.rnp-page *::after {
	box-sizing: border-box;
}

.rnp-shell {
	max-width: 1080px;
	margin-inline: auto;
	display: grid;
	gap: var(--rnp-gap);
}

.rnp-shell--narrow {
	max-width: 720px;
}

.rnp-head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 12px;
}

.rnp-title {
	margin: 0;
	font: 800 clamp(26px, 3.4vw, 38px)/1.08 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: -0.03em;
	color: var(--rx-ink, #0d1117);
}

.rnp-lede {
	margin: 6px 0 0;
	max-width: 62ch;
	font: 500 15.5px/1.5 var(--rx-sans, system-ui, sans-serif);
	color: var(--rx-ink-2, #39424f);
}

.rnp-page .rx-panel {
	border-radius: var(--rx-radius, 10px);
}

.rnp-panel__body {
	padding: 22px 24px;
}

.rnp-panel__foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: flex-end;
	gap: 10px;
	padding: 14px 24px;
	border-top: 1px solid var(--rx-line, #dde1e7);
	background: var(--rx-soft, #f4f5f8);
}

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

.rnp-page .rx-btn {
	min-height: 44px;
	padding-inline: 20px;
}

.rnp-page .rx-btn:focus-visible,
.rnp-page a:focus-visible,
.rnp-page summary:focus-visible {
	outline: 2px solid var(--rx-accent, #e11d2e);
	outline-offset: 2px;
}

.rnp-page .rx-btn[disabled],
.rnp-page .rx-btn[aria-disabled="true"] {
	opacity: 0.55;
	cursor: not-allowed;
	transform: none;
}

/* A button that is waiting on the server: label stays, spinner joins it. */
.rnp-page .rx-btn[aria-busy="true"] {
	cursor: progress;
}

.rnp-page .rx-btn[aria-busy="true"]::after {
	content: "";
	width: 14px;
	height: 14px;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: rnp-spin 0.8s linear infinite;
}

.rnp-btn--block {
	width: 100%;
}

.rnp-btn--danger {
	border-color: var(--rnp-bad);
	color: var(--rnp-bad);
}

/* --------------------------------------------------------------- forms -- */

.rnp-form {
	display: grid;
	gap: 20px;
	margin: 0;
}

.rnp-form__row {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	gap: 20px;
}

.rnp-fieldset {
	margin: 0;
	padding: 0;
	border: 0;
	display: grid;
	gap: 16px;
	min-width: 0;
}

.rnp-fieldset > legend,
.rnp-legend {
	margin: 0 0 4px;
	padding: 0;
	font: 800 13px/1.2 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--rx-ink, #0d1117);
}

.rnp-field {
	display: grid;
	gap: 6px;
	min-width: 0;
}

.rnp-label {
	font: 700 14.5px/1.3 var(--rx-sans, system-ui, sans-serif);
	color: var(--rx-ink, #0d1117);
}

.rnp-required {
	color: var(--rx-accent, #e11d2e);
	font-weight: 800;
}

.rnp-hint {
	margin: 0;
	font: 500 13.5px/1.45 var(--rx-sans, system-ui, sans-serif);
	color: var(--rx-mute, #687180);
}

.rnp-input {
	width: 100%;
	min-height: 44px;
	padding: 10px 13px;
	border: 1px solid var(--rx-line-2, #c6ccd5);
	border-radius: 8px;
	background: var(--rx-panel, #fff);
	color: var(--rx-ink, #0d1117);
	font: 500 16px/1.4 var(--rx-sans, system-ui, sans-serif); /* 16px: iOS zooms into anything smaller */
	transition: border-color 140ms ease, box-shadow 140ms ease;
	appearance: none;
}

.rnp-input::placeholder {
	color: var(--rx-mute, #687180);
	opacity: 1;
}

.rnp-input:hover {
	border-color: var(--rx-ink-2, #39424f);
}

.rnp-input:focus,
.rnp-input:focus-visible {
	outline: 2px solid transparent; /* forced-colours mode draws this */
	border-color: var(--rx-accent, #e11d2e);
	box-shadow: var(--rnp-focus);
}

.rnp-input[disabled],
.rnp-input[readonly] {
	background: var(--rx-soft, #f4f5f8);
	color: var(--rx-ink-2, #39424f);
	cursor: not-allowed;
}

.rnp-textarea {
	min-height: 140px;
	resize: vertical;
	line-height: 1.55;
}

.rnp-select {
	padding-right: 38px;
	background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
	background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%;
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
}

.rnp-field--file .rnp-input {
	padding: 9px;
	cursor: pointer;
}

.rnp-input[type="file"]::file-selector-button {
	margin-right: 12px;
	min-height: 32px;
	padding: 0 14px;
	border: 1px solid var(--rx-line-2, #c6ccd5);
	border-radius: 6px;
	background: var(--rx-soft, #f4f5f8);
	color: var(--rx-ink, #0d1117);
	font: 700 13.5px/1 var(--rx-sans, system-ui, sans-serif);
	cursor: pointer;
}

/* Checkbox and radio: the whole label is the target, 44px tall. */
.rnp-check {
	display: inline-flex;
	align-items: flex-start;
	gap: 10px;
	min-height: 44px;
	padding: 10px 0;
	font: 500 15px/1.45 var(--rx-sans, system-ui, sans-serif);
	color: var(--rx-ink, #0d1117);
	cursor: pointer;
}

.rnp-check__box {
	flex: 0 0 auto;
	width: 20px;
	height: 20px;
	margin: 1px 0 0;
	accent-color: var(--rx-accent, #e11d2e);
	cursor: pointer;
}

.rnp-check__box:focus-visible {
	outline: 2px solid var(--rx-accent, #e11d2e);
	outline-offset: 3px;
}

/* Errors: a red edge and a message in words, never colour alone. */
.rnp-field--error .rnp-input,
.rnp-input[aria-invalid="true"] {
	border-color: var(--rnp-bad);
	border-width: 2px;
	padding: 9px 12px;
}

.rnp-field--error .rnp-input:focus {
	box-shadow: 0 0 0 3px var(--rnp-bad-bg);
}

.rnp-error {
	display: flex;
	gap: 6px;
	margin: 0;
	font: 700 13.5px/1.4 var(--rx-sans, system-ui, sans-serif);
	color: var(--rnp-bad);
}

.rnp-error::before {
	content: "!";
	flex: 0 0 auto;
	display: inline-grid;
	place-items: center;
	width: 17px;
	height: 17px;
	margin-top: 1px;
	border-radius: 50%;
	background: var(--rnp-bad);
	color: #fff;
	font: 800 11px/1 var(--rx-sans, system-ui, sans-serif);
}

/* The summary at the top of a form that failed to submit. */
.rnp-summary {
	padding: 16px 18px;
	border: 2px solid var(--rnp-bad);
	border-radius: var(--rx-radius, 10px);
	background: var(--rnp-bad-bg);
}

.rnp-summary:focus {
	outline: 3px solid var(--rnp-bad);
	outline-offset: 2px;
}

.rnp-summary__title {
	margin: 0 0 8px;
	font: 800 16px/1.3 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: -0.01em;
	color: var(--rx-ink, #0d1117);
}

.rnp-summary__list {
	margin: 0;
	padding-left: 20px;
	display: grid;
	gap: 4px;
}

.rnp-summary__list a {
	color: var(--rnp-bad);
	font-weight: 700;
	text-underline-offset: 3px;
}

.rnp-turnstile {
	min-height: 65px;
}

.rnp-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
}

.rnp-actions--end {
	justify-content: flex-end;
}

/* Honeypot: off-screen, out of the tab order, ignored by assistive tech. */
.rnp-hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

/* ------------------------------------------------------------- notices -- */

.rnp-notice {
	display: flex;
	gap: 10px;
	align-items: flex-start;
	padding: 13px 16px;
	border: 1px solid var(--rx-line, #dde1e7);
	border-left-width: 4px;
	border-radius: 8px;
	background: var(--rx-panel, #fff);
	font: 500 14.5px/1.5 var(--rx-sans, system-ui, sans-serif);
	color: var(--rx-ink, #0d1117);
}

.rnp-notice p {
	margin: 0;
}

.rnp-notice--success {
	border-left-color: var(--rnp-ok);
	background: var(--rnp-ok-bg);
}

.rnp-notice--error {
	border-left-color: var(--rnp-bad);
	background: var(--rnp-bad-bg);
}

.rnp-notice--warning {
	border-left-color: var(--rnp-warn);
	background: var(--rnp-warn-bg);
}

.rnp-notice--info {
	border-left-color: var(--rnp-info);
	background: var(--rnp-info-bg);
}

/* ------------------------------------------------------------- stepper -- */

/*
 * <ol class="rnp-stepper">
 *   <li class="rnp-step is-done"><span class="rnp-step__dot">1</span><span class="rnp-step__label">Details</span></li>
 *   <li class="rnp-step is-current" aria-current="step">…</li>
 *   <li class="rnp-step">…</li>
 * </ol>
 */
.rnp-stepper {
	display: flex;
	gap: 0;
	margin: 0;
	padding: 0;
	list-style: none;
	counter-reset: rnp-step;
}

.rnp-step {
	position: relative;
	flex: 1 1 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	min-width: 0;
	text-align: center;
	font: 700 13px/1.25 var(--rx-sans, system-ui, sans-serif);
	color: var(--rx-mute, #687180);
}

/* The rail between dots. */
.rnp-step + .rnp-step::before {
	content: "";
	position: absolute;
	top: 15px;
	right: 50%;
	width: 100%;
	height: 2px;
	background: var(--rx-line, #dde1e7);
	z-index: 0;
}

.rnp-step.is-done + .rnp-step::before,
.rnp-step.is-done + .rnp-step.is-current::before {
	background: var(--rx-accent, #e11d2e);
}

.rnp-step__dot {
	position: relative;
	z-index: 1;
	display: grid;
	place-items: center;
	width: 32px;
	height: 32px;
	border: 2px solid var(--rx-line-2, #c6ccd5);
	border-radius: 50%;
	background: var(--rx-panel, #fff);
	color: var(--rx-ink-2, #39424f);
	font: 800 13px/1 var(--rx-sans, system-ui, sans-serif);
}

.rnp-step.is-current {
	color: var(--rx-ink, #0d1117);
}

.rnp-step.is-current .rnp-step__dot {
	border-color: var(--rx-accent, #e11d2e);
	color: var(--rx-accent, #e11d2e);
	box-shadow: var(--rnp-focus);
}

.rnp-step.is-done .rnp-step__dot {
	border-color: var(--rx-accent, #e11d2e);
	background: var(--rx-accent, #e11d2e);
	color: var(--rx-on-accent, #fff);
}

.rnp-step__label {
	overflow-wrap: anywhere;
}

@media (max-width: 560px) {
	/* Narrow screens: dots only, with the current step named under them. */
	.rnp-step__label {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(1px, 1px, 1px, 1px);
		white-space: nowrap;
	}

	.rnp-step.is-current .rnp-step__label {
		position: static;
		width: auto;
		height: auto;
		clip: auto;
		white-space: normal;
	}
}

/* --------------------------------------------------------------- pills -- */

.rnp-pill {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 10px 4px;
	border-radius: 999px;
	background: var(--rx-soft, #f4f5f8);
	color: var(--rx-ink-2, #39424f);
	font: 800 11px/1 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: 0.08em;
	text-transform: uppercase;
	white-space: nowrap;
}

.rnp-pill::before {
	content: "";
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: currentColor;
}

.rnp-pill--ok,
.rnp-pill--sent,
.rnp-pill--done,
.rnp-pill--paid,
.rnp-pill--approved,
.rnp-pill--published,
.rnp-pill--live {
	background: var(--rnp-ok-bg);
	color: var(--rnp-ok);
}

.rnp-pill--queued,
.rnp-pill--running,
.rnp-pill--pending,
.rnp-pill--review,
.rnp-pill--submitted,
.rnp-pill--scheduled {
	background: var(--rnp-info-bg);
	color: var(--rnp-info);
}

.rnp-pill--warn,
.rnp-pill--failed,
.rnp-pill--changes,
.rnp-pill--expiring {
	background: var(--rnp-warn-bg);
	color: var(--rnp-warn);
}

.rnp-pill--error,
.rnp-pill--dead,
.rnp-pill--rejected,
.rnp-pill--refunded,
.rnp-pill--cancelled {
	background: var(--rnp-bad-bg);
	color: var(--rnp-bad);
}

.rnp-pill--draft,
.rnp-pill--blocked,
.rnp-pill--expired,
.rnp-pill--muted {
	background: var(--rx-soft, #f4f5f8);
	color: var(--rx-mute, #687180);
}

/* ---------------------------------------------------------- dashboards -- */

.rnp-stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
	gap: var(--rnp-gap);
}

.rnp-stat {
	padding: 16px 18px;
	border: 1px solid var(--rx-line, #dde1e7);
	border-radius: var(--rx-radius, 10px);
	background: var(--rx-panel, #fff);
}

.rnp-stat__label {
	margin: 0;
	font: 800 11.5px/1.2 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--rx-mute, #687180);
}

.rnp-stat__value {
	margin: 6px 0 0;
	font: 800 30px/1 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: -0.03em;
	font-variant-numeric: tabular-nums;
	color: var(--rx-ink, #0d1117);
}

.rnp-table-wrap {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.rnp-table {
	width: 100%;
	border-collapse: collapse;
	font: 500 14.5px/1.4 var(--rx-sans, system-ui, sans-serif);
	color: var(--rx-ink, #0d1117);
}

.rnp-table caption {
	padding: 0 0 10px;
	text-align: left;
	font: 800 13px/1.2 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

.rnp-table th,
.rnp-table td {
	padding: 12px 16px;
	border-bottom: 1px solid var(--rx-line, #dde1e7);
	text-align: left;
	vertical-align: middle;
}

.rnp-table thead th {
	background: var(--rx-soft, #f4f5f8);
	font: 800 11.5px/1.2 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--rx-mute, #687180);
	white-space: nowrap;
}

.rnp-table tbody tr:hover {
	background: var(--rx-soft, #f4f5f8);
}

.rnp-table tbody tr:last-child td {
	border-bottom: 0;
}

.rnp-table .is-num {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.rnp-table a {
	color: inherit;
	font-weight: 700;
	text-decoration-color: var(--rx-accent, #e11d2e);
	text-underline-offset: 3px;
}

.rnp-table__meta {
	display: block;
	margin-top: 2px;
	font-size: 12.5px;
	font-weight: 500;
	color: var(--rx-mute, #687180);
}

/*
 * Phones: each row becomes a card, each cell a "Label: value" line. Cells
 * need data-label="…" for this; the header row is hidden visually but kept
 * for screen readers.
 */
@media (max-width: 640px) {
	.rnp-table--stack thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(1px, 1px, 1px, 1px);
	}

	.rnp-table--stack tr {
		display: block;
		padding: 10px 0;
		border-bottom: 1px solid var(--rx-line, #dde1e7);
	}

	.rnp-table--stack tbody tr:hover {
		background: transparent;
	}

	.rnp-table--stack td {
		display: flex;
		justify-content: space-between;
		gap: 16px;
		padding: 6px 16px;
		border: 0;
		text-align: right;
	}

	.rnp-table--stack td::before {
		content: attr(data-label);
		flex: 0 0 auto;
		text-align: left;
		font: 800 11.5px/1.6 var(--rx-sans, system-ui, sans-serif);
		letter-spacing: 0.06em;
		text-transform: uppercase;
		color: var(--rx-mute, #687180);
	}

	.rnp-table--stack td:not([data-label])::before {
		content: none;
	}
}

/* -------------------------------------------- empty / loading / error -- */

.rnp-state {
	display: grid;
	justify-items: center;
	gap: 8px;
	padding: 44px 24px;
	text-align: center;
	border: 1px dashed var(--rx-line-2, #c6ccd5);
	border-radius: var(--rx-radius, 10px);
	background: var(--rx-panel, #fff);
}

.rnp-state__icon {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(--rx-soft, #f4f5f8);
	box-shadow: inset 0 0 0 2px var(--rx-line, #dde1e7);
}

.rnp-state__title {
	margin: 4px 0 0;
	font: 800 18px/1.3 var(--rx-sans, system-ui, sans-serif);
	letter-spacing: -0.01em;
	color: var(--rx-ink, #0d1117);
}

.rnp-state__body {
	margin: 0;
	max-width: 52ch;
	font: 500 14.5px/1.5 var(--rx-sans, system-ui, sans-serif);
	color: var(--rx-ink-2, #39424f);
}

.rnp-state__action {
	margin-top: 10px;
}

.rnp-state--error {
	border-style: solid;
	border-color: var(--rnp-bad);
	background: var(--rnp-bad-bg);
}

.rnp-state--error .rnp-state__icon {
	background: var(--rnp-bad);
	box-shadow: none;
}

.rnp-state--error .rnp-state__icon::after {
	content: "!";
	display: grid;
	place-items: center;
	height: 100%;
	color: #fff;
	font: 800 20px/1 var(--rx-sans, system-ui, sans-serif);
}

.rnp-state--loading {
	border-style: solid;
}

.rnp-spinner {
	width: 32px;
	height: 32px;
	border: 3px solid var(--rx-line, #dde1e7);
	border-top-color: var(--rx-accent, #e11d2e);
	border-radius: 50%;
	animation: rnp-spin 0.8s linear infinite;
}

/* Placeholder blocks for content that is on its way. */
.rnp-skeleton {
	display: block;
	height: 14px;
	border-radius: 6px;
	background: linear-gradient(90deg, var(--rx-soft, #f4f5f8) 0%, var(--rx-line, #dde1e7) 50%, var(--rx-soft, #f4f5f8) 100%);
	background-size: 200% 100%;
	animation: rnp-shimmer 1.4s ease-in-out infinite;
}

.rnp-skeleton + .rnp-skeleton {
	margin-top: 10px;
}

@keyframes rnp-spin {
	to {
		transform: rotate(360deg);
	}
}

@keyframes rnp-shimmer {
	0% {
		background-position: 200% 0;
	}
	100% {
		background-position: -200% 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.rnp-spinner,
	.rnp-page .rx-btn[aria-busy="true"]::after {
		animation-duration: 2.4s;
	}

	.rnp-skeleton {
		animation: none;
	}

	.rnp-input {
		transition: none;
	}
}

/* ------------------------------------------------------------- mobile -- */

@media (max-width: 760px) {
	.rnp-panel__body {
		padding: 18px 16px;
	}

	.rnp-panel__foot {
		padding: 12px 16px;
	}

	.rnp-actions .rx-btn,
	.rnp-panel__foot .rx-btn {
		flex: 1 1 auto;
	}

	.rnp-table th,
	.rnp-table td {
		padding: 10px 12px;
	}
}

/* Coarse pointers: every target at least 44px, whatever the width. */
@media (pointer: coarse) {
	.rnp-page .rx-btn,
	.rnp-input,
	.rnp-check,
	.rnp-table a {
		min-height: 44px;
	}

	.rnp-table a {
		display: inline-flex;
		align-items: center;
	}
}

/* Windows high-contrast: keep focus and error edges visible. */
@media (forced-colors: active) {
	.rnp-input:focus,
	.rnp-check__box:focus-visible {
		outline: 2px solid CanvasText;
	}

	.rnp-pill,
	.rnp-step__dot {
		border: 1px solid CanvasText;
	}
}
