:root {
	--fond: #f3f1ec;
	--surface: #ffffff;
	--bord: #dcd8cf;
	--texte: #1f1d1a;
	--discret: #6b665d;
	--accent: #c2410c;
	--accent-survol: #9a3412;
	--sur-accent: #ffffff;
	--editeur: #fbfaf7;

	/* Réglages de la page, pilotés par app.js */
	--page-l: 210mm;
	--page-h: 297mm;
	--marge: 20mm;
	--taille: 11.5pt;

	color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
	:root {
		--fond: #171614;
		--surface: #22201d;
		--bord: #38342f;
		--texte: #ece8e1;
		--discret: #a29c91;
		--accent: #ea580c;
		--accent-survol: #f97316;
		--editeur: #1c1b18;
	}
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
	margin: 0;
	display: flex;
	flex-direction: column;
	background: var(--fond);
	color: var(--texte);
	font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- Barre d'outils ---------- */

.barre {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 10px 14px;
	padding: 10px 16px;
	background: var(--surface);
	border-bottom: 1px solid var(--bord);
}

.logo {
	margin: 0 6px 4px 0;
	font-size: 20px;
	font-weight: 700;
	letter-spacing: -0.02em;
}
.logo span { color: var(--accent); }

.champ {
	display: flex;
	flex-direction: column;
	gap: 3px;
	font-size: 11px;
	color: var(--discret);
}
.champ.nom { flex: 1 1 140px; max-width: 260px; }

input[type="text"], select, button {
	height: 34px;
	padding: 0 10px;
	border: 1px solid var(--bord);
	border-radius: 7px;
	background: var(--surface);
	color: var(--texte);
	font: inherit;
}
input[type="text"] { width: 100%; }
button { cursor: pointer; font-weight: 500; white-space: nowrap; }
button:hover { border-color: var(--discret); }

button.principal {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--sur-accent);
	font-weight: 600;
}
button.principal:hover { background: var(--accent-survol); border-color: var(--accent-survol); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- Éditeur et aperçu ---------- */

.onglets { display: none; }

.plan {
	flex: 1;
	min-height: 0;
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
}

.volet { min-width: 0; min-height: 0; overflow: auto; }

.edition { border-right: 1px solid var(--bord); background: var(--editeur); }

#source {
	display: block;
	width: 100%;
	height: 100%;
	padding: 20px;
	border: 0;
	outline: 0;
	resize: none;
	background: transparent;
	color: var(--texte);
	font: 13.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	tab-size: 4;
}

.apercu { padding: 24px 16px; }

.astuce {
	margin: 0;
	padding: 7px 16px;
	border-top: 1px solid var(--bord);
	background: var(--surface);
	color: var(--discret);
	font-size: 12px;
}

.depot {
	position: fixed;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	background: color-mix(in srgb, var(--accent) 88%, transparent);
	color: #fff;
	font-size: 22px;
	font-weight: 600;
	pointer-events: none;
}
body.survol .depot { display: flex; }

/* ---------- La feuille : toujours claire, c'est ce qui part dans le PDF ---------- */

.feuille {
	width: var(--page-l);
	max-width: 100%;
	min-height: var(--page-h);
	margin: 0 auto;
	padding: var(--marge);
	background: #fff;
	color: #1a1a1a;
	color-scheme: light;
	box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 8px 24px rgba(0, 0, 0, .08);
	font: var(--taille)/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
	overflow-wrap: break-word;
}

.feuille > :first-child { margin-top: 0; }
.feuille > :last-child { margin-bottom: 0; }

.feuille h1, .feuille h2, .feuille h3, .feuille h4, .feuille h5, .feuille h6 {
	margin: 1.5em 0 .55em;
	line-height: 1.25;
	font-weight: 650;
	break-after: avoid;
}
.feuille h1 { font-size: 2em; padding-bottom: .25em; border-bottom: 1px solid #ddd; }
.feuille h2 { font-size: 1.5em; padding-bottom: .2em; border-bottom: 1px solid #e6e6e6; }
.feuille h3 { font-size: 1.22em; }
.feuille h4 { font-size: 1.05em; }
.feuille h5, .feuille h6 { font-size: 1em; color: #555; }

.feuille p, .feuille ul, .feuille ol, .feuille blockquote, .feuille pre, .feuille table { margin: 0 0 1em; }
.feuille p { orphans: 3; widows: 3; }
.feuille ul, .feuille ol { padding-left: 1.7em; }
.feuille li + li { margin-top: .2em; }
.feuille li > ul, .feuille li > ol { margin: .2em 0 0; }
.feuille li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.4em; }
.feuille li > input[type="checkbox"] { margin: 0 .45em 0 0; }

.feuille a { color: #0b57d0; text-decoration: underline; text-underline-offset: 2px; }

.feuille blockquote {
	padding: .1em 1em;
	border-left: 4px solid #d5d5d5;
	color: #555;
}
.feuille blockquote > :last-child { margin-bottom: 0; }

.feuille code {
	padding: .15em .35em;
	border-radius: 4px;
	background: #f1f1ef;
	font: .88em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.feuille pre {
	padding: .9em 1em;
	border: 1px solid #e3e3e0;
	border-radius: 6px;
	background: #f7f7f5;
	white-space: pre-wrap;
	break-inside: avoid;
}
.feuille pre code { padding: 0; background: none; font-size: .85em; }

.feuille table { width: 100%; border-collapse: collapse; font-size: .95em; }
.feuille th, .feuille td { padding: .45em .7em; border: 1px solid #d5d5d5; text-align: left; vertical-align: top; }
.feuille th { background: #f3f3f1; font-weight: 600; }
.feuille tr { break-inside: avoid; }
.feuille thead { display: table-header-group; }

.feuille img { max-width: 100%; height: auto; break-inside: avoid; }
.feuille hr { height: 1px; margin: 2em 0; border: 0; background: #d5d5d5; }

/* ---------- Petits écrans : un volet à la fois ---------- */

@media (max-width: 800px) {
	.onglets {
		display: flex;
		background: var(--surface);
		border-bottom: 1px solid var(--bord);
	}
	.onglets button {
		flex: 1;
		height: 40px;
		border: 0;
		border-bottom: 2px solid transparent;
		border-radius: 0;
		background: none;
		color: var(--discret);
	}
	.onglets button.actif { border-bottom-color: var(--accent); color: var(--texte); }

	.plan { grid-template-columns: minmax(0, 1fr); }
	.plan[data-vue="edition"] .apercu,
	.plan[data-vue="apercu"] .edition { display: none; }
	.edition { border-right: 0; }

	.actions { margin-left: 0; width: 100%; }
	.actions button { flex: 1; }
	.apercu { padding: 12px 8px; }
	.feuille { padding: min(var(--marge), 6vw); min-height: 0; }
	#source { font-size: 16px; padding: 16px; }
}

/* ---------- Impression : seule la feuille sort, les marges viennent de @page ---------- */

@media print {
	html, body { height: auto; background: #fff; }
	body { display: block; }
	.barre, .onglets, .edition, .astuce, .depot { display: none !important; }
	.plan, .apercu { display: block !important; overflow: visible; padding: 0; }
	.feuille {
		width: auto;
		max-width: none;
		min-height: 0;
		margin: 0;
		padding: 0;
		box-shadow: none;
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}
}
