:root {
	color-scheme: light dark;
	--bg: #ffffff;
	--fg: #0b0d12;
	--muted: #5b6472;
	--accent: #2f6df6;
	--border: #e4e7ec;
	--danger: #b42318;
	--radius: 10px;
	--space: 1rem;
	--font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0b0d12;
		--fg: #f4f6fa;
		--muted: #9aa4b2;
		--accent: #6f9bff;
		--border: #232833;
		--danger: #ff9a8f;
	}
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--fg);
	font-family: var(--font);
	line-height: 1.55;
	-webkit-font-smoothing: antialiased;
}

.shell {
	max-width: 42rem;
	margin: 0 auto;
	padding: calc(var(--space) * 3) var(--space);
}

h1 {
	margin: 0 0 0.5rem;
	font-size: clamp(1.6rem, 4vw, 2.25rem);
	letter-spacing: -0.02em;
}

.lede {
	margin: 0 0 0.75rem;
	font-size: 1.05rem;
}

.hint {
	margin: 0;
	color: var(--muted);
}

.btn {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.55rem 0.9rem;
	border: 1px solid transparent;
	border-radius: var(--radius);
	background: var(--accent);
	color: #fff;
	font: inherit;
	font-weight: 500;
	cursor: pointer;
}

.btn:hover {
	filter: brightness(1.05);
}

.btn-secondary {
	background: transparent;
	color: var(--fg);
	border-color: var(--border);
}

.card {
	padding: var(--space);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
}

.input,
.select,
.textarea {
	width: 100%;
	padding: 0.55rem 0.7rem;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	color: var(--fg);
	font: inherit;
}

.field {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0.35rem;
	margin-bottom: var(--space);
}

.field > label {
	font-size: 0.875rem;
	color: var(--muted);
}

/*
 * 390px-safe, like .grid below. A grid with no column list gets one implicit
 * auto column, and an auto column is never narrower than its widest item's
 * min-content width. One nowrap scrolling strip (days, time slots) anywhere
 * inside an item therefore widened the whole column past the screen: the page
 * scrolled sideways instead of the strip scrolling on its own. minmax(0, 1fr)
 * caps the column at the container; the min-width rule keeps a child from
 * bringing the same floor back if an app redefines the columns. :where() adds
 * no specificity, so a min-width the app sets on a child still wins.
 */
.stack {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--space);
}

:where(.field, .stack, .list) > * {
	min-width: 0;
}

.row {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	flex-wrap: wrap;
}

/*
 * 390px-safe. An unclamped minmax track overflows a 390px viewport once the
 * shell padding is subtracted, and nothing in the pipeline ever looked at a
 * phone-width layout, so every generated app inherited the horizontal scroll.
 * min() clamps the track to the container instead.
 */
.grid {
	display: grid;
	gap: var(--space);
	grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr));
}

.list {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0.5rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.list-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
	padding: 0.7rem 0.85rem;
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.table {
	width: 100%;
	border-collapse: collapse;
}

.table th,
.table td {
	padding: 0.6rem 0.5rem;
	text-align: left;
	border-bottom: 1px solid var(--border);
}

.table th {
	font-size: 0.8125rem;
	color: var(--muted);
	font-weight: 600;
}

.empty {
	padding: calc(var(--space) * 2);
	text-align: center;
	color: var(--muted);
}

.empty-title {
	margin: 0 0 0.25rem;
	color: var(--fg);
	font-weight: 600;
}

/* Loading. Every fetch has one; without a primitive each app invented its own. */
.loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.6rem;
	padding: calc(var(--space) * 1.5);
	color: var(--muted);
}

.spinner {
	flex: none;
	width: 1.15rem;
	height: 1.15rem;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: fab-spin 0.7s linear infinite;
}

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

/* Placeholder for content whose shape is known before its data arrives. */
.skeleton {
	display: block;
	height: 1rem;
	border-radius: calc(var(--radius) / 2);
	background: linear-gradient(90deg, var(--border), transparent, var(--border));
	background-size: 200% 100%;
	animation: fab-shimmer 1.2s linear infinite;
}

@keyframes fab-shimmer {
	to {
		background-position: -200% 0;
	}
}

/* Error strip: a failure the user can see and retry, never a silent no-op. */
.alert {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
	padding: 0.7rem 0.85rem;
	border: 1px solid var(--border);
	border-left: 3px solid var(--muted);
	border-radius: var(--radius);
}

