/* ==========================================================================
   THEEB-FEATURE-LEGAL-LIBRARY-V1 — archive + document-detail styles. Loaded ONLY on Legal
   Library pages (see inc/assets.php's conditional enqueue) — never on unrelated pages.
   Namespaced to `.lib-*` throughout (BRIEF §140): no broad selectors like .card/.grid/button.
   Rollback: delete this file + its conditional enqueue in inc/assets.php.
   ========================================================================== */

/* ---- Controls: search + category filter + clear (BRIEF §17/18/119) --------------------------- */
.lib-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 2rem; padding-block-end: 1.1rem; margin-block-end: clamp(1.5rem, 3vw, 2.5rem); border-block-end: 1px solid var(--c-line); }
.lib-search { position: relative; display: flex; align-items: center; gap: 0.75rem; flex: 1 1 16rem; min-width: 0; }
.lib-search input { flex: 1; min-width: 0; background: none; border: 0; border-block-end: 1px solid var(--c-line); padding-block: 0.5rem; font-family: var(--font-body); font-size: var(--fs-small); color: var(--c-ink); }
html:lang(en) .lib-search input { font-family: var(--font-label); }
.lib-search input::-webkit-search-cancel-button { display: none; }
.lib-search button { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; color: var(--c-gold-ink); flex: none; }
.lib-filters { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; }
.lib-filters a { padding-block: 0.4rem; font-family: var(--font-label); font-size: 0.8125rem; font-weight: 500; letter-spacing: 0.05em; color: var(--c-text-muted); }
html:lang(ar) .lib-filters a { font-family: var(--font-body); letter-spacing: 0.01em; }
.lib-filters a:hover { color: var(--c-ink); }
.lib-filters a[aria-current] { color: var(--c-ink); box-shadow: 0 1px 0 var(--c-gold); }
.lib-clear { margin-inline-start: auto; }

/* ---- Archive grid (BRIEF §11/58/59): 3 desktop · 2 tablet · compact rows on phones ------------
   Empty-slot fix (kept — see the frame rule below): every visual surface (the frame, the gap)
   belongs to `.lib-card` itself, which exists only for a real document; an unused grid track has
   no element in it at all, so it can never show a border, background or any other surface. A real
   `gap` (not the earlier background/1px-line trick) also means every card can carry a full,
   unconditional 4-side border with no nth-child bookkeeping and no doubled lines between cards. */
.lib-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
@media (min-width: 640px) { .lib-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .lib-grid { grid-template-columns: repeat(3, 1fr); } }

/* Document frame + premium hover (BRIEF: frame/spacing/hover refinement). Restrained bronze-tinted
   1px border around the complete item; on hover/keyboard-focus the border warms slightly and the
   card lifts a few px — transform/opacity/border-color only (BRIEF §7), one-time, no loop. Gated
   behind (hover: hover) for the mouse-hover part so touch never gets a stuck hover state (BRIEF §6);
   :focus-within gives keyboard users the same feedback regardless of pointer type, on top of the
   sitewide :focus-visible outline (base.css), which is untouched and still applies underneath. */
.lib-card {
	position: relative; background: var(--c-bg); display: flex; align-items: center; gap: 1rem; padding: 0.85rem;
	border: 1px solid rgb(192 138 62 / 0.32);
	transition: transform 300ms var(--ease), border-color 300ms var(--ease);
}
@media (min-width: 640px) { .lib-card { flex-direction: column; align-items: stretch; padding: 0 0 1.5rem; gap: 0; } }
@media (hover: hover) {
	.lib-card:hover { transform: translateY(-4px); border-color: rgb(192 138 62 / 0.6); }
	.lib-card:hover .lib-cover { filter: brightness(1.06); }
	.lib-card:hover .lib-card__act { color: var(--c-ink); }
}
.lib-card:focus-within { transform: translateY(-4px); border-color: rgb(192 138 62 / 0.6); }
.lib-card:focus-within .lib-cover { filter: brightness(1.06); }

/* Optional micro-effect: a thin bronze line draws in along the card's top edge, once per hover —
   plain CSS transform (scaleX from the reading-start side, matching the site's existing hairline-
   reveal idiom, e.g. .in-row__link::after), no SVG/dasharray/glow/loop — deliberately unlike the
   Hero Travelling Light in technique and feel. */
.lib-card::after {
	content: ""; position: absolute; inset-inline: -1px; inset-block-start: -1px; height: 2px;
	background: linear-gradient(90deg, var(--c-gold), var(--c-gold-soft));
	transform: scaleX(0); transform-origin: var(--o-start); transition: transform 350ms var(--ease);
	pointer-events: none;
}
@media (hover: hover) { .lib-card:hover::after { transform: scaleX(1); } }
.lib-card:focus-within::after { transform: scaleX(1); }

