/* ============================================================
   Page templates: the outer spacing for each kind of page.
   A page template knows where its content sits in the shell, so
   it sets the gutter around the content and the padding inside
   the surface that holds it. Reads only --t-* tokens.
   ============================================================ */

/* page_kinds/task.html: a page for doing one thing, in one work surface. */
@layer layout {
	.task-page {
		/* No side gutter on a phone: the card uses the full width. */
		padding: var(--t-space-4) 0 var(--t-space-12);

		& > .work-surface {
			display: grid;
			grid-template-columns: minmax(0, 1fr);
			align-content: start;
			gap: var(--t-space-6);
			padding-block: var(--t-space-3);
			container-type: inline-size;
		}
	}

	@media (min-width: 48rem) {
		.task-page {
			padding: var(--t-space-6) var(--t-space-7) var(--t-space-12);
		}
	}
}

/* page_kinds/overview.html: a page of several parts on the page background.
   It keeps a gutter, so headings and plain text stay off a phone's edge. Its
   parts sit the gutter's width apart, so the space around each card is the
   same on every side. */
@layer layout {
	.overview-page {
		display: grid;
		gap: var(--t-space-4);
		align-content: start;
		padding-inline: var(--t-space-4);
		container-type: inline-size;

		/* The page's primary content uses the full width of a phone, as a
		   task page's work surface does. The cards it breaks out above it
		   keep the gutter. */
		& > .primary-content {
			margin-inline: calc(-1 * var(--t-space-4));
		}
	}

	@media (min-width: 48rem) {
		.overview-page > .primary-content {
			margin-inline: 0;
		}
	}
}

/* flows/check_in.html: every page of the participant's check-in flow, in one
   work surface. */
@layer layout {
	.check-in-page {
		/* No side gutter on a phone: the card uses the full width. */
		padding: var(--t-space-4) 0 var(--t-space-12);

		& > .work-surface {
			display: grid;
			grid-template-columns: minmax(0, 1fr);
			align-content: start;
			gap: var(--t-space-6);
			padding-block: var(--t-space-3);
		}
	}

	@media (min-width: 48rem) {
		.check-in-page {
			padding: var(--t-space-6) var(--t-space-7) var(--t-space-12);
		}
	}
}

/* shells/signed_in.html: the top bar, the nav, the page and the footer.
   The shell is the page background (the lowest surface). The nav, filled
   with that surface's colour, is fixed at the window's start.
   On a phone the top bar stays at the top and the nav is a drawer that
   slides in over the page. The drawer is a popover; a browser without the
   Popover API keeps its open state in the fallback menu button's checkbox.
   On a wide screen the nav is always open. The shell leaves room for it at
   its start, so the page, the seal over it and the background's glow centre
   on the space beside the nav, and a line separates the two. */
