/* ==========================================================================
   Discovery search
   ========================================================================== */

/* Search band ------------------------------------------------------------- */

.disc-head {
	position: relative;
	overflow: hidden;
	padding-block: clamp(2rem, 5vw, 3rem) clamp(1.75rem, 4vw, 2.5rem);
	background: var(--ink);
	color: #c7ced6;
}
.disc-head .container { position: relative; z-index: 1; }
.disc-head__pattern {
	position: absolute;
	inset-inline-end: -80px;
	top: 50%;
	width: 420px;
	height: 420px;
	color: var(--gold);
	opacity: .28;
	transform: translateY(-50%);
}
.disc-head__title { margin: 0 0 1.25rem; color: var(--white); font-size: clamp(1.7rem, 3.4vw, 2.35rem); }

.disc-form { max-width: 920px; }
.disc-form__main {
	display: flex;
	align-items: stretch;
	background: var(--white);
	border-radius: var(--radius-lg);
	box-shadow: 0 18px 50px -24px rgb(0 0 0 / 70%);
	padding: .35rem;
	gap: .35rem;
}
.disc-form__main:focus-within { box-shadow: 0 0 0 3px rgb(175 140 69 / 55%), 0 18px 50px -24px rgb(0 0 0 / 70%); }
.disc-form .disc-form__field {
	flex: 0 0 auto;
	width: auto;
	min-width: 9.5rem;
	min-height: 52px;
	border: 0;
	border-inline-end: 1px solid var(--line);
	border-radius: var(--radius) 0 0 var(--radius);
	background-color: var(--sand);
	font-weight: 500;
	font-size: .95rem;
}
[dir="rtl"] .disc-form__field { border-radius: 0 var(--radius) var(--radius) 0; }
.disc-form .disc-form__q {
	flex: 1;
	min-width: 0;
	min-height: 52px;
	border: 0;
	font-size: 1.1rem;
	padding-inline: .75rem;
}
.disc-form .disc-form__field:focus, .disc-form .disc-form__q:focus { box-shadow: none; }
.disc-form__submit { min-height: 52px; padding-inline: 1.5rem; }
.disc-form.is-busy .disc-form__submit { pointer-events: none; }
.disc-form.is-busy .disc-form__submit .icon { animation: disc-pulse 1s ease-in-out infinite; }

.disc-form__adv-toggle { margin-top: .75rem; color: var(--gold-light); }
.disc-form__adv-toggle:hover { color: var(--white); }
.disc-form__adv-toggle[aria-expanded="true"] { color: var(--white); text-decoration: underline; text-underline-offset: .25em; }

