/* ==========================================================================
   MSM Tools — floating help: the Help button and its panel
   Loaded on every page that shows the button. Colours come from the theme's
   tokens, with the same zero-specificity floor tools.css sets for any other
   theme, so dark mode follows the theme without rules of its own here.

   Layers, against the theme's fixed elements:
     70    language suggestion bar (the button is lifted above it instead)
     990   the button — under the menu scrim (998), so an open phone menu
           covers it
     999   navigation bar
     1100  the panel — over the navigation bar
     1200  phone menu drawer
     100000 the panel on a phone, where it covers the screen as a dialog
   Sides are logical (inset-inline-end), so on an Urdu page the button sits
   bottom-left and the panel opens from the left, as the menu drawer does.
   ========================================================================== */

:where(html) {
	--msm-brand-rgb: 13, 124, 109;
	--msm-brand: rgb(var(--msm-brand-rgb));
	--msm-brand-soft: rgba(var(--msm-brand-rgb), 0.08);
	--msm-brand-hover: #0b6357;
	--msm-on-brand: #ffffff;
	--msm-success: #007c42;
	--card-solid: #ffffff;
	--bg-surface-alt: #f5f4f1;
	--card-border: rgba(231, 229, 228, 0.9);
	--text-primary: #1c1917;
	--text-secondary: #57534e;
	--text-muted: #78716c;
	--input-bg: #ffffff;
	--radius-sm: 12px;
}

:where(body.dark) {
	--msm-brand-rgb: 45, 212, 191;
	--msm-brand-hover: #5eead4;
	--msm-on-brand: #0c0a09;
	--msm-success: #4ade80;
	--card-solid: #1c1917;
	--bg-surface-alt: #292524;
	--card-border: #3f3b38;
	--text-primary: #fafaf9;
	--text-secondary: #a8a29e;
	--text-muted: #948d88;
	--input-bg: #292524;
}

.msm-hw {
	--msm-hw-lift: 0px;
	--msm-hw-gap: 24px;
}

.msm-hw[hidden],
.msm-hw [hidden] {
	display: none !important;
}

.msm-hw-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

/* --------------------------------------------------------------------------
   The button
   -------------------------------------------------------------------------- */