@layer layout {
	.signed-in {
		/* The nav's width on a wide screen, and the room the shell leaves
		   for it: they change together. */
		--c-signed-in-nav-inline-size: 16rem;

		display: grid;
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: auto 1fr auto;
		/* Fill the body's rows, whose floor is the window's height (web.css),
		   rather than setting a floor of its own, so the page measures as
		   its content once that floor is lifted. */
		grid-row: 1 / -1;

		& > .top-bar {
			position: sticky;
			inset-block-start: 0;
			z-index: var(--t-z-index-sticky);
			display: flex;
			align-items: center;
			justify-content: center;
			padding: var(--t-space-3) var(--t-space-4);
		}

		& > .top-bar > .menu-button {
			position: absolute;
			inset-inline-start: var(--t-space-4);
			display: grid;
			place-items: center;
			min-inline-size: var(--t-target-min-size);
			min-block-size: var(--t-target-min-size);
			cursor: pointer;

			/* The fallback's checkbox covers its label, so a tap anywhere
			   on it toggles the menu, and it keeps its own keyboard focus. */
			& > input {
				position: absolute;
				inset: 0;
				margin: 0;
				opacity: 0;
				cursor: pointer;
			}
		}

		& > .top-bar > .brand {
			display: flex;
			align-items: center;
		}

		/* Fixed at every width: a drawer on a phone, always open beside the
		   page on a wide screen. */
		& > .nav-drawer {
			position: fixed;
			inset-block: 0;
			inset-inline-start: 0;
			/* The drawer is a popover. Undo the browser's popover frame
			   and its content height (the reset layer already drops its
			   centring margin), and show it closed too: on a wide screen
			   it is the rail, and on a phone the rules below hide it
			   while it is closed, so it can slide out instead of
			   vanishing. */
			border: 0;
			block-size: auto;
			display: grid;
			align-content: start;
			gap: var(--t-space-4);
			padding: var(--t-space-4);
			overflow-y: auto;
		}

		& > .nav-drawer > .drawer-head {
			display: flex;
			align-items: center;
			justify-content: space-between;
			gap: var(--t-space-3);
		}

		& > .nav-drawer .menu-close {
			display: grid;
			place-items: center;
			min-inline-size: var(--t-target-min-size);
			min-block-size: var(--t-target-min-size);
			cursor: pointer;
		}

		& > .signed-in-page {
			display: grid;
			gap: var(--t-space-6);
			align-content: start;
			min-inline-size: 0;
			container-type: inline-size;
		}
	}

	@media not all and (min-width: 48rem) {
		.signed-in {
			& > .nav-drawer {
				z-index: var(--t-z-index-drawer);
				inline-size: min(20rem, 85vw);
				border-start-end-radius: var(--t-radius-lg);
				border-end-end-radius: var(--t-radius-lg);
				translate: -100% 0;
				visibility: hidden;
				transition: translate 0.3s ease, visibility 0s linear 0.3s;
			}

			& > .nav-backdrop {
				position: fixed;
				inset: 0;
				z-index: var(--t-z-index-drawer);
				visibility: hidden;
				opacity: 0;
				transition: opacity 0.3s ease, visibility 0s linear 0.3s;
			}

			/* Open. The same rules twice: a browser that doesn't know
			   :popover-open drops the first rule whole, since :has() is
			   not forgiving, and the checkbox's twin is fenced off where
			   the popover works, because a tap on the backdrop still
			   toggles the checkbox there. */
			&:has(> .nav-drawer:popover-open) {
				& > .nav-drawer,
				& > .nav-backdrop {
					visibility: visible;
					transition: translate 0.3s ease, opacity 0.3s ease;
				}

				& > .nav-drawer {
					translate: 0 0;
				}

				& > .nav-backdrop {
					opacity: 1;
				}
			}

			@supports not selector(:popover-open) {
				&:has(.menu-button > input:checked) {
					& > .nav-drawer,
					& > .nav-backdrop {
						visibility: visible;
						transition: translate 0.3s ease, opacity 0.3s ease;
					}

					& > .nav-drawer {
						translate: 0 0;
					}

					& > .nav-backdrop {
						opacity: 1;
					}
				}
			}

			/* Keep the participant's fixed tab bar off the end of the page. */
			& > .signed-in-page.has-tabbar {
				padding-block-end: calc(var(--t-space-12) + var(--t-target-min-size));
			}
		}

		/* The page under an open drawer doesn't scroll. */
		body:has(.signed-in > .nav-drawer:popover-open) {
			overflow: hidden;
		}

		@supports not selector(:popover-open) {
			body:has(.signed-in .menu-button > input:checked) {
				overflow: hidden;
			}
		}
	}

	/* One set of menu controls: the popover's buttons where the browser
	   has the Popover API, the checkbox and its labels where it doesn't. */
	@supports selector(:popover-open) {
		.signed-in {
			& > .top-bar > .menu-button--fallback,
			& > .nav-drawer .menu-close--fallback {
				display: none;
			}
		}
	}

	@supports not selector(:popover-open) {
		.signed-in {
			& > .top-bar > .menu-button:not(.menu-button--fallback),
			& > .nav-drawer .menu-close:not(.menu-close--fallback) {
				display: none;
			}
		}
	}

	@media (min-width: 48rem) {
		.signed-in {
			margin-inline-start: var(--c-signed-in-nav-inline-size);

			& > .top-bar {
				position: static;
			}

			/* The same room beside the nav as at the window's edge. */
			& > .signed-in-page {
				padding-inline: var(--t-space-5);
			}

			& > .top-bar > .menu-button,
			& > .nav-backdrop,
			& > .nav-drawer > .drawer-head {
				display: none;
			}

			& > .nav-drawer {
				inline-size: var(--c-signed-in-nav-inline-size);
				border-inline-end: var(--t-border-width-interactive) solid;
			}
		}
	}

	@media (prefers-reduced-motion: reduce) {
		.signed-in > .nav-drawer,
		.signed-in > .nav-backdrop {
			transition: none;
		}
	}
}