.lib-cover { display: block; position: relative; aspect-ratio: 3 / 4; overflow: hidden; background: var(--c-ink); flex: none; width: 4.5rem; }
.lib-cover--img img { width: 100%; height: 100%; object-fit: cover; transition: transform 700ms var(--ease); }
@media (min-width: 640px) { .lib-cover { width: 100%; } }
/* Card-height reduction (archive grid only — the mobile row thumbnail above and the document-detail
   page's own cover, .lib-detail__cover, are untouched: this is scoped to .lib-card specifically).
   ~30% of the previous card height at the 1440px reference width (measured 730px → ~218px); the
   proportion eases up slightly at narrower grid widths as the fixed-height text block below the
   cover takes up relatively more of the shorter card — still a 60%+ reduction everywhere tested. */
@media (min-width: 640px) { .lib-card .lib-cover { aspect-ratio: 6 / 1; } }

/* Generated fallback cover (BRIEF §12/13/60): pure HTML/CSS, THEEB identity, no icons/gradients. */
.lib-cover--gen {
	display: flex; flex-direction: column; justify-content: space-between;
	padding: 0.65rem; background: linear-gradient(180deg, var(--c-ink), var(--c-brown));
	color: var(--c-text-on-dark); text-align: center;
}
@media (min-width: 640px) { .lib-cover--gen { padding: 1.5rem 1.25rem; } }
.lib-cover__mark { font-family: var(--font-label); font-size: 0.5rem; letter-spacing: 0.16em; text-transform: uppercase; color: rgb(247 242 233 / 0.55); }
html:lang(ar) .lib-cover__mark { font-family: var(--font-body); letter-spacing: 0.03em; text-transform: none; }
.lib-cover__kind { display: none; margin-block-start: 0.15rem; font-family: var(--font-label); font-size: 0.5625rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--c-gold-soft); position: relative; padding-block-start: 0.6rem; }
html:lang(ar) .lib-cover__kind { font-family: var(--font-body); letter-spacing: 0.04em; text-transform: none; }
.lib-cover__kind::before { content: ""; position: absolute; inset-inline: 35%; inset-block-start: 0; height: 1px; background: var(--c-gold); }
@media (min-width: 640px) { .lib-cover__kind { display: block; } }
.lib-cover__title { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; margin-block: auto; padding-block: 0.75rem; font-family: var(--font-display); font-size: 0.8125rem; font-weight: 400; line-height: 1.5; }
html:lang(en) .lib-cover__title { font-family: var(--font-label); letter-spacing: -0.01em; }
@media (min-width: 640px) { .lib-cover__title { font-size: clamp(0.9375rem, 0.8rem + 0.6vw, 1.0625rem); -webkit-line-clamp: 6; } }
.lib-cover__meta { display: none; font-size: 0.625rem; color: rgb(247 242 233 / 0.45); }
@media (min-width: 640px) { .lib-cover__meta { display: block; } }

/* Rebalance the fallback cover's own internal stack for the much shorter archive-card banner (still
   the same mark/title content and typography scale — only re-centered, and the kind/meta lines step
   aside since there's no room for a 4-tier stack in ~50–85px; they still show in full on the
   document-detail page's own cover, which keeps the original tall proportions). */
@media (min-width: 640px) {
	.lib-card .lib-cover--gen { padding: 0.4rem 1rem; justify-content: center; gap: 0.2rem; }
	.lib-card .lib-cover__kind, .lib-card .lib-cover__meta { display: none; }
	.lib-card .lib-cover__title { margin: 0; padding: 0; -webkit-line-clamp: 1; }
}

.lib-card__link { display: flex; align-items: center; gap: 1rem; flex: 1; min-width: 0; }
@media (min-width: 640px) { .lib-card__link { flex-direction: column; align-items: stretch; gap: 0; } }
.lib-card__body { display: grid; gap: 0.2rem; min-width: 0; }
@media (min-width: 640px) { .lib-card__body { padding: 1rem 0.9rem 0; gap: 0.3rem; } }
.lib-card__title { font-family: var(--font-display); font-size: 1.0625rem; font-weight: 400; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; transition: color var(--dur-base) var(--ease); }
html:lang(en) .lib-card__title { font-family: var(--font-label); letter-spacing: -0.01em; line-height: 1.35; }
/* THEEB-REFINEMENT-MOBILE-TYPOGRAPHY: 17px → 15px on the smallest phones (the row layout below
   640px, matching library.css's own existing breakpoint) — card design/frame untouched. */
@media (max-width: 639px) { .lib-card__title { font-size: 0.9375rem; } }
.lib-card__meta { font-size: var(--fs-caption); color: var(--c-text-muted); }
@media (hover: hover) {
	.lib-card:hover .lib-card__title { color: var(--c-gold-ink); }
	.lib-card:hover .lib-cover--img img { transform: scale(1.03); }
}
.lib-card:focus-within .lib-card__title { color: var(--c-gold-ink); }
.lib-card__actions { display: flex; align-items: center; gap: 0.5rem; flex: none; }
@media (min-width: 640px) { .lib-card__actions { padding: 0.6rem 0.9rem 0; } }
.lib-card:focus-within .lib-card__act { color: var(--c-ink); }
.lib-card__act { padding-block: 0.35rem; font-size: var(--fs-small); font-weight: 500; color: var(--c-gold-ink); transition: color var(--dur-fast) var(--ease); }
.lib-card__act:hover, .lib-card__act:focus-visible { color: var(--c-ink); }
.lib-card__sep { width: 3px; height: 3px; border-radius: 50%; background: var(--c-line); }