.msm-hw-button {
	position: fixed;
	inset-inline-end: var(--msm-hw-gap);
	bottom: calc(var(--msm-hw-gap) + var(--msm-hw-lift) + env(safe-area-inset-bottom, 0px));
	z-index: 990;
	display: inline-flex;
	align-items: center;
	gap: 9px;
	height: 52px;
	margin: 0;
	padding-block: 0;
	padding-inline: 16px 22px;
	border: 0;
	border-radius: 999px;
	background: var(--msm-brand);
	color: var(--msm-on-brand);
	font-family: var(--msm-font-display, inherit);
	font-size: 1rem;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 10px 28px rgba(var(--msm-brand-rgb), 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
	transition: bottom 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.msm-hw-button:hover {
	background: var(--msm-brand-hover);
	transform: translateY(-1px);
}

.msm-hw-button:focus-visible {
	outline: 3px solid var(--text-primary);
	outline-offset: 3px;
}

.msm-hw-button svg {
	flex-shrink: 0;
}

.msm-hw-button-label {
	font-family: inherit;
}

.msm-hw.is-open .msm-hw-button,
body.nav-open .msm-hw-button {
	visibility: hidden;
}

/* --------------------------------------------------------------------------
   The panel
   -------------------------------------------------------------------------- */
.msm-hw-panel {
	--msm-hw-from: 28px;
	position: fixed;
	top: 0;
	bottom: 0;
	inset-inline-end: 0;
	z-index: 1100;
	display: flex;
	flex-direction: column;
	width: min(420px, 100vw);
	box-sizing: border-box;
	background: var(--card-solid);
	color: var(--text-primary);
	border-inline-start: 1px solid var(--card-border);
	box-shadow: -18px 0 48px rgba(0, 0, 0, 0.14);
	font-family: var(--msm-font-body, inherit);
	font-size: 1rem;
	text-align: start;
	animation: msm-hw-in 0.22s ease-out;
}

[dir="rtl"] .msm-hw-panel {
	--msm-hw-from: -28px;
	box-shadow: 18px 0 48px rgba(0, 0, 0, 0.14);
}

body.admin-bar .msm-hw-panel {
	top: 32px;
}

@keyframes msm-hw-in {
	from {
		opacity: 0;
		transform: translateX(var(--msm-hw-from));
	}
}

.msm-hw-panel:focus {
	outline: none;
}

.msm-hw-head {
	display: flex;
	align-items: center;
	gap: 6px;
	padding-block: 12px;
	padding-inline: 20px 10px;
	border-bottom: 1px solid var(--card-border);
}

.msm-hw-panel.is-reading .msm-hw-head {
	padding-inline-start: 8px;
}

.msm-hw-title {
	flex-grow: 1;
	margin: 0;
	font-family: var(--msm-font-display, inherit);
	font-size: 1.3rem;
	font-weight: 700;
	line-height: 1.4;
	color: var(--text-primary);
}

.msm-hw-title:focus {
	outline: none;
}

.msm-hw-title:focus-visible {
	outline: 2px solid var(--msm-brand);
	outline-offset: 2px;
	border-radius: 4px;
}

.msm-hw-icon {
	display: inline-flex;
	flex-shrink: 0;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--radius-sm);
	background: transparent;
	color: var(--text-secondary);
	cursor: pointer;
}

.msm-hw-icon:hover {
	background: var(--bg-surface-alt);
	color: var(--text-primary);
}

[dir="rtl"] .msm-hw-back svg,
[dir="rtl"] .msm-hw-arrow {
	transform: scaleX(-1);
}

/* Search ------------------------------------------------------------------ */
.msm-hw-search {
	position: relative;
	margin: 0;
	padding-block: 14px 4px;
	padding-inline: 20px;
}

.msm-hw-search-icon {
	position: absolute;
	inset-inline-start: 34px;
	top: 28px;
	color: var(--text-muted);
	pointer-events: none;
}

.msm-hw-search input[type="search"] {
	display: block;
	width: 100%;
	height: 46px;
	box-sizing: border-box;
	margin: 0;
	padding-block: 0;
	padding-inline: 42px 46px;
	border: 1px solid var(--card-border);
	border-radius: var(--radius-sm);
	background: var(--bg-surface-alt);
	color: var(--text-primary);
	font: inherit;
	font-size: 1rem;
	-webkit-appearance: none;
	appearance: none;
}

.msm-hw-search input[type="search"]::-webkit-search-cancel-button {
	display: none;
}

.msm-hw-search input[type="search"]::placeholder {
	color: var(--text-muted);
	opacity: 1;
}

.msm-hw-search input[type="search"]:focus {
	outline: none;
	border-color: var(--msm-brand);
	background: var(--input-bg);
	box-shadow: 0 0 0 3px rgba(var(--msm-brand-rgb), 0.18);
}

.msm-hw-clear {
	position: absolute;
	inset-inline-end: 21px;
	top: 15px;
}

.msm-hw-note {
	display: flex;
	gap: 6px;
	margin: 8px 20px 0;
	font-size: 0.85rem;
	line-height: 1.6;
	color: var(--text-secondary);
}

.msm-hw-count {
	margin: 0;
	padding-inline: 20px;
	font-size: 0.85rem;
	color: var(--text-secondary);
}

.msm-hw-count:not(:empty) {
	padding-block: 10px 0;
}

/* Body -------------------------------------------------------------------- */
.msm-hw-body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding-block: 6px 20px;
	padding-inline: 12px;
}

.msm-hw-section + .msm-hw-section {
	margin-top: 18px;
}

.msm-hw-section-head {
	padding-block: 10px 4px;
	padding-inline: 8px;
}

.msm-hw-eyebrow {
	margin: 0;
	font-family: var(--msm-font-mono, ui-monospace, monospace);
	font-size: 0.7rem;
	font-weight: 500;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--text-muted);
}

