/* Agent — one continuous thread. The agent writes in serif prose; the user in sans blocks; folded context shows as seams. */

:root {
	--fog: #EEF1F4;
	--surface: #F8FAFB;
	--ink: #1C2430;
	--muted: #6B7685;
	--line: #D5DBE2;
	--accent: #3F4FB8;
	--accent-ink: #FFFFFF;
	--user-bg: #DDE2F3;
	--danger: #B3261E;
	--seam: #C5CDD7;

	--sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
	--serif: ui-serif, "New York", "Iowan Old Style", Charter, Georgia, serif;
	--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

	--measure: 40rem;
	--gutter: 16px;
	color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
	:root {
		--fog: #12161C;
		--surface: #1A2028;
		--ink: #E6EAF0;
		--muted: #8A95A5;
		--line: #252C36;
		--accent: #8C9BFF;
		--accent-ink: #0F1424;
		--user-bg: #232B45;
		--danger: #F2B8B5;
		--seam: #333C48;
	}
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
	margin: 0;
	background: var(--fog);
	color: var(--ink);
	font: 16px/1.45 var(--sans);
	-webkit-text-size-adjust: 100%;
	-webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- gates: sign in, pending ---------- */

.gate {
	min-height: 100dvh;
	display: grid;
	place-items: center;
	padding: max(env(safe-area-inset-top), 24px) var(--gutter) max(env(safe-area-inset-bottom), 24px);
}
.gate-inner { width: min(100%, 22rem); display: grid; gap: 14px; justify-items: start; }
.gate-mark { border-radius: 13px; }
.gate h1 { font: 600 2rem/1.1 var(--serif); margin: 8px 0 0; }
.gate-lede { margin: 0 0 10px; color: var(--muted); }
.gate-note { margin: 0; color: var(--muted); font-size: 0.875rem; }
.gate-error { margin: 0; color: var(--danger); font-size: 0.9375rem; }

.apple-button {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px;
	width: 100%; height: 48px; border: 0; border-radius: 10px;
	background: var(--ink); color: var(--fog); font-weight: 600; font-size: 1.0625rem;
}
.quiet-button {
	border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 10px 14px;
}
.pair { width: 100%; }
.pair summary { color: var(--accent); cursor: pointer; padding: 6px 0; }
.pair-form { display: flex; gap: 8px; margin: 8px 0; }
.pair-form input {
	flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
	background: var(--surface); font: 500 1.25rem/1 var(--mono); letter-spacing: 0.2em;
}
.pair-form button, .inline-form button, .sheet-actions button {
	border: 0; border-radius: 10px; padding: 10px 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.identity { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 8px; font-size: 0.9375rem; }
.identity dt { color: var(--muted); }
.identity dd { margin: 0; overflow-wrap: anywhere; font-family: var(--mono); font-size: 0.8125rem; align-self: center; }

/* ---------- app frame ---------- */

.app { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }

.bar {
	display: flex; align-items: center; gap: 10px;
	padding: calc(env(safe-area-inset-top) + 6px) var(--gutter) 6px;
	background: color-mix(in srgb, var(--fog) 88%, transparent);
	backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
	border-bottom: 1px solid var(--line);
}
.bar-title { font: 600 1.0625rem/1 var(--serif); }
.status { flex: 1; color: var(--muted); font-size: 0.8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.working::before {
	content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
	background: var(--accent); margin-right: 6px; vertical-align: 1px;
	animation: pulse 1.4s ease-in-out infinite;
}
.status.offline { color: var(--danger); }
.spend {
	display: flex; flex-direction: column; align-items: flex-end;
	color: var(--muted); font: 0.6875rem/1.3 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap;
}
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .status.working::before, .waiting i { animation: none; } }

.icon-button {
	display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%;
	background: transparent; color: var(--ink);
}

.thread { overflow-y: auto; overscroll-behavior: contain; padding: 12px var(--gutter) 24px; }
.entries { list-style: none; margin: 0 auto; padding: 0; max-width: var(--measure); display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.load-older, .empty { display: block; margin: 8px auto 16px; max-width: var(--measure); color: var(--muted); }
.load-older { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 14px; font-size: 0.875rem; }
.empty { text-align: center; margin-top: 30vh; }

/* ---------- entries ---------- */

/* The user: compact sans blocks, right-aligned. */
.e-user { justify-self: end; max-width: min(85%, 32rem); }
.e-user .body {
	background: var(--user-bg); border-radius: 16px 16px 4px 16px; padding: 9px 13px;
	white-space: pre-wrap; overflow-wrap: anywhere;
}
.e-user img { display: block; max-width: 100%; max-height: 240px; margin: 0 0 4px auto; border-radius: 12px; }
.meta { display: block; color: var(--muted); font-size: 0.75rem; margin-top: 3px; text-align: right; }

/* The agent: full-width serif prose, no container. */
.e-assistant { font: 1.0625rem/1.6 var(--serif); overflow-wrap: anywhere; }
.e-assistant.silent { color: var(--muted); font-size: 0.9375rem; }
.e-assistant > :first-child { margin-top: 0; }
.e-assistant > :last-child { margin-bottom: 0; }
.e-assistant p, .e-assistant ul, .e-assistant ol { margin: 0 0 0.7em; }
.e-assistant h1, .e-assistant h2, .e-assistant h3 { font-size: 1.0625rem; margin: 1em 0 0.4em; }
.e-assistant a { color: var(--accent); }
.e-assistant img { display: block; max-width: 100%; height: auto; margin: 0.4em 0; border-radius: 8px; }
.e-assistant code { font: 0.85em var(--mono); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 0 3px; }
.e-assistant pre { font: 0.8125rem/1.45 var(--mono); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.e-assistant pre code { border: 0; padding: 0; background: none; }
.e-assistant table { border-collapse: collapse; font: 0.875rem var(--sans); display: block; overflow-x: auto; }
.e-assistant th, .e-assistant td { border-bottom: 1px solid var(--line); padding: 4px 10px 4px 0; text-align: left; }
.e-error { color: var(--danger); font-size: 0.875rem; }

/* Tool work: one quiet monospace line per call, expandable. */
.e-tools { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.tool { font: 0.8125rem/1.5 var(--mono); color: var(--muted); }
.tool summary { cursor: pointer; list-style: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "▸ "; }
.tool[open] summary::before { content: "▾ "; }
.tool.failed summary { color: var(--danger); }
.tool pre {
	margin: 4px 0 8px; padding: 8px 10px; max-height: 50vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
	background: var(--surface); border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
}
.thought-body {
	margin: 4px 0 8px; padding: 2px 0 2px 12px; max-height: min(14em, 40vh); overflow-y: auto; border-left: 2px solid var(--line);
	font: italic 0.9375rem/1.55 var(--serif); color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere;
}

/* Scheduled wakeups: an event, not a person. */
.e-wakeup { color: var(--muted); font-size: 0.875rem; display: flex; gap: 8px; align-items: baseline; }
.e-wakeup svg { flex: none; transform: translateY(2px); }
.e-wakeup b { color: var(--ink); font-weight: 600; }
.e-wakeup .prompt { display: block; }

/* Seams: where context was folded away. The one bold device in the design. */
.e-seam { margin: 10px 0; }
.e-seam summary {
	list-style: none; cursor: pointer; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
	color: var(--muted); font-size: 0.8125rem;
}
.e-seam summary::-webkit-details-marker { display: none; }
.e-seam summary::before, .e-seam summary::after {
	content: ""; height: 7px;
	background:
		linear-gradient(135deg, transparent 50%, var(--seam) 50% calc(50% + 1px), transparent calc(50% + 1px)) 0 0 / 7px 7px repeat-x,
		linear-gradient(45deg, transparent 50%, var(--seam) 50% calc(50% + 1px), transparent calc(50% + 1px)) 3.5px 0 / 7px 7px repeat-x;
}
.e-seam .seam-body {
	margin-top: 10px; padding: 12px 14px; border-left: 3px solid var(--seam);
	font: 0.9375rem/1.55 var(--serif); color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere;
}

/* In-flight answer and tools. */
.live { margin: 14px auto 0; max-width: var(--measure); display: grid; grid-template-columns: minmax(0, 1fr); }
.live .e-assistant { color: var(--ink); }
.live .note { color: var(--muted); font-size: 0.8125rem; }
.waiting { display: flex; gap: 5px; padding: 8px 0; }
.waiting i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: pulse 1.4s ease-in-out infinite; }
.waiting i:nth-child(2) { animation-delay: 0.2s; }
.waiting i:nth-child(3) { animation-delay: 0.4s; }

/* ---------- composer ---------- */

.composer {
	padding: 8px var(--gutter) calc(env(safe-area-inset-bottom) + 8px);
	border-top: 1px solid var(--line); background: var(--fog);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; max-width: var(--measure); margin: 0 auto; }
.composer textarea {
	flex: 1; min-width: 0; resize: none; max-height: 40vh; padding: 9px 14px; font-size: 16px; /* 16px stops iOS zoom */
	border: 1px solid var(--line); border-radius: 20px; background: var(--surface); line-height: 1.4;
}
.send, .stop {
	flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; display: grid; place-items: center;
	background: var(--accent); color: var(--accent-ink);
}
.stop { background: var(--ink); color: var(--fog); }
.attach {
	flex: none; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; display: grid; place-items: center;
	background: var(--surface); color: var(--muted); cursor: pointer;
}
.tray { display: flex; gap: 8px; overflow-x: auto; max-width: var(--measure); margin: 0 auto 2px; padding: 6px 6px 6px 0; }
.tray div { position: relative; flex: none; }
.tray img { display: block; height: 64px; border-radius: 8px; }
.tray button {
	position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%;
	background: var(--ink); color: var(--fog); font-size: 14px; line-height: 22px;
}
.steer { display: flex; gap: 6px; align-items: center; max-width: var(--measure); margin: 6px auto 0; color: var(--muted); font-size: 0.8125rem; }

/* ---------- sheet ---------- */

.sheet {
	width: min(100%, 30rem); max-height: 90dvh; margin: auto auto 0; padding: 0 var(--gutter) calc(env(safe-area-inset-bottom) + 16px);
	border: 0; border-radius: 16px 16px 0 0; background: var(--surface); color: var(--ink);
}
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 16px; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.35); }
.sheet[open] { animation: rise 0.22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 14px 0 6px; background: var(--surface); }
.sheet-head h2 { font: 600 1.25rem/1 var(--serif); margin: 0; }
.sheet-group { padding: 14px 0; border-top: 1px solid var(--line); }
.sheet-head + .sheet-group { border-top: 0; }
.sheet-group h3 { font-size: 0.9375rem; margin: 0 0 8px; }
.sheet-note { margin: 0 0 8px; color: var(--muted); font-size: 0.875rem; overflow-wrap: anywhere; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sheet-actions button.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.inline-form { display: flex; gap: 8px; }
.inline-form input {
	flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--fog);
	font: 0.875rem var(--mono);
}
.schedules { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.schedules li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 0.875rem; }
.schedules .when { color: var(--muted); grid-column: 1; }
.schedules .what { grid-column: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.schedules button { grid-row: 1 / span 3; grid-column: 2; align-self: center; border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 6px 10px; }
.pair-display { font: 600 2rem/1.2 var(--mono); letter-spacing: 0.25em; margin: 12px 0 0; }
