/**
 * Newsletter Signup Form Styles
 * Infomaniak Newsletter Integration
 *
 * @package Ernesto
 * @since 1.0.0
 */

/* Newsletter Container */
.ernesto-newsletter-form,
.ernesto-newsletter-shortcode {
	background-color: var(--color-bg-alt);
	border-radius: var(--border-radius-md);
	margin-bottom: var(--space-xl);
}

.newsletter-title {
	margin-top: 0;
	margin-bottom: var(--space-md);
}

.newsletter-description {
	margin-top: 0;
	margin-bottom: var(--space-lg);
	color: var(--color-text-light);
	line-height: var(--line-height-loose);
}

/* Newsletter Form */
.newsletter-form {
	display: flex;
	flex-direction: column;
	gap: var(--space-md);
}

.newsletter-form .form-field,
.newsletter-form .newsletter-field {
	display: flex;
	flex-direction: column;
}

/* Field styling deliberately mirrors the theme's own contact form
   (ernesto/assets/css/contact.css), declaration for declaration, so the two
   forms are indistinguishable.

   The tokens matter: --input-border is the field border (50% of the body text
   colour), while --color-border is the theme's LEGACY alias for --border-color,
   a pale divider grey (#DEE2E6). This rule used to ask for --color-border and
   --color-bg, which is why the border was almost invisible and the field had no
   background at all — --color-bg is not defined on the front end, so the
   declaration resolved to transparent.

   Every var() carries a fallback so the form still looks like a form when this
   plugin runs outside an Ernesto theme. */
