/* ============================================================
   SICO Grid — unified grid + facet component
   Visual pass aligned with sicoinc.com card spec.
   ============================================================ */

.sico-grid {
	--sico-border: #ddd;
	--sico-border-strong: #b8b8b8;
	--sico-text: #1f1f1f;
	--sico-muted: #777;
	--sico-accent: #d20f26;
	--sico-bg: #fff;

	display: grid;
	grid-template-columns: 280px 1fr;
	gap: 32px;
	max-width: 1280px;
	margin: 0 auto;
	padding: 0 24px;
	font-family: "Open Sans", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--sico-text);
}

/* Hide-filters toggle: collapse the sidebar and centre the main column
   so the grid sits in the middle of the page, not flush-left. */
.sico-grid[data-filters-hidden="true"] {
	grid-template-columns: minmax(0, 968px);
	justify-content: center;
}
.sico-grid[data-filters-hidden="true"] .sico-grid__filter {
	display: none;
}

/* ---------- Filter sidebar ---------- */

.sico-grid__filter {
	min-width: 0;
}

.sico-grid__filter-head {
	display: none;            /* visible only when drawer is open on mobile */
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	border-bottom: 1px solid var(--sico-border);
}
.sico-grid__filter-title {
	font: 700 16px/1 inherit;
	margin: 0;
}
.sico-grid__filter-close {
	background: none;
	border: 0;
	font-size: 28px;
	line-height: 1;
	padding: 4px 8px;
	cursor: pointer;
	color: var(--sico-text);
}

/* ---------- Postmaster facet — RAW mode + accordion behaviour ---------- */

.sico-grid__facets .wpgb-facet fieldset {
	border: 0;
	padding: 0;
	margin: 0 0 12px;
}
.sico-grid__facets .wpgb-facet fieldset:last-child {
	margin-bottom: 0;
}
/* Section header (was sr-only legend) — now a clickable accordion toggle */
.sico-grid__facets .wpgb-facet legend.wpgb-sr-only {
	position: static !important;
	width: 100% !important;
	height: auto !important;
	clip: auto !important;
	clip-path: none !important;
	overflow: visible !important;
	opacity: 1 !important;
	visibility: visible !important;
	white-space: normal !important;
	display: flex !important;
	align-items: center;
	justify-content: space-between;
	font: 600 14px/1 inherit !important;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--sico-text);
	padding: 14px 0 !important;
	margin: 0 !important;
	cursor: pointer;
	user-select: none;
}
.sico-grid__facets .wpgb-facet legend.wpgb-sr-only::after {
	content: "";
	width: 8px;
	height: 8px;
	border-right: 2px solid var(--sico-text);
	border-bottom: 2px solid var(--sico-text);
	transform: rotate(45deg);
	margin-right: 4px;
	transition: transform 180ms ease;
}
.sico-grid__facets .wpgb-facet[data-collapsed="true"] legend.wpgb-sr-only::after {
	transform: rotate(-45deg);
}
.sico-grid__facets .wpgb-facet[data-collapsed="true"] .wpgb-checkbox-facet {
	display: none;
}

/* Raw-mode checkbox list */
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] ul {
	list-style: none;
	padding: 6px 0 14px;
	margin: 0;
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] li {
	margin: 0;
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] .wpgb-checkbox {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 6px 0;
	cursor: pointer;
	user-select: none;
	position: relative;
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] .wpgb-checkbox::before {
	content: "";
	flex: 0 0 auto;
	width: 16px;
	height: 16px;
	border: 1px solid var(--sico-border-strong);
	border-radius: 2px;
	background: #fff;
	display: inline-block;
	position: relative;
}
/* Checkmark is an SVG inset on the ::before box itself — keeps the tick
   perfectly centred regardless of label wrap (an absolute ::after on the
   parent .wpgb-checkbox would drift on multi-line items). */
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] .wpgb-checkbox[aria-pressed="true"]::before {
	border-color: var(--sico-accent);
	background-color: var(--sico-accent);
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M2.5 6 L5 8.5 L9.5 4' stroke='white' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 90%;
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] .wpgb-checkbox-label {
	font-size: 14px;
	line-height: 1.4;
	color: var(--sico-text);
}
/* Modern pill-badge count. Postmaster (26.04.39+) emits the bare integer
   for raw-mode facets; we render it as a small filled pill to set it
   apart from the label without leaning on parens. */
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] .wpgb-checkbox-count {
	display: inline-block;
	flex: 0 0 auto;
	margin-left: auto;
	padding: 2px 8px;
	min-width: 26px;
	background: #efefef;
	color: #555;
	border-radius: 999px;
	font-size: 11px;
	font-weight: 600;
	line-height: 1.5;
	text-align: center;
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] .wpgb-checkbox[aria-pressed="true"] .wpgb-checkbox-count {
	background: var(--sico-accent);
	color: #fff;
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] .wpgb-checkbox:hover .wpgb-checkbox-label {
	color: var(--sico-accent);
}

