/**
 * DKM Account.
 *
 * A header control and the panel under it. The panel is anchored to the button
 * on a desktop, where there is room beside it, and becomes a sheet across the
 * bottom of a phone, where there is not - a 320px dropdown hanging off the
 * right edge of a 360px screen is nobody's idea of a sign-in form.
 */

.wcg-acc {
	--wcg-acc-icon: var(--text-primary);
	--wcg-acc-text: var(--text-primary);
	--wcg-acc-muted: var(--text-tertiary);
	--wcg-acc-border: var(--border-subtle);
	/* A field's edge is what shows where to type. Ink 200 (1.2:1) left the
	   sign-in fields all but invisible; Ink 500 (5.3:1) was stark. DS v3.5:
	   an Ink 400 edge round an Ink 50 fill, Ink 500 on hover. */
	--wcg-acc-field-border: var(--input-border);
	/* Focus is the interactive blue, as everywhere in the system. The lime
	   ring it replaced was 1.3:1 against the white panel. */
	--wcg-acc-focus: var(--border-focus);
	--wcg-acc-panel-bg: var(--bg-surface);
	/* Not var(--wcg-accent): that is the gallery's accent, and the
	   settings screen writes every chosen colour onto every one of this
	   plugin's roots - so chaining through it made the gallery's colour
	   the account panel's colour too. */
	--wcg-acc-button-bg: var(--button-primary-bg);
	--wcg-acc-button-hover-bg: var(--button-primary-hover-bg);
	--wcg-acc-button-text: var(--button-primary-text);
	--wcg-acc-danger: var(--text-danger);
	--wcg-acc-height: var(--control-md);

	position: relative;
	display: inline-block;
	margin: 0;
	padding: 0;
}

.wcg-acc--size-sm {
	--wcg-acc-height: var(--control-sm);
}

.wcg-acc--size-md {
	--wcg-acc-height: var(--control-md);
}

.wcg-acc--size-lg {
	--wcg-acc-height: var(--control-lg);
}

/* --------------------------------------------------------------- trigger */

.wcg-acc .wcg-acc__trigger.wcg-acc__trigger {
	display: inline-flex;
	align-items: center;
	box-sizing: border-box;
	gap: 8px;
	min-height: var(--wcg-acc-height);
	margin: 0;
	padding: 0 10px;
	border: 0;
	/* DS v3.4: about a person ("Tere, Joonas"), so a pill - Atlassian's
	   radius.full is for people and user-related UI. */
	border-radius: var(--radius-full);
	background: transparent;
	color: var(--wcg-acc-text);
	font: inherit;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	cursor: pointer;
	transition: var(--motion-control);
}

.wcg-acc .wcg-acc__trigger.wcg-acc__trigger:hover,
.wcg-acc .wcg-acc__trigger.wcg-acc__trigger:focus-visible {
	background: var(--button-tertiary-hover-bg, var(--bg-subtle));
	color: var(--wcg-acc-text);
}

.wcg-acc .wcg-acc__trigger.wcg-acc__trigger:focus {
	outline: none;
}

.wcg-acc .wcg-acc__trigger.wcg-acc__trigger:focus-visible {
	outline: 2px solid var(--wcg-acc-focus);
	outline-offset: 2px;
}

.wcg-acc__icon {
	width: 24px;
	height: 24px;
	flex: none;
	color: var(--wcg-acc-icon);
}

.wcg-acc__label {
	white-space: nowrap;
}

/* DS v3.4.2: the account and the cart are one pair of header controls - a
   tertiary button each: no fill at rest, an Ink 100 pill on hover and focus
   (and, for the account, while its panel is open). One shape, one behaviour.
   Below 768px the mobile choice (tile, icon, ...) still decides. */
@media (min-width: 768px) {
	.wcg-acc .wcg-acc__trigger.wcg-acc__trigger:hover,
	.wcg-acc .wcg-acc__trigger.wcg-acc__trigger:focus-visible,
	.wcg-acc .wcg-acc__trigger.wcg-acc__trigger[aria-expanded="true"] {
		background: var(--button-tertiary-hover-bg, var(--bg-subtle));
		color: var(--button-tertiary-hover-text, var(--wcg-acc-text));
	}

	.wcg-acc .wcg-acc__trigger.wcg-acc__trigger:active {
		background: var(--bg-press);
	}
}