[dir="rtl"] .msm-hw-eyebrow,
[lang="ur"] .msm-hw-eyebrow {
	font-family: inherit;
	font-size: 0.85rem;
	font-weight: 600;
	letter-spacing: 0;
}

.msm-hw-label {
	margin: 2px 0 0;
	font-size: 1rem;
	font-weight: 700;
	line-height: 1.5;
	color: var(--text-primary);
}

.msm-hw-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.msm-hw-list li {
	margin: 0;
	padding: 0;
	border-top: 1px solid var(--card-border);
}

.msm-hw-list li:first-child {
	border-top: 0;
}

.msm-hw-q {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	padding: 12px 8px;
	border-radius: 10px;
	color: var(--text-primary);
	text-decoration: none;
	text-align: left;
}

.msm-hw-q:hover {
	background: var(--bg-surface-alt);
	color: var(--text-primary);
}

.msm-hw-q:focus-visible {
	outline: 2px solid var(--msm-brand);
	outline-offset: -2px;
}

.msm-hw-q svg {
	flex-shrink: 0;
	margin-top: 3px;
	color: var(--text-muted);
}

.msm-hw-qtext {
	flex-grow: 1;
	min-width: 0;
}

.msm-hw-qt {
	display: block;
	font-size: 0.95rem;
	font-weight: 600;
	line-height: 1.4;
}

.msm-hw-qe {
	display: -webkit-box;
	margin-top: 3px;
	overflow: hidden;
	font-size: 0.82rem;
	line-height: 1.5;
	color: var(--text-secondary);
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.msm-hw-tag {
	display: block;
	margin: 0 0 3px;
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	color: var(--msm-brand);
}

.msm-hw-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 6px 0 0;
	padding-block: 0;
	padding-inline: 8px;
	list-style: none;
}

.msm-hw-chips li {
	margin: 0;
	padding: 0;
}

.msm-hw-chip {
	display: inline-flex;
	align-items: center;
	min-height: 36px;
	padding: 0 13px;
	border: 1px solid var(--card-border);
	border-radius: 999px;
	color: var(--text-secondary);
	font-size: 0.82rem;
	font-weight: 500;
	text-decoration: none;
}

.msm-hw-chip:hover {
	border-color: var(--msm-brand);
	color: var(--msm-brand);
}

.msm-hw-loading,
.msm-hw-message {
	margin: 8px;
	font-size: 0.95rem;
	line-height: 1.6;
	color: var(--text-secondary);
}

.msm-hw-message {
	padding: 18px;
	border-radius: 14px;
	background: var(--bg-surface-alt);
}

.msm-hw-message p {
	margin: 0;
}

.msm-hw-message a,
.msm-hw-vote-thanks a {
	color: var(--msm-brand);
	font-weight: 600;
}

/* One answer -------------------------------------------------------------- */
.msm-hw-article {
	padding-block: 12px 0;
	padding-inline: 8px;
	text-align: left;
}

.msm-hw-atitle {
	margin: 2px 0 12px;
	font-family: var(--msm-font-display, inherit);
	font-size: 1.35rem;
	font-weight: 700;
	line-height: 1.3;
	letter-spacing: -0.01em;
	color: var(--text-primary);
}

.msm-hw-atitle:focus {
	outline: none;
}

.msm-hw-short {
	margin: 0 0 6px;
	font-size: 0.98rem;
	line-height: 1.6;
	color: var(--text-primary);
}

.msm-hw-content {
	font-size: 0.95rem;
	line-height: 1.65;
	color: var(--text-primary);
	overflow-wrap: break-word;
}

.msm-hw-content h4,
.msm-hw-content h5,
.msm-hw-content h6 {
	margin: 20px 0 8px;
	font-family: var(--msm-font-display, inherit);
	font-size: 1.05rem;
	line-height: 1.35;
}

.msm-hw-content p,
.msm-hw-content ul,
.msm-hw-content ol {
	margin: 0 0 10px;
}

.msm-hw-content ul,
.msm-hw-content ol {
	padding-left: 20px;
}

.msm-hw-content li {
	margin-bottom: 6px;
}

.msm-hw-content a {
	color: var(--msm-brand);
	font-weight: 600;
}

