/* =============================================================================
   GridXray: design tokens, base styles and the looks several components share.

   Built on the structure of Microsoft's Fluent 2 (https://fluent2.microsoft.design):
   its type ramp, spacing, shapes, elevation, motion and colour roles, drawn in
   GridXray's own blue, ink and Geist. Light theme only.

   Colours come in two layers:
   - the palette (brand, gray, status), which nothing but the roles below and a
     chart should need;
   - the roles (--fg-*, --bg-*, --stroke-*), which say what a colour is for and
     how it changes on hover and press. Components use these.

   --primary, --dark, --gray-500, --info-off, --p-lg, --r-md, --fs-xs, --shadow-sm…
   are the names realstate-front uses, so a screen brought over from there takes
   this brand's values as it is.
   ============================================================================= */

/* Geist, variable (100–900). License: SIL OFL. */
@font-face {
	font-family: 'Geist';
	font-weight: 100 900;
	font-display: swap;
	src: url('../font/Geist.woff2') format('woff2');
}

@font-face {
	font-family: 'GeistMono';
	font-weight: 100 900;
	font-display: swap;
	src: url('../font/GeistMono.woff2') format('woff2');
}

:root {
	color-scheme: light;

	/* --- Palette ---------------------------------------------------------------- */

	/* Brand: Fluent's 16 steps drawn through the logo's signal blue (step 90).
	   White text passes 4.5:1 from step 80 down; the signal itself is for marks,
	   lines and icons (3.4:1 on white), never for text. */
	--brand-10: #091224;
	--brand-20: #0b1c3a;
	--brand-30: #0c2651;
	--brand-40: #09326d;
	--brand-50: #023d89;
	--brand-60: #004ca4;
	--brand-70: #005bbd;
	--brand-80: #006cd7;
	--brand-90: #0b8cff;
	--brand-100: #4ca1ff;
	--brand-110: #69afff;
	--brand-120: #82bcff;
	--brand-130: #9dcbff;
	--brand-140: #b9daff;
	--brand-150: #d3e7ff;
	--brand-160: #ebf4ff;

	--primary: var(--brand-80);
	--primary-mark: var(--brand-90); /* marks, icons, chart fills */
	--primary-dark: var(--brand-70); /* labels and small text */
	--primary-off: var(--brand-160);
	--primary-bright: var(--brand-140); /* a light fill, under ink */
	--primary-bright-hover: var(--brand-130);

	/* Neutrals: Fluent's gray steps with a trace of the logo's ink. */
	--white: #ffffff;
	--off: #f4f5f8; /* the page behind the cards */
	--gray-25: #f9fafc;
	--gray-50: #f4f5f8;
	--gray-100: #eef0f3;
	--gray-150: #e9ebef;
	--gray-200: #dde0e5;
	--gray-300: #cdd1d8;
	--gray-350: #aeb4bd;
	--gray-400: #78818f;
	--gray-450: #677180;
	--gray-500: #586272;
	--gray-550: #4d5869;
	--gray-600: #374356;
	--gray-700: #222f42;
	--dark: #101a2e; /* the ink */

	/* Status: for state and urgency only, never decoration. `-dark` is the text
	   on `-off`, `-line` its border. */
	--success: #107c10;
	--success-dark: #0e700e;
	--success-off: #e8f5e8;
	--success-line: #9fd89f;

	--warning: #f7630c;
	--warning-dark: #bc4b09;
	--warning-off: #fff1e8;
	--warning-line: #fdcfb4;

	--danger: #c50f1f;
	--danger-dark: #b10e1c;
	--danger-off: #fdebed;
	--danger-line: #eeacb2;

	--accent: #6656d1;
	--accent-dark: #5649b0;
	--accent-off: #f0eefd;
	--accent-line: #d2ccf8;

	--info: var(--brand-80);
	--info-dark: var(--brand-70);
	--info-off: var(--brand-160);
	--info-line: var(--brand-140);

	/* Chart series, in this order and never cycled: the order is what keeps
	   neighbours apart for color-blind readers. Past seven, fold into `other`. */
	--chart-1: var(--brand-90);
	--chart-2: #ca5010;
	--chart-3: #009ba5;
	--chart-4: #6656d1;
	--chart-5: #ae8c00;
	--chart-6: #bf0077;
	--chart-7: #13a10e;
	--chart-other: var(--gray-400);

	/* --- Roles ------------------------------------------------------------------ */

	/* Text and icons */
	--fg-1: var(--dark);
	--fg-2: var(--gray-600);
	--fg-3: var(--gray-500);
	--fg-4: var(--gray-450); /* placeholders */
	--fg-disabled: #b8bdc6;
	--fg-on-brand: var(--white);
	--fg-brand: var(--brand-80);
	--fg-brand-hover: var(--brand-70);
	--fg-brand-pressed: var(--brand-60);
	--fg-link: var(--brand-70);
	--fg-link-hover: var(--brand-60);
	--fg-link-pressed: var(--brand-40);

	/* Surfaces */
	--bg-1: var(--white); /* cards, fields, dialogs */
	--bg-1-hover: var(--gray-50);
	--bg-1-pressed: var(--gray-200);
	--bg-1-selected: var(--gray-150);
	--bg-2: var(--gray-25);
	--bg-3: var(--gray-50);
	--bg-4: var(--gray-100);
	--bg-disabled: var(--gray-100);
	--bg-inverted: var(--dark);
	--bg-overlay: rgba(16, 26, 46, 0.4); /* behind dialogs and drawers */
	/* Over any surface: a control with no fill of its own */
	--bg-subtle-hover: rgba(16, 26, 46, 0.05);
	--bg-subtle-pressed: rgba(16, 26, 46, 0.12);
	--bg-subtle-selected: rgba(16, 26, 46, 0.08);
	/* Brand fills: buttons, checked controls, selected states */
	--bg-brand: var(--brand-80);
	--bg-brand-hover: var(--brand-70);
	--bg-brand-pressed: var(--brand-40);
	--bg-checked: var(--brand-80);
	--bg-checked-hover: var(--brand-70);
	--bg-checked-pressed: var(--brand-60);
	--bg-tint: var(--brand-160);
	--bg-tint-hover: var(--brand-150);
	--bg-tint-pressed: var(--brand-130);
	--bg-stencil: #e4e6ea; /* skeletons */
	--bg-stencil-shine: var(--gray-25);

	/* Strokes */
	--stroke-1: var(--gray-300); /* controls */
	--stroke-1-hover: #c3c8cf;
	--stroke-1-pressed: var(--gray-350);
	--stroke-2: var(--gray-200); /* dividers, table rows, outlined cards */
	--stroke-3: var(--gray-100);
	--stroke-accessible: var(--gray-500); /* what must be seen: a checkbox, a field's base line */
	--stroke-accessible-hover: var(--gray-550);
	--stroke-accessible-pressed: #424e60;
	--stroke-brand: var(--brand-90); /* active lines: focus, the selected tab, progress */
	--stroke-tint: var(--brand-140);
	--stroke-disabled: var(--gray-200);
	--stroke-focus: var(--dark); /* keyboard focus ring */

	/* --- Type ------------------------------------------------------------------- */

	--font-family-sans-serif:
		'Geist', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue',
		sans-serif;
	--font-family-mono: 'GeistMono', ui-monospace, 'SF Mono', Consolas, Menlo, monospace;

	--fw-regular: 400;
	--fw-medium: 500;
	--fw-semibold: 600;
	--fw-bold: 700;
	--fw-black: 700; /* Fluent stops at bold */

	/* Fluent's ramp, each size with its line height */
	--fs-xxs: 10px; /* caption 2 */
	--fs-xs: 12px; /* caption 1 */
	--fs-sm: 13px; /* off the ramp: kept for screens brought over, new ones take xs or base */
	--fs-base: 14px; /* body 1 */
	--fs-md: 16px; /* body 2, subtitle 2 */
	--fs-lg: 20px; /* subtitle 1 */
	--fs-xl: 24px; /* title 3 */
	--fs-2xl: 28px; /* title 2 */
	--fs-3xl: 32px; /* title 1 */
	--fs-4xl: 40px; /* large title */
	--fs-5xl: 68px; /* display */

	--lh-xxs: 14px;
	--lh-xs: 16px;
	--lh-base: 20px;
	--lh-md: 22px;
	--lh-lg: 28px;
	--lh-xl: 32px;
	--lh-2xl: 36px;
	--lh-3xl: 40px;
	--lh-4xl: 52px;
	--lh-5xl: 76px;

	/* --- Space, shape, elevation, motion ------------------------------------------ */

	/* Multiples of 4; 2, 6 and 10 align icons and text inside controls */
	--p-2: 2px;
	--p-sm: 4px;
	--p-6: 6px;
	--p: 8px;
	--p-10: 10px;
	--p-md: 12px;
	--p-lg: 16px;
	--p-20: 20px;
	--p-xl: 24px;
	--p-32: 32px;
	--p-xxl: 40px;
	--p-xxxl: 64px;

	--r-sm: 2px; /* under 32px: checkboxes, small marks */
	--r: 4px; /* buttons, fields, menu items */
	--r-md: 4px;
	--r-lg: 6px;
	--r-xl: 8px; /* cards, dialogs, popups */
	--r-xxl: 12px;
	--r-pill: 10000px;

	--shadow-none: 0 0 transparent;
	--shadow-edge: 0 0 transparent; /* a dark theme's: here so a list that names it stays valid */
	--shadow-ambient: rgba(16, 26, 46, 0.12);
	--shadow-key: rgba(16, 26, 46, 0.14);
	--shadow-xs: 0 0 2px var(--shadow-ambient), 0 1px 2px var(--shadow-key); /* shadow2 */
	--shadow-sm: 0 0 2px var(--shadow-ambient), 0 2px 4px var(--shadow-key); /* 4: cards */
	--shadow: 0 0 2px var(--shadow-ambient), 0 4px 8px var(--shadow-key); /* 8: toasts, raised cards */
	--shadow-md: 0 0 2px var(--shadow-ambient), 0 8px 16px var(--shadow-key); /* 16: menus, popups */
	--shadow-lg: 0 0 8px var(--shadow-ambient), 0 14px 28px var(--shadow-key); /* 28: bars, side sheets */
	--shadow-xl: 0 0 8px var(--shadow-ambient), 0 32px 64px var(--shadow-key); /* 64: dialogs */

	--dur-ultra-fast: 50ms;
	--dur-faster: 100ms;
	--dur-fast: 150ms;
	--dur: 200ms;
	--dur-gentle: 250ms;
	--dur-slow: 300ms;
	--dur-slower: 400ms;
	--ease: cubic-bezier(0.33, 0, 0.67, 1);
	--ease-out: cubic-bezier(0, 0, 0, 1);
	--ease-out-max: cubic-bezier(0.1, 0.9, 0.2, 1);
	--ease-in: cubic-bezier(1, 0, 1, 1);

	/* --- Controls and layers -------------------------------------------------------- */

	/* Fluent's small / medium / large control heights */
	--control-h-sm: 24px;
	--control-h: 32px;
	--control-h-lg: 40px;
	--control-fs: var(--fs-base);
	--control-lh: var(--lh-base);

	--z-sticky: 10;
	--z-overlay: 1000;
	--z-raised: 1001;
	--z-popup: 1050;
	--z-tooltip: 1100;
	--z-toast: 1200;
	--z-loading: 1500;
	--z-banner: 2000;
}