/* ------------------------------------------------------------ icon alone

   The words go; the trigger keeps its aria-label, so it is still named. A
   button with nothing but an icon in it is square, its box the control's
   height - a 44px target stays a 44px target on a phone. */

.wcg-acc--show-icon .wcg-acc__label {
	display: none;
}

.wcg-acc--show-icon .wcg-acc__trigger.wcg-acc__trigger {
	gap: 0;
	width: var(--wcg-acc-height);
	padding: 0;
	justify-content: center;
}

@media (max-width: 767px) {
	.wcg-acc--m-icon .wcg-acc__label {
		display: none;
	}

	.wcg-acc--m-icon .wcg-acc__trigger.wcg-acc__trigger {
		gap: 0;
		width: var(--wcg-acc-height);
		padding: 0;
		justify-content: center;
	}

	/* Words on a phone even when the desktop drops them. */
	.wcg-acc--show-icon.wcg-acc--m-inherit .wcg-acc__label {
		display: revert;
	}

	.wcg-acc--show-icon.wcg-acc--m-inherit .wcg-acc__trigger.wcg-acc__trigger {
		gap: 8px;
		width: auto;
		padding: 0 10px;
	}
}

@media (max-width: 767px) {
	/* Icon on a grey tile: the icon alone in a square the control's height,
	   drawn as an 8px Ink 100 tile so it reads as a button rather than a
	   glyph. Hover and focus go one step darker, to Ink 200. */
	.wcg-acc--m-tile .wcg-acc__label {
		display: none;
	}

	.wcg-acc--m-tile .wcg-acc__trigger.wcg-acc__trigger {
		gap: 0;
		width: var(--wcg-acc-height);
		padding: 0;
		justify-content: center;
		/* 8px, not the 4px button radius: kept by the shop's choice (1.48.0). */
		border-radius: var(--radius-md);
		background: var(--button-secondary-bg);
	}

	.wcg-acc--m-tile .wcg-acc__trigger.wcg-acc__trigger:hover,
	.wcg-acc--m-tile .wcg-acc__trigger.wcg-acc__trigger:focus-visible,
	.wcg-acc--m-tile .wcg-acc__trigger.wcg-acc__trigger[aria-expanded="true"] {
		background: var(--button-secondary-hover-bg);
	}
}

/* ----------------------------------------------------------------- panel */

.wcg-acc__panel {
	position: absolute;
	top: calc(100% + 8px);
	right: 0;
	z-index: 99999;
	box-sizing: border-box;
	width: 320px;
	max-width: calc(100vw - 32px);
	padding: 20px;
	border: var(--border-hairline) solid var(--wcg-acc-border);
	border-radius: var(--modal-radius);
	background: var(--wcg-acc-panel-bg);
	box-shadow: var(--shadow-lg);
	color: var(--wcg-acc-text);
	text-align: left;
	opacity: 0;
	transform: translateY(-6px);
	transition: opacity 0.18s ease, transform 0.18s ease;
}

.wcg-acc__panel[hidden] {
	display: none;
}

.wcg-acc__panel.is-open {
	opacity: 1;
	transform: translateY(0);
}

/* Flipped by the script when hanging off the right of the button would take
   the panel off the left of the screen. */
.wcg-acc__panel.is-left {
	right: auto;
	left: 0;
}

/* The preview on the settings screen, which is not going anywhere. */
.wcg-acc__panel--static {
	position: static;
	width: 320px;
	opacity: 1;
	transform: none;
}

.wcg-acc .wcg-acc__close.wcg-acc__close {
	position: absolute;
	top: 10px;
	right: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--control-sm);
	height: var(--control-sm);
	padding: 0;
	border: 0;
	border-radius: var(--button-radius);
	background: var(--button-tertiary-bg);
	color: var(--wcg-acc-muted);
	cursor: pointer;
}

.wcg-acc .wcg-acc__close.wcg-acc__close:hover {
	background: var(--button-tertiary-hover-bg);
	color: var(--wcg-acc-text);
}

.wcg-acc__close .wcg-acc__icon {
	width: 18px;
	height: 18px;
	color: inherit;
}

/* Themes style their headings hard - uppercase, letter-spaced, coloured,
   sized off a scale that has nothing to do with a 320px panel - and these are
   headings inside somebody else's header. Everything that would carry over is
   said here. */
