/*
 * app-navigation.css: the way between an app's screens. It stands on app-shell.css, which is
 * beside it; load that first.
 *
 * Copy this file. Keep every line marked TRAP.
 *
 * Back, first in a bar, before the title. A link to the parent, never only a script:
 *
 *   <header class="shell-bar">
 *     <a class="shell-back" href="/settings" aria-label="Back to Settings"><svg/><span>Settings</span></a>
 *     <h1 class="shell-title">Notifications</h1>
 *
 * A list beside the thing chosen from it. On the shell: data-shell="split".
 *
 *   <main class="shell-content" id="content" tabindex="-1">
 *     <div class="shell-split" data-open>                  data-open: something is chosen
 *       <section class="shell-pane" data-pane="list">      each pane: its bar, then the part that scrolls
 *         <header class="shell-bar"> <h2 class="shell-title">Inbox</h2>
 *         <ul class="shell-scroll"> <li><a href="/inbox/2" aria-current="page">
 *       <article class="shell-pane" data-pane="detail">
 *         <header class="shell-bar"> <a class="shell-back" href="/inbox"> <h1 class="shell-title">
 *         <div class="shell-scroll">
 *
 * Working examples: index.html (a list and its messages), settings.html (a pushed page).
 */

:root {
	--shell-list-width: clamp(16rem, 38%, 24rem); /* the list's column when both panes show */
}

/* ---- Back ---- */

/* Compact: a key with the chevron. Where it leads is its name for assistive tech (aria-label). */
.shell-back {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	min-width: var(--shell-hit);
	min-height: var(--shell-hit);
	/* the chevron, not its hit area, sits on the content's edge */
	margin-inline-start: calc((var(--shell-hit) - 1.25rem) / -2);
	border-radius: 0.5rem;
	color: inherit;
	text-decoration: none;
}

.shell-back svg {
	flex: none;
	width: 1.25rem;
	height: 1.25rem;
}

.shell-back span {
	display: none;
}

/* In a right-to-left page Back points the other way. */
[dir='rtl'] .shell-back svg {
	transform: scaleX(-1);
}

@media (hover: hover) {
	.shell-back:hover {
		background: var(--shell-current);
	}
}

/* Regular: Back says where it goes, in words, before the title. */
@media (min-width: 37.5em) {
	.shell-back {
		gap: 0.125rem;
		justify-content: flex-start;
		/* the chevron stays on the content's edge; the ground under the pointer reaches past it */
		margin-inline-start: -0.375rem;
		padding-inline: 0.375rem 0.5rem;
		color: var(--shell-muted);
		font-size: 0.9375rem;
	}

	.shell-back span {
		display: inline;
	}
}

/* ---- A list beside the thing chosen from it ---- */

/* The panes answer to the room the content has, not to the window: beside a sidebar the window
   is wide long before the content is. */
.shell-content:has(> .shell-split) {
	container: shell-content / inline-size;
}

.shell-split {
	display: grid;
	flex: 1;
	grid-template-columns: minmax(0, 1fr);
	min-height: 0;
}

.shell-pane {
	display: flex;
	flex-direction: column;
	/* TRAP: both, or a pane grows with what is in it and the other pane or the page scrolls */
	min-width: 0;
	min-height: 0;
}

/* TRAP: one pane at a time. With something chosen the list gives way to it; with nothing chosen
   there is only the list. Never both squeezed into a phone's width. */
.shell-split[data-open] > [data-pane='list'],
.shell-split:not([data-open]) > [data-pane='detail'] {
	display: none;
}

/* The row that is open, for when the list shows beside it. */
.shell-split [data-pane='list'] a[aria-current='page'] {
	background: var(--shell-current);
}

/* What the detail's pane says while nothing is chosen. */
.shell-empty {
	display: grid;
	flex: 1;
	place-items: center;
	margin: 0;
	padding: var(--shell-gutter);
	color: var(--shell-muted);
	text-align: center;
}

/* Both panes from 40rem of content: a list of 16rem and 24rem left to read in. (A custom property
   can't stand in a container query, so the number is here.) */
@container shell-content (min-width: 40rem) {
	.shell-split {
		grid-template-columns: var(--shell-list-width) minmax(0, 1fr);
	}

	/* both panes, whatever is chosen */
	.shell-split[data-open] > [data-pane='list'],
	.shell-split:not([data-open]) > [data-pane='detail'] {
		display: flex;
	}

	.shell-split > [data-pane='list'] {
		border-inline-end: 1px solid var(--shell-line);
	}

	/* TRAP: no Back where the list is in view. It would only do what a click on the list does. */
	.shell-split .shell-back {
		display: none;
	}
}
