/*
 * Forecast chart viewer, styled to the CPWL UI/UX Specification.
 * Token values are copied from the specification's app.css (light theme). The page
 * has no dark theme: first load is light, and the charts themselves are light.
 * Fonts are self-hosted whole-face woff2 files (no CDN, no split subsets), so the
 * Fontsource Jost macron fault cannot occur.
 */

@font-face {
	font-family: 'Montserrat';
	src: url('fonts/Montserrat-600.woff2') format('woff2');
	font-weight: 600;
	font-style: normal;
	font-display: swap;
}
@font-face {
	font-family: 'Jost';
	src: url('fonts/Jost-400.woff2') format('woff2');
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}
@font-face {
	font-family: 'Jost';
	src: url('fonts/Jost-500.woff2') format('woff2');
	font-weight: 500;
	font-style: normal;
	font-display: swap;
}

:root {
	--radius: 0.625rem;
	--primary: oklch(0.259 0.084 255); /* CPWL Dark Blue #00234b */
	--primary-foreground: oklch(0.99 0.005 255);
	--background: oklch(0.99 0.002 230);
	--foreground: oklch(0.464 0.003 264); /* CPWL Charcoal #58595b */
	--card: oklch(1 0 0);
	--secondary: oklch(0.955 0.018 234);
	--secondary-foreground: oklch(0.32 0.06 250);
	--muted: oklch(0.965 0.008 234);
	--muted-foreground: oklch(0.5 0.015 250);
	--border: oklch(0.91 0.012 235);
	--ring: oklch(0.677 0.141 234); /* CPWL Mid Blue: rings and fills only */
	--status-danger: oklch(0.54 0.23 23);
	--status-danger-bg: oklch(0.95 0.04 23);
	--sidebar-foreground: oklch(0.93 0.01 240);

	--font-heading: 'Montserrat', system-ui, sans-serif;
	--font-body: 'Jost', system-ui, sans-serif;
	--gap: 12px; /* gap-3 */
	--card-pad: 12px; /* p-3 */
	--card-border: 2px;
	color-scheme: light;
}

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

html {
	-webkit-text-size-adjust: 100%;
}

body {
	margin: 0;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
	background: var(--background);
	color: var(--foreground);
	font-family: var(--font-body);
	font-weight: 400;
	font-size: 15px;
	line-height: 1.5;
}

h1 {
	font-family: var(--font-heading);
	font-weight: 600;
	color: var(--primary);
	font-size: 1.5rem;
	line-height: 1.25;
	margin: 0;
}

img {
	display: block;
	max-width: 100%;
}

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

.skip-link {
	position: absolute;
	left: 16px;
	top: -48px;
	padding: 8px 12px;
	background: var(--card);
	color: var(--primary);
	border-radius: var(--radius);
	z-index: 10;
}
.skip-link:focus {
	top: 8px;
}

.icon {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}
.icon polygon {
	fill: currentColor;
}

/* ---- Top bar: the navy spine ------------------------------------------------------ */

.topbar {
	background: var(--primary);
	padding: 14px 16px;
	padding-top: max(14px, env(safe-area-inset-top));
}
.topbar-inner {
	max-width: 1440px;
	margin: 0 auto;
}
.topbar-logo {
	width: 240px; /* screen minimum for the secondary logo (spec 3.4) */
	height: auto;
}

/* ---- Page ----------------------------------------------------------------------------- */

.page {
	flex: 1;
	width: 100%;
	max-width: 1440px;
	margin: 0 auto;
	padding: 20px 16px 32px;
}

.page-head {
	margin-bottom: 16px;
}
.issued {
	margin: 4px 0 0;
	color: var(--muted-foreground);
}
.issued + .issued {
	margin-top: 0;
}

.controls {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 12px;
	align-items: center;
	margin-bottom: 16px;
}

/* Segmented day selector */
.segmented {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 4px;
	padding: 4px;
	background: var(--muted);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}
.segmented button,
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-height: 32px;
	padding: 0 12px;
	border: 0;
	border-radius: calc(var(--radius) - 4px);
	background: transparent;
	color: var(--foreground);
	font: inherit;
	font-weight: 500;
	cursor: pointer;
	text-decoration: none;
	transition: background-color 0.15s, color 0.15s;
}
.segmented button:hover,
.btn-ghost:hover {
	background: var(--card);
}
.segmented button:active,
.btn-ghost:active {
	background: var(--secondary);
}
.segmented button[aria-pressed='true'] {
	background: var(--primary);
	color: var(--primary-foreground);
}
.btn-ghost {
	border: 1px solid var(--border);
	background: var(--card);
}

