:root {
	--primary: #059669;
	--primary-dark: #047857;
	--primary-light: #d1fae5;
	--text: #1f2937;
	--text-muted: #6b7280;
	--bg: #ffffff;
	--bg-alt: #f9fafb;
	--border: #e5e7eb;
	--sidebar-width: 380px;
	--topbar-height: 56px;
	--adminbar-height: 0px;
}
body.admin-bar { --adminbar-height: 32px; }
@media screen and (max-width: 782px) {
	body.admin-bar { --adminbar-height: 46px; }
}
:root {
	--radius: 8px;
	--shadow: 0 1px 3px rgba(0,0,0,0.1);
	--savoy-font-scale: 1;
}
/* Text scaling: rescales the root font-size, so every rem-based size in the
   viewer (headings, body text, buttons) scales together, same as browser
   zoom -- rather than only affecting .html-panel's own font-size, which
   wouldn't cascade to its rem-sized children at all. */
html { font-size: calc(16px * var(--savoy-font-scale)); }
/* Real, non-overlay high-contrast palette (WCAG 1.4.3/1.4.6): pure black
   text on pure white, no soft grays, applied via the same CSS variables
   every component already reads -- not a bolted-on filter over arbitrary
   page content. */
html.savoy-high-contrast {
	--text: #000000;
	--text-muted: #000000;
	--bg: #ffffff;
	--bg-alt: #ffffff;
	--border: #000000;
	--primary: #003d99;
	--primary-dark: #002a6e;
	--primary-light: #cfe0ff;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
	color: var(--text);
	background: var(--bg-alt);
	line-height: 1.6;
}
.skip-link {
	position: absolute;
	top: -100%;
	left: 8px;
	z-index: 1000;
	padding: 8px 16px;
	background: var(--primary);
	color: #fff;
	border-radius: var(--radius);
	text-decoration: none;
	font-weight: 600;
}
.skip-link:focus { top: 8px; }
.topbar {
	position: fixed;
	top: var(--adminbar-height); left: 0; right: 0;
	height: var(--topbar-height);
	background: var(--bg);
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	padding: 0 20px;
	z-index: 100;
	box-shadow: var(--shadow);
}
.topbar h1 {
	font-size: 1.05rem;
	font-weight: 600;
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	margin-right: 12px;
}
.tab-group {
	display: flex;
	gap: 4px;
	background: var(--bg-alt);
	border-radius: var(--radius);
	padding: 3px;
}
.tab-btn {
	padding: 6px 16px;
	border: none;
	background: transparent;
	border-radius: 6px;
	cursor: pointer;
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--text-muted);
	transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn:focus-visible {
	outline: 2px solid var(--primary);
	outline-offset: 2px;
}
.tab-btn[aria-selected="true"] {
	background: var(--bg);
	color: var(--primary);
	box-shadow: var(--shadow);
}
.sidebar-toggle {
	display: none;
	margin-left: 12px;
	padding: 6px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	cursor: pointer;
	font-size: 0.875rem;
	color: var(--text);
}
.sidebar-toggle:focus-visible {
	outline: 2px solid var(--primary);
	outline-offset: 2px;
}
.a11y-controls {
	display: flex;
	align-items: center;
	gap: 4px;
	margin-left: 12px;
	padding-left: 12px;
	border-left: 1px solid var(--border);
}
.a11y-btn {
	padding: 6px 10px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	cursor: pointer;
	font-size: 0.8rem;
	font-weight: 600;
	color: var(--text);
	line-height: 1;
	white-space: nowrap;
}
.a11y-btn:hover { background: var(--bg-alt); }
.a11y-btn:focus-visible {
	outline: 2px solid var(--primary);
	outline-offset: 2px;
}
.a11y-contrast-btn[aria-pressed="true"] {
	background: var(--text);
	color: var(--bg);
	border-color: var(--text);
}
#a11y-text-smaller, #a11y-text-larger { font-size: 0.75rem; }
#a11y-text-reset { font-size: 0.9rem; }
@media (max-width: 900px) {
	/* Keep the contrast toggle, drop the text-size steppers -- the topbar is
	   too tight for both on narrow screens and contrast is the higher-value
	   control at a glance. */
	#a11y-text-smaller, #a11y-text-reset, #a11y-text-larger { display: none; }
}
.layout {
	display: flex;
	margin-top: calc(var(--topbar-height) + var(--adminbar-height));
	height: calc(100vh - var(--topbar-height) - var(--adminbar-height));
}
.main-content {
	flex: 1;
	overflow: auto;
	position: relative;
}
.tab-panel { display: none; height: 100%; }
.tab-panel.active { display: block; }
.pdf-panel iframe, .pdf-panel embed {
	width: 100%;
	height: 100%;
	border: none;
}
.pdf-panel .no-pdf {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	color: var(--text-muted);
	font-size: 1rem;
	padding: 40px;
	text-align: center;
}
.html-panel {
	padding: 32px 40px;
	max-width: 800px;
	margin: 0 auto;
	background: var(--bg);
	min-height: 100%;
}
.html-panel h2 { font-size: 1.5rem; margin-bottom: 0.75em; }
.html-panel h3 { font-size: 1.25rem; margin-top: 1.25em; margin-bottom: 0.5em; }
.html-panel p { margin-bottom: 1em; }
.html-panel ul, .html-panel ol { margin-bottom: 1em; padding-left: 1.5em; }
.html-panel table { border-collapse: collapse; width: 100%; margin-bottom: 1em; }
.html-panel th, .html-panel td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.html-panel th { background: var(--bg-alt); font-weight: 600; }
.html-panel img { max-width: 100%; height: auto; }
.no-content {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	color: var(--text-muted);
	padding: 40px;
	text-align: center;
}
.chat-sidebar {
	width: var(--sidebar-width);
	border-left: 1px solid var(--border);
	background: var(--bg);
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
}
.chat-header {
	padding: 14px 16px;
	border-bottom: 1px solid var(--border);
	font-weight: 600;
	font-size: 0.95rem;
}
.chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}
.chat-msg {
	max-width: 90%;
	padding: 10px 14px;
	border-radius: 12px;
	font-size: 0.9rem;
	line-height: 1.5;
	word-wrap: break-word;
}
.chat-msg.user {
	align-self: flex-end;
	background: var(--primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
	align-self: flex-start;
	background: var(--bg-alt);
	color: var(--text);
	border-bottom-left-radius: 4px;
}
.chat-msg.typing {
	align-self: flex-start;
	background: var(--bg-alt);
	color: var(--text-muted);
	font-style: italic;
}
.chat-input-area {
	padding: 12px 16px;
	border-top: 1px solid var(--border);
	display: flex;
	gap: 8px;
}
.chat-input {
	flex: 1;
	padding: 10px 14px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	font-size: 0.9rem;
	font-family: inherit;
	resize: none;
	outline: none;
	transition: border-color 0.15s;
}
.chat-input:focus {
	border-color: var(--primary);
	box-shadow: 0 0 0 3px rgba(5,150,105,0.15);
}
.chat-send {
	padding: 10px 18px;
	border: none;
	border-radius: var(--radius);
	background: var(--primary);
	color: #fff;
	font-weight: 600;
	font-size: 0.9rem;
	cursor: pointer;
	transition: background 0.15s;
	white-space: nowrap;
}
.chat-send:hover { background: var(--primary-dark); }
.chat-send:focus-visible {
	outline: 2px solid var(--primary);
	outline-offset: 2px;
}
.chat-send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}
@media (max-width: 768px) {
	.sidebar-toggle { display: inline-block; }
	.chat-sidebar {
		position: fixed;
		top: calc(var(--topbar-height) + var(--adminbar-height));
		right: 0;
		bottom: 0;
		width: 100%;
		max-width: 400px;
		z-index: 90;
		transform: translateX(100%);
		transition: transform 0.25s ease;
		box-shadow: -4px 0 12px rgba(0,0,0,0.1);
	}
	.chat-sidebar.open { transform: translateX(0); }
	.html-panel { padding: 20px 16px; }
}
