/* Owner Maintenance Assistant widget. Uses site design tokens (--raw-navy, --raw-cyan,
   --raw-orange) with fallbacks so the widget renders correctly even outside the theme. */
.dtb-ma {
	--ma-navy: var(--raw-navy, #041E42);
	--ma-cyan: var(--raw-cyan, #47C7FC);
	--ma-orange: var(--raw-orange, #FF8000);
	--ma-line: rgba(71, 199, 252, 0.18);
	max-width: 1120px; /* match the content width below on desktop */
	margin: 0 auto;
	font-family: var(--font-body, 'Inter', system-ui, sans-serif);
	color: var(--text-primary, #eaf2fb);
}
/* The hidden panel uses display:flex below, which would otherwise override the
   [hidden] attribute and show both the gate and the chat at once. */
.dtb-ma [hidden] { display: none !important; }

/* ---- Gate ---- */
.dtb-ma__gate {
	background: rgba(4, 30, 66, 0.55);
	border: 1px solid var(--ma-line);
	border-radius: 12px;
	padding: 32px 24px;
	text-align: center;
}
.dtb-ma__gate-title {
	font-family: var(--font-display, 'Barlow Condensed', sans-serif);
	font-size: 2rem;
	margin: 0 0 8px;
	text-transform: uppercase;
	letter-spacing: 0.02em;
}
.dtb-ma__gate-copy {
	max-width: 46ch;
	margin: 0 auto 20px;
	color: var(--text-muted, #9fb6cc);
	line-height: 1.5;
}
.dtb-ma__gate-form {
	display: flex;
	gap: 8px;
	justify-content: center;
	flex-wrap: wrap;
}
.dtb-ma__pw {
	flex: 1 1 220px;
	max-width: 320px;
	padding: 12px 14px;
	border-radius: 8px;
	border: 1px solid var(--ma-line);
	background: rgba(0, 0, 0, 0.25);
	color: inherit;
	font-size: 1rem;
}
.dtb-ma__pw-btn,
.dtb-ma__send {
	padding: 12px 22px;
	border: none;
	border-radius: 8px;
	background: var(--ma-orange);
	color: #0a0f16;
	font-weight: 700;
	font-size: 1rem;
	cursor: pointer;
}
.dtb-ma__pw-btn:hover,
.dtb-ma__send:hover { filter: brightness(1.08); }
.dtb-ma__send:disabled { opacity: 0.5; cursor: default; }
.dtb-ma__gate-err {
	color: #ff6b6b;
	margin: 14px 0 0;
	font-size: 0.9rem;
}

/* ---- Chat ---- */
.dtb-ma__chat {
	background: rgba(4, 30, 66, 0.45);
	border: 1px solid var(--ma-line);
	border-radius: 12px;
	display: flex;
	flex-direction: row;
	/* Fill the viewport below the page hero; user-draggable up to 90vh. */
	height: min(82vh, 900px);
	min-height: 380px;
	max-height: 90vh;
	resize: vertical;
	overflow: hidden; /* required for the resize grip; inner areas scroll */
	position: relative;
}

/* Sidebar — conversation list */
.dtb-ma__sidebar {
	flex: 0 0 210px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 12px;
	border-right: 1px solid var(--ma-line);
	background: rgba(0, 0, 0, 0.18);
	border-radius: 12px 0 0 12px;
	min-height: 0;
}
.dtb-ma__newchat {
	flex: 0 0 auto;
	padding: 10px;
	border: 1px solid var(--ma-line);
	border-radius: 8px;
	background: transparent;
	color: var(--ma-cyan);
	font-weight: 600;
	font-size: 0.9rem;
	cursor: pointer;
}
.dtb-ma__newchat:hover { background: rgba(71, 199, 252, 0.1); }
.dtb-ma__history {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 3px;
	overflow-y: auto;
	min-height: 0;
}
.dtb-ma__history li {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 6px;
	padding: 8px 10px;
	border-radius: 8px;
	font-size: 0.85rem;
	color: var(--text-muted, #9fb6cc);
	cursor: pointer;
}
.dtb-ma__history li:hover { background: rgba(255, 255, 255, 0.05); }
.dtb-ma__history li.active { background: rgba(71, 199, 252, 0.14); color: var(--text-primary, #eaf2fb); }
.dtb-ma__hist-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dtb-ma__history li .del { flex: 0 0 auto; opacity: 0.45; font-size: 1.1rem; line-height: 1; }
.dtb-ma__history li .del:hover { opacity: 1; color: #ff6b6b; }

/* Main column */
.dtb-ma__main {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	padding: 14px 16px;
}
.dtb-ma__toolbar {
	flex: 0 0 auto;
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-bottom: 8px;
}
.dtb-ma__history-toggle { display: none; } /* mobile only */
.dtb-ma__print,
.dtb-ma__fullscreen {
	background: none;
	border: 1px solid var(--ma-line);
	color: var(--text-muted, #9fb6cc);
	border-radius: 6px;
	padding: 5px 10px;
	font-size: 0.8rem;
	cursor: pointer;
}
.dtb-ma__print:hover,
.dtb-ma__fullscreen:hover { color: var(--ma-cyan); border-color: var(--ma-cyan); }

/* Desktop full screen (⛶ toolbar button): the chat takes over the viewport below
   the site header (JS sets --dtb-ma-fs-top to the header's bottom edge; 0 when the
   header is scrolled away). Scoped to desktop widths so it can never out-specify the
   phone takeover in the max-width:700px query below — on a phone the chat is already
   full-viewport (inset:0), so a lingering .dtb-ma--fs class must not pin it below the
   header and push it down. The button itself is hidden on phones (see that query). */
@media (min-width: 701px) {
	.dtb-ma--fs .dtb-ma__chat:not([hidden]) {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		top: var(--dtb-ma-fs-top, 0px);
		height: auto;
		min-height: 0;
		max-height: none;
		border-radius: 0;
		resize: none;
		z-index: 9999;
		box-sizing: border-box;
		background: var(--ma-navy, #041E42);
	}
}
body.dtb-ma-lock { overflow: hidden; }

.dtb-ma__log {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 6px 4px 10px;
}
.dtb-ma__msg {
	max-width: 88%;
	padding: 10px 14px;
	border-radius: 12px;
	line-height: 1.5;
	white-space: pre-wrap;
	word-wrap: break-word;
}
.dtb-ma__msg--user {
	align-self: flex-end;
	background: var(--ma-cyan);
	color: #041322;
	border-bottom-right-radius: 4px;
}
.dtb-ma__msg--assistant {
	align-self: flex-start;
	background: rgba(255, 255, 255, 0.06);
	border: 1px solid var(--ma-line);
	border-bottom-left-radius: 4px;
	/* markdown-it emits block HTML (with literal newlines between tags) and its own <br>
	   for soft breaks, so pre-wrap here would double every line break. User bubbles keep
	   the base pre-wrap since their text is inserted raw via textContent. */
	white-space: normal;
}
.dtb-ma__msg--error { border-color: #ff6b6b; color: #ffb3b3; }
.dtb-ma__msg--typing::after {
	content: '▋';
	animation: dtb-ma-blink 1s steps(2) infinite;
	color: var(--ma-cyan);
}
@keyframes dtb-ma-blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* Rendered markdown inside assistant messages. Spacing kept tight — these are chat
   bubbles, not documents; first/last child margins are collapsed so the bubble padding
   sets the visual edge instead of stacking on top of it. */
.dtb-ma__msg a { color: var(--ma-cyan); text-decoration: underline; word-break: break-word; }
.dtb-ma__msg p { margin: 0 0 6px; }
.dtb-ma__msg > :first-child { margin-top: 0; }
.dtb-ma__msg > :last-child { margin-bottom: 0; }
.dtb-ma__msg ul,
.dtb-ma__msg ol { margin: 4px 0; padding-left: 20px; }
.dtb-ma__msg ul { list-style: disc; }
.dtb-ma__msg li { margin: 1px 0; }
.dtb-ma__msg li > p { margin: 0; } /* loose-list <p> wrappers shouldn't add a blank line per item */
/* Model headings render modestly — chat bubbles, not documents. */
.dtb-ma__msg h1,
.dtb-ma__msg h2,
.dtb-ma__msg h3,
.dtb-ma__msg h4,
.dtb-ma__msg h5,
.dtb-ma__msg h6 { margin: 10px 0 4px; line-height: 1.3; color: inherit; }
.dtb-ma__msg h1, .dtb-ma__msg h2 { font-size: 1.15em; }
.dtb-ma__msg h3 { font-size: 1.05em; }
.dtb-ma__msg h4, .dtb-ma__msg h5, .dtb-ma__msg h6 { font-size: 1em; }
.dtb-ma__msg hr { border: none; border-top: 1px solid var(--ma-line); margin: 12px 0; }
.dtb-ma__msg blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--ma-line); color: var(--text-muted, #9fb6cc); }
.dtb-ma__msg pre { overflow-x: auto; background: rgba(255, 255, 255, 0.06); border-radius: 6px; padding: 10px 12px; margin: 8px 0; }
.dtb-ma__msg pre code { background: none; padding: 0; }
.dtb-ma__msg code {
	background: rgba(0, 0, 0, 0.3);
	padding: 1px 5px;
	border-radius: 4px;
	font-size: 0.9em;
	word-break: break-word;
}
/* Markdown tables */
.dtb-ma__tablewrap { overflow-x: auto; margin: 8px 0; }
.dtb-ma__table {
	border-collapse: collapse;
	font-size: 0.88rem;
	min-width: 100%;
}
.dtb-ma__table th,
.dtb-ma__table td {
	border: 1px solid var(--ma-line);
	padding: 6px 10px;
	text-align: left;
	white-space: nowrap;
}
.dtb-ma__table th {
	background: rgba(71, 199, 252, 0.12);
	color: var(--text-primary, #eaf2fb);
	font-weight: 600;
}
.dtb-ma__table tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.03); }
/* Inline emphasis stays inline. The model's status asides ("checking the … page")
   are pulled onto their own line by the renderer as .dtb-ma__status blocks instead. */
.dtb-ma__msg em { font-style: italic; }
/* De-emphasized status / "fetching…" notes: small, muted, blockquote-style */
.dtb-ma__status {
	font-size: 0.8rem;
	color: var(--text-dim, #7089a1);
	border-left: 2px solid var(--ma-line);
	padding: 1px 0 1px 10px;
	margin: 4px 0;
}
.dtb-ma__status em { font-style: normal; margin: 0; }

.dtb-ma__form {
	display: flex;
	gap: 8px;
	margin-top: 12px;
	align-items: flex-end;
}
.dtb-ma__input {
	flex: 1;
	resize: vertical; /* draggable handle */
	padding: 12px 14px;
	border-radius: 10px;
	border: 1px solid var(--ma-line);
	background: rgba(0, 0, 0, 0.25);
	color: inherit;
	font-size: 1rem;
	font-family: inherit;
	line-height: 1.4;
	/* Tall enough to show the full two-line placeholder without clipping. */
	min-height: 3.4em;
	max-height: 300px;
}
.dtb-ma__disclaimer {
	margin: 12px 4px 2px;
	font-size: 0.78rem;
	color: var(--text-dim, #7089a1);
	line-height: 1.45;
}

@media (max-width: 700px) {
	.dtb-ma { max-width: 100%; }
	.dtb-ma__gate { padding: 24px 16px; }
	.dtb-ma__gate-title { font-size: 1.6rem; }
	.dtb-ma__msg { max-width: 92%; font-size: 1rem; }
	/* On phones the chat is already a full-viewport overlay, so a "full screen" toggle has
	   nothing to add and (by pinning below the header) only pushes the chat down. Hide it. */
	.dtb-ma__fullscreen { display: none; }
	/* On phones, once the chat is active it takes over the whole screen (fixed,
	   full viewport) so it's the only panel and the on-screen keyboard doesn't push
	   the page. JS syncs the height to visualViewport so the input sits just above
	   the keyboard. */
	.dtb-ma__chat:not([hidden]) {
		position: fixed;
		inset: 0;
		height: 100dvh;
		min-height: 0;
		max-height: none;
		border-radius: 0;
		resize: none;
		z-index: 9999;
		/* Opaque + full-height so the page behind never bleeds through, even when JS
		   reserves keyboard space via padding-bottom (border-box keeps the panel at
		   100dvh; the padding shrinks the inner content, not the covered area). */
		box-sizing: border-box;
		background: var(--ma-navy, #041E42);
	}
	.dtb-ma__input {
		font-size: 16px;   /* >=16px stops iOS zoom-on-focus */
		min-height: 4.6em; /* fit the wrapped placeholder without clipping */
		line-height: 1.35;
	}
	.dtb-ma__disclaimer { font-size: 0.72rem; }

	/* Sidebar becomes a slide-over drawer toggled by the ☰ Chats button. */
	.dtb-ma__history-toggle { display: inline-block; margin-right: auto; background: none; border: 1px solid var(--ma-line); color: var(--text-muted, #9fb6cc); border-radius: 6px; padding: 5px 10px; font-size: 0.8rem; cursor: pointer; }
	.dtb-ma__sidebar {
		position: absolute;
		z-index: 5;
		top: 0;
		left: 0;
		bottom: 0;
		width: 78%;
		max-width: 300px;
		border-radius: 10px 0 0 10px;
		background: #06264f;
		transform: translateX(-102%);
		transition: transform 0.2s ease;
	}
	.dtb-ma--drawer-open .dtb-ma__sidebar { transform: translateX(0); box-shadow: 0 0 0 100vw rgba(0,0,0,0.4); }
	.dtb-ma__toolbar { justify-content: space-between; }
}

/* Print / Save-as-PDF of the surrounding page: fall back to just the log if the
   in-widget Print button isn't used. (The button opens a clean standalone window.) */
@media print {
	.dtb-ma__sidebar, .dtb-ma__toolbar, .dtb-ma__form, .dtb-ma__disclaimer, .dtb-ma__gate { display: none !important; }
	.dtb-ma__chat { height: auto !important; max-height: none !important; border: none !important; }
	.dtb-ma__log { overflow: visible !important; }
}
