/* =========================================================================
 * Floating support chooser — MARK GALLERY
 *
 * A card with the two channels rises out of the shop-logo button, which beats
 * like a heart while closed and cycles logo → WhatsApp → Telegram.
 *
 * CONTRACTS KEPT — checked before the rewrite, do not "clean up" these:
 *   1. `a.chat-fab{display:none!important}` hides the legacy anchor that
 *      brand-store/footer.php still prints.
 *   2. `.mgt-support` must stay the position:fixed wrapper that owns `bottom`
 *      and `z-index`. buybar.css lifts it with
 *      `html.mg-buybar-on .mgt-support{bottom:84px}` above the mobile buy bar,
 *      and child.css drops it with `body.lock .mgt-support{z-index:40}` under
 *      the nav drawer. The chips are absolute INSIDE it, never fixed.
 *   3. `.chat-fab .chat-letter` is required by includes/support-logo.php (which
 *      inlines the logo size and the `--mgt-support-mark` property) and by
 *      assets/support-shimmer.css (which masks the logo reflection with it).
 *      Both files are untouched, so both hooks stay.
 *   4. `.chat-letter img` keeps 40×28 desktop / 34×24 phone, and the option
 *      hooks (`--disabled`, `__icon`, `small`) stay, so the markup contract
 *      with support-chooser.php is unchanged in kind.
 *
 * WHAT CHANGED: the titled white card became a card of two rows with a badge and
 * a tail; the open state's stray white outline became a gold close glyph;
 * `display:none` became `visibility` so that closing can animate at all; focus
 * rings were ink-on-black, i.e. invisible, and are gold now.
 * ========================================================================= */

/* Hide the legacy per-theme floating anchor (see contract 1). */
a.chat-fab{display:none!important}

/* -------------------------------------------------------------------------
 * Wrapper — the fixed box everything hangs off (see contract 2)
 * ---------------------------------------------------------------------- */
.mgt-support{
	--mg-ink:#0a0a0a;
	--mg-bg:#fff;
	--mg-muted:#595959;
	--mg-line:#e9e9e9;
	--mg-surface:#fafafa;
	--mg-gold:#c69630;
	--mg-ease:cubic-bezier(.16,1,.3,1);
	/* The button's own edge length, in one place: the toggle is sized from it and
	 * the chips are anchored above it. This is deliberately a length and not
	 * `calc(100% + 12px)`: measured, the percentage resolved against the wrapper's
	 * auto height as 0 while the panel was hidden, so the chips sat 50px lower
	 * when closed and jumped that distance the moment `[open]` flipped. */
	--mg-size:56px;
	position:fixed;
	bottom:calc(24px + env(safe-area-inset-bottom,0px));
	z-index:90;
	font-family:var(--mg-font,Estedad,Tahoma,sans-serif);
	color:var(--mg-ink);
	text-align:right;
}

.mgt-support--right{right:24px}
.mgt-support--left{left:24px}
.mgt-support,.mgt-support *{box-sizing:border-box}

/* -------------------------------------------------------------------------
 * Pulse — a heartbeat, not a metronome
 *
 * Two dark rings on the wrapper's own pseudo-elements. The second one is offset
 * by 0.35s against a 3.2s cycle, so the pair reads as one double beat followed
 * by a rest — the same shape as a pulse — instead of the steady tick-tock the
 * old half-cycle offset produced.
 *
 * `ease-out` rather than the project's `--mg-ease`: that curve reaches its end
 * value almost immediately, which turned the fade-out into a flash when it was
 * measured on the previous version.
 *
 * The opacity ramp still starts at 0 on purpose — a ring that begins visible
 * pops at the button's edge.
 * ---------------------------------------------------------------------- */
.mgt-support::before,
.mgt-support::after{
	content:"";
	position:absolute;
	inset:0;
	z-index:0;
	pointer-events:none;
	border:2px solid var(--mg-ink);
	border-radius:50%;
	opacity:0;
	animation:mgt-support-wave 2.4s ease-out infinite;
}

.mgt-support::after{animation-delay:.35s}

/* The wave is a "closed" invitation; an open panel already says enough. */
.mgt-support[open]::before,
.mgt-support[open]::after{animation:none;opacity:0}

/* Short visible life (0.7s of the 2.8s cycle). At the previous 1.1s the two
 * rings overlapped by 700ms and read as one thick wave instead of two beats. */
@keyframes mgt-support-wave{
	0%{transform:scale(1);opacity:0}
	4%{opacity:.55}
	25%{opacity:0}
	45%{transform:scale(1.55);opacity:0}
	100%{transform:scale(1.55);opacity:0}
}

