/* Compare modal: the full-page overlay plus the comparison table it hosts.
   Loaded site-wide (the modal shell lives in the footer), so the fetched table
   fragment is styled wherever the modal opens. Built on the --sg-* tokens. */

/* --- Overlay and dialog --- */
.pdir-compare-modal {
	position: fixed;
	inset: 0;
	z-index: var(--sg-z-modal, 200);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
}

.pdir-compare-modal[hidden] {
	display: none;
}

.pdir-compare-modal__backdrop {
	position: absolute;
	inset: 0;
	background: color-mix(in srgb, var(--sg-ink) 55%, transparent);
	backdrop-filter: blur(2px);
	opacity: 0;
	transition: opacity 0.22s var(--sg-ease);
}

.pdir-compare-modal__dialog {
	position: relative;
	display: flex;
	flex-direction: column;
	width: min(1180px, 100%);
	max-height: 92vh;
	overflow: hidden;
	background: var(--sg-bg);
	border-radius: var(--sg-radius-card);
	box-shadow: var(--sg-shadow-search);
	opacity: 0;
	transform: translateY(14px) scale(0.985);
	transition: opacity 0.22s var(--sg-ease), transform 0.26s var(--sg-ease);
}

/* compare.js unhides the modal, then adds .is-open on the next frame so the
   backdrop fades and the dialog rises; closing reverses it, then hides. */
.pdir-compare-modal.is-open .pdir-compare-modal__backdrop,
.pdir-compare-modal.is-open .pdir-compare-modal__dialog {
	opacity: 1;
}

.pdir-compare-modal.is-open .pdir-compare-modal__dialog {
	transform: none;
}

@media (prefers-reduced-motion: reduce) {
	.pdir-compare-modal__backdrop,
	.pdir-compare-modal__dialog {
		transition: none;
	}

	.pdir-compare-modal__dialog {
		transform: none;
	}
}

.pdir-compare-modal__head {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 16px 24px;
	border-bottom: 1px solid var(--sg-line);
}

.pdir-compare-modal__title {
	margin: 0;
	color: var(--sg-ink);
	font-family: var(--sg-font-head);
	font-size: 1.25rem;
	font-weight: 600;
}

.pdir-compare-modal__close {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	background: var(--sg-bg);
	border: 1px solid var(--sg-line-strong);
	border-radius: var(--sg-radius-pill);
	color: var(--sg-ink);
	line-height: 0;
	cursor: pointer;
}

.pdir-compare-modal__close:hover {
	border-color: var(--sg-ink);
}

.pdir-compare-modal__close:focus-visible {
	outline: 2px solid var(--sg-blue);
	outline-offset: 2px;
}

/* The body hands its bounded height down the flex chain to the table's scroll
   region, so one container scrolls both axes and both scrollbars sit at the
   visible edges. */
.pdir-compare-modal__body {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	min-height: 0;
	overflow: hidden;
	padding: 20px 24px 24px;
}

.pdir-compare-modal__loading {
	margin: 20px 0;
	color: var(--sg-muted);
	text-align: center;
}

/* --- The comparison table (fetched into the modal body) --- */
.pdir-compare {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	justify-content: center;
	min-height: 0;
	margin: 0;
}

.pdir-compare--empty .pdir-compare__prompt {
	max-width: 460px;
	margin: 24px auto;
	padding: 32px 24px;
	text-align: center;
}

.pdir-compare__prompt-title {
	margin: 0 0 8px;
	color: var(--sg-ink);
	font-family: var(--sg-font-head);
	font-size: 1.375rem;
	font-weight: 600;
}

.pdir-compare__prompt-text {
	margin: 0 0 18px;
	color: var(--sg-muted);
	font-size: 0.9375rem;
	line-height: 1.55;
}

.pdir-compare__prompt-link {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding: 10px 22px;
	background: var(--sg-teal-700);
	border-radius: var(--sg-radius-pill);
	color: #fff;
	font-family: var(--sg-font-head);
	font-size: 0.9375rem;
	font-weight: 600;
	text-decoration: none;
}

.pdir-compare__prompt-link:hover {
	background: var(--sg-teal-600);
	color: #fff;
	text-decoration: none;
}

