/* =====================================================================
 * Faragiri - Theme Switcher UI (trigger button + popover panel)
 * Enqueued by mu-plugin faragiri-theme-switcher.php.
 *
 * FLAT / UNIFIED (2026-07-27): the trigger is now literally the same
 * control as every other header icon chip - same 40px box, same 10px
 * radius, same hairline, same hover fill (the --fgh-* primitives come
 * from header.css §0, with fallbacks here so this file still stands on
 * its own). The panel follows: solid surface, hairline edges, one
 * radius scale, no blur, no gradients, no lift transforms.
 *
 * Palette tokens (--fg-*) come from theme-switcher-core.css, inlined in
 * <head>, so all 8 colour modes repaint with no duplication here.
 * ===================================================================== */

/* ---- trigger button (lives in the header icon row) ------------------ */
.fgts-trigger {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--fgh-ctl, 40px);
	height: var(--fgh-ctl, 40px);
	margin: 0;
	padding: 0;
	/* same resting skin as the search field and the other header chips
	 * (header.css §7) - hairline + faint fill, never a bare icon */
	border: 1px solid var(--fgh-line, rgba(255, 255, 255, .13));
	border-radius: var(--fgh-r-ctl, 10px);
	background: var(--fgh-fill, rgba(255, 255, 255, .06));
	color: var(--fg-header-ink, #fff);
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background-color .14s ease, border-color .14s ease, color .14s ease;
	-webkit-tap-highlight-color: transparent;
}