@layer design {
	.signed-in {
		& > .top-bar > .menu-button:is(:focus-visible, :has(> input:focus-visible)),
		& > .nav-drawer .menu-close:focus-visible {
			outline: 2px solid var(--t-border-focus);
			outline-offset: 2px;
		}

		/* The popover's buttons draw as bare icons, like the fallback's
		   labels. */
		& > .top-bar > .menu-button,
		& > .nav-drawer .menu-close {
			background: none;
			color: inherit;
		}

		& > .nav-backdrop {
			background-color: var(--t-bg-overlay);
			backdrop-filter: blur(8px);
		}
	}

	/* On a phone the top bar is a layout element with no fill of its own
	   until the page scrolls under it; then it takes the colour of the
	   surface it sits on, without the glow, so the page doesn't show
	   through the seal. The scroll drives it in CSS alone. A browser that
	   can't tie an animation to scrolling fills the bar from the start
	   instead. */
	@keyframes top-bar-scrolled {
		from { background-color: transparent; }
		to { background-color: var(--c-surface-background-color); }
	}

	@media not all and (min-width: 48rem) {
		@supports (animation-timeline: scroll()) {
			.signed-in > .top-bar {
				animation: top-bar-scrolled linear both;
				animation-timeline: scroll(root);
				animation-range: 0 1px;
			}
		}

		@supports not (animation-timeline: scroll()) {
			.signed-in > .top-bar {
				background-color: var(--c-surface-background-color);
			}
		}
	}

	@media (min-width: 48rem) {
		.signed-in > .nav-drawer {
			border-inline-end-color: var(--t-border);
		}
	}

	/* The nav stays put over the page, so it fills with the colour of the
	   surface it sits on, without the glow, and reads that surface's inks,
	   at every width. The current item and a hovered one keep their own
	   highlight. */
	.signed-in > .nav-drawer {
		background-color: var(--c-surface-background-color);
		color: var(--c-surface-text-color-base);

		& :is(.desk-nav__item, .citizen-nav__item, .role-switcher__item):not([aria-current], :hover),
		& .lang-form {
			color: var(--c-surface-text-color-base);
		}

		& :is(.desk-nav__label, .citizen-nav__label, .role-switcher__label) {
			color: var(--c-surface-text-color-muted);
		}
	}
}

/* shells/signed_out.html: no nav. The seal is centred at the top, the
   language picker in the top-left corner, and the page centred under them. */
@layer layout {
	.signed-out {
		display: grid;
		grid-template-rows: auto 1fr auto;
		/* Fill the body's rows, whose floor is the window's height (web.css),
		   so the footer sits at the bottom of a short page. */
		grid-row: 1 / -1;

		/* Three columns, so the seal stays centred and the picker keeps its
		   own room beside it on the narrowest phone. */
		& > .top-bar {
			display: grid;
			grid-template-columns: 1fr auto 1fr;
			align-items: start;
			gap: var(--t-space-2);
			padding: var(--t-space-3) var(--t-space-4);
		}

		& > .top-bar > .corner {
			grid-column: 1;
			justify-self: start;
			position: relative;
			z-index: var(--t-z-index-sticky);
		}

		& > .top-bar > .brand {
			grid-column: 2;
		}

		& > .signed-out-page {
			display: grid;
			gap: var(--t-space-6);
			align-content: start;
			inline-size: 100%;
			max-inline-size: var(--t-max-inline-size-page);
			margin-inline: auto;
			padding-inline: var(--t-space-4);
			container-type: inline-size;

			&.narrow {
				max-inline-size: var(--t-max-inline-size-page-narrow);
			}
		}
	}
}

/* The signed-out corner language picker (nav/language.html corner()): its
   summary reads on the page background, and its list opens as a card over
   the page. */
@layer layout {
	.signed-out > .top-bar > .corner .lang-options {
		position: absolute;
		margin: var(--t-space-1) 0 0;
		padding: var(--t-space-2);
		border-radius: var(--t-radius-md);
		min-inline-size: 12rem;
	}

	.signed-out > .top-bar > .corner summary {
		gap: var(--t-space-2);
		min-block-size: var(--t-target-min-size);
		cursor: pointer;
	}
}

@layer design {
	.signed-out > .top-bar > .corner summary {
		color: var(--c-surface-text-color-base);
	}

	.signed-out > .top-bar > .corner summary:focus-visible {
		outline: 2px solid var(--t-border-focus);
		outline-offset: 2px;
	}
}
