/*
 * The portal's one stylesheet (docs/ui_enhansment_plan.md, section 5). Colours, spacing and type come from the
 * tokens below; a template never sets its own. Component classes are listed in templates/portal/components.html.
 * Every colour is a token, and every token has a dark value in the block after this one, used when the OS asks for
 * dark: a rule that needs a new colour adds a token to both blocks, never a literal.
 */
:root {
	--bg: #f5f7f5;
	--surface: #ffffff;
	--surface-2: #f0f3f0;
	--sidebar-bg: #fbfcfb;
	--row-hover: #f7f9f7;
	--border: #e1e6e2;
	--border-strong: #c5ccc7;
	--text: #16201a;
	--text-muted: #59655d;
	--accent: #1f7a4d;
	--accent-hover: #186340;
	--accent-soft: #e4f2ea;
	--accent-text: #145233;
	--accent-border: #bfe0cc;
	--on-accent: #ffffff;
	--success: #1f7a4d;
	--success-soft: #e4f2ea;
	--success-border: #bfe0cc;
	--danger: #b42318;
	--danger-hover: #93190f;
	--danger-soft: #fdecea;
	--danger-border: #f2c4bf;
	--warning: #8a5a00;
	--warning-soft: #fff3d6;
	--warning-border: #efd9a4;
	--info: #1d5fa8;
	--info-soft: #e7effa;
	--info-border: #c5d8f2;
	--neutral-soft: #eceeec;
	--log-bg: #111814;
	--log-text: #d5dcd7;
	--log-muted: #8fa198;
	--log-error: #ff9b8f;
	--log-warn: #f2c85b;
	--log-link: #8cc4ff;
	--log-rule: rgb(255 255 255 / 0.05);
	--log-flash: rgb(255 255 255 / 0.12);
	--scrim: rgb(0 0 0 / 0.3);

	--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	--radius: 10px;
	--radius-sm: 6px;
	--shadow: 0 1px 2px rgb(16 32 22 / 0.05), 0 1px 3px rgb(16 32 22 / 0.04);
	--shadow-pop: 0 12px 32px rgb(16 32 22 / 0.18), 0 2px 6px rgb(16 32 22 / 0.08);
	--shadow-drawer: 0 0 24px rgb(0 0 0 / 0.18);
	--sidebar-w: 15rem;
	color-scheme: light;
}