.fgts-trigger:hover,
.fgts-trigger[aria-expanded="true"] {
	background: var(--fgh-fill-hover, rgba(255, 255, 255, .11));
	border-color: color-mix(in srgb, var(--fg-header-ink, #fff) 24%, transparent);
}

.fgts-trigger:focus-visible {
	outline: 2px solid var(--fg-accent, #24baef);
	outline-offset: 2px;
}

/* The signature orb mark (fgts_mark_svg() in the mu-plugin). It carries the
 * palette itself - 6 solid scheme dots around a sun/moon medallion - so the
 * chip needs no extra colour cue of its own. Flat: the SVG ships solid
 * fills, and the drop-shadow filters + orbit/twinkle animations the old
 * build ran on .fgts-orb__ring / __rays / __dot / __sun / __moon are gone.
 * Nothing here may reintroduce a filter or an animation. */
.fgts-orb {
	display: block;
	width: 24px;
	height: 24px;
	overflow: visible;
}

/* ---- backdrop ------------------------------------------------------- */
.fgts-backdrop {
	position: fixed;
	inset: 0;
	z-index: 100000;
	background: rgba(4, 6, 12, .55);
	opacity: 0;
	visibility: hidden;
	transition: opacity .18s ease, visibility .18s;
}

.fgts-open .fgts-backdrop {
	opacity: 1;
	visibility: visible;
}

/* ---- panel ---------------------------------------------------------- */
.fgts-panel {
	position: fixed;
	z-index: 100001;
	inset-block-start: 50%;
	inset-inline-end: 24px;
	inset-inline-start: auto;
	transform: translateY(-50%);
	width: min(370px, calc(100vw - 32px));
	max-height: min(86vh, 720px);
	overflow: auto;
	direction: rtl;
	padding: 18px;
	border-radius: var(--fgh-r-panel, 14px);
	border: 1px solid var(--fg-border, rgba(255, 255, 255, .14));
	background: var(--fg-surface, #131722);
	box-shadow: 0 16px 40px -24px rgba(0, 0, 0, .7);
	color: var(--fg-text, #eef1f7);
	opacity: 0;
	visibility: hidden;
	transition: opacity .18s ease, visibility .18s;
	font-family: inherit;
}

.fgts-open .fgts-panel {
	opacity: 1;
	visibility: visible;
}

/* header of the panel */
.fgts-panel__head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }

.fgts-panel__icon {
	display: inline-flex; align-items: center; justify-content: center;
	width: 36px; height: 36px; flex: none;
	border: 1px solid var(--fg-border, rgba(255, 255, 255, .12));
	border-radius: var(--fgh-r-ctl, 10px);
	background: transparent;
	color: var(--fg-text, #fff);
}
.fgts-panel__icon .fgts-orb { width: 22px; height: 22px; }

.fgts-panel__title { font-size: 15px; font-weight: 700; margin: 0; line-height: 1.3; }
.fgts-panel__sub { font-size: 12px; margin: 0; color: var(--fg-text-2, #9aa3b8); }

.fgts-panel__close {
	margin-inline-start: auto; flex: none;
	width: 32px; height: 32px;
	/* !important: the theme's generic button rule ships "padding:10px 20px",
	 * which blew the box out to 42x32 AND squeezed the X svg (a flex item
	 * with no intrinsic size → automatic minimum size 0) to a USED width of
	 * 0 - the button rendered as an empty rounded rectangle even though
	 * "width:16px" computed correctly. Every icon-in-button in this theme
	 * needs the explicit reset (cf. .fgh-drawer__close in header.css). */
	padding: 0 !important;
	border-radius: var(--fgh-r-ctl, 10px);
	display: inline-flex; align-items: center; justify-content: center;
	background: transparent; color: var(--fg-text-2, #9aa3b8);
	border: 1px solid var(--fg-border, rgba(255, 255, 255, .12));
	cursor: pointer;
	transition: color .14s ease, background-color .14s ease;
}
.fgts-panel__close:hover {
	color: var(--fg-text, #fff);
	background: color-mix(in srgb, var(--fg-text, #fff) 8%, transparent);
}
.fgts-panel__close svg { width: 16px; height: 16px; }

/* quick light / dark segmented toggle */
.fgts-base {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 4px;
	margin: 16px 0;
	padding: 4px;
	border-radius: var(--fgh-r-ctl, 10px);
	background: transparent;
	border: 1px solid var(--fg-border, rgba(255, 255, 255, .1));
}
.fgts-base__btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px;
	padding: 9px; border: 0; border-radius: 7px; cursor: pointer;
	font: inherit; font-size: 13.5px; font-weight: 600;
	background: transparent; color: var(--fg-text-2, #9aa3b8);
	transition: background-color .14s ease, color .14s ease;
}
.fgts-base__btn svg { width: 17px; height: 17px; }
.fgts-base__btn:hover { color: var(--fg-text, #fff); }
.fgts-base__btn[aria-pressed="true"] {
	background: var(--fg-accent, #24baef);
	color: var(--fg-accent-ink, #fff);
}

.fgts-label {
	font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
	text-transform: uppercase; color: var(--fg-text-2, #9aa3b8);
	margin: 0 2px 10px;
}

/* swatch grid */
.fgts-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 8px;
}
.fgts-swatch {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 7px;
	padding: 9px 6px 8px;
	border: 1px solid var(--fg-border, rgba(255, 255, 255, .1));
	border-radius: var(--fgh-r-ctl, 10px);
	background: transparent;
	cursor: pointer;
	font: inherit;
	color: var(--fg-text, #eef1f7);
	transition: border-color .14s ease, background-color .14s ease;
}
.fgts-swatch:hover {
	border-color: var(--sw-accent);
	background: color-mix(in srgb, var(--sw-accent) 10%, transparent);
}
.fgts-swatch:focus-visible { outline: 2px solid var(--sw-accent); outline-offset: 2px; }

.fgts-swatch__chip {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 11;
	border-radius: 6px;
	overflow: hidden;
	background: var(--sw-bg);
	border: 1px solid var(--fg-border, rgba(255, 255, 255, .08));
}
.fgts-swatch__chip::before { /* accent stroke */
	content: "";
	position: absolute;
	inset-block-start: 26%;
	inset-inline: 16%;
	height: 13%;
	border-radius: 2px;
	background: var(--sw-accent);
}
.fgts-swatch__chip::after { /* secondary bar */
	content: "";
	position: absolute;
	inset-block-end: 22%;
	inset-inline: 16%;
	height: 10%;
	border-radius: 2px;
	background: var(--sw-surface);
}
.fgts-swatch__name { font-size: 12px; font-weight: 600; line-height: 1.2; }

.fgts-swatch__tick {
	position: absolute;
	inset-block-start: 5px;
	inset-inline-start: 5px;
	width: 18px; height: 18px;
	display: flex; align-items: center; justify-content: center;
	border-radius: 5px;
	background: var(--sw-accent);
	color: #fff;
	opacity: 0;
	transition: opacity .14s ease;
}
.fgts-swatch__tick svg { width: 12px; height: 12px; }

.fgts-swatch[aria-checked="true"] {
	border-color: var(--sw-accent);
	background: color-mix(in srgb, var(--sw-accent) 14%, transparent);
}
.fgts-swatch[aria-checked="true"] .fgts-swatch__tick { opacity: 1; }

.fgts-foot {
	margin: 16px 2px 0;
	font-size: 11.5px; line-height: 1.7;
	color: var(--fg-text-2, #9aa3b8);
	text-align: center;
}

/* ---- mobile: dock as a bottom sheet -------------------------------- */
@media (max-width: 560px) {
	.fgts-panel {
		inset-block-start: auto;
		inset-block-end: 0;
		inset-inline: 0;
		width: 100%;
		max-height: 88vh;
		transform: translateY(100%);
		border-radius: var(--fgh-r-panel, 14px) var(--fgh-r-panel, 14px) 0 0;
		padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
		transition: opacity .18s ease, transform .22s ease, visibility .22s;
	}
	.fgts-open .fgts-panel { transform: translateY(0); }
	.fgts-swatch__name { font-size: 11px; }
}
@media (max-width: 360px) {
	.fgts-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---- reduced motion ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	.fgts-trigger, .fgts-panel, .fgts-backdrop, .fgts-swatch,
	.fgts-base__btn, .fgts-panel__close, .fgts-swatch__tick {
		transition: none !important;
	}
}

/* graceful fallback if color-mix is unsupported (very old browsers) */
@supports not (background: color-mix(in srgb, red 10%, transparent)) {
	.fgts-panel { background: var(--fg-surface, #131722); }
	.fgts-swatch:hover { background: rgba(255, 255, 255, .06); }
}
