/**
 * MSH Photo Search - public search page.
 * RTL-first via CSS logical properties; accent matches the site theme
 * and can be overridden from plugin settings (--msh-accent).
 */

.msh-ps {
	--msh-accent: #1abc9c;
	--msh-text: #222;
	--msh-muted: #666;
	--msh-border: #ddd;
	--msh-bg: #fff;
	--msh-radius: 8px;
	--msh-field-font: 1.7rem;
	--msh-field-height: 3.2em; /* Relative to the field font. */
	--msh-btn-bg: #69727d;
	color: var(--msh-text);
}

/* One size for every control: search, filters, buttons, inquiry fields.
   Scoped by ID so theme button/input rules cannot win on specificity -
   otherwise the search button renders shorter than its input. */
#msh-ps-app input,
#msh-ps-app select,
#msh-ps-app textarea,
#msh-ps-app .msh-ps-btn {
	font-size: var(--msh-field-font);
	line-height: 1.2;
}

#msh-ps-app input:not([type="checkbox"]):not(.msh-ps-hp),
#msh-ps-app select,
#msh-ps-app .msh-ps-btn {
	height: var(--msh-field-height);
	padding-block: 0;
	box-sizing: border-box;
}

.msh-ps *,
.msh-ps *::before,
.msh-ps *::after {
	box-sizing: border-box;
}

/* One font for everything, including form controls (which never inherit
   it on their own). ID-scoped so theme rules cannot win. */
#msh-ps-app,
#msh-ps-app * {
	font-family: var(--msh-font, Assistant), sans-serif;
}

.msh-ps-intro {
	margin-block-end: 1rem;
}

/* Search bar */

.msh-ps-searchbar {
	display: flex;
	gap: 8px;
	margin-block-end: 12px;
}

.msh-ps-search-wrap {
	position: relative;
	flex: 1;
}

#msh-ps-q {
	width: 100%;
	padding-inline: 14px;
	border: 1px solid var(--msh-border);
	border-radius: var(--msh-radius);
	background: var(--msh-bg);
}

#msh-ps-q:focus {
	outline: 2px solid var(--msh-accent);
	outline-offset: 1px;
	border-color: var(--msh-accent);
}

#msh-ps-suggestions {
	position: absolute;
	inset-inline: 0;
	inset-block-start: 100%;
	z-index: 30;
	margin: 4px 0 0;
	padding: 4px;
	list-style: none;
	background: var(--msh-bg);
	border: 1px solid var(--msh-border);
	border-radius: var(--msh-radius);
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
	max-height: 320px;
	overflow-y: auto;
}

#msh-ps-suggestions li {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
	padding: 8px 10px;
	border-radius: 6px;
	cursor: pointer;
}

#msh-ps-suggestions li:hover,
#msh-ps-suggestions li:focus {
	background: color-mix(in srgb, var(--msh-accent) 12%, transparent);
	outline: none;
}

.msh-ps-sug-type {
	font-size: 0.8em;
	color: var(--msh-muted);
	border: 1px solid var(--msh-border);
	border-radius: 999px;
	padding: 1px 8px;
	white-space: nowrap;
}

/* Buttons */

.msh-ps-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding-inline: 18px;
	border: 1px solid var(--msh-border);
	border-radius: var(--msh-radius);
	background: var(--msh-bg);
	color: var(--msh-text);
	cursor: pointer;
	text-decoration: none;
	text-align: center;
}

.msh-ps-btn:hover {
	border-color: var(--msh-accent);
	color: var(--msh-accent);
}

/* Search and Send share one look: the background never changes, only
   the label darkens on hover. ID-scoped so the theme cannot recolour it. */
#msh-ps-app .msh-ps-btn-primary {
	background: var(--msh-btn-bg);
	border-color: var(--msh-btn-bg);
	color: #fff;
}

#msh-ps-app .msh-ps-btn-primary:hover,
#msh-ps-app .msh-ps-btn-primary:focus-visible {
	background: var(--msh-btn-bg);
	border-color: var(--msh-btn-bg);
	color: #000;
}

.msh-ps-btn-whatsapp,
.msh-ps-btn-whatsapp:hover {
	background: #25d366;
	border-color: #25d366;
	color: #fff;
}

.msh-ps-btn:focus-visible {
	outline: 2px solid var(--msh-accent);
	outline-offset: 2px;
}

/* Filters */

.msh-ps-filters {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	align-items: end;
	margin-block-end: 8px;
}