.newsletter-form input[type="text"],
.newsletter-form input[type="email"] {
	width: 100%;
	padding: var(--space-sm, 0.5rem) var(--space-md, 1rem);
	border: 1px solid var(--input-border, var(--color-border, #767676));
	border-radius: var(--border-radius-md, 0.375rem);
	font-size: var(--font-size-base, 1rem);
	font-family: inherit;
	background-color: var(--input-bg, var(--color-bg, #fff));
	color: var(--input-text, inherit);
	transition: border-color var(--transition-fast, 150ms ease-in-out), box-shadow var(--transition-fast, 150ms ease-in-out);
	appearance: none;
	-webkit-appearance: none;
}

/* Same focus treatment as the contact form, including its blue ring — that
   colour is hardcoded there too, so matching it keeps the two consistent. */
.newsletter-form input[type="text"]:focus,
.newsletter-form input[type="email"]:focus {
	outline: none;
	border-color: var(--color-primary, #0066ff);
	box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.12);
}

/* Consent Checkbox */
.form-consent {
	margin: var(--space-sm) 0;
}

.consent-label {
	display: flex;
	align-items: flex-start;
	gap: var(--space-sm);
	cursor: pointer;
	font-size: var(--font-size-sm);
	line-height: var(--line-height-loose);
}

.consent-label input[type="checkbox"] {
	margin-top: 0.25rem;
	width: 18px;
	height: 18px;
	cursor: pointer;
	accent-color: var(--color-primary);
	flex-shrink: 0;
}

.consent-label a {
	color: var(--color-primary);
	text-decoration: underline;
}

.consent-label a:hover {
	color: var(--color-primary-dark);
}

/* Submit Button */
.newsletter-submit {
	align-self: flex-start;
	display: inline-block;
	padding: var(--space-md) var(--space-xl);
	background-color: var(--color-primary);
	color: white;
	border: none;
	border-radius: var(--border-radius-md);
	font-size: var(--font-size-base);
	font-weight: 600;
	cursor: pointer;
	transition: background-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
	min-width: 180px;
}

.newsletter-submit:hover {
	background-color: var(--color-primary-dark);
	transform: translateY(-2px);
	box-shadow: var(--shadow-md);
}

.newsletter-submit:active {
	transform: translateY(0);
}

.newsletter-submit:disabled {
	opacity: 0.6;
	cursor: not-allowed;
	transform: none;
}

/* Loading State */
.newsletter-form.loading .newsletter-submit {
	position: relative;
	color: transparent;
}

.newsletter-form.loading .newsletter-submit::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 20px;
	height: 20px;
	margin-top: -10px;
	margin-left: -10px;
	border: 2px solid rgba(255, 255, 255, 0.3);
	border-top-color: white;
	border-radius: 50%;
	animation: newsletter-spinner 0.6s linear infinite;
}

@keyframes newsletter-spinner {
	to {
		transform: rotate(360deg);
	}
}

/* Success/Error Messages */
.newsletter-message {
	padding: var(--space-sm, 0.5rem) var(--space-md, 1rem);
	border-radius: var(--border-radius-md, 0.375rem);
	font-size: var(--font-size-sm, 0.875rem);
	line-height: var(--line-height-loose, 1.75);
	margin-top: var(--space-md, 1rem);
}

/* Deliberately quiet: a thin accent rule and muted text rather than a filled
   panel. Confirming a newsletter signup is not an event that needs to shout,
   and the filled green box read as heavier than the form it sat under. */
.newsletter-message.success {
	background-color: transparent;
	border: 0;
	border-left: 3px solid var(--color-success, #28a745);
	border-radius: 0;
	color: var(--color-text-light, #65676b);
	font-weight: 400;
}

/* Errors keep a filled panel — on an Ernesto theme the global [role="alert"]
   rule takes this over and paints them in the site's own error colours, so
   this is the fallback for everywhere else. */
.newsletter-message.error {
	background-color: #fee2e2;
	border: 1px solid var(--color-error, #dc2626);
	color: #991b1b;
}

.newsletter-message strong {
	display: block;
	margin-bottom: var(--space-xs);
	font-weight: 600;
}

/* Sidebar Widget Style */
.widget .ernesto-newsletter-form {
	background-color: transparent;
	padding: 0;
}

/* Footer Widget Style */
.site-footer .ernesto-newsletter-form {
	background-color: rgba(255, 255, 255, 0.05);
	padding: var(--space-lg);
}

.site-footer .newsletter-description {
	color: #cbd5e1;
}

.site-footer .newsletter-form input[type="text"],
.site-footer .newsletter-form input[type="email"] {
	background-color: rgba(255, 255, 255, 0.1);
	border-color: rgba(255, 255, 255, 0.2);
	color: white;
}

.site-footer .newsletter-form input[type="text"]::placeholder,
.site-footer .newsletter-form input[type="email"]::placeholder {
	color: rgba(255, 255, 255, 0.6);
}

.site-footer .newsletter-form input[type="text"]:focus,
.site-footer .newsletter-form input[type="email"]:focus {
	background-color: rgba(255, 255, 255, 0.15);
	border-color: var(--color-primary);
}

.site-footer .consent-label {
	color: #cbd5e1;
}

/* Desktop Layout - Horizontal Form */
@media (min-width: 768px) {
	.newsletter-form.horizontal {
		flex-direction: row;
		flex-wrap: wrap;
		align-items: flex-end;
	}

	.newsletter-form.horizontal .form-field:not(.form-consent) {
		flex: 1;
		min-width: 200px;
	}

	.newsletter-form.horizontal .form-consent {
		flex-basis: 100%;
	}

	.newsletter-form.horizontal .newsletter-submit {
		width: auto;
		min-width: 150px;
	}
}

/* Compact Style */
.newsletter-form.compact {
	gap: var(--space-sm);
}

.newsletter-form.compact input[type="text"],
.newsletter-form.compact input[type="email"] {
	padding: var(--space-sm);
}

.newsletter-form.compact .newsletter-submit {
	padding: var(--space-sm) var(--space-lg);
}

/* Inline Style */
.newsletter-form.inline {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: var(--space-sm);
}

.newsletter-form.inline .form-consent {
	grid-column: 1 / -1;
}

.newsletter-form.inline .newsletter-message {
	grid-column: 1 / -1;
}

@media (max-width: 767px) {
	.newsletter-form.inline {
		grid-template-columns: 1fr;
	}

	.newsletter-submit {
		width: 100%;
	}
}

/* Accessibility */
.newsletter-form input:focus {
	outline: 2px solid var(--color-primary);
	outline-offset: 2px;
}

.newsletter-form .screen-reader-text {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

/* Print */
@media print {
	.ernesto-newsletter-form,
	.ernesto-newsletter-shortcode {
		display: none;
	}
}

/* ============================================================
   STYLING HOOKS
   Added alongside the older class names, which stay in place so
   existing theme CSS keeps matching. Nothing here changes the
   default look — these are anchors for a theme to hang rules on.
   ============================================================ */

/* Status area starts out hidden via the attribute rather than an inline
   style, so a theme can still control its display. Kept at this specificity
   so it beats a plain .newsletter-message rule that sets display. */
.newsletter-message[hidden] {
	display: none;
}

/* Field labels are screen-reader-only by default. Pass show_labels="1" to
   the shortcode to drop that class and get a visible, stylable label. */
.newsletter-label {
	font-size: var(--font-size-sm, 0.875rem);
	line-height: var(--line-height-normal, 1.5);
	margin-bottom: var(--space-xs, 0.25rem);
}

/* Context modifiers — style one placement without touching the others. */
.ernesto-newsletter--widget {
	margin-bottom: 0;
}

/* No title means the description is the first thing in the box; drop the
   gap that would otherwise sit above it. */
.ernesto-newsletter--no-title .newsletter-description {
	margin-top: 0;
}

/* Layout modifiers are mirrored onto the container so a theme can react to
   the layout from outside the form as well. */
.ernesto-newsletter--inline .newsletter-form,
.ernesto-newsletter--horizontal .newsletter-form,
.ernesto-newsletter--compact .newsletter-form {
	width: 100%;
}

/* Double opt-in confirmation page. Its form deliberately does NOT carry
   .newsletter-form — that class is the hook newsletter.js binds the AJAX
   signup handler to — so the few layout rules it needs live here. */
.ernesto-newsletter-confirm__form {
	display: flex;
	flex-direction: column;
	gap: var(--space-md, 1rem);
}

.ernesto-newsletter-confirm .newsletter-description {
	margin-bottom: var(--space-lg, 2rem);
}