.in-empty { border-block-start: 1px solid var(--c-line); }

/* ---- Document detail (BRIEF §121–125): editorial split, cover second on mobile ---------------- */
.lib-detail__grid { display: grid; gap: clamp(2rem, 4vw, 3rem); }
.lib-detail__main { min-width: 0; order: 1; }
.lib-detail__side { order: 2; }
@media (min-width: 1024px) {
	.lib-detail__grid { grid-template-columns: minmax(0, 7fr) minmax(0, 3fr); align-items: start; }
	.lib-detail__side { position: sticky; inset-block-start: calc(var(--header-h-scrolled) + 2rem); }
}
.lib-detail__lead { font-size: var(--fs-lead); line-height: 1.85; color: var(--c-text-muted); max-width: 60ch; }
.lib-detail__meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 1.25rem; margin-block: var(--space-4); padding-block: 1.1rem; border-block: 1px solid var(--c-line); }
.lib-detail__meta dt { font-family: var(--font-label); font-size: 0.6875rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--c-text-muted); }
html:lang(ar) .lib-detail__meta dt { font-family: var(--font-body); letter-spacing: 0.02em; text-transform: none; font-size: 0.8125rem; }
.lib-detail__meta dd { margin: 0.2rem 0 0; font-size: var(--fs-small); }
.lib-detail__body { margin-block-end: var(--space-4); }
.lib-detail__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 2rem; }
.lib-detail__unavailable { color: var(--c-text-muted); font-size: var(--fs-small); }

/* Semantic action icons (View keeps the existing shared .arrow unchanged). Same stroke weight/size
   as the site's existing arrow icon, own classes so they never inherit the generic .arrow hover
   rule (which nudges horizontally) — each gets a movement that matches its own meaning instead. */
.lib-icon { flex: none; transition: transform var(--dur-fast) var(--ease); }
.link-line:hover .lib-icon--download, .link-line:focus-visible .lib-icon--download { transform: translateY(2px); }
/* Curved return/back icon: drawn pointing left (its raw authored direction). scaleX(var(--dir)) —
   the SAME formula the sitewide base .arrow uses for its own (rightward) raw direction — leaves it
   pointing left in LTR (the universal browser-back reading) and mirrors it to point right in RTL,
   i.e. back toward the reading-start side, consistent with the rest of the site's directional icons. */
.lib-icon--back { transform: scaleX(var(--dir)); }
.link-line:hover .lib-icon--back, .link-line:focus-visible .lib-icon--back { transform: scaleX(var(--dir)) rotate(-10deg); }
@media (prefers-reduced-motion: reduce) { .lib-icon { transition: none; } }
.lib-detail__cover { display: block; width: 100%; max-width: 18rem; margin-inline: auto; }
@media (min-width: 1024px) { .lib-detail__cover { margin-inline: 0; } }

/* ---- Lazy PDF viewer (BRIEF §22–25/64–68): empty until requested, generous but not extreme height */
.lib-viewer { margin-block-start: var(--space-5); border: 1px solid var(--c-line); }
.lib-viewer__bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 1rem; border-block-end: 1px solid var(--c-line); background: var(--c-sand); }
.lib-viewer__title { font-size: var(--fs-small); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-viewer__bar-actions { display: flex; align-items: center; gap: 1rem; flex: none; }
.lib-viewer__bar-actions a { font-size: var(--fs-caption); color: var(--c-gold-ink); }
.lib-viewer__bar-actions button { display: grid; place-items: center; width: 2rem; height: 2rem; color: var(--c-text-muted); }
.lib-viewer__bar-actions button:hover { color: var(--c-ink); }
.lib-viewer__frame { position: relative; height: min(82vh, 68rem); background: var(--c-sand); }
.lib-viewer__frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.lib-viewer.is-loading .lib-viewer__frame::after {
	content: ""; position: absolute; inset-block-start: 1rem; inset-inline-end: 1rem; width: 1rem; height: 1rem;
	border: 2px solid var(--c-line); border-inline-start-color: var(--c-gold); border-radius: 50%;
	animation: lib-spin 800ms linear infinite;
}
@keyframes lib-spin { to { transform: rotate(360deg); } }
.lib-viewer__fallback { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; padding: 1.5rem; font-size: var(--fs-small); color: var(--c-text-muted); }
.lib-viewer__fallback a { color: var(--c-gold-ink); font-weight: 500; }

@media (max-width: 767px) {
	.lib-viewer__frame { height: min(75vh, 42rem); }
}
@media (prefers-reduced-motion: reduce) {
	.lib-viewer.is-loading .lib-viewer__frame::after { animation: none; }
}