/* Fingers: one step up for every control, and 16px text in fields, under which
   iOS zooms the page into the field it focuses. */
@media (pointer: coarse) {
	:root {
		--control-h-sm: 32px;
		--control-h: 40px;
		--control-h-lg: 48px;
		--control-fs: var(--fs-md);
		--control-lh: var(--lh-md);
	}
}

/* =============================================================================
   Base
   ============================================================================= */

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

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

body {
	margin: 0;
	background: var(--off);
	color: var(--fg-1);
	font-family: var(--font-family-sans-serif);
	font-size: var(--fs-base);
	font-weight: var(--fw-regular);
	line-height: var(--lh-base);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	margin: 0;
	color: var(--fg-1);
	font-family: inherit;
	font-weight: var(--fw-semibold);
}

h1 {
	font-size: var(--fs-3xl);
	line-height: var(--lh-3xl);
	letter-spacing: -0.02em;
}

h2 {
	font-size: var(--fs-2xl);
	line-height: var(--lh-2xl);
	letter-spacing: -0.02em;
}

h3 {
	font-size: var(--fs-xl);
	line-height: var(--lh-xl);
	letter-spacing: -0.015em;
}

h4 {
	font-size: var(--fs-lg);
	line-height: var(--lh-lg);
	letter-spacing: -0.01em;
}

