/*
 * Login (wp-login.php) incl. the next-events-2fa challenge/setup views.
 *
 * Uses the shared design tokens (pt-tokens.css is loaded as dependency) and
 * the same theme logic as the app: stored choice via pt_theme_bootstrap_script(),
 * otherwise the OS preference. Branding (logo variants, poster) comes from
 * Systemeinstellungen → Design and is injected by Theme::enqueue_login_assets()
 * as custom properties — never hardcoded here.
 *
 * !important is only used where WordPress core login styles would win.
 */

/* --- Page ------------------------------------------------------------------ */

html {
	height: 100%;
}

/* Login surface is self-contained (no pt-theme.css / WP admin reset).
   Without border-box, width:100% + padding + border overflows the card. */
body.login,
body.login *,
body.login *::before,
body.login *::after {
	box-sizing: border-box;
}

body.login {
	min-height: 100%;
	min-height: 100dvh;
	margin: 0;
	padding: var(--sp-6);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	justify-content: safe center;
	font-family: var(--pt-font);
	font-size: var(--fs-base);
	color: var(--c-text);
	background: var(--c-bg);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	/* Scroll only when the card is taller than the viewport (mobile/zoom). */
	overflow-x: hidden;
	overflow-y: auto;
}

/* Poster image (Systemeinstellungen → Design) as full-bleed background with
   a theme-aware scrim, so the glass card stays readable on any photo. */
body.login.pt-has-poster {
	background: var(--c-bg) var(--pt-login-poster) center / cover no-repeat fixed;
}
body.login.pt-has-poster::before {
	content: '';
	position: fixed;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	background: var(--mat-poster-scrim);
}

/* --- Card ------------------------------------------------------------------ */

#login {
	position: relative;
	z-index: 1;
	width: min(400px, 100%);
	max-width: 100%;
	margin: 0;
	padding: var(--sp-7) var(--sp-7) var(--sp-6);
	background: var(--c-surface);
	border: 1px solid var(--c-border);
	border-radius: var(--r-xl);
	box-shadow: var(--shadow-3), var(--shadow-highlight);
	flex-shrink: 0;
}

/* Glass material only where it has something to refract: on the poster. */
body.login.pt-has-poster #login {
	background: var(--mat-sheet);
	-webkit-backdrop-filter: var(--mat-blur);
	backdrop-filter: var(--mat-blur);
	border-color: var(--c-separator);
}

/* --- Logo -------------------------------------------------------------------
   The card follows the active theme, so the logo variant follows the card:
   positive logo on the light card, negative logo on the dark card. */

.login h1 {
	margin-bottom: var(--sp-2);
}

/* WordPress site title — always visible (under logo, or as brand when no logo). */
.pt-login-site-title {
	margin: 0 0 var(--sp-6);
	padding: 0;
	font-family: var(--pt-font);
	font-size: var(--fs-sm);
	font-weight: var(--fw-medium);
	line-height: 1.3;
	letter-spacing: 0.01em;
	text-align: center;
	color: var(--c-text-muted);
}

/* Without logo: h1 is empty/hidden; site title becomes the primary brand line. */
body.login:not(.pt-has-logo) h1 {
	display: none;
}

body.login:not(.pt-has-logo) .pt-login-site-title {
	font-size: var(--fs-xl);
	font-weight: var(--fw-bold);
	letter-spacing: -.02em;
	color: var(--c-text);
}

.login h1 a {
	display: block;
	width: auto;
	height: auto;
	margin: 0;
	background: none;
	font-size: var(--fs-xl);
	font-weight: var(--fw-bold);
	line-height: 1.2;
	letter-spacing: -.02em;
	text-align: center;
	text-indent: 0;
	color: var(--c-text);
	text-decoration: none;
}

body.login.pt-has-logo h1 a {
	height: 52px;
	background-image: var(--pt-logo-on-light);
	background-position: center;
	background-repeat: no-repeat;
	background-size: contain;
	text-indent: -9999px;
	overflow: hidden;
}
html[data-theme="dark"] body.login.pt-has-logo h1 a { background-image: var(--pt-logo-on-dark); }
@media (prefers-color-scheme: dark) {
	html:not([data-theme]) body.login.pt-has-logo h1 a { background-image: var(--pt-logo-on-dark); }
}

/* --- Form ------------------------------------------------------------------ */

/* The card is #login itself — the core form box becomes transparent. */
.login form,
#loginform,
#registerform,
#lostpasswordform {
	margin: 0 !important;
	padding: 0 !important;
	border: none !important;
	background: none !important;
	box-shadow: none !important;
	overflow: visible;
}

.login label {
	display: block;
	margin-bottom: var(--sp-2);
	font-family: var(--pt-font);
	font-size: var(--fs-sm);
	font-weight: var(--fw-semibold);
	color: var(--c-text);
}