.msm-hw-content code {
	font-size: 0.88em;
}

.msm-hw-full {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 44px;
	margin-block: 8px 0;
	margin-inline: 8px;
	color: var(--msm-brand);
	font-size: 0.9rem;
	font-weight: 600;
	text-decoration: none;
}

.msm-hw-full:hover {
	text-decoration: underline;
}

.msm-hw-vote {
	margin: 14px 8px 0;
	padding: 16px;
	border-radius: 14px;
	background: var(--bg-surface-alt);
}

.msm-hw-vote-q {
	margin: 0 0 10px;
	font-size: 0.95rem;
	font-weight: 700;
}

.msm-hw-vote-buttons {
	display: flex;
	gap: 8px;
}

.msm-hw-vote-button {
	min-height: 40px;
	margin: 0;
	padding: 0 18px;
	border: 1px solid var(--card-border);
	border-radius: 999px;
	background: var(--card-solid);
	color: var(--text-primary);
	font: inherit;
	font-size: 0.9rem;
	font-weight: 600;
	cursor: pointer;
}

.msm-hw-vote-button:hover:not(:disabled) {
	border-color: var(--msm-brand);
	color: var(--msm-brand);
}

.msm-hw-vote-button:disabled {
	cursor: default;
	opacity: 0.6;
}

.msm-hw-vote-button[aria-pressed="true"] {
	border-color: var(--msm-brand);
	background: var(--msm-brand);
	color: var(--msm-on-brand);
	opacity: 1;
}

.msm-hw-vote-thanks:not([hidden]) {
	margin-top: 12px;
}

.msm-hw-vote-thanks {
	margin: 0;
	font-size: 0.95rem;
	font-weight: 600;
	line-height: 1.6;
	color: var(--text-primary);
}

.msm-hw-vote-thanks:focus {
	outline: none;
}

/* Footer ------------------------------------------------------------------ */
.msm-hw-foot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding-block: 6px calc(6px + env(safe-area-inset-bottom, 0px));
	padding-inline: 20px;
	border-top: 1px solid var(--card-border);
	font-size: 0.9rem;
	font-weight: 600;
}

.msm-hw-foot a {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 44px;
	color: var(--msm-brand);
	text-decoration: none;
}

.msm-hw-foot a:hover {
	text-decoration: underline;
}

.msm-hw-foot .msm-hw-contact {
	color: var(--text-secondary);
}

.msm-hw-panel a:focus-visible,
.msm-hw-panel button:focus-visible {
	outline: 2px solid var(--msm-brand);
	outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Phone: the panel covers the screen
   -------------------------------------------------------------------------- */
@media (max-width: 782px) {
	body.admin-bar .msm-hw-panel {
		top: 46px;
	}
}

@media (max-width: 640px) {
	.msm-hw {
		--msm-hw-gap: 16px;
	}

	.msm-hw-button {
		height: 50px;
		padding-inline: 14px 18px;
		font-size: 0.95rem;
	}

	/*
	 * Full screen, and over everything — the WordPress admin bar (99999)
	 * included. Scrolling is locked while it is open, so a bar left on top
	 * would cover the close button with no way to move it.
	 */
	.msm-hw-panel {
		z-index: 100000;
		width: 100%;
		border-inline-start: 0;
		box-shadow: none;
	}

	body.admin-bar .msm-hw-panel {
		top: 0;
	}

	.msm-hw-head {
		padding-inline: 18px 8px;
	}

	.msm-hw-search {
		padding-inline: 16px;
	}

	.msm-hw-search-icon {
		inset-inline-start: 30px;
	}

	.msm-hw-clear {
		inset-inline-end: 17px;
	}

	.msm-hw-search input[type="search"] {
		font-size: 16px; /* Below 16px iOS zooms the page on focus. */
	}
}

html.msm-hw-lock,
html.msm-hw-lock body {
	overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
	.msm-hw-panel {
		animation: none;
	}

	.msm-hw-button {
		transition: none;
	}
}

@media print {
	.msm-hw {
		display: none !important;
	}
}