.disc-form__adv { margin-top: .75rem; display: grid; gap: .5rem; }
.disc-form__adv .text-button { justify-self: start; color: var(--gold-light); }
.disc-form__adv .text-button:hover { color: var(--white); }
.adv-row {
	display: grid;
	grid-template-columns: 6.5rem 10rem minmax(0, 1fr) 40px;
	gap: .5rem;
	align-items: center;
}
.adv-row select, .adv-row input { min-height: 44px; border-color: transparent; }
.adv-row .icon-button { color: #c7ced6; }
.adv-row .icon-button:hover { background: rgb(255 255 255 / 8%); color: var(--white); }

@media (max-width: 640px) {
	.disc-form__main { flex-wrap: wrap; }
	.disc-form__field { flex-basis: 100%; border-inline-end: 0; border-bottom: 1px solid var(--line); border-radius: var(--radius); min-height: 44px; }
	.disc-form__q { flex-basis: 60%; }
	.disc-form__submit span { display: none; }
	.disc-form__submit { padding-inline: 1rem; }
	.adv-row { grid-template-columns: 5.5rem minmax(0, 1fr) 40px; }
	.adv-row__term { grid-column: 1 / 3; }
}

/* Progress bar ------------------------------------------------------------ */

.progress {
	position: sticky;
	top: var(--header-h);
	z-index: 40;
	height: 3px;
	overflow: hidden;
	background: var(--gold-wash);
}
.admin-bar .progress { top: calc(var(--header-h) + 32px); }
.progress span {
	position: absolute;
	inset-block: 0;
	width: 40%;
	background: var(--gold);
	animation: disc-progress 1.1s var(--ease) infinite;
}
@keyframes disc-progress {
	from { inset-inline-start: -40%; }
	to { inset-inline-start: 100%; }
}
@keyframes disc-pulse { 50% { opacity: .35; } }

/* Layout ------------------------------------------------------------------ */

.disc-layout {
	display: grid;
	grid-template-columns: 280px minmax(0, 1fr);
	gap: 2.5rem;
	align-items: start;
	padding-block: 2rem 4rem;
}

/* Filters ----------------------------------------------------------------- */

.disc-filters {
	position: sticky;
	top: calc(var(--header-h) + 1.25rem);
	max-height: calc(100vh - var(--header-h) - 2.5rem);
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: var(--line-strong) transparent;
	padding-inline-end: .5rem;
}
.disc-filters__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.disc-filters__head h2 { margin: 0; font-family: var(--font-sans); font-size: 1.05rem; }
.disc-filters__close, .disc-filters__foot { display: none; }

.filter { margin: 0; padding: 1rem 0; border: 0; border-top: 1px solid var(--line); min-width: 0; }
.filter fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.filter__title {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: 0;
	margin-bottom: .6rem;
	font-weight: 600;
	font-size: .95rem;
	color: var(--ink);
}
details.filter > .filter__title { margin: 0; cursor: pointer; list-style: none; }
details.filter > .filter__title::-webkit-details-marker { display: none; }
details.filter > .filter__title .icon { width: 18px; height: 18px; color: var(--muted); transition: transform .2s var(--ease); }
details.filter[open] > .filter__title { margin-bottom: .6rem; }
details.filter[open] > .filter__title .icon { transform: rotate(180deg); }

.filter__list { margin: 0; padding: 0; list-style: none; }
.filter__list .is-extra { display: none; }
.filter__list.is-expanded .is-extra { display: list-item; }
.filter__more { margin-top: .35rem; font-size: .875rem; }

.check {
	display: grid;
	grid-template-columns: 18px minmax(0, 1fr) auto;
	align-items: start;
	gap: .6rem;
	padding: .3rem 0;
	cursor: pointer;
	font-size: .925rem;
	line-height: 1.4;
}
.check input {
	appearance: none;
	width: 18px;
	height: 18px;
	margin: .1rem 0 0;
	border: 1.5px solid var(--line-strong);
	border-radius: 3px;
	background: var(--white);
	cursor: pointer;
	display: grid;
	place-items: center;
	transition: background-color .12s, border-color .12s;
}
.check input::after {
	content: "";
	width: 10px;
	height: 6px;
	border: 2px solid var(--white);
	border-top: 0;
	border-inline-end: 0;
	transform: translateY(-1px) rotate(-45deg) scale(0);
	transition: transform .12s;
}
[dir="rtl"] .check input::after { border-inline-end: 2px solid var(--white); border-inline-start: 0; transform: translateY(-1px) rotate(45deg) scale(0); }
.check input:checked { background: var(--ink); border-color: var(--ink); }
.check input:checked::after { transform: translateY(-1px) rotate(-45deg) scale(1); }
[dir="rtl"] .check input:checked::after { transform: translateY(-1px) rotate(45deg) scale(1); }
.check:hover input:not(:checked) { border-color: var(--ink); }
.check__label { overflow-wrap: anywhere; }
.check__label::first-letter { text-transform: uppercase; }
.check__count { color: var(--muted); font-size: .825rem; font-variant-numeric: tabular-nums; padding-top: .1rem; }
.check input:checked ~ .check__label { font-weight: 600; color: var(--ink); }

/* Switch variant for limiters */
.check--switch { grid-template-columns: 34px minmax(0, 1fr); align-items: center; }
.check--switch input {
	width: 34px;
	height: 20px;
	margin: 0;
	border-radius: 999px;
	background: var(--line);
	border: 0;
	position: relative;
	display: block;
}
.check--switch input::after {
	position: absolute;
	top: 3px;
	inset-inline-start: 3px;
	width: 14px;
	height: 14px;
	border: 0;
	border-radius: 50%;
	background: var(--white);
	box-shadow: 0 1px 2px rgb(0 0 0 / 25%);
	transform: none;
	transition: inset-inline-start .15s var(--ease);
}
[dir="rtl"] .check--switch input::after { border: 0; transform: none; }
.check--switch input:checked { background: var(--gold-deep); }
.check--switch input:checked::after { inset-inline-start: 17px; transform: none; }
[dir="rtl"] .check--switch input:checked::after { transform: none; }

.years { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem; align-items: end; }
.years label { display: grid; gap: .2rem; font-size: .8rem; color: var(--muted); }
.years input { min-height: 38px; padding: .35rem .5rem; font-size: .925rem; -moz-appearance: textfield; }
.years input::-webkit-inner-spin-button, .years input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Toolbar ----------------------------------------------------------------- */

.disc-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: .75rem 1.5rem;
	min-height: 46px;
	margin-bottom: 1rem;
}
.disc-toolbar__status { margin: 0; font-weight: 600; color: var(--ink); font-size: 1.05rem; }
.disc-toolbar__status .muted { font-weight: 400; font-size: .9rem; }
.disc-toolbar__actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.disc-toolbar__filters { display: none; }
.disc-toolbar__filters .count:not(:empty) {
	display: inline-grid;
	place-items: center;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: 4px;
	background: var(--ink);
	color: var(--white);
	font-size: .75rem;
}
.sort { display: inline-flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--muted); }
.sort select { width: auto; min-height: 38px; padding-block: .3rem; font-size: .9rem; color: var(--ink); }
[data-save-search].is-done { border-color: var(--ok); color: var(--ok); }