h5 {
	font-size: var(--fs-md);
	line-height: var(--lh-md);
}

h6 {
	font-size: var(--fs-base);
	line-height: var(--lh-base);
}

a {
	color: inherit;
	text-decoration: underline;
}

button {
	appearance: none;
	margin: 0;
	padding: 0;
	border: none;
	background: none;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

input,
textarea,
select {
	color: inherit;
	font: inherit;
}

img,
svg {
	vertical-align: middle;
}

::selection {
	background: var(--brand-140);
	color: var(--dark);
}

/* Keyboard focus, on whatever has no ring of its own */
:focus-visible {
	outline: 2px solid var(--stroke-focus);
	outline-offset: 1px;
}

/* For assistive tech only */
.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	/* The spinner is the one motion that carries meaning */
	*:not(.spinner, .spinner *),
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}

/* =============================================================================
   Type
   ============================================================================= */

.text-caption-2 {
	font-size: var(--fs-xxs);
	line-height: var(--lh-xxs);
}

.text-caption {
	font-size: var(--fs-xs);
	line-height: var(--lh-xs);
}

.text-body {
	font-size: var(--fs-base);
	line-height: var(--lh-base);
}

.text-body-2 {
	font-size: var(--fs-md);
	line-height: var(--lh-md);
}

.text-subtitle-2 {
	font-size: var(--fs-md);
	font-weight: var(--fw-semibold);
	line-height: var(--lh-md);
}