.msh-ps-filter {
	display: flex;
	flex-direction: column;
	gap: 2px;
	font-size: 1.05rem;
	color: var(--msh-muted);
}

.msh-ps-filter select,
.msh-ps-filter input {
	padding-inline: 10px;
	border: 1px solid var(--msh-border);
	border-radius: 6px;
	background: var(--msh-bg);
	min-width: 160px;
}

.msh-ps-count {
	color: var(--msh-muted);
	min-height: 1.2em;
	margin-block: 4px;
}

/* Grid */

.msh-ps-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
	gap: 12px;
}

.msh-ps-card {
	position: relative;
	display: block;
	padding: 0;
	border: 1px solid #000;
	border-radius: 0;
	overflow: hidden;
	cursor: pointer;
	background: #f2f2f2;
	aspect-ratio: 4 / 3;
	text-align: start;
}

.msh-ps-card img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	transition: transform 0.25s ease;
}

.msh-ps-card:hover img,
.msh-ps-card:focus-visible img {
	transform: scale(1.04);
}

.msh-ps-card:focus-visible {
	outline: 3px solid var(--msh-accent);
	outline-offset: 2px;
}

.msh-ps-card-meta {
	position: absolute;
	inset-inline: 0;
	inset-block-end: 0;
	display: flex;
	justify-content: space-between;
	gap: 8px;
	padding: 20px 10px 8px;
	color: #fff;
	font-size: 0.85rem;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.65), transparent);
	opacity: 0;
	transition: opacity 0.2s ease;
}

.msh-ps-card:hover .msh-ps-card-meta,
.msh-ps-card:focus-visible .msh-ps-card-meta {
	opacity: 1;
}

.msh-ps-card-title {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Single photo page */

.msh-ps-single {
	max-width: 1100px;
	margin-inline: auto;
}

.msh-ps-single-figure {
	margin: 0 0 16px;
}

.msh-ps-single-figure img {
	max-width: 100%;
	height: auto;
	display: block;
	border: var(--msh-img-border, 2px) solid #000;
}

.msh-ps-single-figure figcaption {
	white-space: pre-line;
	color: var(--msh-muted);
	font-size: 1rem;
	margin-block-start: 8px;
}

.msh-ps-single .msh-ps-lb-meta {
	max-width: 600px;
}

.msh-ps-status {
	text-align: center;
	color: var(--msh-muted);
	padding-block: 16px;
	min-height: 1.4em;
}

.msh-ps-sentinel {
	height: 1px;
}

.msh-ps-footer-note {
	margin-block-start: 1.5rem;
	color: var(--msh-muted);
	font-size: 0.9rem;
}

/* Lightbox */

.msh-ps-noscroll {
	overflow: hidden;
}

.msh-ps-lightbox {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
}

.msh-ps-lightbox[hidden] {
	display: none;
}

.msh-ps-lightbox-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.82);
}

.msh-ps-lightbox-inner {
	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
	grid-template-rows: minmax(0, 1fr); /* Rows may shrink so children can scroll. */
	gap: 0;
	width: min(1100px, 94vw);
	height: 90vh;
	background: var(--msh-bg, #fff);
	border-radius: 10px;
	overflow: hidden;
}

.msh-ps-lb-figure {
	margin: 0;
	background: #111;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0; /* Without this a grid item never shrinks below its content. */
	overflow: hidden;
}

#msh-ps-lb-img {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	display: block;
	border: var(--msh-img-border, 2px) solid #000;
}

.msh-ps-lb-panel {
	padding: 20px;
	background: var(--msh-bg);
	min-height: 0; /* Enables the scrollbar below instead of overflowing the dialog. */
	overflow-y: auto;
	overscroll-behavior: contain;
}

.msh-ps-lb-panel h2 {
	margin: 0 0 8px;
	font-size: 1.15rem;
}

/* Caption and details sit side by side, one row, and stack only when
   the panel is genuinely too narrow for two readable columns. */
.msh-ps-lb-info {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 12px;
	font-size: 14px; /* px on purpose: the theme redefines the rem base. */
	margin-block: 10px;
}

#msh-ps-lb-caption {
	white-space: pre-line;
	color: var(--msh-muted);
	font-size: inherit;
	margin: 0;
}

/* Label / value columns; max-content keeps every label the same width
   so the values line up in one clean second column. */
.msh-ps-lb-meta {
	display: grid;
	grid-template-columns: max-content minmax(0, 1fr);
	gap: 6px 12px;
	align-items: baseline;
	font-size: inherit;
	margin: 0;
	align-content: start;
}