.login input[type="text"],
.login input[type="password"],
.login input[type="email"],
.login input[type="number"] {
	display: block;
	width: 100%;
	max-width: 100%;
	height: 44px;
	margin: 0 !important;
	padding: 0 var(--sp-3) !important;
	border: 1px solid var(--c-control-border) !important;
	border-radius: var(--control-radius) !important;
	background: var(--c-control-bg) !important;
	color: var(--c-text) !important;
	font-family: var(--pt-font);
	font-size: var(--fs-base);
	box-shadow: var(--shadow-1) !important;
	transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.login input[type="text"]:hover,
.login input[type="password"]:hover,
.login input[type="email"]:hover { border-color: var(--c-border-strong) !important; }

.login input[type="text"]:focus,
.login input[type="password"]:focus,
.login input[type="email"]:focus,
.login input[type="number"]:focus {
	outline: none;
	background: var(--c-surface) !important;
	border-color: var(--c-primary) !important;
	box-shadow: var(--focus-ring) !important;
}

.login input.is-invalid,
.login input[type="email"].is-invalid,
.login input[type="text"].is-invalid {
	border-color: var(--c-danger) !important;
}
.login input.is-invalid:focus,
.login input[type="email"].is-invalid:focus,
.login input[type="text"].is-invalid:focus {
	border-color: var(--c-danger) !important;
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-danger) 28%, transparent) !important;
}

/* Password visibility toggle (core) */
.login .wp-pwd { position: relative; }
.login .button.wp-hide-pw {
	height: 44px;
	min-height: 0;
	color: var(--c-text-muted);
	background: none;
	border: none;
	box-shadow: none;
}
.login .button.wp-hide-pw:hover,
.login .button.wp-hide-pw:focus { color: var(--c-text); background: none; }
.login .button.wp-hide-pw:focus { box-shadow: var(--focus-ring); border-radius: var(--r-sm); }

/* Primary button */
.wp-core-ui .button-primary {
	display: block;
	width: 100% !important;
	max-width: 100% !important;
	height: 44px !important;
	padding: 0 var(--sp-4) !important;
	border: none !important;
	border-radius: var(--control-radius) !important;
	background: var(--c-primary-fill) !important;
	color: var(--c-on-primary) !important;
	font-family: var(--pt-font);
	font-size: var(--fs-md);
	font-weight: var(--fw-semibold);
	line-height: 1 !important;
	text-shadow: none !important;
	box-shadow: var(--shadow-1), inset 0 1px 0 var(--c-highlight-on-fill) !important;
	transition: background-color var(--t-fast), transform var(--t-fast);
}
.wp-core-ui .button-primary:hover { background: var(--c-primary-fill-hover) !important; }
.wp-core-ui .button-primary:active { transform: scale(.98); }
.wp-core-ui .button-primary:focus-visible {
	outline: 2px solid var(--c-primary);
	outline-offset: 2px;
}

/* --- Form layout (flex order) -----------------------------------------------
   DOM:    username → password → .pt-lost-password-row → forgetmenot → submit
   Visual: username → password → lost-password → submit → forgetmenot */

#loginform {
	display: flex !important;
	flex-direction: column;
	gap: var(--sp-4);
}
#loginform > p,
#loginform > div { margin: 0 !important; }

#loginform .pt-lost-password-row { margin-top: calc(var(--sp-2) * -1) !important; }
.login .submit { order: 4; margin-top: var(--sp-1) !important; }
.login .forgetmenot {
	order: 5;
	display: flex !important;
	justify-content: center;
	float: none;
}

.forgetmenot label {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	margin: 0;
	font-size: var(--fs-sm);
	font-weight: var(--fw-regular);
	color: var(--c-text-muted);
	cursor: pointer;
	user-select: none;
}

/* Checkbox (same look as in the app) */
.forgetmenot input[type="checkbox"] {
	position: relative;
	-webkit-appearance: none;
	appearance: none;
	width: 16px;
	height: 16px;
	margin: 0;
	flex-shrink: 0;
	border: 1.5px solid var(--c-border-strong);
	border-radius: var(--r-2xs);
	background: var(--c-surface);
	box-shadow: none;
	cursor: pointer;
	transition: border-color var(--t-fast), background-color var(--t-fast);
}
.forgetmenot input[type="checkbox"]:checked {
	background: var(--c-primary-fill);
	border-color: var(--c-primary-fill);
}
.forgetmenot input[type="checkbox"]:checked::before { content: none; }
.forgetmenot input[type="checkbox"]:checked::after {
	content: '';
	position: absolute;
	left: 4px;
	top: 1px;
	width: 5px;
	height: 9px;
	border: 2px solid var(--c-on-primary);
	border-top: none;
	border-left: none;
	transform: rotate(45deg);
}
.forgetmenot input[type="checkbox"]:focus-visible {
	outline: none;
	box-shadow: var(--focus-ring);
}

/* "Passwort vergessen?" (added inside the form via login_form hook) */
.pt-lost-password-row { text-align: right; }
.pt-lost-password-row a {
	font-size: var(--fs-xs);
	font-weight: var(--fw-medium);
	color: var(--c-text-muted);
	text-decoration: none;
	transition: color var(--t-fast);
}
.pt-lost-password-row a:hover { color: var(--c-primary); text-decoration: underline; }