.text-subtitle {
	font-size: var(--fs-lg);
	font-weight: var(--fw-semibold);
	line-height: var(--lh-lg);
	letter-spacing: -0.01em;
}

.text-title-3 {
	font-size: var(--fs-xl);
	font-weight: var(--fw-semibold);
	line-height: var(--lh-xl);
	letter-spacing: -0.015em;
}

.text-title-2 {
	font-size: var(--fs-2xl);
	font-weight: var(--fw-semibold);
	line-height: var(--lh-2xl);
	letter-spacing: -0.02em;
}

.text-title {
	font-size: var(--fs-3xl);
	font-weight: var(--fw-semibold);
	line-height: var(--lh-3xl);
	letter-spacing: -0.02em;
}

.text-large-title {
	font-size: var(--fs-4xl);
	font-weight: var(--fw-semibold);
	line-height: var(--lh-4xl);
	letter-spacing: -0.03em;
}

.text-display {
	font-size: var(--fs-5xl);
	font-weight: var(--fw-semibold);
	line-height: var(--lh-5xl);
	letter-spacing: -0.04em;
}

.text-strong {
	font-weight: var(--fw-semibold);
}

.link {
	color: var(--fg-link);
	text-decoration: none;
	cursor: pointer;
}

.link:hover {
	color: var(--fg-link-hover);
	text-decoration: underline;
}

.link:active {
	color: var(--fg-link-pressed);
}