.status:empty {
	display: none;
}
.status {
	margin: 0 0 16px;
	padding: 12px 16px;
	border-radius: var(--radius);
	background: var(--muted);
	display: flex;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
}
.status.error {
	background: var(--status-danger-bg);
	color: var(--status-danger);
}

/* ---- Chart grid: N chart cards per row ----------------------------------------------------
 * Cards match the OpsAssistant forecast strip (MetvuwStrip / MetvuwThumbnail): rounded-xl,
 * 2px primary/20 border, secondary gradient, a soft accent glow, a clock + time header, and
 * the chart in a white rounded panel; lift on hover.
 */

.grid {
	display: flex;
	flex-direction: column;
	gap: var(--gap);
}
.row {
	display: flex;
	gap: var(--gap);
	align-items: stretch;
}
.card {
	position: relative;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	padding: var(--card-pad);
	border: var(--card-border) solid oklch(0.259 0.084 255 / 0.2); /* primary/20 */
	border-radius: 0.75rem; /* rounded-xl */
	background: linear-gradient(
		to bottom right,
		var(--secondary),
		oklch(0.955 0.018 234 / 0.5) /* secondary/50 */
	);
	color: inherit;
	font: inherit;
	text-align: left;
	transition:
		transform 0.3s,
		box-shadow 0.3s;
}
.card::before {
	/* The soft Mid Blue glow in the top-right corner (accent/20, blur-2xl). */
	content: '';
	position: absolute;
	top: -2rem;
	right: -2rem;
	width: 6rem;
	height: 6rem;
	border-radius: 50%;
	background: oklch(0.677 0.141 234 / 0.2);
	filter: blur(40px);
	pointer-events: none;
}
.tile {
	width: calc(var(--thumb-w, 200px) + 2 * (var(--card-pad) + var(--card-border)));
	cursor: zoom-in;
}
.tile:hover {
	transform: translateY(-4px);
	box-shadow:
		0 10px 15px -3px oklch(0.259 0.084 255 / 0.12),
		0 4px 6px -4px oklch(0.259 0.084 255 / 0.12); /* shadow-lg */
}
.tile:active {
	box-shadow: 0 0 0 2px var(--ring);
}
.card-head {
	position: relative;
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 8px;
	min-height: 20px;
	color: var(--primary);
	font-size: 14px;
	font-weight: 500;
	line-height: 20px;
}
.card-time {
	flex: 1;
	min-width: 0;
}
.card-lead {
	color: var(--muted-foreground);
	font-size: 12px;
	white-space: nowrap;
}
.card-img {
	position: relative;
	overflow: hidden;
	border-radius: 0.5rem; /* rounded-lg */
	background: oklch(1 0 0 / 0.6); /* card/60 */
}
.card-img img {
	width: 100%;
	height: auto;
}

/* ---- Colour legend: one per tab, above the cards ------------------------------------------ */

.legend {
	max-width: 640px;
	margin: 0 0 20px;
}
.legend figcaption {
	margin-bottom: 8px;
	color: var(--foreground);
	font-size: 14px;
	font-weight: 500;
}
.legend-bar {
	display: flex;
	gap: 2px; /* surface gap between classes (dataviz spacer) */
	padding-bottom: 24px; /* room for the labels under the bar */
}
.legend-seg {
	position: relative;
	flex: 1;
	height: 16px;
	box-shadow: inset 0 0 0 1px oklch(0 0 0 / 0.08); /* keeps the near-white class visible */
}
.legend-seg:first-child {
	border-radius: 4px 0 0 4px;
}
.legend-seg:last-child {
	border-radius: 0 4px 4px 0;
}
.legend-label {
	position: absolute;
	top: calc(100% + 4px);
	left: -1px;
	transform: translateX(-50%);
	color: var(--foreground);
	font-size: 14px;
	font-variant-numeric: tabular-nums;
	line-height: 20px;
	white-space: nowrap;
}
.legend-label.first {
	transform: none;
}

/* ---- Key ---------------------------------------------------------------------------------- */

.key {
	margin-top: 24px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--card);
}
.key summary {
	padding: 12px 16px;
	cursor: pointer;
	font-weight: 500;
	color: var(--primary);
}
.key-body {
	padding: 0 16px 16px;
}
.key-body p {
	margin: 0 0 12px;
	max-width: 70ch;
}
.key-images {
	display: flex;
	gap: 24px;
	align-items: flex-start;
	flex-wrap: wrap;
}
#key-scale,
#wind-key-scale {
	height: 300px;
	width: auto;
}

/* ---- Tabs (CPWL spec 8.16: tab semantics, 8.12 pill vocabulary for the selected state) ---- */

.tabs {
	display: inline-flex;
	gap: 4px;
	padding: 4px;
	margin-bottom: 20px;
	background: var(--muted);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}