/* Core links outside the form are redundant (own lost-password link). */
#backtoblog,
#nav { display: none !important; }

.login .privacy-policy-page-link { margin: var(--sp-4) 0 0; text-align: center; }
.login .privacy-policy-page-link a { color: var(--c-text-muted); font-size: var(--fs-xs); }

/* --- Messages --------------------------------------------------------------- */

.login #login_error,
.login .message,
.login .notice,
.login .success {
	margin: 0 0 var(--sp-5) !important;
	padding: var(--sp-3) var(--sp-4) !important;
	border: 1px solid var(--c-info-border) !important;
	border-left-width: 1px !important;
	border-radius: var(--r-md) !important;
	background: var(--c-info-bg) !important;
	color: var(--c-text) !important;
	font-size: var(--fs-sm);
	box-shadow: none !important;
}
.login #login_error,
.login .notice-error {
	border-color: var(--c-danger-border) !important;
	background: var(--c-danger-bg) !important;
	color: var(--c-danger) !important;
}
.login #login_error a,
.login .message a { color: inherit; text-decoration: underline; }

/* --- 2FA (next-events-2fa) -------------------------------------------------- */

.login .ne2fa-code-input {
	font-size: var(--fs-2xl) !important;
	letter-spacing: 0.5em !important;
	text-align: center !important;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important;
}

/* --- OTP employee login (standalone page; styles live here, not pt-theme) --- */

.pt-otp-form {
	display: flex;
	flex-direction: column;
	gap: var(--sp-4);
	width: 100%;
	max-width: 100%;
	margin: 0;
}

.pt-otp-form > p,
.pt-otp-form > .pt-otp-field {
	margin: 0;
	width: 100%;
	max-width: 100%;
}

.pt-otp-lead {
	margin: 0;
	font-size: var(--fs-sm);
	color: var(--c-text-muted);
}

.pt-otp-field-error {
	margin: var(--sp-2) 0 0;
	width: 100%;
	max-width: 100%;
}

.pt-otp-field-error__title {
	display: block;
	margin: 0 0 var(--sp-1);
	font-size: var(--fs-sm);
	font-weight: var(--fw-semibold);
	color: var(--c-danger);
}

.pt-otp-field-error__desc {
	margin: 0;
	font-size: var(--fs-xs);
	line-height: 1.45;
	color: var(--c-danger);
}

.pt-otp-message {
	margin: 0 0 var(--sp-4);
	padding: var(--sp-3) var(--sp-4);
	width: 100%;
	max-width: 100%;
	border: 1px solid var(--c-danger-border);
	border-radius: var(--r-md);
	background: var(--c-danger-bg);
	color: var(--c-danger);
	font-size: var(--fs-sm);
}

.pt-otp-code-input {
	width: 100% !important;
	max-width: 100% !important;
	height: 56px !important;
	font-size: var(--fs-2xl) !important;
}

.pt-otp-actions {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-wrap: wrap;
	gap: var(--sp-3);
	margin: var(--sp-4) 0 0;
	width: 100%;
	max-width: 100%;
	font-size: var(--fs-xs);
	color: var(--c-text-muted);
}

.pt-otp-link {
	padding: 0;
	border: none;
	background: none;
	color: var(--c-text-muted);
	font-family: var(--pt-font);
	font-size: var(--fs-xs);
	font-weight: var(--fw-medium);
	cursor: pointer;
	text-decoration: none;
	transition: color var(--t-fast);
}
.pt-otp-link:hover { color: var(--c-primary); text-decoration: underline; }
.pt-otp-link:disabled { opacity: .5; cursor: default; text-decoration: none; }
.pt-otp-link:focus-visible {
	outline: none;
	box-shadow: var(--focus-ring);
	border-radius: var(--r-2xs);
}

.pt-otp-admin-login {
	margin: var(--sp-6) 0 0;
	width: 100%;
	max-width: 100%;
	text-align: center;
	font-size: var(--fs-2xs);
	font-weight: var(--fw-medium);
	color: var(--c-text-subtle);
}
.pt-otp-admin-login a {
	color: inherit;
	text-decoration: none;
}
.pt-otp-admin-login a:hover {
	color: var(--c-text-muted);
	text-decoration: underline;
}
.pt-otp-admin-login a:focus-visible {
	outline: none;
	box-shadow: var(--focus-ring);
	border-radius: var(--r-2xs);
}

.pt-otp-field-error__admin-link {
	display: inline-block;
	margin-top: var(--sp-2);
	color: var(--c-primary-text);
	font-weight: var(--fw-semibold);
	text-decoration: underline;
}
.pt-otp-field-error__admin-link:hover {
	color: var(--c-primary);
}

/* --- Small screens ---------------------------------------------------------- */

@media (max-width: 480px) {
	body.login {
		padding: var(--sp-5);
		padding-top: max(var(--sp-5), env(safe-area-inset-top, 0px));
	}
	#login {
		padding: var(--sp-6) var(--sp-5) var(--sp-5);
	}
	.login .ne2fa-code-input {
		letter-spacing: 0.35em !important;
	}
}