.alert-error {
	border-left-color: var(--danger);
	color: var(--danger);
}

.badge {
	display: inline-block;
	padding: 0.1rem 0.5rem;
	border: 1px solid var(--border);
	border-radius: 999px;
	font-size: 0.8125rem;
	color: var(--muted);
}

/*
 * The scaffold had exactly one @media rule (prefers-color-scheme) and no width
 * breakpoint at all, so the shell was a 42rem column at every size.
 * Mobile-first stays the default; these only widen it.
 */
@media (min-width: 48rem) {
	.shell {
		max-width: 52rem;
		padding: calc(var(--space) * 3) calc(var(--space) * 1.5);
	}
}

@media (min-width: 64rem) {
	.shell {
		max-width: 64rem;
	}
}

.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.logo { display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 8px; background: var(--accent); color: #fff; }
.auth-wrap { display: grid; gap: 1.5rem; padding: 1.5rem 1rem; max-width: 60rem; margin: 0 auto; }
@media (min-width: 52rem) { .auth-wrap { grid-template-columns: 1.2fr 1fr; align-items: center; min-height: 100vh; } }
.auth-hero h1 { margin-top: 1rem; }
.sample { margin-top: 1rem; border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }
.sample-head { font-weight: 600; color: var(--muted); margin-bottom: .5rem; }
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; background: var(--border); padding: .25rem; border-radius: var(--radius); }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--fg); padding: .5rem; border-radius: 8px; font: inherit; cursor: pointer; }
.tabs button.on { background: var(--bg); font-weight: 600; }
.full { width: 100%; justify-content: center; margin-top: .75rem; }
.forgot { display: block; margin-top: .75rem; text-align: center; color: var(--accent); }
.chat { display: grid; height: 100dvh; }
@media (min-width: 45rem) { .chat { grid-template-columns: 18rem minmax(0, 1fr); } }
.side { overflow-y: auto; padding: .75rem; border-right: 1px solid var(--border); }
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
.side-tools { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.side-tools .btn { padding: .4rem .65rem; font-size: .875rem; }
.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: .25rem; }
.panel { margin-bottom: .75rem; }
.panel.row { flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }
.nav-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1rem 0 .25rem; }
.nav, .hits { list-style: none; margin: 0; padding: 0; }
.nav-item { display: flex; align-items: center; gap: .6rem; width: 100%; padding: .6rem; border: 0; border-radius: 8px; background: none; color: var(--fg); font: inherit; text-align: left; cursor: pointer; }
.nav-item:hover { background: var(--border); }
.nav-item.on { background: var(--accent); color: #fff; }
.nav-item.unread .nav-name { font-weight: 700; }
.nav-icon { display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 6px; background: var(--border); color: var(--fg); font-size: .75rem; font-weight: 600; flex: none; }
.nav-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .75rem; font-weight: 700; }
.small { font-size: .85rem; }
.hit { display: grid; width: 100%; text-align: left; gap: .15rem; padding: .5rem; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--fg); font: inherit; cursor: pointer; }
.room { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.room-empty { margin: auto; }
.room-head { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.room-head h2 { margin: 0; font-size: 1.1rem; }
.back { font-size: 1.6rem; line-height: 1; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0 .5rem; }
.msgs { flex: 1; overflow-y: auto; padding: 1rem; }
.older { display: block; margin: 0 auto 1rem; }
.msg { display: flex; gap: .6rem; margin-top: .75rem; }
.msg.grouped { margin-top: .1rem; }
.avatar { width: 2.1rem; height: 2.1rem; flex: none; border-radius: 8px; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.grouped .avatar { background: none; height: 0; }
.msg-body { min-width: 0; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.time { color: var(--muted); font-size: .75rem; }
.composer { display: flex; gap: .5rem; padding: .75rem; border-top: 1px solid var(--border); }
.composer textarea { resize: none; }
@media (max-width: 44.99rem) {
	.chat.has-active .side { display: none; }
	.chat:not(.has-active) .room { display: none; }
}
@media (min-width: 45rem) { .back { display: none; } }

@media (prefers-reduced-motion: reduce) {
	.spinner,
	.skeleton {
		animation: none;
	}
}

:where(a, button, input, select, textarea):focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}