/* -------------------------------------------------------------------------
 * The button (summary)
 * ---------------------------------------------------------------------- */
.mgt-support>.mgt-support__toggle{
	position:relative;
	z-index:1;
	inset:auto;
	display:flex;
	align-items:center;
	justify-content:center;
	width:var(--mg-size);
	height:var(--mg-size);
	padding:0;
	margin:0;
	background:var(--mg-ink);
	color:var(--mg-bg);
	border:1px solid var(--mg-ink);
	border-radius:50%;
	cursor:pointer;
	list-style:none;
	/* Depth only. The gold hairline that used to sit on the edge is gone: on a
	 * round button it read as a second ring around the logo. */
	box-shadow:0 10px 30px -8px rgba(10,10,10,.45);
}

.mgt-support>.mgt-support__toggle::-webkit-details-marker{display:none}
.mgt-support>.mgt-support__toggle::marker{content:''}
.mgt-support>.mgt-support__toggle:focus-visible{outline:2px solid var(--mg-gold);outline-offset:4px}

/* The shop logo.
 *
 * The parent theme fades the logo out on hover (`.chat-fab:hover .chat-letter`)
 * because it used to swap in a paper-plane glyph. That swap no longer exists, so
 * the hover state is neutralised first and the open state takes over below.
 * Width and height deliberately stay with support-logo.php. */
.mgt-support .mgt-support__toggle .chat-letter,
.mgt-support .mgt-support__toggle:hover .chat-letter,
.mgt-support .mgt-support__toggle:focus-visible .chat-letter{
	opacity:1;
	transform:none;
	transition:opacity .2s ease,transform .3s var(--mg-ease);
}

.mgt-support .chat-letter img{display:block;width:40px;height:28px;object-fit:contain}

/* While closed the slot cycles: shop logo (4s) → WhatsApp (1.2s) → Telegram
 * (1.2s), on a 6.4s loop. The slots are deliberately unequal, so each layer
 * carries its own keyframes instead of sharing one with a delay — a shared
 * animation can only divide the loop into equal thirds.
 *
 * Each icon grows out of the centre and shrinks back into it, on a ~160ms fade
 * at each end. Two earlier versions were measured and dropped: a horizontal row
 * of cross-fades left ~0.3s where the button showed nothing, and a vertical
 * slide read as mechanical. Scaling from the middle keeps the glyph inside the
 * circle at every frame and needs no clipping.
 *
 * Animations outrank normal declarations, so the neutraliser above cannot fight
 * this, and the open state below cancels all three with `animation:none`. */
.mgt-support .mgt-support__toggle .chat-letter,
.mgt-support .mgt-support__spin{
	animation-duration:6.4s;
	animation-timing-function:ease-out;
	animation-iteration-count:infinite;
}

.mgt-support .mgt-support__toggle .chat-letter{animation-name:mgt-support-roll-a}
.mgt-support .mgt-support__spin--wa{animation-name:mgt-support-roll-b}
.mgt-support .mgt-support__spin--tg{animation-name:mgt-support-roll-c}

.mgt-support .mgt-support__spin{
	position:absolute;
	inset:0;
	display:flex;
	align-items:center;
	justify-content:center;
	color:var(--mg-bg);
	opacity:0;
	pointer-events:none;
}

.mgt-support .mgt-support__spin svg{width:24px;height:24px}

/* Each handoff overlaps by ~half a fade (~48ms) so the sum never drops to zero:
 * the outgoing glyph finishes shrinking away while the next one is already on
 * its way in. Sampling the previous version at 100ms found instants where all
 * three layers were at opacity 0, which is the "blink" this closes. The one
 * place it cannot overlap is the loop seam (last icon → logo), so both ends of
 * that seam fade in ~64ms. */
@keyframes mgt-support-roll-a{
	0%{opacity:0;transform:scale(.55)}
	1%{opacity:1;transform:scale(1)}
	60.5%{opacity:1;transform:scale(1)}
	62%{opacity:0;transform:scale(.55)}
	100%{opacity:0;transform:scale(.55)}
}

@keyframes mgt-support-roll-b{
	0%{opacity:0;transform:scale(.55)}
	61%{opacity:0;transform:scale(.55)}
	62.5%{opacity:1;transform:scale(1)}
	78.5%{opacity:1;transform:scale(1)}
	80%{opacity:0;transform:scale(.55)}
	100%{opacity:0;transform:scale(.55)}
}