/* =============================================================================
   Buttons. Button.svelte is this; the classes also dress what cannot be one, such
   as a Popover's activator: <span class="btn tone-outline">.

   A tone is a set of colours. One `primary`/`default` per layout, for the action
   that matters most; `outline` beside it, `transparent` for the many small ones.
   ============================================================================= */

.btn,
.tone-default,
.tone-primary,
.tone-info {
	--tone-bg: var(--bg-brand);
	--tone-bg-hover: var(--bg-brand-hover);
	--tone-bg-pressed: var(--bg-brand-pressed);
	--tone-fg: var(--fg-on-brand);
	--tone-fg-hover: var(--tone-fg);
	--tone-line: transparent;
	--tone-line-hover: var(--tone-line);
	--tone-line-pressed: var(--tone-line);
}

.tone-outline {
	--tone-bg: var(--bg-1);
	--tone-bg-hover: var(--bg-1-hover);
	--tone-bg-pressed: var(--bg-1-pressed);
	--tone-fg: var(--fg-1);
	--tone-line: var(--stroke-1);
	--tone-line-hover: var(--stroke-1-hover);
	--tone-line-pressed: var(--stroke-1-pressed);
}

.tone-transparent,
.tone-bold {
	--tone-bg: transparent;
	--tone-bg-hover: var(--bg-subtle-hover);
	--tone-bg-pressed: var(--bg-subtle-pressed);
	--tone-fg: var(--fg-2);
	--tone-fg-hover: var(--fg-1);
}

.tone-light {
	--tone-bg: var(--white);
	--tone-bg-hover: var(--brand-160);
	--tone-bg-pressed: var(--brand-140);
	--tone-fg: var(--fg-link);
}

.tone-accent {
	--tone-bg: var(--accent);
	--tone-bg-hover: var(--accent-dark);
	--tone-bg-pressed: #3f3682;
}

.tone-success {
	--tone-bg: var(--success);
	--tone-bg-hover: var(--success-dark);
	--tone-bg-pressed: #0c5e0c;
}

.tone-warning {
	--tone-bg: var(--warning);
	--tone-bg-hover: #f98845;
	--tone-bg-pressed: #de590b;
	--tone-fg: var(--dark);
}

.tone-danger {
	--tone-bg: var(--danger);
	--tone-bg-hover: var(--danger-dark);
	--tone-bg-pressed: #960b18;
}

.tone-info-off {
	--tone-bg: var(--bg-tint);
	--tone-bg-hover: var(--bg-tint-hover);
	--tone-bg-pressed: var(--bg-tint-pressed);
	--tone-fg: var(--info-dark);
	--tone-line: var(--info-line);
}

.tone-success-off {
	--tone-bg: var(--success-off);
	--tone-bg-hover: #c9eac9;
	--tone-bg-pressed: var(--success-line);
	--tone-fg: var(--success-dark);
	--tone-line: var(--success-line);
}

.tone-warning-off {
	--tone-bg: var(--warning-off);
	--tone-bg-hover: #fee5d7;
	--tone-bg-pressed: var(--warning-line);
	--tone-fg: #8a3707;
	--tone-line: var(--warning-line);
}

.tone-danger-off {
	--tone-bg: var(--danger-off);
	--tone-bg-hover: #f6d1d5;
	--tone-bg-pressed: var(--danger-line);
	--tone-fg: var(--danger-dark);
	--tone-line: var(--danger-line);
}

.tone-info-foreground,
.tone-success-foreground,
.tone-warning-foreground,
.tone-danger-foreground {
	--tone-bg: transparent;
	--tone-bg-hover: var(--bg-subtle-hover);
	--tone-bg-pressed: var(--bg-subtle-pressed);
}

.tone-info-foreground {
	--tone-fg: var(--fg-link);
}

.tone-success-foreground {
	--tone-fg: var(--success-dark);
}

.tone-warning-foreground {
	--tone-fg: var(--warning-dark);
}

