/*
 * usss-analytics. Brand values come only from tokens.css (ski-vault's, unchanged); this file uses
 * them by role. Mobile first: base styles are the phone, `min-width` queries restore the desk.
 * Chart colors (validated with the dataviz palette script, both modes, against the card surface):
 * one series, --chart-1.
 */

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

:root {
	color-scheme: light;
	--surface: hsl(var(--card));
	--ink: hsl(var(--foreground));
	--ink-2: hsl(var(--muted-foreground));
	--hairline: hsl(var(--border));
	--series: hsl(var(--chart-1));
	/* Status: the dataviz method's fixed status palette (never themed, never a series color),
	   always beside an icon and a word. */
	--good: #0ca30c;
	--warning: #fab219;
	--critical: #d03b3b;
	--touch: 44px;
	font-family:
		system-ui,
		-apple-system,
		'Segoe UI',
		Roboto,
		sans-serif;
}

:root.dark {
	color-scheme: dark;
}

body {
	margin: 0;
	background: hsl(var(--background));
	color: var(--ink);
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

a {
	color: hsl(var(--link));
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

/* Header */
.bar {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	min-height: 4rem;
	padding: 0 1rem;
	border-bottom: 1px solid var(--hairline);
}

.brand {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	color: var(--ink);
	font-weight: 700;
	text-decoration: none;
}

.mark {
	border-radius: 0.25rem;
}

:root.dark .mark {
	background: #fff;
	padding: 2px;
}

.badge {
	padding: 0.125rem 0.5rem;
	border-radius: 999px;
	background: hsl(var(--secondary));
	color: hsl(var(--secondary-foreground));
	font-size: 0.75rem;
	font-weight: 600;
}

#sign-out {
	margin-left: auto;
}

/* Controls */
.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: var(--touch);
	min-width: var(--touch);
	padding: 0 1rem;
	border: 1px solid hsl(var(--primary));
	border-radius: var(--radius);
	background: hsl(var(--primary));
	color: hsl(var(--primary-foreground));
	font: inherit;
	font-weight: 600;
	text-decoration: none;
	cursor: pointer;
}

.button:active {
	opacity: 0.85;
}

.button.ghost {
	background: transparent;
	color: var(--ink);
	border-color: var(--hairline);
}

.button.ghost:active {
	background: hsl(var(--muted));
}

.button.small {
	min-height: 2rem;
	padding: 0 0.75rem;
	font-size: 0.875rem;
}

main {
	max-width: 72rem;
	margin: 0 auto;
	padding: 1rem;
}

main[aria-busy='true'] #content {
	opacity: 0.5;
	transition: opacity 120ms;
}

.status {
	color: var(--ink-2);
}

.notice {
	max-width: 36rem;
	margin: 3rem auto;
	text-align: center;
}

.notice h1 {
	font-size: 1.25rem;
}

.notice p {
	color: var(--ink-2);
}

.filters {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 0.75rem;
}

.field {
	display: grid;
	gap: 0.25rem;
	font-size: 0.875rem;
	color: var(--ink-2);
}

select {
	min-height: var(--touch);
	min-width: 12rem;
	padding: 0 0.75rem;
	border: 1px solid hsl(var(--input));
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--ink);
	font: inherit;
}

.segmented {
	display: inline-flex;
	margin: 0;
	padding: 0;
	border: 1px solid hsl(var(--input));
	border-radius: var(--radius);
	overflow: hidden;
}

.segmented label {
	position: relative;
}

.segmented input {
	position: absolute;
	opacity: 0;
	inset: 0;
	margin: 0;
	cursor: pointer;
}

.segmented span {
	display: inline-flex;
	align-items: center;
	min-height: calc(var(--touch) - 2px);
	padding: 0 0.875rem;
	font-size: 0.875rem;
	font-weight: 600;
}

.segmented label + label span {
	border-left: 1px solid hsl(var(--input));
}

.segmented input:checked + span {
	background: hsl(var(--primary));
	color: hsl(var(--primary-foreground));
}

.segmented input:focus-visible + span {
	outline: 2px solid hsl(var(--ring));
	outline-offset: -2px;
}

.segmented label:active span {
	background: hsl(var(--muted));
}

.range {
	margin: 0.5rem 0 1rem;
	color: var(--ink-2);
	font-size: 0.875rem;
}

/* Totals */
.tiles {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.75rem;
	margin-bottom: 0.75rem;
}

.tile {
	display: grid;
	gap: 0.125rem;
	padding: 1rem;
	border: 1px solid var(--hairline);
	border-radius: var(--radius);
	background: var(--surface);
}