/* Applied filters: understated text buttons, not pills */
.applied { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-bottom: 1.25rem; padding: .75rem 1rem; background: var(--sand); border-radius: var(--radius); }
.applied__label { font-size: .85rem; color: var(--muted); }
.applied__item {
	display: inline-flex;
	align-items: center;
	gap: .3rem;
	padding: .2rem .45rem;
	border: 1px solid var(--line-strong);
	border-radius: 4px;
	background: var(--white);
	font-size: .85rem;
	cursor: pointer;
}
.applied__item span:first-child::first-letter { text-transform: uppercase; }
.applied__item .icon { width: 14px; height: 14px; color: var(--muted); }
.applied__item:hover { border-color: var(--ink); }
.applied__item:hover .icon { color: var(--danger); }

/* Results ----------------------------------------------------------------- */

.disc-list { transition: opacity .2s; }
.disc-list.is-stale { opacity: .45; pointer-events: none; }

.rec {
	display: grid;
	grid-template-columns: 72px minmax(0, 1fr);
	gap: 1.25rem;
	padding: 1.5rem 0;
	border-top: 1px solid var(--line);
}
.rec:last-child { border-bottom: 1px solid var(--line); }
.rec__cover {
	width: 72px;
	aspect-ratio: 3 / 4;
	overflow: hidden;
	border-radius: 3px;
	background: var(--sand);
	display: grid;
	place-items: center;
}
.rec__cover img { width: 100%; height: 100%; object-fit: cover; }
.rec__type-icon { color: var(--line-strong); }
.rec__type-icon .icon { width: 30px; height: 30px; stroke-width: 1.2; }

.rec__meta { margin: 0 0 .3rem; font-size: .85rem; color: var(--muted); }
.rec__title { margin: 0 0 .35rem; font-family: var(--font-display); font-size: 1.2rem; line-height: 1.35; }
html[lang^="ar"] .rec__title { font-family: var(--font-sans); }
.rec__open {
	padding: 0;
	border: 0;
	background: none;
	color: var(--ink);
	text-align: start;
	font: inherit;
	cursor: pointer;
}
.rec__open:hover { color: var(--gold-deep); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; }
.rec mark { background: none; color: inherit; font-weight: 700; }
.rec__title mark { color: inherit; background: linear-gradient(transparent 62%, var(--gold-wash) 62%); font-weight: inherit; }
.rec__by { margin: 0 0 .15rem; font-size: .95rem; color: var(--text); }
.rec__source { margin: 0 0 .6rem; font-size: .9rem; font-style: italic; color: var(--muted); }
html[lang^="ar"] .rec__source { font-style: normal; }
.rec__abstract {
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
	margin: 0 0 .75rem;
	font-size: .95rem;
	color: var(--muted);
	max-width: 78ch;
}
.rec.is-open .rec__abstract { display: none; }

/* One action bar per result: access buttons on one side, cite/save on the other. */
.rec__bar {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: .6rem 1.5rem;
	margin-top: .9rem;
	padding-top: .9rem;
	border-top: 1px dashed var(--line);
}
.rec__access { display: flex; flex-wrap: wrap; gap: .5rem; }
.rec__access .button { min-height: 36px; padding: .35rem .8rem; font-size: .875rem; }
.rec__access .button .icon { width: 16px; height: 16px; }
.avail { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--ok); font-weight: 500; }
.avail .icon { width: 16px; height: 16px; }
.rec__actions { display: flex; gap: 1.1rem; }
.rec__actions .text-button { font-size: .875rem; }
.rec__actions .is-done { color: var(--ok); }

