/**
 * The fatwa index: search tools above, and a panel holding a page of rows
 * with its pager underneath.
 *
 * The panel is one card, not three stacked boxes, so that switching it from
 * browsing to search results reads as the same surface changing its heading
 * rather than as a second list appearing below the first.
 *
 * Colours are the design's, read back from the rendered page rather than
 * invented: the same greens, cream and hairline the cards were cut from.
 */
.as-fx {
	--fx-ink: #14231c;
	--fx-ink-2: #3c5147;
	--fx-faint: #6d7f76;
	--fx-green: #2e6e51;
	--fx-green-deep: #1a4232;
	--fx-gold: #7d5f27;
	--fx-cream: #f2ede1;
	--fx-paper: #fbf9f4;
	--fx-line: #ded6c4;
	--fx-line-soft: #ece6da;
	--fx-shadow: 0 4px 16px rgba( 20, 35, 28, 0.09 );

	font-family: Tajawal, sans-serif;
	direction: rtl;
	text-align: right;
}

.as-fx-i {
	flex: none;
	width: 16px;
	height: 16px;
}

/* ------------------------------------------------------------------ tools */

.as-fx-tools {
	background: #fff;
	border: 1px solid var(--fx-line);
	border-radius: 12px;
	padding: 20px;
	box-shadow: var(--fx-shadow);
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.as-fx-seek {
	display: flex;
	align-items: center;
	gap: 12px;
}

.as-fx-field {
	position: relative;
	display: block;
	flex: 1 1 auto;
	min-width: 0;
}

.as-fx-field > .as-fx-i-search {
	position: absolute;
	inset-inline-start: 16px;
	top: 50%;
	width: 18px;
	height: 18px;
	margin-top: -9px;
	color: var(--fx-faint);
	pointer-events: none;
	transition: color 0.15s ease;
}

.as-fx-field:focus-within > .as-fx-i-search {
	color: var(--fx-green);
}

/*
 * Scoped through the label rather than written flat: the theme styles search
 * inputs as input[type="search"], which outranks a lone class and was taking
 * the padding back, dropping the placeholder underneath the icon.
 */
.as-fx-field .as-fx-input {
	width: 100%;
	box-sizing: border-box;
	font: 400 16px/1.5 Tajawal, sans-serif;
	color: var(--fx-ink);
	background: var(--fx-paper);
	border: 1px solid var(--fx-line);
	border-radius: 999px;
	padding: 12px 46px 12px 46px;
	outline: none;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.as-fx-field .as-fx-input::placeholder {
	color: var(--fx-faint);
	opacity: 1;
}

.as-fx-field .as-fx-input:focus {
	background: #fff;
	border-color: var(--fx-green);
	box-shadow: 0 0 0 3px rgba( 46, 110, 81, 0.15 );
}

/* Safari draws its own clear affordance over ours. */
.as-fx-field .as-fx-input::-webkit-search-cancel-button,
.as-fx-field .as-fx-input::-webkit-search-decoration {
	-webkit-appearance: none;
	appearance: none;
}

.as-fx-clear {
	position: absolute;
	inset-inline-end: 10px;
	top: 50%;
	width: 26px;
	height: 26px;
	margin-top: -13px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--fx-ink-2);
	background: var(--fx-cream);
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	padding: 0;
	transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.as-fx-clear .as-fx-i {
	width: 14px;
	height: 14px;
}

.as-fx-clear:hover {
	background: var(--fx-green);
	color: #fff;
	transform: rotate( 90deg );
}

/*
 * Everything the script switches with the hidden attribute needs this: a
 * display of its own outranks the user agent's [hidden] rule, and the
 * element stays on screen while the script believes it is gone.
 */
.as-fx-clear[hidden] {
	display: none;
}

/* ------------------------------------------------------------------ scope */

.as-fx-scope {
	display: flex;
	align-items: center;
	gap: 8px;
	flex: none;
}

.as-fx-scope-label {
	font: 700 11px/1 Tajawal, sans-serif;
	letter-spacing: 1.3px;
	color: var(--fx-gold);
	white-space: nowrap;
}

.as-fx-scope-box {
	position: relative;
	display: block;
}

.as-fx-scope-box .as-fx-i-caret {
	position: absolute;
	inset-inline-end: 12px;
	top: 50%;
	margin-top: -8px;
	color: var(--fx-faint);
	pointer-events: none;
}

.as-fx-scope-box .as-fx-scope-select {
	font: 500 13px/1 Tajawal, sans-serif;
	color: var(--fx-ink-2);
	background: var(--fx-paper);
	border: 1px solid var(--fx-line);
	border-radius: 999px;
	padding: 11px 16px 11px 34px;
	max-width: 220px;
	cursor: pointer;
	outline: none;
	-webkit-appearance: none;
	appearance: none;
	transition: border-color 0.15s ease, color 0.15s ease;
}

.as-fx-scope-box .as-fx-scope-select:hover,
.as-fx-scope-box .as-fx-scope-select:focus {
	border-color: var(--fx-green);
	color: var(--fx-green-deep);
}

/* A narrowed search is a state worth seeing without opening the menu. */
.as-fx-scope-box .as-fx-scope-select.is-set {
	background: var(--fx-cream);
	border-color: var(--fx-gold);
	color: var(--fx-gold);
	font-weight: 700;
}

/* ------------------------------------------------------------------ chips */

.as-fx-chips {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	transition: opacity 0.2s ease;
}

.as-fx-chips[hidden] {
	display: none;
}

.as-fx-chips-label {
	font: 700 11px/1 Tajawal, sans-serif;
	letter-spacing: 1.3px;
	color: var(--fx-gold);
	margin: 0 0 0 4px;
	white-space: nowrap;
}

.as-fx-chip {
	display: inline-flex;
	align-items: baseline;
	gap: 6px;
	font: 500 13px/1 Tajawal, sans-serif;
	color: var(--fx-ink-2);
	background: var(--fx-paper);
	border: 1px solid var(--fx-line);
	border-radius: 999px;
	padding: 7px 14px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.as-fx-chip:hover {
	border-color: var(--fx-green);
	color: var(--fx-green-deep);
}

.as-fx-chip[aria-pressed="true"] {
	background: var(--fx-green);
	border-color: var(--fx-green);
	color: #fff;
}

.as-fx-chip-n {
	font-size: 11px;
	font-weight: 700;
	opacity: 0.65;
}

/*
 * A child bab reads as a child: the dash is a marker, not a character in the
 * name, so it is drawn rather than written into the label.
 */
.as-fx-chip[data-depth="1"]::before,
.as-fx-chip[data-depth="2"]::before {
	content: "";
	width: 10px;
	height: 1px;
	background: currentColor;
	opacity: 0.45;
	align-self: center;
}

.as-fx-chip[data-depth="1"] {
	font-size: 12.5px;
}

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

.as-fx-panel {
	margin-top: 18px;
	background: #fff;
	border: 1px solid var(--fx-line);
	border-radius: 12px;
	box-shadow: var(--fx-shadow);
	overflow: hidden;
	transition: border-color 0.25s ease;
}

/* The results state is the same card wearing a different head. */
.as-fx-panel.is-results {
	border-color: var(--fx-green);
}

.as-fx-head {
	display: flex;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
	padding: 12px 20px;
	background: var(--fx-paper);
	border-bottom: 1px solid var(--fx-line-soft);
	min-height: 26px;
}

.as-fx-panel.is-results .as-fx-head {
	background: var(--fx-green);
	border-bottom-color: var(--fx-green);
}

.as-fx-count {
	margin: 0;
	font: 400 13px/1.6 Tajawal, sans-serif;
	color: var(--fx-faint);
}

.as-fx-count b {
	font-weight: 700;
	color: var(--fx-ink-2);
}

.as-fx-count[hidden],
.as-fx-found[hidden] {
	display: none;
}

.as-fx-found {
	display: flex;
	align-items: center;
	gap: 10px 14px;
	flex-wrap: wrap;
	width: 100%;
	color: #fff;
	animation: as-fx-head-in 0.25s ease both;
}

.as-fx-found-said {
	font: 400 13px/1.6 Tajawal, sans-serif;
	color: rgba( 255, 255, 255, 0.78 );
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.as-fx-found-q {
	color: #fff;
	font-weight: 700;
}

.as-fx-found-q::before {
	content: "\201D";
}

.as-fx-found-q::after {
	content: "\201C";
}

.as-fx-found-n {
	margin-inline-start: auto;
	font: 700 12px/1 Tajawal, sans-serif;
	color: var(--fx-green-deep);
	background: rgba( 255, 255, 255, 0.92 );
	border-radius: 999px;
	padding: 6px 12px;
	white-space: nowrap;
}

.as-fx-close {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	font: 500 12.5px/1 Tajawal, sans-serif;
	color: #fff;
	background: rgba( 255, 255, 255, 0.14 );
	border: 1px solid rgba( 255, 255, 255, 0.34 );
	border-radius: 999px;
	padding: 7px 13px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.as-fx-close .as-fx-i {
	width: 13px;
	height: 13px;
	transition: transform 0.15s ease;
}

.as-fx-close:hover {
	background: #fff;
	color: var(--fx-green-deep);
}

.as-fx-close:hover .as-fx-i {
	transform: translateX( 3px );
}

/* ------------------------------------------------------------------- rows */

.as-fx-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.as-fx-list[hidden] {
	display: none;
}

.as-fx-row {
	margin: 0;
	border-top: 1px solid var(--fx-line-soft);
}

.as-fx-row:first-child {
	border-top: 0;
}

.as-fx-link {
	display: flex;
	align-items: flex-start;
	gap: 14px;
	padding: 16px 20px;
	text-decoration: none;
	color: inherit;
	transition: background 0.15s ease;
}

.as-fx-link:hover,
.as-fx-link:focus-visible {
	background: var(--fx-paper);
	text-decoration: none;
}

.as-fx-link:focus-visible {
	outline: 2px solid var(--fx-green);
	outline-offset: -2px;
}

/*
 * The fatwa's own number rather than its place in the list, so it reads the
 * same however the list is filtered, searched or paged — and so it can be
 * cited. Tabular figures keep the column straight from ١ to ١٠٠.
 */
.as-fx-num {
	flex: none;
	min-width: 26px;
	padding-top: 5px;
	font: 700 11.5px/1.6 Tajawal, sans-serif;
	color: var(--fx-gold);
	font-feature-settings: "tnum";
	text-align: center;
}

.as-fx-body {
	flex: 1 1 auto;
	min-width: 0;
}

.as-fx-line {
	display: flex;
	align-items: baseline;
	gap: 12px;
}

.as-fx-title {
	flex: 1 1 auto;
	font: 700 17px/1.55 Tajawal, sans-serif;
	color: var(--fx-ink);
	transition: color 0.15s ease;
}

.as-fx-link:hover .as-fx-title,
.as-fx-link:focus-visible .as-fx-title {
	color: var(--fx-green);
}

.as-fx-title mark,
.as-fx-ask mark {
	background: rgba( 212, 175, 55, 0.3 );
	color: inherit;
	border-radius: 3px;
	padding: 0 1px;
}

.as-fx-bab {
	flex: none;
	align-self: flex-start;
	font: 700 10.5px/1 Tajawal, sans-serif;
	letter-spacing: 0.9px;
	color: var(--fx-gold);
	background: var(--fx-cream);
	border-radius: 999px;
	padding: 5px 10px;
	white-space: nowrap;
}

/* ------------------------------------------------------------ the question */

.as-fx-ask {
	display: block;
	margin-top: 4px;
	font: 400 14.5px/1.75 Tajawal, sans-serif;
	color: var(--fx-ink-2);
}

.as-fx-ell {
	color: var(--fx-faint);
}

/*
 * "More" is not a link of its own — a link inside a link is not valid markup,
 * and the whole row already goes to the fatwa. It is written to look like the
 * end of the sentence it follows, so the eye reads straight into it.
 */
.as-fx-more {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	margin-inline-start: 8px;
	font: 700 12.5px/1 Tajawal, sans-serif;
	color: var(--fx-green);
	white-space: nowrap;
	vertical-align: baseline;
}

.as-fx-more .as-fx-i {
	width: 13px;
	height: 13px;
	transition: transform 0.18s ease;
}

.as-fx-link:hover .as-fx-more .as-fx-i,
.as-fx-link:focus-visible .as-fx-more .as-fx-i {
	transform: translateX( -3px );
}

/* The arrow points the way the script runs, and only leans in on hover. */
.as-fx-link > .as-fx-i-go {
	flex: none;
	margin-top: 4px;
	color: var(--fx-line);
	transition: color 0.15s ease, transform 0.15s ease;
}

.as-fx-link:hover > .as-fx-i-go,
.as-fx-link:focus-visible > .as-fx-i-go {
	color: var(--fx-green);
	transform: translateX( -3px );
}

/* ------------------------------------------------------------------ pager */

.as-fx-pager {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-wrap: wrap;
	gap: 6px;
	padding: 14px 20px;
	background: var(--fx-paper);
	border-top: 1px solid var(--fx-line-soft);
}

.as-fx-pager[hidden] {
	display: none;
}

.as-fx-page {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	min-width: 34px;
	justify-content: center;
	font: 500 13px/1 Tajawal, sans-serif;
	color: var(--fx-ink-2);
	background: #fff;
	border: 1px solid var(--fx-line);
	border-radius: 999px;
	padding: 8px 12px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.as-fx-page:hover:not( [disabled] ):not( [aria-current="page"] ) {
	border-color: var(--fx-green);
	color: var(--fx-green-deep);
}

.as-fx-page[aria-current="page"] {
	background: var(--fx-green);
	border-color: var(--fx-green);
	color: #fff;
	font-weight: 700;
	cursor: default;
}

.as-fx-page[disabled] {
	opacity: 0.4;
	cursor: default;
}

.as-fx-page .as-fx-i {
	width: 13px;
	height: 13px;
	transition: transform 0.15s ease;
}

.as-fx-page-step:hover:not( [disabled] ) .as-fx-i-go {
	transform: translateX( -3px );
}

.as-fx-page-step:hover:not( [disabled] ) .as-fx-i-back {
	transform: translateX( 3px );
}

/* A gap in the run of numbers, not a button. */
.as-fx-gap {
	color: var(--fx-faint);
	padding: 0 2px;
	user-select: none;
}

/* ------------------------------------------------------------------ empty */

.as-fx-empty {
	margin: 0;
	padding: 48px 20px;
	text-align: center;
	font: 400 16px/1.7 Tajawal, sans-serif;
	color: var(--fx-ink-2);
	animation: as-fx-in 0.3s ease both;
}

.as-fx-empty[hidden] {
	display: none;
}

.as-fx-empty .as-fx-i {
	display: block;
	margin: 0 auto 12px;
	width: 30px;
	height: 30px;
	color: var(--fx-line);
}

.as-fx-empty b {
	display: block;
	color: var(--fx-ink);
	font-weight: 700;
}

.as-fx-reset {
	display: inline-block;
	margin-top: 14px;
	font: 500 13px/1 Tajawal, sans-serif;
	color: var(--fx-green-deep);
	background: var(--fx-cream);
	border: 1px solid var(--fx-line);
	border-radius: 999px;
	padding: 9px 18px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.as-fx-reset:hover {
	background: var(--fx-green);
	border-color: var(--fx-green);
	color: #fff;
}

/* ----------------------------------------------------------------- motion */

@keyframes as-fx-in {
	from {
		opacity: 0;
		transform: translateY( 6px );
	}

	to {
		opacity: 1;
		transform: none;
	}
}

@keyframes as-fx-head-in {
	from {
		opacity: 0;
		transform: translateY( -4px );
	}

	to {
		opacity: 1;
		transform: none;
	}
}

/*
 * Turning a page redraws the same strip of screen, and without a cue the eye
 * cannot tell whether anything happened. The rows arrive in quick succession;
 * the delay is capped so a full page still settles in well under a second.
 */
.as-fx-list.is-turning .as-fx-row {
	animation: as-fx-in 0.3s ease both;
	animation-delay: calc( var( --i, 0 ) * 22ms );
}

/* ------------------------------------------------------------------ small */

@media ( max-width: 700px ) {
	.as-fx-seek {
		flex-wrap: wrap;
	}

	.as-fx-scope {
		width: 100%;
	}

	.as-fx-scope-box {
		flex: 1 1 auto;
	}

	.as-fx-scope-box .as-fx-scope-select {
		width: 100%;
		max-width: none;
	}
}

@media ( max-width: 600px ) {
	.as-fx-tools {
		padding: 16px;
	}

	.as-fx-link {
		gap: 10px;
		padding: 14px 16px;
	}

	.as-fx-num {
		min-width: 18px;
	}

	.as-fx-line {
		display: block;
	}

	.as-fx-title {
		font-size: 16px;
	}

	.as-fx-bab {
		display: inline-block;
		margin-top: 6px;
	}

	.as-fx-ask {
		font-size: 14px;
	}

	/* A phone has no hover, so the chevron only costs width. */
	.as-fx-link > .as-fx-i-go {
		display: none;
	}

	.as-fx-chips-label {
		flex: 1 1 100%;
		margin: 0 2px 2px;
	}

	.as-fx-head {
		padding: 12px 16px;
	}

	.as-fx-found-n {
		margin-inline-start: 0;
	}

	.as-fx-pager {
		padding: 12px 10px;
		gap: 5px;
	}

	.as-fx-page {
		min-width: 30px;
		padding: 7px 10px;
		font-size: 12.5px;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.as-fx *,
	.as-fx *::before,
	.as-fx *::after {
		transition: none !important;
		animation: none !important;
	}
}

/* While the server is asked for another page, the old one fades rather
   than vanishing; delayed, so a quick answer never flickers. */
.as-fx-panel.is-loading .as-fx-list,
.as-fx-panel.is-loading .as-fx-empty {
	opacity: .5;
	transition: opacity .2s ease .12s;
}

/* Sub-bab chips wait until their bab is chosen; .as-fx-chip sets a
   display that would otherwise outrank [hidden]. */
.as-fx-chip[hidden] {
	display: none;
}