.tile.hero {
	grid-column: 1 / -1;
}

.tile-label {
	font-size: 0.875rem;
	color: var(--ink-2);
}

.tile-value {
	font-size: 1.75rem;
	font-weight: 600;
	line-height: 1.2;
}

.tile.hero .tile-value {
	font-size: 3rem;
}

.tile-note {
	font-size: 0.75rem;
	color: var(--ink-2);
}

/* Cards */
.grid {
	display: grid;
	gap: 0.75rem;
	margin-bottom: 0.75rem;
}

.card {
	min-width: 0;
	margin-bottom: 0.75rem;
	padding: 1rem;
	border: 1px solid var(--hairline);
	border-radius: var(--radius);
	background: var(--surface);
}

.grid .card {
	margin-bottom: 0;
}

.card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	margin-bottom: 0.75rem;
}

.card-head h2 {
	margin: 0;
	font-size: 1rem;
}

.chart {
	position: relative;
	min-height: 13rem;
}

.chart svg {
	display: block;
	width: 100%;
	overflow: visible;
}

.chart svg:focus-visible {
	outline: 2px solid hsl(var(--ring));
	outline-offset: 4px;
	border-radius: 2px;
}

.axis text,
.chart text {
	fill: var(--ink-2);
	font-size: 11px;
	font-variant-numeric: tabular-nums;
}

.chart .peak {
	fill: var(--ink);
	font-weight: 600;
}

.grid-line {
	stroke: var(--hairline);
	stroke-width: 1;
	shape-rendering: crispEdges;
}

.baseline {
	stroke: var(--ink-2);
	stroke-opacity: 0.5;
	stroke-width: 1;
	shape-rendering: crispEdges;
}

.mark-series {
	fill: var(--series);
}

.mark-series.active {
	opacity: 0.7;
}

.empty {
	color: var(--ink-2);
	font-size: 0.875rem;
}

/* Ranked bars (roles, surfaces) */
.bars {
	display: grid;
	gap: 0.5rem;
}

.bar-row {
	display: grid;
	grid-template-columns: minmax(6rem, 9rem) 1fr;
	align-items: center;
	gap: 0.75rem;
	font-size: 0.875rem;
}

.bar-name {
	overflow-wrap: anywhere;
}

.bar-track {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	min-width: 0;
}

.bar-fill {
	height: 16px;
	min-width: 2px;
	border-radius: 0 4px 4px 0;
	background: var(--series);
}

.bar-value {
	font-variant-numeric: tabular-nums;
	color: var(--ink);
	white-space: nowrap;
}

/* Tables */
.table-wrap {
	overflow-x: auto;
}

table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.875rem;
}

th,
td {
	padding: 0.5rem 0.5rem;
	border-bottom: 1px solid var(--hairline);
	text-align: left;
	vertical-align: top;
}

th {
	color: var(--ink-2);
	font-weight: 600;
}

td.num,
th.num {
	text-align: right;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.route {
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 0.8125rem;
	overflow-wrap: anywhere;
}

.tag {
	display: inline-block;
	margin-right: 0.375rem;
	padding: 0 0.375rem;
	border-radius: 0.25rem;
	background: hsl(var(--muted));
	color: hsl(var(--muted-foreground));
	font-size: 0.75rem;
	font-weight: 600;
	white-space: nowrap;
}

.footnote {
	margin: 1.5rem 0;
	color: var(--ink-2);
	font-size: 0.75rem;
}

/* Tooltip: value first, label after (dataviz interaction rules) */
.tooltip {
	position: fixed;
	z-index: 10;
	padding: 0.5rem 0.625rem;
	border: 1px solid var(--hairline);
	border-radius: var(--radius);
	background: hsl(var(--popover));
	color: hsl(var(--popover-foreground));
	box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
	font-size: 0.8125rem;
	pointer-events: none;
}

.tooltip strong {
	display: block;
	font-size: 1rem;
	font-variant-numeric: tabular-nums;
}

.tooltip span {
	color: var(--ink-2);
}

@media (min-width: 40rem) {
	.bar {
		padding: 0 1.5rem;
	}
	main {
		padding: 1.5rem;
	}
	.tiles {
		grid-template-columns: 2fr 1fr 1fr;
	}
	.tile.hero {
		grid-column: auto;
	}
}

@media (min-width: 60rem) {
	.grid {
		grid-template-columns: 1fr 1fr;
	}
}

@media (forced-colors: active) {
	.mark-series,
	.bar-fill {
		fill: CanvasText;
		background: CanvasText;
	}
}

/* Pages: Usage | Health. On a phone they take their own row under the header's first. */
.bar {
	flex-wrap: wrap;
}

.nav {
	order: 2;
	display: flex;
	flex-basis: 100%;
	gap: 0.25rem;
	margin: 0 -0.5rem;
}

.nav a {
	display: inline-flex;
	align-items: center;
	min-height: var(--touch);
	padding: 0 0.5rem;
	border-bottom: 2px solid transparent;
	color: var(--ink-2);
	font-weight: 600;
	text-decoration: none;
}

.nav a[aria-current='page'] {
	color: var(--ink);
	border-bottom-color: hsl(var(--primary));
}

:root.dark .nav a[aria-current='page'] {
	border-bottom-color: hsl(var(--ring));
}

.nav a:active {
	background: hsl(var(--muted));
}

#sign-out {
	order: 1;
}