.tone-danger-foreground {
	--tone-fg: var(--danger-dark);
}

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--p-6);
	min-width: 96px;
	min-height: var(--control-h);
	padding: 0 var(--p-md);
	border: 1px solid var(--tone-line);
	border-radius: var(--r);
	background: var(--tone-bg);
	color: var(--tone-fg);
	font-family: inherit;
	font-size: var(--control-fs);
	font-weight: var(--fw-semibold);
	line-height: var(--control-lh);
	text-decoration: none;
	white-space: nowrap;
	user-select: none;
	cursor: pointer;
	transition:
		background var(--dur-faster) var(--ease),
		border-color var(--dur-faster) var(--ease),
		color var(--dur-faster) var(--ease);
}

.btn svg {
	flex-shrink: 0;
}

.btn:hover {
	background: var(--tone-bg-hover);
	border-color: var(--tone-line-hover);
	color: var(--tone-fg-hover);
}

.btn:active {
	background: var(--tone-bg-pressed);
	border-color: var(--tone-line-pressed);
}

.btn.tone-transparent:hover svg {
	color: var(--fg-brand);
}

.btn.tone-transparent:active svg {
	color: var(--fg-brand-pressed);
}

.btn.tone-bold {
	font-weight: var(--fw-bold);
}

.btn.is-small {
	gap: var(--p-sm);
	min-width: 64px;
	min-height: var(--control-h-sm);
	padding: 0 var(--p);
	font-size: var(--fs-xs);
	font-weight: var(--fw-regular);
	line-height: var(--lh-xs);
}

.btn.is-large {
	min-height: var(--control-h-lg);
	padding: 0 var(--p-lg);
	font-size: var(--fs-md);
	line-height: var(--lh-md);
}

/* A glyph alone: square */
.btn.is-icon {
	min-width: var(--control-h);
	padding: 0;
}

.btn.is-icon.is-small {
	min-width: var(--control-h-sm);
}

.btn.is-icon.is-large {
	min-width: var(--control-h-lg);
}

.btn.is-full-width {
	width: 100%;
	padding-block: 5px;
	white-space: normal;
}

.btn.tone-unstyled {
	min-width: 0;
	min-height: 0;
	padding: 0;
	border: none;
	background: none;
	color: inherit;
	font-weight: inherit;
}

.btn:disabled,
.btn.is-disabled,
.btn.tone-disabled {
	border-color: var(--stroke-disabled);
	background: var(--bg-disabled);
	color: var(--fg-disabled);
	cursor: not-allowed;
}

.btn.tone-transparent:disabled,
.btn.tone-transparent.is-disabled,
.btn[class*='-foreground']:disabled,
.btn[class*='-foreground'].is-disabled,
.btn.tone-unstyled:disabled {
	border-color: transparent;
	background: transparent;
}

.btn:disabled:hover svg,
.btn.is-disabled:hover svg {
	color: inherit;
}

/* Busy keeps its colours: the action is on its way, not out of reach */
.btn.is-loading,
.btn.is-loading:disabled {
	border-color: var(--tone-line);
	background: var(--tone-bg);
	color: var(--tone-fg);
	cursor: wait;
}

/* =============================================================================
   Fields. The frame of every input: a light outline on a stronger base line, and
   a brand line that grows along the base while it has the focus.

     <div class="control">
       <span class="control-icon">…</span>
       <input class="control-input" />
       <button class="control-btn">…</button>
     </div>
   ============================================================================= */

.control {
	position: relative;
	display: flex;
	align-items: center;
	gap: var(--p-6);
	width: 100%;
	min-width: 0;
	min-height: var(--control-h);
	padding: 0 var(--p-10);
	border: 1px solid var(--stroke-1);
	border-bottom-color: var(--stroke-accessible);
	border-radius: var(--r);
	background: var(--bg-1);
	color: var(--fg-1);
	font-size: var(--control-fs);
	line-height: var(--control-lh);
	text-align: left;
}