.wcg-acc .wcg-acc__title,
.wcg-acc .wcg-acc__subtitle,
.wcg-acc .wcg-acc__greeting {
	color: var(--wcg-acc-text);
	font-family: inherit;
	text-transform: none;
	letter-spacing: normal;
}

.wcg-acc .wcg-acc__title {
	margin: 0 0 14px;
	font-size: 1.0625rem;
	font-weight: 700;
	line-height: 1.2;
}

.wcg-acc .wcg-acc__subtitle {
	margin: 0 0 6px;
	font-size: 0.9375rem;
	font-weight: 700;
	line-height: 1.3;
}

.wcg-acc__text {
	margin: 0 0 12px;
	color: var(--wcg-acc-muted);
	font-size: 0.875rem;
	line-height: 1.45;
}

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

.wcg-acc__field {
	display: block;
	margin: 0 0 12px;
}

.wcg-acc__label-text {
	display: block;
	margin-bottom: 4px;
	color: var(--wcg-acc-text);
	font-size: 0.8125rem;
	font-weight: 600;
}

/* Doubled class: WordPress themes reach form fields as `input[type="text"]`,
   which outranks a single class of ours. */
.wcg-acc .wcg-acc__input.wcg-acc__input {
	display: block;
	box-sizing: border-box;
	width: 100%;
	min-height: var(--control-md);
	margin: 0;
	padding: 8px 12px;
	border: var(--border-hairline) solid var(--wcg-acc-field-border);
	border-radius: var(--input-radius);
	background: var(--input-bg);
	color: var(--input-text);
	font: inherit;
	font-size: 16px; /* Below 16px a phone zooms the page in on focus. */
	line-height: 1.3;
}

.wcg-acc .wcg-acc__input.wcg-acc__input::placeholder {
	color: var(--wcg-acc-muted);
	opacity: 1;
}

.wcg-acc .wcg-acc__input.wcg-acc__input:focus {
	background-color: var(--input-focus-bg);
	border-color: var(--wcg-acc-focus);
	outline: 2px solid var(--wcg-acc-focus);
	outline-offset: 1px;
}

/* The preview has no fields to fill, only the shape of them. */
span.wcg-acc__input {
	display: block;
	height: var(--control-md);
	background: var(--bg-subtle);
}

.wcg-acc__remember {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0 0 14px;
	color: var(--wcg-acc-text);
	font-size: 0.875rem;
	accent-color: var(--wcg-acc-focus);
}

.wcg-acc .wcg-acc__button.wcg-acc__button {
	display: block;
	box-sizing: border-box;
	width: 100%;
	min-height: var(--wcg-acc-height);
	padding: 0 20px;
	border: 0;
	border-radius: var(--button-radius);
	background: var(--wcg-acc-button-bg);
	color: var(--wcg-acc-button-text);
	font: inherit;
	font-size: 15px;
	font-weight: 700;
	line-height: var(--wcg-acc-height);
	text-align: center;
	text-decoration: none;
	cursor: pointer;
}

.wcg-acc .wcg-acc__button.wcg-acc__button:hover:not(:disabled) {
	background: var(--wcg-acc-button-hover-bg);
	color: var(--wcg-acc-button-text);
}

.wcg-acc .wcg-acc__button.wcg-acc__button:focus-visible {
	outline: 2px solid var(--wcg-acc-focus);
	outline-offset: 2px;
}

/* Signing out is not the panel's main step: a secondary button. */
.wcg-acc .wcg-acc__button--ghost.wcg-acc__button--ghost {
	background: var(--button-secondary-bg);
	color: var(--button-secondary-text);
	font-weight: 600;
}

.wcg-acc .wcg-acc__button--ghost.wcg-acc__button--ghost:hover:not(:disabled) {
	background: var(--button-secondary-hover-bg);
	color: var(--button-secondary-text);
}

.wcg-acc__form.is-busy {
	opacity: 0.6;
	pointer-events: none;
}

.wcg-acc__error {
	margin: 0 0 12px;
	padding: 8px 10px;
	border-radius: var(--radius-sm);
	background: var(--bg-danger);
	color: var(--wcg-acc-danger);
	font-size: 0.875rem;
}

.wcg-acc__error[hidden] {
	display: none;
}