/* Health */
.health-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 0.75rem;
}

.page-title {
	margin: 0;
	font-size: 1.25rem;
}

.pill {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	padding: 0.125rem 0.625rem 0.125rem 0.5rem;
	border: 1px solid var(--hairline);
	border-radius: 999px;
	font-size: 0.875rem;
	font-weight: 600;
	white-space: nowrap;
}

.pill-icon,
.mini {
	flex: none;
	fill: none;
	stroke-width: 2.5;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.pill-icon {
	width: 16px;
	height: 16px;
}

.pill-healthy .pill-icon,
.mini-healthy {
	stroke: var(--good);
}

.pill-degraded .pill-icon,
.mini-degraded {
	stroke: var(--warning);
}

.pill-down .pill-icon,
.mini-down {
	stroke: var(--critical);
}

.mini {
	width: 14px;
	height: 14px;
	margin-right: 0.375rem;
	vertical-align: -2px;
}

.answer {
	white-space: nowrap;
}

.check-name {
	display: block;
	font-weight: 600;
}

.check-url {
	display: block;
	color: var(--ink-2);
	font-size: 0.75rem;
	overflow-wrap: anywhere;
}

.subhead {
	margin: 1rem 0 0.25rem;
	font-size: 0.875rem;
	color: var(--ink-2);
}

.tag-inline {
	margin-left: 0.5rem;
	vertical-align: 2px;
}

@media (min-width: 40rem) {
	.nav {
		order: 0;
		flex-basis: auto;
		margin: 0 0 0 1rem;
	}
	#sign-out {
		order: 0;
		margin-left: auto;
	}
}

@media (forced-colors: active) {
	.pill-icon,
	.mini {
		stroke: CanvasText;
	}
}

/* A table that stacks on a phone: each row a block, its first cell across the top and every other
   cell under it with the column's name (data-label) above the value. */
@media (max-width: 39.99rem) {
	table.stack thead {
		display: none;
	}
	table.stack tr {
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
		gap: 0.25rem 0.75rem;
		padding: 0.625rem 0;
		border-bottom: 1px solid var(--hairline);
	}
	table.stack td {
		display: block;
		padding: 0;
		border: 0;
		text-align: left;
		white-space: normal;
		overflow-wrap: anywhere;
	}
	table.stack td.lead {
		grid-column: 1 / -1;
	}
	table.stack td[data-label]::before {
		content: attr(data-label);
		display: block;
		color: var(--ink-2);
		font-size: 0.75rem;
	}
	table.stack td.answer {
		white-space: normal;
	}
}

.health-head .button {
	flex: none;
}

/* Cost */
.cost-tiles {
	grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
}

.cost-tiles .tile.hero {
	grid-column: 1 / -1;
}

.money {
	font-size: 1.125rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.card-note {
	margin: -0.25rem 0 0.75rem;
	color: var(--ink-2);
	font-size: 0.875rem;
}

.group-row th,
.group-row td {
	padding-top: 1rem;
	color: var(--ink);
	font-weight: 600;
}

td.rate {
	color: var(--ink-2);
	font-size: 0.8125rem;
}

.notice-inline {
	margin: 0 0 0.75rem;
	padding: 0.5rem 0.75rem;
	border: 1px solid var(--hairline);
	border-left: 4px solid var(--warning);
	border-radius: var(--radius);
	background: var(--surface);
	font-size: 0.875rem;
}

@media (min-width: 40rem) {
	.cost-tiles .tile.hero {
		grid-column: auto;
	}
}

@media (max-width: 39.99rem) {
	table.stack tr.group-row {
		display: flex;
		justify-content: space-between;
		border-bottom: 0;
		padding-bottom: 0;
	}
	table.stack tr.group-row th {
		padding: 0;
		border: 0;
	}
}

/* Cost: the disclaimer, then a list of rows that open (a meter list: name, bar, figure, bars aligned) */
.disclaimer {
	display: flex;
	align-items: flex-start;
	gap: 0.75rem;
	margin: 0.25rem 0 1rem;
	padding: 0.75rem 1rem;
	border: 1px solid var(--hairline);
	border-left: 4px solid hsl(var(--ring));
	border-radius: var(--radius);
	background: var(--surface);
	font-size: 0.9375rem;
}

.disclaimer p {
	margin: 0;
}

.disclaimer svg {
	flex: none;
	width: 20px;
	height: 20px;
	margin-top: 2px;
	fill: none;
	stroke: hsl(var(--ring));
	stroke-width: 2;
	stroke-linecap: round;
}

.list-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin: 1.25rem 0 0.5rem;
}