.msh-ps-lb-meta dt {
	color: var(--msh-muted);
	white-space: nowrap;
}

.msh-ps-lb-meta dd {
	margin: 0;
	overflow-wrap: anywhere;
}

.msh-ps-lb-ref {
	font-size: 0.9rem;
}

.msh-ps-lb-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-block: 12px;
}

/* WhatsApp and Call share one row; they wrap only when very narrow. */
.msh-ps-lb-actions .msh-ps-btn {
	flex: 1 1 45%;
	gap: 8px;
}

.msh-ps-icon {
	width: 1.1em;
	height: 1.1em;
	flex: none;
}

.msh-ps-inquiry-title {
	font-size: 1.2rem;
	margin: 18px 0 6px;
}

.msh-ps-lb-close {
	position: absolute;
	inset-block-start: 8px;
	inset-inline-start: 8px;
	z-index: 5;
	width: 36px;
	height: 36px;
	border: none;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.5);
	color: #fff;
	font-size: 1rem;
	cursor: pointer;
}

.msh-ps-lb-nav {
	position: absolute;
	inset-block-start: 50%;
	transform: translateY(-50%);
	z-index: 5;
	width: 40px;
	height: 56px;
	border: none;
	background: rgba(0, 0, 0, 0.4);
	color: #fff;
	font-size: 1.6rem;
	cursor: pointer;
}

.msh-ps-lb-prev {
	inset-inline-end: 0;
}

.msh-ps-lb-next {
	inset-inline-start: 0;
}

.msh-ps-lb-nav:hover,
.msh-ps-lb-close:hover {
	background: rgba(0, 0, 0, 0.7);
}

/* Inquiry form */

.msh-ps-inquiry {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px 10px;
	border-block-start: 1px solid var(--msh-border);
	padding-block-start: 12px;
}

/* Name and phone share the first row; everything else spans both columns. */
.msh-ps-inquiry > * {
	grid-column: 1 / -1;
}

.msh-ps-inquiry > label:nth-of-type(1),
.msh-ps-inquiry > label:nth-of-type(2) {
	grid-column: span 1;
}

.msh-ps-inquiry label {
	display: flex;
	flex-direction: column;
	gap: 2px;
	font-size: 1.05rem;
	color: var(--msh-muted);
}

.msh-ps-inquiry input,
.msh-ps-inquiry textarea {
	padding: 8px 10px;
	border: 1px solid var(--msh-border);
	border-radius: 6px;
}

/* Exactly four lines. The theme sets its own textarea font-size with
   higher specificity, which made an em-based height resolve against the
   wrong font and fit six lines - so pin font, line-height and height
   together at ID specificity. */
#msh-ps-inquiry textarea {
	font-size: var(--msh-field-font) !important;
	line-height: 1.35 !important;
	height: calc(4 * 1.35em + 20px) !important;
	min-height: 0;
	max-height: none;
	resize: vertical;
}

.msh-ps-hp {
	position: absolute !important;
	inset-inline-start: -9999px;
}

.msh-ps-inquiry-status {
	min-height: 1.2em;
	font-size: 1.1rem;
	font-weight: 600;
}

/* Responsive */

@media (max-width: 782px) {
	/* Full-screen sheet: the whole card scrolls, nothing gets clipped. */
	.msh-ps-lightbox {
		align-items: stretch;
		justify-content: stretch;
	}

	.msh-ps-lightbox-inner {
		grid-template-columns: 1fr;
		grid-template-rows: auto auto; /* Whole sheet scrolls, not each pane. */
		width: 100%;
		height: 100dvh;
		max-height: none;
		border-radius: 0;
		overflow-y: auto;
	}

	.msh-ps-lb-figure {
		min-height: 200px;
	}

	.msh-ps-lb-panel {
		overflow: visible;
		padding-block-end: 40px;
	}

	#msh-ps-lb-img {
		max-height: 45vh;
	}

	.msh-ps-grid {
		grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
		gap: 8px;
	}

	.msh-ps-card-meta {
		opacity: 1; /* Always show on touch screens. */
	}
}

@media (max-width: 480px) {
	/* Too narrow for two fields side by side. */
	.msh-ps-inquiry {
		grid-template-columns: 1fr;
	}
}

@media (prefers-reduced-motion: reduce) {
	.msh-ps-card img,
	.msh-ps-card-meta {
		transition: none;
	}
}