.wcg-acc .wcg-acc__lost {
	display: inline-block;
	margin-top: 12px;
	/* A link, so the link blue - which the guidelines keep at 14px or more. */
	color: var(--wcg-acc-focus);
	font-size: 0.875rem;
}

.wcg-acc__register {
	margin-top: 20px;
	padding-top: 18px;
	border-top: 1px solid var(--wcg-acc-border);
}

/* ------------------------------------------------------------ signed in */

.wcg-acc__head {
	margin: 0 0 12px;
	padding-right: 32px;
}

.wcg-acc__greeting {
	margin: 0;
	font-size: 1rem;
	font-weight: 700;
}

.wcg-acc__email {
	margin: 2px 0 0;
	color: var(--wcg-acc-muted);
	font-size: 0.8125rem;
	overflow-wrap: anywhere;
}

.wcg-acc__menu {
	margin: 0;
	padding: 0;
	list-style: none;
	border-top: 1px solid var(--wcg-acc-border);
}

.wcg-acc__menu li + li {
	border-top: 1px solid var(--wcg-acc-border);
}

.wcg-acc .wcg-acc__menu a {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 4px;
	color: var(--wcg-acc-text);
	font-size: 0.9375rem;
	text-decoration: none;
}

.wcg-acc .wcg-acc__menu a:hover,
.wcg-acc .wcg-acc__menu a:focus-visible {
	color: var(--wcg-link-hover, var(--text-link-hover));
	text-decoration: none;
}

/* The wallet's balance, at the end of its row: the amount is the thing being
   looked for, so it is set like one - and never underlined with the link. */
.wcg-acc .wcg-acc__menu-meta {
	flex: none;
	color: var(--wcg-acc-text);
	font-weight: 700;
	white-space: nowrap;
}

.wcg-acc .wcg-acc__menu a:hover .wcg-acc__menu-meta {
	text-decoration: none;
	display: inline-block;
}

/* A dropdown hanging off the right edge of a phone is not a sign-in form, and
   a sheet across the bottom left it floating halfway up a tall screen. Below
   the phone breakpoint it is a screen of its own: a title bar with the close
   button, the form under it, the page behind it still. */
@media (max-width: 767px) {
	.wcg-acc__panel:not(.wcg-acc__panel--static) {
		position: fixed;
		inset: 0;
		z-index: 100001;
		width: auto;
		max-width: none;
		height: 100%;
		max-height: none;
		overflow-y: auto;
		overscroll-behavior: contain;
		padding: 0 20px calc(24px + env(safe-area-inset-bottom, 0px));
		border: 0;
		border-radius: 0;
		box-shadow: none;
		transform: translateY(16px);
	}

	/* No transform once it is open, so the close button can be fixed to the
	   screen rather than scroll away with the form. */
	.wcg-acc__panel.is-open:not(.wcg-acc__panel--static) {
		transform: none;
	}

	/* The first heading - "Sign in", or the greeting - is the title bar. */
	.wcg-acc__panel:not(.wcg-acc__panel--static) > [data-wcg-acc-form="login"] > .wcg-acc__title,
	.wcg-acc__panel:not(.wcg-acc__panel--static) > .wcg-acc__head {
		position: sticky;
		top: 0;
		z-index: 1;
		margin: 0 -20px 20px;
		padding: calc(18px + env(safe-area-inset-top, 0px)) 64px 18px 20px;
		border-bottom: 1px solid var(--wcg-acc-border);
		background: var(--wcg-acc-panel-bg);
	}

	.wcg-acc__panel:not(.wcg-acc__panel--static) .wcg-acc__close.wcg-acc__close {
		position: fixed;
		top: calc(12px + env(safe-area-inset-top, 0px));
		right: 12px;
		z-index: 2;
		width: var(--control-md);
		height: var(--control-md);
	}

	/* The page behind does not scroll while the screen is up. */
	html:has(.wcg-acc__panel.is-open:not(.wcg-acc__panel--static)) {
		overflow: hidden;
	}
}

@media (prefers-reduced-motion: reduce) {
	.wcg-acc__panel {
		transition: none;
	}
}

/* DS v3.5: a field's edge goes one step darker under the pointer. */
.wcg-acc .wcg-acc__input.wcg-acc__input:hover:not(:focus) {
	border-color: var(--input-hover-border);
}
