/*
	"Ask about David" chat widget — brutalist to match brutalist.css.
	Uses the same CSS custom properties (--ink, --accent, --accent-2, etc.).
*/

.dn-chat-launcher {
	position: fixed;
	right: clamp(1rem, 3vw, 2rem);
	bottom: clamp(1rem, 3vw, 2rem);
	z-index: 1000;
	display: inline-flex;
	align-items: center;
	gap: 0.6em;
	padding: 0.85em 1.2em;
	background: var(--accent);
	color: var(--ink);
	border: var(--border-thin) solid var(--ink);
	box-shadow: 6px 6px 0 var(--ink);
	font-family: var(--font-mono);
	font-weight: 700;
	font-size: 0.9rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	cursor: pointer;
	transition: transform 0.12s steps(2), box-shadow 0.12s steps(2);
}

.dn-chat-launcher:hover {
	transform: translate(-3px, -3px);
	box-shadow: 9px 9px 0 var(--accent-2);
}

.dn-chat-launcher[aria-expanded="true"] { display: none; }

.dn-chat {
	position: fixed;
	right: clamp(1rem, 3vw, 2rem);
	bottom: clamp(1rem, 3vw, 2rem);
	z-index: 1001;
	width: min(420px, calc(100vw - 2rem));
	height: min(620px, calc(100vh - 2rem));
	display: flex;
	flex-direction: column;
	background: var(--panel);
	border: var(--border) solid var(--ink);
	box-shadow: var(--shadow-x) var(--shadow-y) 0 var(--ink);
	font-family: var(--font-mono);
	font-size: 0.88rem;
}

.dn-chat[hidden] { display: none; }

.dn-chat__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5em;
	padding: 0.75em 1em;
	background: var(--ink);
	color: var(--accent);
}

.dn-chat__title {
	margin: 0;
	font-size: 1rem;
	color: var(--accent);
}

.dn-chat__status {
	display: block;
	font-family: var(--font-mono);
	font-size: 0.7rem;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: #b8b6ac;
}

.dn-chat__actions { display: flex; gap: 0.4em; }

.dn-chat__icon-btn {
	width: 2.2em;
	height: 2.2em;
	background: transparent;
	color: var(--paper);
	border: var(--border-thin) solid var(--paper);
	font-family: var(--font-mono);
	font-weight: 700;
	cursor: pointer;
}

.dn-chat__icon-btn:hover {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--ink);
}

.dn-chat__log {
	flex: 1;
	overflow-y: auto;
	padding: 1em;
	display: flex;
	flex-direction: column;
	gap: 0.85em;
}

.dn-msg {
	max-width: 88%;
	padding: 0.65em 0.85em;
	border: var(--border-thin) solid var(--ink);
	line-height: 1.5;
	word-wrap: break-word;
}

.dn-msg p { margin: 0 0 0.6em 0; }
.dn-msg p:last-child { margin-bottom: 0; }
.dn-msg ul { margin: 0.3em 0 0.6em 1.2em; padding: 0; }
.dn-msg ul:last-child { margin-bottom: 0; }

.dn-msg--bot {
	align-self: flex-start;
	background: var(--paper);
	box-shadow: 4px 4px 0 var(--ink);
}

.dn-msg--user {
	align-self: flex-end;
	background: var(--ink);
	color: var(--paper);
	box-shadow: 4px 4px 0 var(--accent-2);
}

.dn-msg--note {
	align-self: stretch;
	max-width: none;
	background: transparent;
	border-style: dashed;
	color: var(--fg-muted);
	font-size: 0.8rem;
}

.dn-msg--typing::after {
	content: '▍';
	animation: dn-blink 1s steps(2) infinite;
}

@keyframes dn-blink { 50% { opacity: 0; } }

.dn-chat__suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.45em;
	padding: 0.75em 1em;
	border-top: var(--border-thin) solid var(--ink);
}

.dn-chat__suggestions[hidden] { display: none; }

.dn-chip {
	padding: 0.4em 0.7em;
	background: var(--paper);
	color: var(--ink);
	border: var(--border-thin) solid var(--ink);
	box-shadow: 3px 3px 0 var(--ink);
	font-family: var(--font-mono);
	font-size: 0.76rem;
	font-weight: 700;
	cursor: pointer;
	text-align: left;
}

.dn-chip:hover:not(:disabled) {
	background: var(--accent);
	transform: translate(-1px, -1px);
	box-shadow: 4px 4px 0 var(--ink);
}

.dn-chip:disabled { opacity: 0.5; cursor: not-allowed; }

.dn-chat__form {
	display: flex;
	border-top: var(--border) solid var(--ink);
}

.dn-chat__input {
	flex: 1;
	min-width: 0;
	padding: 0.85em 1em;
	border: 0;
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font-mono);
	font-size: 0.88rem;
}

.dn-chat__input:focus-visible { outline-offset: -3px; }
.dn-chat__input:disabled { background: #e8e6dc; }

.dn-chat__send {
	padding: 0 1.1em;
	background: var(--accent);
	color: var(--ink);
	border: 0;
	border-left: var(--border-thin) solid var(--ink);
	font-family: var(--font-mono);
	font-weight: 700;
	text-transform: uppercase;
	cursor: pointer;
}

.dn-chat__send:hover:not(:disabled) { background: var(--ink); color: var(--accent); }
.dn-chat__send:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 480px) {
	.dn-chat {
		right: 0;
		bottom: 0;
		width: 100vw;
		height: 100dvh;
		box-shadow: none;
		border-width: 0;
	}
}

/* ---------- Split screen and full screen (the expand button) ----------
   Split: the chat docks to the right edge at full height and the page shrinks
   to make room (body gets padding). Full screen: the chat covers the window.
   js/chat.js picks split on wide windows and full screen on narrow ones. */
:root { --dn-split-w: clamp(380px, 36vw, 560px); }

body.dn-split { padding-right: var(--dn-split-w); }
body.dn-full { overflow: hidden; }

html body .dn-chat.dn-chat--split,
html body .dn-chat.dn-chat--full {
	top: 0;
	right: 0;
	bottom: 0;
	height: 100vh;
	height: 100dvh;
	border-radius: 0;
	box-shadow: none;
}

html body .dn-chat.dn-chat--split {
	width: var(--dn-split-w);
	border-width: 0 0 0 var(--border);
}

html body .dn-chat.dn-chat--full {
	left: 0;
	width: 100vw;
	border-width: 0;
}

/* Wider message column when there's room, but keep lines readable. */
.dn-chat--full .dn-chat__log,
.dn-chat--full .dn-chat__suggestions,
.dn-chat--full .dn-chat__form {
	width: 100%;
	max-width: 52rem;
	margin-left: auto;
	margin-right: auto;
}

/* The download indicator stays centred over the page, not under the chat. */
body.dn-split .dn-dl { left: calc((100% - var(--dn-split-w)) / 2); }

/* Phones already get a full-screen chat, so the button isn't needed there. */
@media (max-width: 480px) {
	.dn-chat__expand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
	.dn-chat-launcher, .dn-chip { transition: none; }
	.dn-chat-launcher:hover, .dn-chip:hover:not(:disabled) { transform: none; }
	.dn-msg--typing::after { animation: none; }
}

.dn-msg__meta {
	margin-top: 0.5em !important;
	font-size: 0.72rem;
	color: var(--fg-muted);
}