.list-head h2 {
	margin: 0;
	font-size: 1rem;
}

.cost-list {
	margin-bottom: 0.75rem;
	border: 1px solid var(--hairline);
	border-radius: var(--radius);
	background: var(--surface);
	overflow: hidden;
}

.cost-list:empty {
	display: none;
}

.cost-item + .cost-item {
	border-top: 1px solid var(--hairline);
}

.cost-summary {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	grid-template-areas:
		'chev label total'
		'. meter meter';
	align-items: center;
	gap: 0.375rem 0.75rem;
	min-height: var(--touch);
	padding: 0.75rem 1rem;
	list-style: none;
	cursor: pointer;
}

.cost-summary::-webkit-details-marker {
	display: none;
}

.cost-summary:active {
	background: hsl(var(--muted));
}

.cost-summary:focus-visible {
	outline: 2px solid hsl(var(--ring));
	outline-offset: -2px;
}

.chevron {
	grid-area: chev;
	width: 16px;
	height: 16px;
	fill: none;
	stroke: var(--ink-2);
	stroke-width: 2.5;
	stroke-linecap: round;
	stroke-linejoin: round;
	transition: transform 120ms;
}

details[open] > .cost-summary .chevron {
	transform: rotate(90deg);
}

.cost-label {
	grid-area: label;
	display: grid;
	min-width: 0;
}

.cost-name {
	font-weight: 600;
}

.cost-note {
	color: var(--ink-2);
	font-size: 0.8125rem;
}

.cost-meter {
	grid-area: meter;
	display: block;
	height: 8px;
	border-radius: 999px;
	background: hsl(var(--muted));
	overflow: hidden;
}

.cost-fill {
	display: block;
	height: 100%;
	min-width: 2px;
	border-radius: 999px;
	background: var(--series);
}

.cost-total {
	grid-area: total;
	font-size: 1.125rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-align: right;
	white-space: nowrap;
}

.cost-reference {
	color: var(--ink-2);
	font-size: 0.875rem;
	font-weight: 400;
}

.cost-body {
	padding: 0 1rem 1rem;
}

.cost-body > .subhead:first-child {
	margin-top: 0.25rem;
}

@media (min-width: 40rem) {
	.cost-summary {
		grid-template-columns: auto minmax(12rem, 1fr) minmax(0, 1.4fr) 7rem;
		grid-template-areas: 'chev label meter total';
	}
}

@media (prefers-reduced-motion: reduce) {
	.chevron {
		transition: none;
	}
}

@media (forced-colors: active) {
	.cost-fill {
		background: CanvasText;
	}
}

/* Whose data: Prod | Dev in the header. On a phone it shares the first row with the brand and Sign out. */
.env-toggle {
	order: 1;
	display: inline-flex;
	margin-left: auto;
	border: 1px solid hsl(var(--input));
	border-radius: var(--radius);
	overflow: hidden;
}

.env-toggle[hidden] {
	display: none;
}

.env-toggle button {
	min-height: var(--touch);
	min-width: var(--touch);
	padding: 0 0.75rem;
	border: 0;
	background: transparent;
	color: var(--ink-2);
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	cursor: pointer;
}

.env-toggle button + button {
	border-left: 1px solid hsl(var(--input));
}

.env-toggle button[aria-pressed='true'] {
	background: hsl(var(--primary));
	color: hsl(var(--primary-foreground));
	cursor: default;
}

.env-toggle button:active {
	background: hsl(var(--muted));
}

.env-toggle button:focus-visible {
	outline: 2px solid hsl(var(--ring));
	outline-offset: -2px;
}

.env-toggle:not([hidden]) ~ #sign-out {
	margin-left: 0.5rem;
}

@media (min-width: 40rem) {
	.env-toggle {
		order: 0;
	}
}
