/* NWEF School Choice Index — rankings widget.
   Semantic, theme-friendly baseline. Colors come from custom properties with sensible
   fallbacks; the host theme can override --sc-* (or the referenced brand tokens) to restyle. */

.scindex-rankings {
	--sc-tier-lead: var(--brand-success, #2e7d5b);
	--sc-tier-grow: var(--brand-warning, #b06d0f);
	--sc-tier-lag:  var(--brand-danger,  #a23b4a);
	--sc-bar-track: var(--surface-2, #edf1f5);
	--sc-border:    var(--surface-3, #e2e8f0);
	--sc-muted:     var(--text-muted, #5b6672);
	--sc-radius: 10px;

	display: block;
	color: inherit;
	font: inherit;
	background: #fff;
	border: 1px solid var(--sc-border);
	border-radius: 14px;
	overflow: hidden;
}
.scindex-rankings *,
.scindex-rankings *::before,
.scindex-rankings *::after { box-sizing: border-box; }

/* Neutralize host-section styles that bleed in (.ay-section ul/li/a). Two classes so these win
   over the theme's `.ay-section ul` / `.ay-section a:not(...)` descendant selectors. */
.scindex-rankings .scindex-list { list-style: none; margin: 0; padding: 0; }
.scindex-rankings .scindex-list > li { margin: 0; padding: 0; }
.scindex-rankings .scindex-row-main { text-decoration: none; color: inherit; }

/* Controls -------------------------------------------------------------- */
.scindex-controls {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	align-items: center;
	justify-content: space-between;
	padding: 1rem;
	border-bottom: 1px solid var(--sc-border);
}
.scindex-search-wrap { flex: 1 1 16rem; min-width: 12rem; }
.scindex-search {
	width: 100%;
	padding: 0.6rem 0.85rem;
	font: inherit;
	color: inherit;
	background: #fff;
	border: 1px solid var(--sc-border);
	border-radius: var(--sc-radius);
}
.scindex-search:focus-visible { outline: 2px solid var(--sc-tier-grow); outline-offset: 1px; }

.scindex-sort { display: inline-flex; border: 1px solid var(--sc-border); border-radius: var(--sc-radius); overflow: hidden; }
.scindex-sort-btn {
	appearance: none;
	font: inherit;
	cursor: pointer;
	padding: 0.55rem 0.95rem;
	border: 0;
	background: #fff;
	color: var(--sc-muted);
	line-height: 1.2;
}
.scindex-sort-btn + .scindex-sort-btn { border-left: 1px solid var(--sc-border); }
.scindex-sort-btn[aria-pressed="true"] { background: var(--sc-tier-grow); color: #fff; }
.scindex-sort-btn:focus-visible { outline: 2px solid var(--sc-tier-grow); outline-offset: -2px; }

/* Column header + screen-reader-only ------------------------------------ */
.scindex-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
.scindex-head {
	display: grid;
	grid-template-columns: 2.5rem minmax(6rem, 1fr) minmax(4rem, 9rem) 3.25rem 6rem 1.25rem;
	gap: 0.75rem;
	align-items: end;
	padding: 0.6rem 1rem;
	background: var(--sc-bar-track);
	border-bottom: 1px solid var(--sc-border);
	font-size: 0.72em;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--sc-muted);
}
.scindex-head-rank  { grid-column: 1; }
.scindex-head-name  { grid-column: 2; }
.scindex-head-score { grid-column: 3 / 5; } /* over the bar + number */
.scindex-head-tier  { grid-column: 5; }

/* List + rows ----------------------------------------------------------- */
.scindex-list { list-style: none; margin: 0; padding: 0; }
.scindex-row { background: #fff; }
.scindex-row + .scindex-row { border-top: 1px solid var(--sc-border); }

.scindex-row-main {
	display: grid;
	grid-template-columns: 2.5rem minmax(6rem, 1fr) minmax(4rem, 9rem) 3.25rem 6rem 1.25rem;
	align-items: center;
	gap: 0.75rem;
	width: 100%;
	padding: 0.7rem 1rem;
	font: inherit;
	text-align: left;
	color: inherit;
	text-decoration: none;
	background: transparent;
	border: 0;
	cursor: pointer;
}
.scindex-row-main:hover { background: rgba(0,0,0,0.02); }
.scindex-row-main:focus-visible { outline: 2px solid var(--sc-tier-grow); outline-offset: -2px; }

.scindex-rank { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--sc-muted); }
.scindex-name { font-weight: 600; }
.scindex-score { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.scindex-tier {
	justify-self: start;
	font-size: 0.72em;
	font-weight: 700;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	padding: 0.15em 0.5em;
	border-radius: 999px;
	white-space: nowrap;
	color: #fff;
	background: var(--sc-muted);
}
.scindex-row[data-tier="lead"] .scindex-tier { background: var(--sc-tier-lead); }
.scindex-row[data-tier="grow"] .scindex-tier { background: var(--sc-tier-grow); }
.scindex-row[data-tier="lag"]  .scindex-tier { background: var(--sc-tier-lag); }

/* Score bars ------------------------------------------------------------ */
.scindex-bar {
	position: relative;
	display: block;
	height: 0.5rem;
	border-radius: 999px;
	background: var(--sc-bar-track);
	overflow: hidden;
}
.scindex-fill {
	display: block;
	height: 100%;
	width: var(--pct, 0%);
	border-radius: inherit;
	background: var(--sc-muted);
	transition: width 0.3s ease;
}
.scindex-row[data-tier="lead"] .scindex-fill { background: var(--sc-tier-lead); }
.scindex-row[data-tier="grow"] .scindex-fill { background: var(--sc-tier-grow); }
.scindex-row[data-tier="lag"]  .scindex-fill { background: var(--sc-tier-lag); }

/* Navigate chevron (each row links to the state page) ------------------- */
.scindex-go {
	justify-self: end;
	width: 0.45rem;
	height: 0.45rem;
	border-top: 2px solid var(--sc-muted);
	border-right: 2px solid var(--sc-muted);
	transform: rotate(45deg);
	transition: transform 0.2s ease;
}
.scindex-row-main:hover .scindex-go,
.scindex-row-main:focus-visible .scindex-go { transform: translateX(2px) rotate(45deg); }

.scindex-empty { padding: 1rem; text-align: center; color: var(--sc-muted); }

/* Responsive ------------------------------------------------------------ */
@media (max-width: 640px) {
	/* Header hidden; each row is a self-labeling card that links to the state page
	   (rank number, name, score, colored tier pill; rank/score also carry sr labels). */
	.scindex-head { display: none; }

	.scindex-row-main {
		grid-template-columns: 2.25rem 1fr auto 1rem;
		row-gap: 0.45rem;
	}
	.scindex-rank  { order: 1; }
	.scindex-name  { order: 2; }
	.scindex-score { order: 3; }
	.scindex-go    { order: 4; }
	.scindex-bar   { order: 5; grid-column: 1 / -1; }
	.scindex-tier  { order: 6; grid-column: 1 / -1; justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
	.scindex-fill, .scindex-go { transition: none; }
}