/* ---------- Treeview hierarchy ---------- */

/* Indent + a quiet rule between parent and children so nesting reads at
   a glance. Postmaster's toggle is absolutely positioned on the parent
   <li> at top:0/right:0 — we keep that, but reserve right-side space on
   the parent's checkbox row so the count badge doesn't slide under the
   toggle on items with children. */
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] ul ul {
	padding: 0 0 0 18px;
	margin: 4px 0 0 8px;
	border-left: 1px solid #e5e5e5;
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] ul ul ul {
	margin-top: 2px;
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] li[aria-expanded] {
	padding-right: 28px;        /* room for the absolute-positioned toggle (20px + 8px gap) */
}
.sico-grid__facets .wpgb-checkbox-facet[data-output-mode="raw"] li[aria-expanded] > .wpgb-checkbox {
	padding-right: 4px;
}
/* Refine Postmaster's default toggle: a smaller, lighter chevron-style
   square that visually defers to the count badge. */
.sico-grid__facets .wpgb-facet .wpgb-checkbox-facet li[aria-expanded]:after {
	width: 18px;
	height: 18px;
	top: 7px;
	right: 0;
	background-color: transparent;
	border: 1px solid #ddd;
	border-radius: 4px;
	background-image: linear-gradient(#555, #555), linear-gradient(#555, #555);
}
.sico-grid__facets .wpgb-facet .wpgb-checkbox-facet li[aria-expanded]:hover:after {
	border-color: var(--sico-accent);
	background-image: linear-gradient(var(--sico-accent), var(--sico-accent)), linear-gradient(var(--sico-accent), var(--sico-accent));
}

/* ---------- Main column: above-grid bar (Hide Filters / Compare) ---------- */

.sico-grid__main {
	min-width: 0;
}
.sico-grid__bar {
	display: flex;
	align-items: center;
	gap: 16px;
	margin-bottom: 16px;
}
.sico-grid__filter-toggle,
.sico-grid__hide-filters {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 8px 14px;
	background: transparent;
	border: 0;
	font: 600 13px/1 inherit;
	color: var(--sico-text);
	cursor: pointer;
	letter-spacing: 0.02em;
}
.sico-grid__hide-filters::after {
	content: "";
	width: 7px;
	height: 7px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg);                         /* down-chevron when shown */
	transition: transform 180ms ease;
}
.sico-grid[data-filters-hidden="true"] .sico-grid__hide-filters::after {
	transform: rotate(-45deg);                        /* up-chevron when hidden */
}
.sico-grid__hide-filters:hover {
	color: var(--sico-accent);
}
.sico-grid__filter-toggle {
	display: none;            /* mobile-only */
	border: 1px solid var(--sico-border);
	border-radius: 4px;
}
.sico-grid__filter-toggle-count[data-active-count="0"] {
	display: none;
}

/* ---------- Card grid: sicoinc-style border 0/1/1/0 per card ---------- */

.sico-grid__main .wp-grid-builder.wpgb-grid-4 {
	background: transparent !important;
	border: 0 !important;
	overflow: visible;
}
.sico-grid__main .wp-grid-builder.wpgb-grid-4 .wpgb-viewport > div {
	background: transparent !important;
	grid-gap: 0 !important;
}
/* Top + left frame borders go on the EDGE cards, not the wrapper —
   Postmaster's enabled-mode wrapper can be wider than the actual
   card-row width (its absolute-positioning math), which would leave
   the border-top extending past the last column. Drawing the frame
   from cards keeps it locked to the actual card geometry regardless
   of how Postmaster sizes its container. */
