/*
 * Search results rendered by INESC ID Customization.
 *
 * That plugin emits Bootstrap 3 accordion markup (.panel / .panel-collapse /
 * [data-toggle="collapse"]). The old Jevelin theme bundled Bootstrap, which is
 * what made it work; Blocksy does not, so the collapse behaviour is reproduced
 * here. Everything is scoped to .iidcs-results to avoid touching Bootstrap-like
 * markup elsewhere on the site.
 */

/* Wrapper and headings ---------------------------------------------------- */

/*
 * Colour tokens live on the wrapper so a theme can override them in one place.
 * The panels copy the WPBakery "outline" accordion of the Institutional
 * Documents page (.institutional-docs-title): light grey 2px frame, blue title
 * with a green bar on its left, green chevron. --blue / --green come from the
 * site-wide CSS; the hex values are the same colours, used as fallbacks.
 */
.iidcs-results {
	--iidcs-border: #ebebeb;
	--iidcs-text: var(--blue, #005f80);
	--iidcs-accent: var(--green, #97ca3d);
	margin-bottom: 2.5rem;
	/*
	 * Site width and side margins. The default render hook
	 * (blocksy:content:top) prints this block directly in <main>, before
	 * Blocksy's .ct-container, so it would otherwise span the full viewport.
	 * Same sizing as .ct-container, read from Blocksy's own variables; with
	 * another theme (or when printed inside the loop via the loop_start
	 * fallback) the variables are missing and the block keeps 100% of its
	 * container.
	 */
	width: min(100%, var(--theme-container-width, 100%));
	max-width: var(--theme-normal-container-max-width, none);
	margin-left: auto;
	margin-right: auto;
}

/*
 * Printed directly in <main> (Blocksy hook): keep the theme's top spacing so
 * the block does not touch the header (.ct-container gets the same value).
 */
main > .iidcs-results {
	padding-top: var(--theme-content-vertical-spacing, 0);
}

/*
 * Section headings. inesc-search.php demotes the upstream <h1>s to <h2> (the
 * theme prints the page's <h1>); h1 is kept in the selectors so the look does
 * not depend on that rewrite.
 */
.iidcs-results h1,
.iidcs-results h2 {
	font-size: 1.5rem;
	line-height: 1.3;
	margin: 2rem 0 1rem;
}

.iidcs-results > h1:first-child,
.iidcs-results > h2:first-child {
	margin-top: 0;
}

.iidcs-posts-heading {
	border-top: 1px solid var(--iidcs-border);
	padding-top: 2rem;
}

/* Panels ------------------------------------------------------------------ */

/*
 * The frame is drawn on the heading and on the body (not on .panel), as in the
 * WPBakery accordion: closed panels are separate boxes 10px apart; an open
 * panel's heading overlaps the body's top border by 2px so they read as one.
 */
.iidcs-results .panel {
	margin: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	box-shadow: none;
}

.iidcs-results .panel-heading {
	margin: 0 0 10px;
	padding: 0;
	border: 2px solid var(--iidcs-border);
	border-radius: 0;
	background: transparent;
}

.iidcs-results .panel:has(.panel-collapse.iidcs-open) .panel-heading {
	margin-bottom: -2px;
}

.iidcs-results .panel-title {
	margin: 0;
	font-family: inherit;
	font-size: inherit;
	font-weight: var(--normal, 400);
	line-height: 1.5;
	text-transform: none;
}

/*
 * Green bar (::before) + title + chevron (::after). The upstream title is a
 * bare text node inside <a>, so the bar cannot sit on a <span> as it does on
 * the documents page; it is a flex item stretched to the line height instead.
 */
.iidcs-results .panel-title > a {
	display: flex;
	align-items: center;
	gap: 1vw;
	padding: 14px 20px;
	text-decoration: none;
	font-weight: inherit;
	color: var(--iidcs-text);
}

.iidcs-results .panel-title > a::before {
	content: "";
	flex: none;
	align-self: stretch;
	width: 4px;
	background: var(--iidcs-accent);
}

.iidcs-results .panel-title > a:hover,
.iidcs-results .panel-title > a:focus {
	text-decoration: none;
	color: var(--iidcs-text);
}

.iidcs-results .panel-title > a:focus-visible {
	outline: 2px solid var(--iidcs-accent);
	outline-offset: 2px;
}

/*
 * The markup carries <i class="fa-solid fa-circle-plus">, which renders only if
 * Font Awesome happens to be loaded. Hide it and draw an indicator that is
 * always present and always reflects the real open/closed state.
 */
.iidcs-results .panel-title > a > i {
	display: none;
}

/* Same chevron as WPBakery's: an 8px corner with 2px green borders. */
.iidcs-results .panel-title > a::after {
	content: "";
	flex: none;
	width: 8px;
	height: 8px;
	margin-left: auto;
	border-right: 2px solid var(--iidcs-accent);
	border-bottom: 2px solid var(--iidcs-accent);
	transform: translateY(-2px) rotate(45deg);
	transition: transform 0.15s ease-in-out;
}

.iidcs-results .panel-title > a[aria-expanded="true"]::after {
	transform: translateY(2px) rotate(-135deg);
}

/* Collapse ---------------------------------------------------------------- */

.iidcs-results .panel-collapse.collapse {
	display: none;
}

.iidcs-results .panel-collapse.collapse.iidcs-open {
	display: block;
	margin-bottom: 10px;
}

/* Panel body -------------------------------------------------------------- */

.iidcs-results .panel-body {
	padding: 14px 20px;
	border: 2px solid var(--iidcs-border);
	color: var(--iidcs-text);
	overflow-x: auto;
}

.iidcs-results .panel-body > ul {
	margin: 0;
	padding-left: 1.25rem;
}

.iidcs-results .panel-body > ul > li {
	margin-bottom: 0.85rem;
	line-height: 1.5;
}

.iidcs-results .panel-body > ul > li:last-child {
	margin-bottom: 0;
}

/* Keep long unbroken strings (DOIs, URLs) from widening the page. */
.iidcs-results .panel-body a {
	overflow-wrap: anywhere;
}