.tab {
	min-height: 36px;
	padding: 0 16px;
	border: 1px solid transparent;
	border-radius: calc(var(--radius) - 4px);
	background: transparent;
	color: var(--muted-foreground);
	font: inherit;
	font-weight: 500;
	cursor: pointer;
	transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.tab:hover {
	color: var(--foreground);
}
.tab:active {
	background: var(--card);
}
.tab[aria-selected='true'] {
	border-color: var(--primary);
	background: oklch(0.259 0.084 255 / 0.1); /* primary/10 */
	color: var(--primary);
}
.tab[aria-selected='true']:hover {
	color: var(--primary); /* load-bearing: keeps the selected label from flickering (8.16) */
}
.panel-title {
	margin-bottom: 12px;
}
.panel-sub {
	margin: -8px 0 12px;
}

/* ---- Evapotranspiration ------------------------------------------------------------------- */

h2 {
	font-family: var(--font-heading);
	font-weight: 600;
	color: var(--primary);
	font-size: 1.25rem;
	line-height: 1.3;
	margin: 0;
}
.et-chart {
	margin: 0 0 12px;
	padding: 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--card);
}
.et-chart svg {
	width: 100%;
	height: auto;
	display: block;
}
.et-chart .grid-line {
	stroke: rgba(148, 163, 184, 0.25); /* CPWL chart grid (spec 9) */
}
.et-chart .axis-line {
	stroke: var(--foreground);
	stroke-width: 1;
}
.et-chart .tick {
	fill: var(--muted-foreground);
	font-size: 11px;
	font-family: var(--font-body);
}
.et-legend {
	display: flex;
	gap: 16px;
	font-size: 12px;
	margin-bottom: 4px;
}
.et-legend span {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}
.et-legend i {
	width: 12px;
	height: 12px;
	border-radius: 2px;
	display: inline-block;
}
.et-numbers {
	margin-bottom: 16px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--card);
}
.et-numbers summary {
	padding: 10px 16px;
	cursor: pointer;
	font-weight: 500;
	color: var(--primary);
}
.et-table {
	overflow-x: auto;
	padding: 0 16px 12px;
}
.et-table table {
	border-collapse: collapse;
	width: 100%;
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}
.et-table caption {
	text-align: left;
	color: var(--muted-foreground);
	padding: 4px 0 8px;
}
.et-table th,
.et-table td {
	padding: 6px 8px;
	border-bottom: 1px solid var(--border);
	text-align: right;
	white-space: nowrap;
}
.et-table th[scope='row'],
.et-table thead th:first-child {
	text-align: left;
	font-weight: 400;
}
.et-table thead th {
	color: var(--muted-foreground);
	font-weight: 500;
}

/* ---- Footer --------------------------------------------------------------------------------- */

.footer {
	background: var(--primary);
	color: var(--sidebar-foreground);
	padding: 16px;
	padding-bottom: max(16px, env(safe-area-inset-bottom));
	font-size: 13px;
}
.footer p {
	margin: 0 auto;
	max-width: 1440px;
}
.footer .strapline {
	opacity: 0.7;
	font-size: 12px;
}
.footer p + .strapline {
	margin-top: 8px;
}
.footer .strapline + .strapline {
	margin-top: 0;
}
.footer .app-version {
	margin-top: 8px;
	font-size: 12px;
	opacity: 0.5;
}

/* ---- Player (full view) ------------------------------------------------------------------
 * A centred card, as OpsAssistant's forecast dialog: heading with the chart's time, the chart
 * as large as the window allows with its colour scale, a timeline, and Previous / Play / Next.
 * Opens with the spec's dialog motion (fade + zoom from 95%, 200ms); frames crossfade.
 */