/* The same tokens for a dark OS setting. Text and its background keep WCAG AA (4.5:1) here as in light. The accent
 * is lighter than in light so it reads on the dark surfaces, which is why a filled button's text is --on-accent,
 * dark here, not white. */
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0e1310;
		--surface: #151c18;
		--surface-2: #1c2520;
		--sidebar-bg: #121814;
		--row-hover: #1a231e;
		--border: #29332d;
		--border-strong: #3c4a42;
		--text: #e2e8e4;
		--text-muted: #9ba9a1;
		--accent: #3fb47a;
		--accent-hover: #5cc590;
		--accent-soft: #163525;
		--accent-text: #6fd2a1;
		--accent-border: #2a5a40;
		--on-accent: #08150e;
		--success: #6fd2a1;
		--success-soft: #163525;
		--success-border: #2a5a40;
		--danger: #f28b82;
		--danger-hover: #f6a8a1;
		--danger-soft: #3a1a17;
		--danger-border: #6e2e28;
		--warning: #e9b94f;
		--warning-soft: #33280e;
		--warning-border: #5f4b1b;
		--info: #82b4ee;
		--info-soft: #16283d;
		--info-border: #2c496c;
		--neutral-soft: #232c27;
		--log-bg: #090d0b;
		--log-text: #d5dcd7;
	--log-muted: #8fa198;
	--log-error: #ff9b8f;
	--log-warn: #f2c85b;
	--log-link: #8cc4ff;
	--log-rule: rgb(255 255 255 / 0.05);
	--log-flash: rgb(255 255 255 / 0.12);
		--scrim: rgb(0 0 0 / 0.55);
		--shadow: 0 1px 2px rgb(0 0 0 / 0.35), 0 1px 3px rgb(0 0 0 / 0.25);
		--shadow-pop: 0 12px 32px rgb(0 0 0 / 0.55), 0 2px 6px rgb(0 0 0 / 0.35);
		--shadow-drawer: 0 0 24px rgb(0 0 0 / 0.6);
		color-scheme: dark;
	}
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--accent-text); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1 { margin: 0 0 0.5rem; font-size: 1.5rem; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h2 { margin: 2rem 0 0.75rem; font-size: 1.1rem; line-height: 1.3; font-weight: 600; }
h3 { margin: 1.5rem 0 0.5rem; font-size: 1rem; font-weight: 600; }
p { margin: 0 0 0.75rem; }
code, kbd, pre { font-family: var(--mono); font-size: 0.85em; }
details > summary { cursor: pointer; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only {
	position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
	clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---- Shell: sidebar, and a top bar with the menu button below 900px ---- */
.wordmark { color: var(--text); font-weight: 800; font-size: 0.95rem; letter-spacing: 0.14em; text-decoration: none; }
.wordmark small { margin-left: 0.4rem; color: var(--text-muted); font-size: 0.75rem; font-weight: 500; letter-spacing: 0.02em; }
.wordmark:hover { color: var(--text); }
.topbar { display: none; }
.sidebar {
	position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--sidebar-w);
	display: flex; flex-direction: column; overflow-y: auto;
	background: var(--sidebar-bg); border-right: 1px solid var(--border);
}
.sidebar > .wordmark { display: block; padding: 1.15rem 1.25rem 0.75rem; }
.nav { flex: 1; padding: 0.25rem 0.75rem 1rem; }
.nav-group { margin-top: 1.1rem; }
.nav-heading {
	margin: 0 0 0.25rem; padding: 0 0.5rem; color: var(--text-muted);
	font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.nav a {
	display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
	padding: 0.4rem 0.55rem; border-radius: var(--radius-sm);
	color: var(--text); font-size: 0.9rem; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
/* How much an Inbox queue holds (components :: nav-count); positioned, so its .sr-only word stays inside it. */
.nav-count {
	position: relative; flex: none; min-width: 1.5rem; padding: 0 0.45rem; border-radius: 999px;
	background: var(--accent-soft); color: var(--accent-text); text-align: center;
	font-size: 0.75rem; font-weight: 600; line-height: 1.5; font-variant-numeric: tabular-nums;
}
.nav a[aria-current="page"] .nav-count { background: var(--surface); }
.sidebar-foot { padding: 0.85rem 1.25rem 1rem; border-top: 1px solid var(--border); font-size: 0.85rem; }
.sidebar-foot .who { margin: 0 0 0.35rem; color: var(--text-muted); overflow-wrap: anywhere; }
.sidebar-foot form { margin: 0; }
.sidebar-actions { display: flex; align-items: center; gap: 1rem; }
.sidebar-actions a { text-decoration: none; }
.sidebar-actions a:hover { text-decoration: underline; }
.sidebar-actions a[aria-current="page"] { font-weight: 600; }
.scrim { display: none; }

main { min-width: 0; max-width: 92rem; padding: 2rem 2.5rem 4rem; overflow-x: auto; }
.sidebar ~ main { margin-left: var(--sidebar-w); }

@media (max-width: 900px) {
	.topbar {
		position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 0.75rem;
		padding: 0.6rem 1rem; background: var(--sidebar-bg); border-bottom: 1px solid var(--border);
	}
	.sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
	.nav-open .sidebar { transform: none; box-shadow: var(--shadow-drawer); }
	.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 19; background: var(--scrim); }
	.sidebar ~ main { margin-left: 0; }
	main { padding: 1.25rem 1rem 3rem; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ---- Page anatomy ---- */
.crumbs { display: flex; flex-wrap: wrap; margin-bottom: 0.5rem; color: var(--text-muted); font-size: 0.85rem; }
.crumbs > * + *::before { content: "/"; margin: 0 0.45rem; color: var(--border-strong); }
.crumbs a { color: var(--text-muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent-text); text-decoration: underline; }
.crumbs [aria-current="page"] { max-width: 48ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; overflow-wrap: anywhere; }
.page-head .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.4rem 0 0; color: var(--text-muted); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.lead { max-width: 75ch; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.note { margin: 0.75rem 0 0; color: var(--text-muted); font-size: 0.85rem; }
.stack > * + * { margin-top: 1rem; }
.section { margin-top: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1rem; align-items: start; }
.layout-main-side { display: grid; grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .layout-main-side { grid-template-columns: minmax(0, 1fr); } }
h2.first { margin-top: 0; }

/* ---- Surfaces ---- */
.card { padding: 1.25rem 1.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card.narrow { max-width: 40rem; }
/* Two short inputs side by side under a field (a unit word's forms for 2 and for 5). */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.4rem; }
.card.danger { margin-top: 2rem; border-color: var(--danger-border); }
.card.danger > h2 { color: var(--danger); }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 0.55rem 1.5rem; margin: 0; }
dl.props dt { color: var(--text-muted); }
dl.props dd { margin: 0; overflow-wrap: anywhere; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
/* A feedback screenshot: big enough to read, and over the whole page while zoomed (portal.js, data-zoom). */
.shot { display: inline-block; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: zoom-in; }
.shot img { display: block; max-width: 100%; max-height: 36rem; }
.shot.zoomed {
	position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; max-width: none;
	padding: 1rem; border: 0; border-radius: 0; background: var(--scrim); cursor: zoom-out;
}
.shot.zoomed img { max-height: 100%; box-shadow: var(--shadow); }
/* A report's app details: label beside value, no table chrome. */
table.context { background: none; }
table.context th, table.context td { padding: 0.35rem 1.5rem 0.35rem 0; border-bottom: 0; }
table.context th {
	width: 1%; background: none; font-size: inherit; font-weight: 400; letter-spacing: normal; text-transform: none;
}
table.context tbody tr:hover > td { background: none; }
/* A sortable column's heading: a link, its arrow from aria-sort. */
th a.sort { color: inherit; text-decoration: none; }
th a.sort:hover { color: var(--text); }
th[aria-sort="ascending"] a.sort::after { content: " \2191"; }
th[aria-sort="descending"] a.sort::after { content: " \2193"; }
.toolbar select { width: auto; }
/* A record's own tabs under its header (a user's Overview, Devices and sessions, Feedback). */
.tabs.page-tabs { margin-bottom: 1.25rem; }
/* Links to days, as small pills (a user's Activity: days with food). */
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin: 0 0 1rem; }
.chips a { padding: 0.15rem 0.55rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.8rem; color: var(--text-muted); text-decoration: none; }
.chips a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
/* A day's totals over its table. */
.totals { display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; margin: 0 0 0.75rem; }
/* A meal's heading row inside the diary table. */
tr.group th { background: var(--surface-2); text-align: left; }
/* Coach: the conversations on the left, the open one's messages on the right; one above the other on a phone. */
.coach-split { display: grid; grid-template-columns: minmax(14rem, 18rem) 1fr; gap: 1rem; align-items: start; margin-top: 1rem; }
@media (max-width: 900px) { .coach-split { grid-template-columns: 1fr; } }
.conversations { display: flex; flex-direction: column; gap: 0.25rem; }
.conversations a { display: flex; flex-direction: column; padding: 0.5rem 0.65rem; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; }
.conversations a:hover { background: var(--surface-2); }
.conversations a[aria-current="page"] { background: var(--accent-soft); }
.messages { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.message { padding: 0.6rem 0.8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.message.user { background: var(--accent-soft); border-color: transparent; }
.message.tool summary { cursor: pointer; color: var(--text-muted); font-size: 0.85rem; }
.message-meta { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0 0 0.3rem; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
/* A section's heading with its action on the right. */
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; }
.section-head h2 { margin: 0; }
/* A second row of tabs filtering the same list (Feedback's kinds). */
.tabs.filters { margin-bottom: 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.range { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 1rem; margin-bottom: 1.5rem; padding: 1rem 1.25rem 0; }
.range .field { flex: 0 1 15rem; }
.range-actions { margin-bottom: 1rem; }
.range-note { flex-basis: 100%; margin: 0 0 1rem; min-height: 0; color: var(--text-muted); font-size: 0.85rem; }
.range-note:empty { display: none; }
.range-note.danger { color: var(--danger); }
.toolbar input[type="text"], .toolbar input[type="search"] { flex: 1 1 18rem; }
.empty { padding: 2.5rem 1rem; color: var(--text-muted); text-align: center; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }

/* ---- Tables ---- */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-variant-numeric: tabular-nums; }
th, td { padding: 0.55rem 0.85rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th {
	background: var(--surface-2); color: var(--text-muted); white-space: nowrap;
	font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}
tbody tr:last-child > td { border-bottom: 0; }
tbody tr:hover > td { background: var(--row-hover); }
th.num, td.num { text-align: right; }
td.nowrap { white-space: nowrap; }
a.row-link { font-weight: 600; text-decoration: none; }
a.row-link:hover { text-decoration: underline; }
.pager { display: flex; gap: 0.5rem; margin-top: 1rem; }
.table-wrap.compact { max-width: 34rem; }
.count { margin: 0 0 0.75rem; color: var(--text-muted); }
.count strong { color: var(--text); }

/* ---- Tabs: links between views of one list ---- */
.tabs { display: inline-flex; gap: 0.25rem; padding: 0.2rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.tabs a { padding: 0.3rem 0.8rem; border-radius: 4px; color: var(--text-muted); font-size: 0.85rem; font-weight: 550; text-decoration: none; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---- Buttons ---- */
button, .btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
	min-height: 2.125rem; padding: 0.4rem 0.9rem; border: 1px solid transparent; border-radius: var(--radius-sm);
	background: var(--accent); color: var(--on-accent); cursor: pointer; white-space: nowrap; text-decoration: none;
	font: inherit; font-size: 0.875rem; font-weight: 550; line-height: 1.2;
}
button:hover, .btn:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-link { min-height: 0; padding: 0; background: none; color: var(--accent-text); font-weight: 500; }
.btn-link:hover { background: none; color: var(--accent-hover); text-decoration: underline; }
.btn-sm { min-height: 1.75rem; padding: 0.2rem 0.6rem; font-size: 0.8rem; }
button:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* ---- Forms ---- */
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"],
input[type="url"], input[type="date"], input[type="datetime-local"], select, textarea {
	min-height: 2.125rem; padding: 0.4rem 0.65rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
	background: var(--surface); color: var(--text); font: inherit; font-size: 0.875rem;
}
textarea { line-height: 1.45; resize: vertical; }
textarea.code, pre.code-block { font-family: var(--mono); font-size: 0.8rem; line-height: 1.55; }
/* A prompt version's changes (prompts/history.html): a line kept, added or removed. */
pre.diff { font-family: var(--mono); font-size: 0.8rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0;
	padding: 0.5rem 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
pre.diff > span { display: block; padding: 0 0.75rem; }
.diff-same { color: var(--text-muted); }
.diff-added { background: var(--success-soft); color: var(--success); }
.diff-removed { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; text-decoration-color: var(--danger-border); }
pre.code-block {
	max-height: 28rem; margin: 0.5rem 0 0; padding: 0.75rem 1rem; overflow: auto;
	background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input.input-short, .field input.input-short { width: 8rem; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-muted); }
label { font-size: 0.85rem; font-weight: 550; }
.field { margin-bottom: 1rem; }
.field > label { display: block; margin-bottom: 0.3rem; }
/* :where() keeps this at one class's weight, so a sizing class such as .input-short still wins. */
.field :where(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea) { width: 100%; }
.hint { margin-top: 0.3rem; color: var(--text-muted); font-size: 0.8rem; font-weight: 400; }
.form-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
fieldset.plain { min-width: 0; margin: 0; padding: 0; border: 0; }
/* A form's fields two to a row (jobs/detail.html): the grid's gap spaces them, not each field's margin. */
.grid-2.fields { gap: 1.25rem 2rem; margin-bottom: 0.5rem; }
.grid-2.fields > .field { margin-bottom: 0; }
/* A pick of several (jobs/detail.html's languages): a box like a select that opens a list of checkboxes. */
details.pick { position: relative; }
details.pick > summary {
	display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; list-style: none;
	min-height: 2.125rem; padding: 0.4rem 0.65rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
	background: var(--surface); color: var(--text); font-size: 0.875rem;
}
details.pick > summary::-webkit-details-marker { display: none; }
details.pick > summary::after { content: "▾"; color: var(--text-muted); }
details.pick[open] > summary, details.pick > summary:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
fieldset:disabled details.pick > summary { background: var(--surface-2); color: var(--text-muted); }
details.pick .pick-list {
	position: absolute; z-index: 10; left: 0; right: 0; margin-top: 0.25rem; padding: 0.35rem 0; max-height: 16rem; overflow: auto;
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-pop);
}
details.pick .pick-list label { display: flex; align-items: center; gap: 0.5rem; margin: 0; padding: 0.35rem 0.75rem; font-weight: 400; cursor: pointer; }
details.pick .pick-list label:hover { background: var(--surface-2); }

/* ---- Status ---- */
.badge {
	display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.1rem 0.55rem; border-radius: 999px;
	background: var(--neutral-soft); color: var(--text-muted); white-space: nowrap;
	font-size: 0.75rem; font-weight: 600; line-height: 1.5;
}
.badge::before { content: ""; width: 0.4rem; height: 0.4rem; border-radius: 50%; background: currentColor; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.quiet { background: transparent; color: var(--text-muted); box-shadow: inset 0 0 0 1px var(--border-strong); }
.badge.quiet::before { background: transparent; box-shadow: inset 0 0 0 1px currentColor; }
.alert { margin-bottom: 1rem; padding: 0.7rem 1rem; border: 1px solid; border-radius: var(--radius-sm); font-size: 0.9rem; }
.alert.success { background: var(--success-soft); border-color: var(--success-border); color: var(--accent-text); }
.alert.danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.alert.warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.alert.info { background: var(--info-soft); border-color: var(--info-border); color: var(--info); }

/* ---- Stats ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 1rem; }
.stat .label { margin: 0; color: var(--text-muted); font-size: 0.85rem; }
.stat .value { margin: 0.25rem 0 0; font-size: 1.75rem; font-weight: 650; font-variant-numeric: tabular-nums; }
/* A word in place of a number, at the number's line height so a row of tiles stays level. */
.stat .value.value-text { font-size: 1.1rem; font-weight: 600; line-height: 2.625rem; }
a.stat-link { display: block; color: inherit; text-decoration: none; transition: border-color 0.15s; }
a.stat-link:hover { border-color: var(--accent); color: inherit; }
a.stat-link .muted, .stat .small { margin: 0.25rem 0 0; }
progress { width: 6rem; height: 0.5rem; vertical-align: middle; accent-color: var(--accent); }
.danger-text { color: var(--danger); }

/* ---- Review: the food's facts stay in view beside the form while it scrolls, once the two sit side by side ---- */
@media (min-width: 1100px) {
	.review-split .review-facts { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
}
.badges { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; margin-left: 0.4rem; vertical-align: middle; }
.keys { margin: 0 0 1rem; color: var(--text-muted); font-size: 0.85rem; }
kbd {
	display: inline-block; min-width: 1.4em; padding: 0 0.3em; border: 1px solid var(--border-strong); border-bottom-width: 2px;
	border-radius: 4px; background: var(--surface); color: var(--text); font-size: 0.8em; line-height: 1.5; text-align: center;
}

/* ---- Recipe pages ---- */
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0 1rem; }
.field-short { max-width: 20rem; }
ul.ingredients, ul.picks { margin: 0; padding: 0; list-style: none; }
ul.ingredients > li { padding: 0.65rem 0; border-bottom: 1px solid var(--border); }
ul.ingredients > li:last-child { border-bottom: 0; }
.ingredient-head { display: flex; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.35rem; }
ul.picks > li { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
ul.picks a[aria-current] { font-weight: 600; color: var(--text); }
ul.picks a[aria-current]::after { content: " (chosen)"; color: var(--text-muted); font-weight: 400; }
.pick-form { margin: 0 0 1.25rem; padding: 1rem; background: var(--accent-soft); border: 1px solid var(--accent-border); border-radius: var(--radius-sm); }
.pick-name { margin: 0 0 0.75rem; }
#add-food { scroll-margin-top: 1rem; }

/* ---- Logs: one .log-entry a line, on the log's dark panel; .wrap breaks long lines, without it each is one line ---- */
.log-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-bottom: 0.75rem; }
.log-status { color: var(--text-muted); font-size: 0.85rem; }
.log-wrap { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0; font-size: 0.85rem; font-weight: 500; }
.log-bar [hidden] { display: none; }
.log {
	max-height: 70vh; margin: 0; padding: 0.75rem 1rem; overflow: auto; border-radius: var(--radius);
	background: var(--log-bg); color: var(--log-text); font-family: var(--mono); font-size: 0.8rem; line-height: 1.5;
}
.log:not(:has(.log-entry)) { display: none; }
.log-entry { padding: 0.1rem 0; border-bottom: 1px solid var(--log-rule); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Wrapped, only the message keeps its own line breaks; the markup's between the parts doesn't count. */
.log.wrap .log-entry { white-space: normal; overflow-wrap: anywhere; }
.log.wrap .log-msg { white-space: pre-wrap; }
.log-time, .log-logger { color: var(--log-muted); }
.log-level { display: inline-block; min-width: 3.2rem; font-weight: 650; }
.log-error .log-level, .log-error .log-msg { color: var(--log-error); }
.log-warn .log-level { color: var(--log-warn); }
.log-debug .log-level, .log-trace .log-level { color: var(--log-muted); }
.log-traceid { margin-left: 0.5rem; color: var(--log-link); font-size: 0.75rem; }
a.log-traceid:hover { color: var(--log-text); }
.log-stack { margin: 0.2rem 0 0.3rem 1rem; white-space: normal; }
.log-stack summary { cursor: pointer; color: var(--log-muted); }
.log-stack pre { margin: 0.25rem 0 0; white-space: pre; overflow-x: auto; color: var(--log-text); font-size: 0.75rem; }
.log-entry.is-new { animation: log-new 2s ease-out; }
@keyframes log-new { from { background: var(--log-flash); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .log-entry.is-new { animation: none; } }

/* ---- Tracing: what's on now on top, then one card a module; a class's logger opens under its name ---- */
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin-bottom: 0.5rem; }
.card-head h2 { margin: 0; }
.trace-now { margin-bottom: 1.5rem; }
.trace-list { margin: 0; padding: 0; list-style: none; }
.trace-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding: 0.6rem 0; border-top: 1px solid var(--border); }
.trace-list li:first-child { border-top: 0; }
.trace-module { margin-bottom: 1rem; }
.trace-module h2 { display: flex; align-items: baseline; gap: 0.6rem; font-size: 1rem; }
.trace-table { width: 100%; table-layout: fixed; }
.trace-table th:nth-child(2) { width: 8rem; }
.trace-table th:nth-child(3) { width: 9.5rem; }
.trace-table th:nth-child(4) { width: 14rem; }
.trace-detail summary { cursor: pointer; overflow-wrap: anywhere; }
.trace-detail code { display: block; margin-top: 0.25rem; overflow-wrap: anywhere; }
@media (max-width: 700px) {
	.trace-table { table-layout: auto; }
	.trace-table th:nth-child(n) { width: auto; }
	/* Class names wrap anywhere, so without a floor the column shrinks to a few letters; the table scrolls instead. */
	.trace-table td:first-child { min-width: 12rem; }
}

/* ---- Catalog imports: the running one's progress, and a release's name checked before it starts ---- */
.import-progress, .import-start { margin-bottom: 1.5rem; }
.progress-row { display: flex; align-items: center; gap: 0.75rem; margin: 0.5rem 0; }
.progress-row progress { flex: 1; height: 0.75rem; }
.progress-row strong { min-width: 3rem; text-align: right; font-variant-numeric: tabular-nums; }
.release-form input.code { font-family: var(--mono); }
.field-status { min-height: 1.25rem; margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--text-muted); }
.field-status.danger { color: var(--danger); }
.field-status.success { color: var(--success); }
.confirm-import ul { margin: 0.25rem 0 0.75rem; padding-left: 1.25rem; }

/* ---- Sign-in ---- */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.auth .card { width: min(100%, 24rem); }
.auth .wordmark { display: block; margin-bottom: 1.25rem; text-align: center; font-size: 1.1rem; }
.auth button[type="submit"] { width: 100%; }

/* ---- The date picker (flatpickr, fragments :: datepicker): its calendar drawn in the portal's colours ---- */
.flatpickr-calendar {
	border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
	box-shadow: var(--shadow-pop);
	font-family: var(--font);
}
.flatpickr-calendar.arrowTop::before { border-bottom-color: var(--border-strong); }
.flatpickr-calendar.arrowBottom::before { border-top-color: var(--border-strong); }
.flatpickr-calendar.arrowTop::after { border-bottom-color: var(--surface); }
.flatpickr-calendar.arrowBottom::after { border-top-color: var(--surface); }
.flatpickr-months .flatpickr-month, .flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-months .flatpickr-prev-month, .flatpickr-months .flatpickr-next-month { color: var(--text); fill: var(--text); }
.flatpickr-current-month .flatpickr-monthDropdown-months:hover, .flatpickr-current-month span.cur-month:hover,
.numInputWrapper:hover { background: var(--surface-2); }
.flatpickr-current-month .numInputWrapper span.arrowUp::after { border-bottom-color: var(--text); }
.flatpickr-current-month .numInputWrapper span.arrowDown::after { border-top-color: var(--text); }
.numInputWrapper span { border-color: var(--border); }
.numInputWrapper span:hover { background: var(--surface-2); }
.flatpickr-current-month { font-size: 1rem; font-weight: 600; }
.flatpickr-months .flatpickr-prev-month:hover svg, .flatpickr-months .flatpickr-next-month:hover svg { fill: var(--accent); }
span.flatpickr-weekday { color: var(--text-muted); font-weight: 600; }
.flatpickr-day { color: var(--text); border-radius: var(--radius-sm); }
.flatpickr-day:hover, .flatpickr-day:focus { background: var(--surface-2); border-color: var(--surface-2); }
.flatpickr-day.today { border-color: var(--accent); }
.flatpickr-day.today:hover { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }
.flatpickr-day.selected, .flatpickr-day.selected:hover, .flatpickr-day.selected:focus {
	background: var(--accent); border-color: var(--accent); color: var(--on-accent);
}
.flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay, .flatpickr-day.flatpickr-disabled { color: var(--border-strong); }
.flatpickr-time { border-top: 1px solid var(--border) !important; }
.flatpickr-time input, .flatpickr-time .flatpickr-am-pm, .flatpickr-time .flatpickr-time-separator { color: var(--text); font-size: 1rem; }
/* Not the portal's boxed fields: the picker's hour and minute are plain cells. */
.flatpickr-time input { min-height: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent; }
.flatpickr-time input:hover, .flatpickr-time input:focus, .flatpickr-time .flatpickr-am-pm:hover, .flatpickr-time .flatpickr-am-pm:focus {
	background: var(--surface-2);
}
.flatpickr-confirm {
	display: none; margin: 0.5rem; padding: 0.45rem 0.9rem; border-radius: var(--radius-sm);
	background: var(--accent); color: var(--on-accent); cursor: pointer; font-size: 0.875rem; font-weight: 550; text-align: center;
}
.flatpickr-confirm.visible { display: block; }
.flatpickr-confirm:hover { background: var(--accent-hover); }
.flatpickr-confirm svg { display: none; }
.datepicker-clear { margin-left: 0.5rem; font-size: 0.8rem; }

/* AI usage: the trend's bars (each --h of the highest), and a feature's or model's share (--w). */
.usage-trend { margin-top: 1.5rem; }
.usage-trend + .tabs, .stats + .tabs { margin-top: 1.5rem; }
/* Each column is a bar with its value written up its top; the bar's --h is of the space under the label. */
.trend { display: flex; align-items: stretch; gap: 2px; height: 13rem; border-bottom: 1px solid var(--border-strong); }
.trend-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.trend-col:hover .trend-bar { background: var(--accent-hover); }
.trend-value { writing-mode: vertical-rl; transform: rotate(180deg); margin-bottom: 0.2rem; color: var(--text-muted); font-size: 0.68rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend-bar { width: 100%; max-width: 2.5rem; height: calc(var(--h) * 0.72); background: var(--accent); border-radius: 2px 2px 0 0; }
.trend-days { display: flex; gap: 2px; margin-top: 0.25rem; }
.trend-days span { flex: 1 1 0; min-width: 0; writing-mode: vertical-rl; transform: rotate(180deg); display: flex; align-items: center; color: var(--text-muted); font-size: 0.68rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend-table { margin-top: 0.75rem; }
.trend-table summary, details.services summary { cursor: pointer; color: var(--text-muted); font-size: 0.85rem; }
details.services table { margin-top: 0.5rem; font-size: 0.85rem; }
.share { display: flex; align-items: center; gap: 0.5rem; min-width: 10rem; }
.share-track { flex: 1; height: 0.5rem; background: var(--neutral-soft); border-radius: 999px; overflow: hidden; }
.share-fill { display: block; height: 100%; width: var(--w); background: var(--accent); }
.share-fill.warning { background: var(--warning); }
.share-fill.danger { background: var(--danger); }
.spend-stats { margin-bottom: 1rem; }
.spend-stats .share { min-width: 0; margin-top: 0.5rem; }
tr.total-row td { border-top: 1px solid var(--border-strong); }
.share-pct { min-width: 2.75rem; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 0.85rem; }

/* Team: one row per area, its levels as a segmented control, and what each level allows (lit up to the chosen one). */
.access-form { margin-bottom: 1rem; }
.access-rows { margin-top: 0.75rem; border-top: 1px solid var(--border); }
.access-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 0.75rem 1.5rem; padding: 0.85rem 0; border-bottom: 1px solid var(--border); }
.access-area { flex: 1 1 22rem; min-width: 0; }
.access-allows { margin: 0.3rem 0 0; padding: 0; list-style: none; font-size: 0.85rem; color: var(--text-muted); }
.access-allows li + li { margin-top: 0.15rem; }
.access-allows li strong { display: inline-block; min-width: 2.6rem; font-weight: 550; }
.access-allows li.is-on { color: var(--text); }
.access-allows li.is-on strong { color: var(--accent-text); }
.segmented { display: inline-flex; flex: 0 0 auto; margin: 0; padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label { margin: 0; padding: 0.4rem 0.85rem; cursor: pointer; font-size: 0.875rem; font-weight: 500; color: var(--text-muted); background: var(--surface); }
.segmented label + input + label { border-left: 1px solid var(--border-strong); }
.segmented label:hover { background: var(--surface-2); color: var(--text); }
.segmented input:checked + label { background: var(--accent); color: var(--on-accent); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid-2 > .card.danger { margin-top: 0; }
/* A checkbox in a toolbar, beside its search box and selects. */
.toolbar .check { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; font-size: 0.875rem; font-weight: 500; white-space: nowrap; cursor: pointer; }
/* Roles to choose from: a checkbox per role, with what it's for. */
.role-choices { margin: 0.75rem 0 0; padding: 0; border: 0; }
.role-choices legend { margin-bottom: 0.35rem; font-weight: 550; }
.role-choice { display: flex; align-items: flex-start; gap: 0.6rem; margin: 0; padding: 0.5rem 0; border-top: 1px solid var(--border); font-weight: 400; cursor: pointer; }
.role-choice:first-of-type { border-top: 0; }
.role-choice input { margin-top: 0.2rem; flex: 0 0 auto; }
.role-choice .muted { font-size: 0.875rem; }

/* Recipes: tags in the list's rows, the tag box as chips, the steps as a list to reorder, and a part loading in place. */
.chips.row-chips { margin: 0.3rem 0 0; }
.chips.row-chips a { padding: 0 0.45rem; font-size: 0.75rem; }
.success-text { color: var(--success); }
.tag-input {
	display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; padding: 0.3rem 0.4rem; cursor: text;
	background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-chip { display: inline-flex; align-items: center; gap: 0.2rem; padding: 0.1rem 0.25rem 0.1rem 0.6rem; background: var(--accent-soft); color: var(--accent-text); border-radius: 999px; font-size: 0.85rem; }
.tag-chip button { min-height: 0; padding: 0 0.35rem; background: transparent; color: inherit; border: 0; font-size: 1rem; line-height: 1.2; cursor: pointer; }
.tag-chip button:hover { color: var(--danger); background: transparent; }
.field .tag-input input.tag-entry { flex: 1 1 8rem; width: auto; min-width: 8rem; min-height: 0; padding: 0.25rem; border: 0; box-shadow: none; background: transparent; }
.steps-editor { margin: 0 0 0.6rem; padding: 0; list-style: none; }
.step-item { display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.4rem 0; }
.step-item.dragging { opacity: 0.5; }
.step-number {
	flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 1.9rem; height: 1.9rem; margin-top: 0.2rem;
	background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px;
	font-size: 0.85rem; font-weight: 600; cursor: grab; user-select: none;
}
.field .step-item textarea { flex: 1 1 auto; min-width: 0; }
.step-actions { flex: 0 0 auto; display: flex; gap: 0.15rem; padding-top: 0.35rem; }
.step-actions button:disabled { visibility: hidden; }
[data-in-place][aria-busy="true"] { opacity: 0.6; transition: opacity 0.15s; }

/* The search on every page, its results, and the keys dialog. */
.sidebar-search { position: relative; margin: 0 1rem 0.75rem; }
.sidebar-search input[type="search"] { width: 100%; padding-right: 2rem; font-size: 0.85rem; }
.sidebar-search kbd { position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.sidebar-search input:focus + kbd { display: none; }
.search-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1rem; align-items: start; }
.search-hits { margin: 0 0 0.6rem; padding: 0; list-style: none; }
.search-hits li { display: flex; flex-direction: column; padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
.search-hits li:last-child { border-bottom: 0; }
.search-hits a { font-weight: 550; overflow-wrap: anywhere; }
.keys-dialog { width: min(26rem, calc(100vw - 2rem)); padding: 1.25rem 1.5rem; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.keys-dialog::backdrop { background: var(--scrim); }
.keys-dialog form { margin: 0; }
.keys-list { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1rem; margin: 0.75rem 0 0; }
.keys-list dd { margin: 0; }