.control:hover {
	border-color: var(--stroke-1-hover);
	border-bottom-color: var(--stroke-accessible-hover);
}

.control:active,
.control:focus-within,
.control.is-open {
	border-color: var(--stroke-1-pressed);
	border-bottom-color: var(--stroke-accessible-pressed);
}

/* As tall as the corners' radius and clipped to its last 2px, so the line follows
   the frame's corners. */
.control::after {
	content: '';
	position: absolute;
	right: -1px;
	bottom: -1px;
	left: -1px;
	height: max(2px, var(--r));
	border-bottom: 2px solid var(--stroke-brand);
	border-radius: 0 0 var(--r) var(--r);
	clip-path: inset(calc(100% - 2px) 0 0 0);
	transform: scaleX(0);
	transition: transform var(--dur-ultra-fast) var(--ease-in);
	pointer-events: none;
}

.control:focus-within::after,
.control.is-open::after {
	transform: scaleX(1);
	transition: transform var(--dur) var(--ease-out);
}

/* The line along the base says it: a ring around a field would say it twice */
.control:focus-visible {
	outline: none;
}

.control.is-invalid:not(:focus-within, .is-open),
.control.is-invalid:hover:not(:focus-within, .is-open) {
	border-color: var(--danger);
}

.control.is-disabled,
.control.is-disabled:hover {
	border-color: var(--stroke-disabled);
	background: transparent;
	color: var(--fg-disabled);
	cursor: not-allowed;
}

.control.is-readonly,
.control.is-readonly:hover {
	border-color: var(--stroke-2);
	background: var(--bg-2);
}

.control.is-disabled::after,
.control.is-readonly::after {
	content: none;
}

.control-input {
	flex: 1;
	align-self: stretch;
	min-width: 0;
	width: 100%;
	margin: 0;
	padding: 0 2px;
	border: none;
	outline: none;
	appearance: none;
	background: transparent;
	color: inherit;
	font: inherit;
	text-overflow: ellipsis;
}

.control-input::placeholder {
	color: var(--fg-4);
	opacity: 1;
}

.control-input:disabled {
	color: var(--fg-disabled);
	-webkit-text-fill-color: var(--fg-disabled);
	opacity: 1;
	cursor: not-allowed;
}

.control-input:disabled::placeholder {
	color: var(--fg-disabled);
}

.control-input:-webkit-autofill {
	-webkit-text-fill-color: var(--fg-1);
	box-shadow: inset 0 0 0 100px var(--bg-1);
}

.control-icon,
.control-addon {
	display: inline-flex;
	flex-shrink: 0;
	color: var(--fg-3);
	white-space: nowrap;
}

.control.is-disabled .control-icon,
.control.is-disabled .control-addon {
	color: var(--fg-disabled);
}

.control-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 24px;
	height: 24px;
	border-radius: var(--r);
	color: var(--fg-3);
	transition:
		background var(--dur-faster) var(--ease),
		color var(--dur-faster) var(--ease);
}

.control-btn:last-child {
	margin-right: -6px;
}

.control-btn:hover {
	background: var(--bg-subtle-hover);
	color: var(--fg-1);
}

.control-btn:active {
	background: var(--bg-subtle-pressed);
}

.control-btn:disabled {
	background: none;
	color: var(--fg-disabled);
	cursor: not-allowed;
}

/* =============================================================================
   Popups: menus, listboxes, date panels
   ============================================================================= */

.popup {
	border: 1px solid transparent;
	border-radius: var(--r-xl);
	background: var(--bg-1);
	color: var(--fg-1);
	box-shadow: var(--shadow-md);
}

.menu-item {
	display: flex;
	align-items: center;
	gap: var(--p-6);
	width: 100%;
	min-height: var(--control-h);
	padding: var(--p-6) var(--p);
	border-radius: var(--r);
	color: var(--fg-2);
	font-size: var(--control-fs);
	line-height: var(--control-lh);
	text-align: left;
	text-decoration: none;
	white-space: nowrap;
	cursor: pointer;
}