@media (min-width: 769px) {                                   /* 3-col desktop */
	.sico-grid__main .wp-grid-builder .wpgb-card:nth-of-type(-n+3) .wpgb-card-inner {
		border-top: 1px solid var(--sico-border) !important;
	}
	.sico-grid__main .wp-grid-builder .wpgb-card:nth-of-type(3n+1) .wpgb-card-inner {
		border-left: 1px solid var(--sico-border) !important;
	}
}
@media (min-width: 577px) and (max-width: 768px) {            /* 3-col tablet (matches grid config) */
	.sico-grid__main .wp-grid-builder .wpgb-card:nth-of-type(-n+3) .wpgb-card-inner {
		border-top: 1px solid var(--sico-border) !important;
	}
	.sico-grid__main .wp-grid-builder .wpgb-card:nth-of-type(3n+1) .wpgb-card-inner {
		border-left: 1px solid var(--sico-border) !important;
	}
}
@media (min-width: 321px) and (max-width: 576px) {            /* 2-col phone */
	.sico-grid__main .wp-grid-builder .wpgb-card:nth-of-type(-n+2) .wpgb-card-inner {
		border-top: 1px solid var(--sico-border) !important;
	}
	.sico-grid__main .wp-grid-builder .wpgb-card:nth-of-type(2n+1) .wpgb-card-inner {
		border-left: 1px solid var(--sico-border) !important;
	}
}
@media (max-width: 320px) {                                    /* 1-col tiny */
	.sico-grid__main .wp-grid-builder .wpgb-card:first-of-type .wpgb-card-inner {
		border-top: 1px solid var(--sico-border) !important;
	}
	.sico-grid__main .wp-grid-builder .wpgb-card .wpgb-card-inner {
		border-left: 1px solid var(--sico-border) !important;
	}
}
.sico-grid__main .wp-grid-builder .wpgb-card {
	margin: 0;
}

/* All card-6 visual rules now live on the card itself — see the CSS tab
   in the Postmaster card builder. The card stores them in its `css`
   column with .wpgb-card-preview as the selector prefix; Postmaster
   substitutes to .wpgb-card-6 and concatenates into the per-grid
   stylesheet at /wpgb/grids/G4C6.css. The arrow itself is a real
   svg_icon_block (settings.blocks.wpgb-block-2) rather than a CSS
   pseudo. Edit either in the card builder and changes propagate. */

/* ---------- Load-more button ---------- */

.sico-grid__load-more {
	display: flex;
	justify-content: center;
	margin: 32px 0 8px;
}
.sico-grid__load-more .wpgb-load-more {
	background: #fff !important;
	color: var(--sico-text) !important;
	border: 1px solid var(--sico-border-strong) !important;
	border-radius: 4px !important;
	padding: 12px 28px !important;
	font: 600 14px/1 "Open Sans", Roboto, Arial, sans-serif !important;
	letter-spacing: 0.02em;
	cursor: pointer;
	transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.sico-grid__load-more .wpgb-load-more:hover {
	background: var(--sico-accent) !important;
	color: #fff !important;
	border-color: var(--sico-accent) !important;
}

/* ---------- Mobile: off-canvas drawer ---------- */

@media (max-width: 768px) {
	.sico-grid {
		display: block;
		padding: 0 16px;
	}
	.sico-grid__hide-filters {
		display: none;        /* desktop-only — drawer is the mobile equivalent */
	}
	.sico-grid__filter-toggle {
		display: inline-flex; /* show on mobile */
	}
	.sico-grid__filter {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		width: min(360px, 88vw);
		max-width: 100%;
		background: #fff;
		z-index: 100000;
		transform: translateX(100%);
		transition: transform 240ms ease-out;
		overflow-y: auto;
		box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
		display: flex;
		flex-direction: column;
	}
	body.admin-bar .sico-grid__filter {
		top: 32px;
	}
	@media (max-width: 782px) {
		body.admin-bar .sico-grid__filter {
			top: 46px;
		}
	}
	.sico-grid__filter[data-open="true"] {
		transform: translateX(0);
	}
	.sico-grid__filter-head {
		display: flex;
		flex: 0 0 auto;
		position: sticky;
		top: 0;
		background: #fff;
		z-index: 1;
	}
	.sico-grid__facets {
		padding: 16px 20px 0;
	}
	.sico-grid__backdrop {
		position: fixed;
		inset: 0;
		background: rgba(0, 0, 0, 0.4);
		z-index: 99999;
		opacity: 0;
		pointer-events: none;
		transition: opacity 240ms ease;
		border: 0;
		padding: 0;
		cursor: pointer;
	}
	.sico-grid[data-drawer-open="true"] .sico-grid__backdrop {
		opacity: 1;
		pointer-events: auto;
	}
	body.sico-grid-locked {
		overflow: hidden;
	}
}

@media (min-width: 769px) {
	.sico-grid__backdrop {
		display: none;
	}
}