.pdir-compare__scroll {
	flex: 0 1 auto;
	min-height: 0;
	max-height: 100%;
	overflow: auto;
	-webkit-overflow-scrolling: touch;
	/* A soft edge on the right while there is more to scroll to (the cover
	   scrolls with the table and hides the shadow at the end). */
	background:
		linear-gradient(to left, var(--sg-bg), var(--sg-bg)) right / 24px 100% no-repeat local,
		radial-gradient(farthest-side at 100% 50%, rgba(16, 24, 40, 0.16), transparent) right / 14px 100% no-repeat scroll,
		var(--sg-bg);
	border: 1px solid var(--sg-line);
	border-radius: var(--sg-radius-card);
}

.pdir-compare__table {
	width: 100%;
	/* Five firms fit the 1440 dialog and the compare page without scrolling. */
	min-width: calc(170px + var(--pdir-compare-cols, 2) * 190px);
	border-collapse: collapse;
	/* Every firm gets the same width, the featured one included. */
	table-layout: fixed;
}

.pdir-compare__table th,
.pdir-compare__table td {
	padding: 14px 18px;
	border-bottom: 1px solid var(--sg-line);
	text-align: left;
	vertical-align: top;
}

.pdir-compare__table tbody tr:last-child th,
.pdir-compare__table tbody tr:last-child td {
	border-bottom: 0;
}

.pdir-compare__corner,
.pdir-compare__label {
	position: sticky;
	left: 0;
	z-index: 2;
	width: 170px;
	min-width: 160px;
	max-width: 190px;
	overflow-wrap: break-word;
	background: var(--sg-soft);
	border-right: 1px solid var(--sg-line);
}