.menu-item svg {
	flex-shrink: 0;
}

.menu-item:hover,
.menu-item.is-highlighted {
	background: var(--bg-1-hover);
	color: var(--fg-1);
}

.menu-item:hover svg {
	color: var(--fg-brand);
}

.menu-item:active {
	background: var(--bg-1-pressed);
}

.menu-item.is-danger,
.menu-item.is-danger:hover svg {
	color: var(--danger-dark);
}

.menu-item:disabled {
	background: none;
	color: var(--fg-disabled);
	cursor: not-allowed;
}

.menu-divider {
	height: 1px;
	margin: var(--p-sm) calc(var(--p-sm) * -1);
	border: none;
	background: var(--stroke-2);
}

/* =============================================================================
   Toasts (utils/toasts.ts)
   ============================================================================= */

#toasts {
	position: fixed;
	right: var(--p-20);
	bottom: var(--p-20);
	z-index: var(--z-toast);
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: var(--p);
	width: 320px;
	max-width: calc(100vw - 2 * var(--p-lg));
	pointer-events: none;
}

.toast {
	display: flex;
	align-items: flex-start;
	gap: var(--p);
	width: 100%;
	padding: var(--p-md);
	border: 1px solid transparent;
	border-radius: var(--r-xl);
	background: var(--bg-1);
	color: var(--fg-1);
	box-shadow: var(--shadow);
	overflow-wrap: anywhere;
	pointer-events: auto;
	animation: toast-in var(--dur-gentle) var(--ease-out) both;
}

.toast.is-leaving {
	animation: toast-out var(--dur-fast) var(--ease-in) both;
}

.toast.is-actionable {
	cursor: pointer;
}

.toast-icon {
	flex-shrink: 0;
	width: 20px;
	height: 20px;
	color: var(--fg-3);
}

.toast.is-info .toast-icon {
	color: var(--fg-brand);
}

.toast.is-success .toast-icon {
	color: var(--success);
}

.toast.is-warning .toast-icon {
	color: var(--warning-dark);
}

.toast.is-danger .toast-icon {
	color: var(--danger);
}

.toast-content {
	flex: 1;
	min-width: 0;
}

.toast-title {
	font-weight: var(--fw-semibold);
}

.toast-body {
	margin-top: var(--p-2);
	color: var(--fg-2);
}

.toast-action {
	display: block;
	margin-top: var(--p-sm);
	color: var(--fg-link);
	text-align: left;
}

.toast-action:hover {
	color: var(--fg-link-hover);
	text-decoration: underline;
}

.toast-close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 24px;
	height: 24px;
	margin: -2px -4px -2px 0;
	border-radius: var(--r);
	color: var(--fg-3);
}

.toast-close:hover {
	background: var(--bg-subtle-hover);
	color: var(--fg-1);
}

@keyframes toast-in {
	from {
		opacity: 0;
		transform: translateY(16px);
	}
}

@keyframes toast-out {
	to {
		opacity: 0;
		transform: translateX(24px);
	}
}

@media (max-width: 480px) {
	#toasts {
		right: var(--p-lg);
		bottom: var(--p-lg);
		width: calc(100vw - 2 * var(--p-lg));
	}
}

/* =============================================================================
   Layout helpers
   ============================================================================= */

.container,
.container-narrow,
.container-wide {
	width: 100%;
	max-width: 1200px;
	margin: 0 auto;
}

.container-narrow {
	max-width: 768px;
}

.container-wide {
	max-width: 1800px;
}

.row,
.column {
	display: flex;
	align-items: flex-start;
	gap: inherit;
	width: 100%;
}

.column {
	flex-direction: column;
}

.row > * {
	flex: 1;
}

.gap-1 {
	gap: var(--p-sm);
}

.gap-2 {
	gap: var(--p);
}

.gap-3 {
	gap: var(--p-md);
}

.gap-4 {
	gap: var(--p-lg);
}

.gap-5 {
	gap: var(--p-xl);
}