.rec__detail { margin-top: 1.1rem; }
.detail { padding: 1.4rem 1.5rem; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.detail__actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.detail__note { margin: -.5rem 0 1.25rem; font-size: .9rem; color: var(--muted); }
.detail__heading { margin: 0 0 .4rem; font-size: .95rem; }
.detail__abstract { margin-bottom: 1.25rem; font-size: .975rem; line-height: 1.7; max-width: 80ch; }
.detail__meta { display: grid; gap: 0; margin: 0; border-top: 1px solid var(--line); font-size: .9rem; }
.detail__meta > div { display: grid; grid-template-columns: 11rem minmax(0, 1fr); gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.detail__meta dt { color: var(--muted); }
.detail__meta dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) { .detail__meta > div { grid-template-columns: 1fr; gap: .1rem; } }
.detail-error { margin: 0; padding: 1rem; background: #fbefec; border-radius: var(--radius); color: var(--danger); }
.detail-loading { display: grid; gap: .5rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius-lg); }

/* Empty / start / error states */
.disc-start, .disc-empty {
	padding: 3rem 2rem;
	text-align: center;
	background: var(--sand);
	border-radius: var(--radius-lg);
}
.disc-start h2, .disc-empty h2 { font-size: 1.5rem; }
.disc-start p, .disc-empty p { max-width: 52ch; margin-inline: auto; color: var(--muted); }
.disc-start .prose { margin: 1.5rem auto 0; text-align: start; }
.disc-empty--warn { background: #fbf4ea; }
.disc-empty .button { margin-top: .5rem; }

/* Loading placeholders */
.ghost {
	display: block;
	height: .8rem;
	border-radius: 3px;
	background: linear-gradient(90deg, var(--sand) 0%, #ece6d9 50%, var(--sand) 100%);
	background-size: 200% 100%;
	animation: disc-shimmer 1.3s ease-in-out infinite;
}
.rec__cover.ghost { height: auto; }
.ghost--s { width: 22%; height: .65rem; margin-bottom: .6rem; }
.ghost--l { width: 78%; height: 1.15rem; margin-bottom: .5rem; }
.ghost--m { width: 40%; margin-bottom: .9rem; }
.ghost--p { width: 100%; margin-bottom: .45rem; }
.ghost--short { width: 62%; }
.rec--ghost { pointer-events: none; }
@keyframes disc-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Dialog (cite / export / full text) -------------------------------------- */

.dialog {
	width: min(640px, calc(100vw - 2rem));
	max-height: min(86vh, 900px);
	padding: 0;
	border: 0;
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-lg);
	color: var(--text);
	background: var(--white);
}
.dialog--wide { width: min(880px, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgb(23 33 43 / 55%); }
.dialog[open] { display: flex; flex-direction: column; animation: dialog-in .2s var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px); } }
.dialog__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.25rem 1rem 1.5rem; border-bottom: 1px solid var(--line); }
.dialog__title { margin: .3rem 0 0; font-size: 1.25rem; line-height: 1.35; }
.dialog__body { padding: 1.25rem 1.5rem 1.5rem; overflow-y: auto; }
.dialog__body .field { margin-bottom: 1rem; max-width: 260px; }
.dialog__actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.cite-box { min-height: 4.5rem; padding: 1rem 1.1rem; background: var(--sand); border-radius: var(--radius); line-height: 1.65; overflow-wrap: anywhere; }
.cite-box--code pre { margin: 0; white-space: pre-wrap; font-size: .85rem; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; direction: ltr; text-align: left; }
.reader { font-size: 1.02rem; max-width: none; }
.reader h3 { font-size: 1.15rem; margin-top: 1.75em; }

/* Mobile ------------------------------------------------------------------ */

@media (max-width: 1023px) {
	.disc-layout { grid-template-columns: minmax(0, 1fr); padding-top: 1.25rem; }
	.disc-toolbar__filters { display: inline-flex; }

	.disc-filters {
		position: fixed;
		inset-block: 0;
		inset-inline-start: 0;
		z-index: 70;
		width: min(380px, 92vw);
		max-height: none;
		display: flex;
		flex-direction: column;
		padding: 0;
		background: var(--white);
		box-shadow: var(--shadow-lg);
		opacity: 0;
		visibility: hidden;
		transform: scale(.98);
		transform-origin: top left;
		transition: opacity .2s var(--ease), transform .2s var(--ease), visibility 0s .2s;
	}
	[dir="rtl"] .disc-filters { transform-origin: top right; }
	.disc-filters.is-open { opacity: 1; transform: none; visibility: visible; transition: opacity .2s var(--ease), transform .2s var(--ease); }
	.disc-filters__head { padding: .75rem 1rem .75rem 1.25rem; margin: 0; border-bottom: 1px solid var(--line); }
	.disc-filters__close { display: inline-grid; }
	.disc-filters__body { flex: 1; overflow-y: auto; padding: 0 1.25rem; }
	.disc-filters__body > :first-child { border-top: 0; }
	.disc-filters__foot { display: block; padding: 1rem 1.25rem; border-top: 1px solid var(--line); }
}

@media (max-width: 560px) {
	.rec { grid-template-columns: 52px minmax(0, 1fr); gap: .9rem; }
	.rec__cover { width: 52px; }
	.rec__title { font-size: 1.08rem; }
	.disc-toolbar { align-items: flex-start; flex-direction: column; }
	.detail { padding: 1.1rem; }
	.rec__access { width: 100%; }
	.rec__access .button { flex: 1 1 auto; }
}

/* A floated legend sits inside its fieldset like a normal heading. */
legend.filter__title { float: inline-start; }
legend.filter__title + * { clear: both; }