.lightbox {
	width: 100vw;
	max-width: 100vw;
	height: 100svh;
	max-height: 100svh;
	margin: 0;
	padding: 1rem;
	border: 0;
	background: transparent;
	color: var(--foreground);
	align-items: center;
	justify-content: center;
	overscroll-behavior: contain;
}
.lightbox[open] {
	display: flex;
}
.lightbox::backdrop {
	background: oklch(0.259 0.084 255 / 0.6);
}
.lb-card {
	display: flex;
	flex-direction: column;
	gap: 12px;
	max-width: min(95vw, 90rem);
	max-height: calc(100svh - 2rem);
	padding: 16px 20px 20px;
	border: 1px solid oklch(0.259 0.084 255 / 0.2); /* primary/20 */
	border-radius: 0.75rem;
	background: var(--card);
	box-shadow: 0 20px 25px -5px oklch(0.259 0.084 255 / 0.18);
}
.lightbox[open] .lb-card {
	animation: lb-in 0.2s ease-out;
}
@keyframes lb-in {
	from {
		opacity: 0;
		transform: scale(0.95);
	}
}
.lb-head {
	display: flex;
	align-items: flex-start;
	gap: 12px;
}
.lb-heading {
	flex: 1;
	min-width: 0;
	text-align: center;
	padding-left: 36px; /* balances the close button so the heading centres on the card */
}
.lb-title {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	font-size: 1.125rem;
	line-height: 1.4;
}
.lb-title .icon {
	width: 20px;
	height: 20px;
}
.lb-detail {
	margin: 2px 0 0;
	color: var(--muted-foreground);
	font-size: 14px;
}
.lb-close {
	color: var(--muted-foreground);
}
.lb-close:hover {
	background: var(--muted);
	color: var(--foreground);
}
.lb-close:active {
	background: var(--secondary);
}
.lb-body {
	display: flex;
	align-items: flex-start;
	justify-content: center;
	gap: 8px;
	min-height: 0;
	touch-action: pan-y;
}
.lb-stage {
	--lb-fade: 0.4s;
	position: relative;
	overflow: hidden;
	border: 1px solid oklch(0.259 0.084 255 / 0.2);
	border-radius: 0.75rem;
	background: var(--secondary);
}
.lb-frame {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: contain;
	opacity: 0;
	transition: opacity var(--lb-fade) cubic-bezier(0.22, 1, 0.36, 1); /* quint out */
}
.lb-frame.on {
	opacity: 1;
}
.lb-stage.instant .lb-frame {
	transition: none;
}
.lb-scale {
	flex-shrink: 0;
	border-radius: 0.5rem;
}

.lb-timeline {
	padding: 0 4px;
}
.lb-scrub {
	width: 100%;
	margin: 0;
	accent-color: var(--primary);
	cursor: pointer;
}
.lb-scrub:focus-visible {
	outline: 2px solid var(--ring);
	outline-offset: 4px;
}
.lb-ends {
	display: flex;
	justify-content: space-between;
	color: var(--muted-foreground);
	font-size: 12px;
	font-variant-numeric: tabular-nums;
}

.lb-controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 12px;
}
.lb-btn {
	min-width: 7.5rem;
	border: 1px solid oklch(0.259 0.084 255 / 0.2);
	color: var(--primary);
	font-weight: 500;
}
.lb-btn:disabled {
	opacity: 0.4;
	cursor: default;
}
.lb-btn:not(:disabled):hover {
	background: var(--secondary);
}
.lb-btn:not(:disabled):active {
	background: var(--muted);
}
.lb-play {
	border-color: oklch(0.259 0.084 255 / 0.3);
	background: var(--card);
}
.lb-play[aria-pressed='true'] {
	border-color: var(--primary);
	background: var(--primary);
	color: var(--primary-foreground);
}
.lb-play[aria-pressed='true']:hover {
	background: oklch(0.259 0.084 255 / 0.9); /* primary/90 */
}
.lb-play .icon-pause,
.lb-play[aria-pressed='true'] .icon-play {
	display: none;
}
.lb-play[aria-pressed='true'] .icon-pause {
	display: block;
}
.lb-play .icon-pause rect {
	fill: currentColor;
	stroke: none;
}

.icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	flex-shrink: 0;
	border: 0;
	border-radius: calc(var(--radius) - 2px);
	background: transparent;
	color: inherit;
	cursor: pointer;
	transition: background-color 0.15s;
}

/* ---- Touch and small screens ------------------------------------------------------------------- */

/* Touch is a different input, not a narrower screen (spec 11): size on pointer type. */
@media (pointer: coarse) {
	.segmented button,
	.btn,
	.tab {
		min-height: 44px;
	}
	.icon-btn {
		width: 44px;
		height: 44px;
	}
	.lb-btn {
		min-height: 44px;
	}
	.lb-scrub {
		min-height: 44px;
	}
}

@media (max-width: 639px) {
	h1 {
		font-size: 1.3rem;
	}
	/* Phones: the player takes the whole screen. */
	.lightbox {
		padding: 0;
	}
	.lb-card {
		width: 100vw;
		max-width: 100vw;
		height: 100svh;
		max-height: 100svh;
		justify-content: center;
		padding: 12px 12px max(12px, env(safe-area-inset-bottom));
		border: 0;
		border-radius: 0;
	}
	.lb-btn {
		min-width: 0;
		flex: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	.card {
		transition: none;
	}
	.lightbox[open] .lb-card {
		animation: none;
	}
	.lb-frame {
		transition: none;
	}
	.tile:hover {
		transform: none;
	}
}
