/* The on-page helper ("Ask"): engine/php/assistant.php prints the markup, engine/js/assistant.js runs it.
   The mockup's design (docs/mockups/observatory): a round copper launcher with three sparks bottom right, and a
   panel above it; on phones the panel is a sheet across the bottom. Engine tokens only, no motion, 44 px tap
   targets, safe-area insets on every fixed box.
   Markup: div.ask#ask[hidden] > button.ask-launcher#ask-launcher (svg + span) + section.ask-panel#ask-panel[role=dialog]
   > div.ask-head (h2#ask-title + button.ask-close) + p.ask-note + div.ask-scroll > (div.ask-chips > button.ask-chip
   + div.ask-log > div.ask-msg.me | .ask-msg.ai) + p.ask-error + form.ask-form > label.sr-only + textarea + button.ask-send */

.ask[hidden],
.ask-panel[hidden],
.ask-error[hidden] { display: none; }

.ask-launcher {
	position: fixed;
	right: max(20px, env(safe-area-inset-right, 0px));
	bottom: max(20px, env(safe-area-inset-bottom, 0px));
	z-index: 60;
	width: 64px;
	height: 64px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--accent);
	color: var(--accent-ink);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1px;
	cursor: pointer;
	font-family: var(--f-body);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.04em;
	line-height: 1.1;
	box-shadow: 0 6px 24px var(--shadow-deep), 0 0 0 4px var(--bg), 0 0 0 5.5px var(--accent-2);
}
.ask-launcher svg { width: 24px; height: 24px; flex: none; }
.ask-launcher[aria-expanded="true"] { display: none; }
.ask-launcher:focus-visible { outline: 2px solid var(--focus); outline-offset: 8px; }

.ask-panel {
	position: fixed;
	right: max(20px, env(safe-area-inset-right, 0px));
	bottom: max(20px, env(safe-area-inset-bottom, 0px));
	z-index: 61;
	width: min(380px, calc(100vw - 32px));
	max-height: min(70vh, 640px);
	display: flex;
	flex-direction: column;
	background: var(--surface);
	color: var(--fg);
	border: 1px solid var(--line);
	border-radius: 12px;
	box-shadow: 0 24px 60px var(--shadow-deep);
	font-family: var(--f-body);
}
/* The panel takes focus only on touch screens (assistant.js), where an outline round the whole sheet says nothing. */
.ask-panel:focus { outline: none; }

.ask-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 12px 8px 18px;
}
.ask-head h2 {
	margin: 0;
	font-size: 1.15rem;
	line-height: 1.25;
	color: var(--heading);
}
.ask-close {
	flex: none;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--clear);
	color: var(--fg-2);
	cursor: pointer;
	display: grid;
	place-items: center;
}
.ask-close svg { width: 20px; height: 20px; }
.ask-close:hover { color: var(--fg); }
.ask-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }

.ask-note {
	margin: 0;
	padding: 0 18px 10px;
	color: var(--fg-2);
	font-size: 0.88rem;
	line-height: 1.45;
	border-bottom: 1px solid var(--line);
}

.ask-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 12px 18px 4px;
}
.ask-chip {
	min-height: 44px;
	padding: 0 14px;
	border-radius: 999px;
	border: 1px solid var(--line);
	background: var(--clear);
	color: var(--fg);
	font-family: var(--f-body);
	font-size: 0.92rem;
	line-height: 1.2;
	cursor: pointer;
}
.ask-chip:hover { border-color: var(--accent); }
.ask-chip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* The chips and the log scroll as one, so the suggestions move up out of the way on a short screen. */
.ask-scroll {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
}
.ask-log {
	padding: 10px 18px;
	display: grid;
	align-content: start;
	gap: 12px;
}
.ask-log:empty { padding: 0; }
.ask-msg {
	padding: 10px 14px;
	border-radius: 10px;
	font-size: 0.95rem;
	line-height: 1.5;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}
.ask-msg.me { background: var(--bg-2); justify-self: end; max-width: 85%; }
.ask-msg.ai { background: var(--clear); border: 1px solid var(--line); }
.ask-msg.ask-thinking { color: var(--fg-2); }

.ask-error {
	margin: 0;
	padding: 8px 18px 0;
	color: var(--fg);
	font-size: 0.88rem;
	line-height: 1.45;
}

.ask-form {
	display: flex;
	gap: 8px;
	padding: 10px 12px 12px 18px;
	border-top: 1px solid var(--line);
	align-items: flex-end;
}
.ask-form textarea {
	flex: 1;
	min-width: 0;
	min-height: 44px;
	max-height: 120px;
	resize: none;
	padding: 10px 12px;
	border-radius: 8px;
	border: 1px solid var(--line);
	background: var(--bg);
	color: var(--fg);
	font: 16px/1.4 var(--f-body);
}
.ask-form textarea::placeholder { color: var(--fg-2); }
.ask-form textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.ask-send { flex: none; min-height: 44px; padding: 0 16px; }
.ask-send[aria-disabled="true"] { cursor: progress; }

/* Phones: the panel is a sheet across the bottom, clear of the home indicator and the side insets; the launcher
   is a little smaller, and it moves up while the page's quick bar (html.has-quickbar) is showing. */
@media (max-width: 560px) {
	.ask-panel {
		right: 0;
		left: 0;
		bottom: 0;
		width: auto;
		max-height: 72vh;
		border-radius: 14px 14px 0 0;
		border-width: 1px 0 0;
		padding-bottom: env(safe-area-inset-bottom, 0px);
		padding-left: env(safe-area-inset-left, 0px);
		padding-right: env(safe-area-inset-right, 0px);
	}
	.ask-launcher { width: 58px; height: 58px; }
	.has-quickbar .ask-launcher { bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }
}

@media print {
	.ask { display: none !important; }
}