.pdir-compare__label,
.pdir-compare__corner-text {
	color: var(--sg-muted);
	font-family: var(--sg-font-head);
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

/* Its own line height, so a wrapped "Comparing 3 / firms" sits tight. */
.pdir-compare__corner-text {
	display: block;
	line-height: 1.4;
}

.pdir-compare__firm {
	min-width: 180px;
	background: var(--sg-bg);
}

/* The firm-name row stays in view while the rows scroll up under it in the
   modal, where the table scrolls in its own box. (On the compare page the
   table grows with the page; see .pdir-compare__names.) The corner sits
   above both sticky edges. */
.pdir-compare__table thead th {
	position: sticky;
	top: 0;
	z-index: 1;
	box-shadow: inset 0 -1px 0 var(--sg-line);
}

.pdir-compare__table thead .pdir-compare__corner {
	z-index: 3;
}

/* A link focused while the table scrolls is not hidden under that row. */
.pdir-compare__scroll {
	scroll-padding-top: 110px;
	scroll-padding-left: 170px;
}

@media (max-width: 640px) {
	.pdir-compare__scroll {
		scroll-padding-top: 170px;
		scroll-padding-left: 116px;
	}
}

.pdir-compare__firm-inner {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 6px;
}

/* Above the "Featured" badge's 44px hit area (components.css), which reaches
   up into the name from the badge under it. */
.pdir-compare__firm-name {
	position: relative;
	z-index: 4;
	color: var(--sg-ink);
	font-family: var(--sg-font-head);
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.3;
	text-decoration: none;
}

.pdir-compare__firm-name:hover {
	color: var(--sg-teal-700);
	text-decoration: none;
}

.pdir-compare__remove-form {
	margin: 0;
}

.pdir-compare__remove {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 2px 0;
	background: none;
	border: 0;
	color: var(--sg-red);
	font-family: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	cursor: pointer;
}

.pdir-compare__remove:hover {
	text-decoration: underline;
	text-underline-offset: 2px;
}

.pdir-compare__remove:focus-visible,
.pdir-compare__firm-name:focus-visible,
.pdir-compare__link:focus-visible {
	outline: 2px solid var(--sg-blue);
	outline-offset: 2px;
}

/* The reviews row stands out in the site's teal (gold is for stars). */
.pdir-compare__row.is-highlight th,
.pdir-compare__row.is-highlight td {
	background: color-mix(in srgb, var(--sg-teal-50) 60%, var(--sg-bg));
}

.pdir-compare__row.is-highlight .pdir-compare__label {
	background: var(--sg-teal-50);
	color: var(--sg-teal-700);
}

.pdir-compare__rating {
	display: flex;
	flex-direction: column;
	/* Content width, so the star fill's width:% clips against the strip. */
	align-items: flex-start;
	gap: 3px;
	font-size: 0.8125rem;
}

.pdir-compare__rating .pdir-stars {
	width: max-content;
	color: var(--sg-line-strong);
}

.pdir-compare__rating .pdir-stars__fill {
	color: var(--sg-gold);
}

.pdir-compare__avg {
	color: var(--sg-ink);
	font-weight: 700;
}

.pdir-compare__count {
	color: var(--sg-muted);
	font-size: 0.75rem;
}

.pdir-compare__unrated {
	color: var(--sg-muted);
	font-size: 0.8125rem;
}

.pdir-compare__cell {
	color: var(--sg-text);
	font-size: 0.875rem;
	line-height: 1.5;
}

/* Plain stored values ("authorised") read as sentences. */
.pdir-compare__cell > span:only-child:not([class]) {
	display: inline-block;
}

.pdir-compare__cell > span:only-child:not([class])::first-letter {
	text-transform: uppercase;
}

.pdir-compare__link {
	color: var(--sg-blue);
	font-size: 0.8125rem;
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.pdir-compare__stack,
.pdir-compare__checklist {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.pdir-compare__checklist li {
	position: relative;
	padding-left: 20px;
	line-height: 1.4;
}

.pdir-compare__checklist li::before {
	content: "";
	position: absolute;
	top: 4px;
	left: 1px;
	width: 11px;
	height: 6px;
	border-bottom: 2px solid var(--sg-teal-700);
	border-left: 2px solid var(--sg-teal-700);
	transform: rotate(-45deg);
}

.pdir-compare__empty-cell {
	color: var(--sg-line-strong);
}

/* Term lists (practice areas, languages) read as a plain comma-separated
   list in a table cell, not a cloud of pills (a firm can list 26 areas). */
.pdir-compare .pdir-chips {
	display: block;
	margin: 0;
	padding: 0;
	list-style: none;
	color: var(--sg-text);
	font-size: 0.875rem;
	line-height: 1.55;
}

.pdir-compare .pdir-chips li {
	display: inline;
}

.pdir-compare .pdir-chips li:not(:last-child)::after {
	content: ", ";
}

.pdir-compare .pdir-chip {
	display: inline;
	padding: 0;
	background: none;
	border: 0;
	color: inherit;
	font: inherit;
	white-space: normal;
}

/* compare.js shows the first few terms of a long list and an "and N more"
   button; without JavaScript, and in print, the whole list shows. */
.pdir-compare .pdir-chips.is-trimmed .pdir-compare__extra {
	display: none;
}

.pdir-compare .pdir-chips.is-trimmed .pdir-compare__last-shown::after {
	content: none;
}

.pdir-compare__more {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding: 0;
	background: none;
	border: 0;
	color: var(--sg-teal-700);
	font-family: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
	cursor: pointer;
}

.pdir-compare__more:hover {
	color: var(--sg-ink);
}

.pdir-compare__more:focus-visible {
	outline: 2px solid var(--sg-blue);
	outline-offset: 2px;
}

@media print {
	.pdir-compare .pdir-chips.is-trimmed .pdir-compare__extra {
		display: inline;
	}

	.pdir-compare .pdir-chips.is-trimmed .pdir-compare__last-shown::after {
		content: ", ";
	}

	.pdir-compare__more {
		display: none;
	}

	.pdir-compare .pdir-compare__names {
		display: none;
	}

	.pdir-compare__table thead th {
		position: static;
	}
}

/* The compare page gives the table the full page width; its notes keep a
   reading width. */
.sg-page--compare .sg-prose {
	max-width: 760px;
}

/* Space between the table and the notes under it. */
.sg-page--compare .pdir-compare + * {
	margin-top: 56px;
}

/* The compare page: a way back to the list above the table. */
.pdir-compare-back {
	margin: 0 0 16px;
}

.pdir-compare-back__link {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	color: var(--sg-teal-700);
	font-weight: 600;
}

/* The compare page: a slim copy of the firm-name row that stays under the
   site header once the real row has scrolled away (compare.js pageNames()).
   It takes no space; the columns line up with the table's. */
.pdir-compare__names {
	position: sticky;
	top: calc(var(--sg-header-h, 72px) + 1px + var(--wp-admin--admin-bar--height, 0px));
	z-index: 5;
	height: 0;
}

.pdir-compare__names[hidden] {
	display: none;
}

/* A focused link is scrolled clear of the header and the copied row, with
   the same 16px gap as the global scroll padding. */
html:has(.pdir-compare__names:not([hidden])) {
	scroll-padding-top: calc(var(--sg-header-h, 72px) + 1px + var(--wp-admin--admin-bar--height, 0px) + var(--pdir-compare-names-h, 96px) + 16px);
}

.pdir-compare__names-inner {
	position: absolute;
	top: 0;
	right: 0;
	left: 0;
	display: flex;
	overflow: hidden;
	background: var(--sg-bg);
	border: 1px solid var(--sg-line);
	box-shadow: 0 10px 18px -14px rgba(16, 24, 40, 0.45);
}

.pdir-compare__names-corner {
	flex: none;
	padding: 10px 18px;
	background: var(--sg-soft);
	border-right: 1px solid var(--sg-line);
	color: var(--sg-muted);
	font-family: var(--sg-font-head);
	font-size: 0.75rem;
	font-weight: 600;
	line-height: 1.4;
}

.pdir-compare__names-view {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
}

.pdir-compare__names-row {
	display: flex;
}

.pdir-compare__names-firm {
	flex: none;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 4px;
	padding: 10px 18px;
}

.pdir-compare__names-name {
	display: -webkit-box;
	overflow: hidden;
	color: var(--sg-ink);
	font-family: var(--sg-font-head);
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.3;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

@media (max-width: 640px) {
	.pdir-compare-modal {
		padding: 0;
	}

	.pdir-compare-modal__dialog {
		width: 100%;
		height: 100%;
		max-height: 100vh;
		border-radius: 0;
	}

	.pdir-compare-modal__head {
		padding: 12px 16px;
	}

	.pdir-compare-modal__body {
		padding: 12px 12px 16px;
	}

	.pdir-compare__table th,
	.pdir-compare__table td {
		padding: 12px 14px;
	}

	.pdir-compare__corner,
	.pdir-compare__label {
		width: 116px;
		min-width: 104px;
		max-width: 116px;
	}

	/* Long labels ("Authorisation status", "Accreditations") fit the narrow
	   column in sentence case and wrap between words. */
	.pdir-compare__table th.pdir-compare__label {
		padding-right: 10px;
		padding-left: 12px;
		letter-spacing: 0;
		text-transform: none;
	}

	/* The corner matches the labels under it. */
	.pdir-compare__table th.pdir-compare__corner {
		padding-right: 10px;
		padding-left: 12px;
	}

	.pdir-compare__corner-text {
		letter-spacing: 0;
		text-transform: none;
	}

	.pdir-compare__names-corner {
		padding-right: 10px;
		padding-left: 12px;
	}

	.pdir-compare__names-firm {
		padding-right: 14px;
		padding-left: 14px;
	}

	/* Narrow firm columns, so the next firm always shows at the edge as a
	   sign that the table scrolls sideways. */
	.pdir-compare__table {
		min-width: calc(116px + var(--pdir-compare-cols, 2) * 168px);
	}

	.pdir-compare__firm {
		min-width: 160px;
	}
}

/* Touch screens: the table's links and buttons are at least 44px to tap. The
   "Featured" badge keeps its size and its own 44px hit area (components.css),
   with room above and below so it does not overlap the firm name or the
   Remove button. */
@media (pointer: coarse) {
	.pdir-compare__remove,
	.pdir-compare__link,
	.pdir-compare__firm-name {
		display: inline-flex;
		align-items: center;
		min-height: 44px;
	}

	.pdir-compare__remove {
		padding: 0;
	}

	.pdir-compare__firm-inner {
		gap: 0;
	}

	.pdir-compare .pdir-featured-chip {
		margin: 11px 0;
	}
}