@keyframes mgt-support-roll-c{
	0%{opacity:0;transform:scale(.55)}
	79.5%{opacity:0;transform:scale(.55)}
	81%{opacity:1;transform:scale(1)}
	99%{opacity:1;transform:scale(1)}
	100%{opacity:0;transform:scale(.55)}
}

.mgt-support[open] .mgt-support__toggle .chat-letter{
	animation:none;
	opacity:0;
	transform:scale(.68) rotate(-10deg);
}

.mgt-support[open] .mgt-support__spin{
	animation:none;
	opacity:0;
	transform:scale(.7);
}

/* The close glyph that replaces the logo while the chips are out. */
.mgt-support .mgt-support__close{
	position:absolute;
	inset:0;
	display:flex;
	align-items:center;
	justify-content:center;
	color:var(--mg-gold);
	opacity:0;
	transform:rotate(-90deg) scale(.7);
	pointer-events:none;
	transition:opacity .18s ease,transform .26s var(--mg-ease);
}

.mgt-support[open] .mgt-support__close{
	opacity:1;
	transform:none;
	transition-delay:.08s;
}

/* -------------------------------------------------------------------------
 * The panel — one card with both rows, and a tail onto the button
 *
 * `visibility` rather than `display:none`: a display switch cannot be
 * transitioned, so the panel used to appear and vanish instantly, and
 * `visibility:hidden` also keeps the hidden links out of the tab order — which
 * `display:none` used to guarantee.
 * ---------------------------------------------------------------------- */
.mgt-support>.mgt-support__options{
	position:absolute;
	z-index:2;
	bottom:calc(var(--mg-size) + 10px);
	right:0;
	left:auto;
	width:248px;
	max-width:calc(100vw - 32px);
	padding:4px 0;
	margin:0;
	background:var(--mg-bg);
	border:1px solid var(--mg-line);
	border-radius:16px;
	/* Deliberately faint: the card should sit ON the page, not float over it. */
	box-shadow:0 16px 36px -26px rgba(10,10,10,.55),0 2px 8px rgba(10,10,10,.04);
	visibility:hidden;
	opacity:0;
	transform:translateY(8px) scale(.97);
	transform-origin:calc(100% - var(--mg-size) / 2) 100%;
	transition:opacity .16s ease-in,transform .16s ease-in,visibility 0s linear .16s;
}

/* The tail: a rotated square carrying the card's border on its two lower
 * faces, so it reads as part of the card and points at the button's centre.
 * Positioned with physical sides because the card itself is anchored with
 * physical `right`, and `inset-inline-end` would resolve to the far edge in RTL
 * — which put the tail under the wrong corner when this was measured. */
.mgt-support>.mgt-support__options::after{
	content:"";
	position:absolute;
	bottom:-6px;
	right:calc(var(--mg-size) / 2 - 6px);
	left:auto;
	width:12px;
	height:12px;
	background:var(--mg-bg);
	/* Physical sides on purpose: the 45° rotation below is physical too, so the
	 * two faces that end up pointing down are always right + bottom. */
	border-right:1px solid var(--mg-line);
	border-bottom:1px solid var(--mg-line);
	transform:rotate(45deg);
}

.mgt-support--left>.mgt-support__options::after{
	right:auto;
	left:calc(var(--mg-size) / 2 - 6px);
}

.mgt-support--left>.mgt-support__options{
	right:auto;
	left:0;
	transform-origin:calc(var(--mg-size) / 2) 100%;
}

.mgt-support[open]>.mgt-support__options{
	visibility:visible;
	opacity:1;
	transform:none;
	transition:opacity .22s var(--mg-ease),transform .22s var(--mg-ease),visibility 0s;
}

/* -------------------------------------------------------------------------
 * The rows
 * ---------------------------------------------------------------------- */
.mgt-support .mgt-support__option{
	display:flex;
	align-items:center;
	gap:12px;
	min-height:56px;
	padding:8px 16px;
	background:none;
	color:var(--mg-ink);
	border:0;
	border-radius:0;
	box-shadow:none;
	font-size:14px;
	line-height:1.6;
	text-decoration:none;
	transition:background-color .14s ease;
}

.mgt-support .mgt-support__option+.mgt-support__option{
	border-top:1px solid var(--mg-line);
}

/* The first and last rows are the card's own corners, so a hover tint has to
 * follow that curve rather than square it off. */
.mgt-support>.mgt-support__options>.mgt-support__option:first-child{border-radius:15px 15px 0 0}
.mgt-support>.mgt-support__options>.mgt-support__option:last-child{border-radius:0 0 15px 15px}

/* Icon at the inline-start, label (and its «به‌زودی» suffix) pushed to the far
 * edge — the two ends the reference shows. */
.mgt-support .mgt-support__option>span:not(.mgt-support__icon){
	margin-inline-start:auto;
}

.mgt-support .mgt-support__option:focus-visible{
	outline:2px solid var(--mg-gold);
	outline-offset:-3px;
}

/* The badge: the messenger mark reversed out of a black disc. */
.mgt-support .mgt-support__icon{
	display:flex;
	align-items:center;
	justify-content:center;
	flex:none;
	width:40px;
	height:40px;
	border-radius:50%;
	background:var(--mg-ink);
	color:var(--mg-bg);
}

.mgt-support .mgt-support__icon svg{width:22px;height:22px}

.mgt-support .mgt-support__option small{
	margin-inline-start:0;
	color:var(--mg-muted);
	font-size:10px;
	line-height:1.8;
}

.mgt-support .mgt-support__option--disabled{
	color:var(--mg-muted);
	cursor:default;
}

/* The badge stays black on a disabled row: it is the shop's mark, not a state
 * indicator. The muted label, the «به‌زودی» suffix, `aria-disabled` and the
 * missing hover are what say "not available yet". */

/* Hover affordances only where a real pointer exists. Opening still happens on
 * click/tap everywhere, so touch never depends on hover. */
@media (hover:hover) and (pointer:fine){
	/* A whole row is the target, so the tint spans it and the badge answers with
	 * the shop's gold. */
	.mgt-support a.mgt-support__option:hover{background:var(--mg-surface)}

	.mgt-support a.mgt-support__option:hover .mgt-support__icon{
		background:var(--mg-gold);
		color:var(--mg-bg);
	}

	/* Freeze the cycle the moment a pointer arrives: nothing should keep moving
	 * under the cursor the user is about to click. */
	.mgt-support:hover .mgt-support__toggle .chat-letter,
	.mgt-support:hover .mgt-support__spin{animation-play-state:paused}

	.mgt-support:hover::before,
	.mgt-support:hover::after{animation-play-state:paused}
}

/* The nav drawer covers the button, so there is nothing to animate underneath
 * it — one less running animation while the menu is open. */
body.lock .mgt-support .mgt-support__toggle .chat-letter,
body.lock .mgt-support .mgt-support__spin{animation-play-state:paused}

/* -------------------------------------------------------------------------
 * Phones
 * ---------------------------------------------------------------------- */
@media(max-width:767px){
	.mgt-support{--mg-size:50px;bottom:calc(16px + env(safe-area-inset-bottom,0px))}
	.mgt-support--right{right:16px}
	.mgt-support--left{left:16px}
	.mgt-support .chat-letter img{width:34px;height:24px}
	/* A phone thumb gets a little more surface, not less: the rows stay 56px and
	 * the card narrows just enough to clear a 320px screen. */
	.mgt-support>.mgt-support__options{width:232px}
	.mgt-support .mgt-support__option{padding:8px 14px}
}

@media(prefers-reduced-motion:reduce){
	.mgt-support::before,
	.mgt-support::after{animation:none;opacity:0}
	.mgt-support .mgt-support__toggle,
	.mgt-support>.mgt-support__options,
	.mgt-support .chat-letter,
	.mgt-support .mgt-support__close{transition:none}
	.mgt-support .chat-letter::after{display:none;animation:none}
	/* No cycling either: the button holds the shop logo. */
	.mgt-support .mgt-support__toggle .chat-letter,
	.mgt-support .mgt-support__spin{animation:none}
	.mgt-support .mgt-support__spin{display:none}
	.mgt-support .mgt-support__toggle .chat-letter{opacity:1;transform:none}
}

@media print{.mgt-support{display:none!important}}

/* -------------------------------------------------------------------------
 * Clearance for the fixed toggle — unchanged.
 *
 * The toggle is fixed, so the end of the document can never be scrolled out
 * from under it. Reserving its footprint keeps the last product row, the cart
 * totals and the footer line reachable; `html` gets the same value so an
 * in-page anchor jump does not land behind it. buybar.css widens this to 150px
 * on product/cart pages.
 * ---------------------------------------------------------------------- */
@media(max-width:767px){
	body{padding-bottom:calc(82px + env(safe-area-inset-bottom,0px))}
	html{scroll-padding-bottom:calc(82px + env(safe-area-inset-bottom,0px))}
}
