/* =============================================================
   styles.css — PDF Forge
   Direction : atelier éditorial. Papier chaud, encre ardoise,
   accent terracotta. Display = Fraunces, UI = Hanken Grotesk.
   ============================================================= */

:root {
	--ink:        #20242e;
	--ink-soft:   #3a4150;
	--paper:      #ece7dc;
	--paper-2:    #f4f0e7;
	--surface:    #fbfaf6;
	--line:       #d8d1c2;
	--accent:     #d8632f;
	--accent-2:   #1b6ca8;
	--danger:     #b23a30;
	--muted:      #8a8475;
	--rail-bg:    #1b1f27;
	--rail-fg:    #b9bdc7;
	--shadow:     0 18px 40px -18px rgba(20,24,30,.45);

	--font-ui: 'Hanken Grotesk', system-ui, sans-serif;
	--font-display: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
	font-family: var(--font-ui);
	color: var(--ink);
	background:
		radial-gradient(120% 120% at 100% 0%, #f0ebe0 0%, #e6e0d2 60%, #ddd6c6 100%);
	display: grid;
	grid-template-rows: auto 1fr auto;
	grid-template-columns: minmax(0, 1fr);   /* la colonne ne dépasse jamais l'écran */
	overflow: hidden;
}

/* ---------------- Boutons génériques ---------------- */
.btn {
	font-family: var(--font-ui);
	font-weight: 600;
	font-size: 13px;
	border: 1px solid transparent;
	border-radius: 9px;
	padding: 8px 14px;
	cursor: pointer;
	background: var(--surface);
	color: var(--ink);
	transition: transform .12s, background .15s, border-color .15s, opacity .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.btn--ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #f4f0e7; }
.btn--ghost:hover { background: rgba(255,255,255,.1); }
.btn--accent { background: var(--accent); color: #fff; box-shadow: 0 6px 16px -8px var(--accent); }
.btn--accent:hover { background: #c2551f; }
.btn--mini { padding: 6px 10px; font-size: 12px; border-color: var(--line); }
.btn--mini:hover { border-color: var(--accent); color: var(--accent); }
.btn--icon { width: 34px; height: 34px; padding: 0; font-size: 20px; line-height: 1; border-color: var(--line); display: inline-flex; align-items: center; justify-content: center; }

.show-sm { display: none; }   /* visible seulement en version mobile */
.btn--danger { color: var(--danger); border-color: rgba(178,58,48,.35); }
.btn--danger:hover { background: var(--danger); color: #fff; }

kbd {
	font-family: var(--font-ui); font-size: 11px; font-weight: 700;
	background: var(--paper); border: 1px solid var(--line);
	border-radius: 5px; padding: 1px 5px;
}

/* ---------------- Topbar ---------------- */
.topbar {
	display: flex; align-items: center; gap: 20px;
	background: var(--ink); color: #f4f0e7;
	padding: 0 20px; height: 60px;
	border-bottom: 3px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand__logo { height: 36px; width: auto; display: block; border-radius: 4px; }
.brand__mark { color: var(--accent); font-size: 22px; }
.brand__txt { display: flex; flex-direction: column; line-height: 1; }
.brand__txt strong { font-family: var(--font-display); font-weight: 900; font-size: 20px; letter-spacing: .2px; }
.brand__txt small { color: var(--rail-fg); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; margin-top: 3px; }

.topbar__file {
	flex: 1; font-size: 13px; color: var(--rail-fg);
	font-style: italic; font-family: var(--font-display);
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__actions { display: flex; gap: 10px; }

/* ---------------- Layout principal ---------------- */
.app { display: flex; min-height: 0; min-width: 0; }

/* ---------------- Rail d'outils ---------------- */
.rail {
	width: 82px; background: var(--rail-bg);
	display: flex; flex-direction: column; gap: 4px;
	padding: 14px 10px; flex-shrink: 0;
}
.tool-btn {
	display: flex; flex-direction: column; align-items: center; gap: 5px;
	background: transparent; border: none; color: var(--rail-fg);
	padding: 11px 4px; border-radius: 11px; cursor: pointer;
	font-size: 11px; font-weight: 600; font-family: var(--font-ui);
	transition: background .15s, color .15s;
}
.tool-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.tool-btn.is-active { background: var(--accent); color: #fff; box-shadow: 0 8px 18px -8px var(--accent); }

/* ---------------- Panneau d'options ---------------- */
.options {
	width: 244px; flex-shrink: 0;
	background: var(--surface);
	border-right: 1px solid var(--line);
	padding: 18px 18px 24px;
	overflow-y: auto;
	display: flex; flex-direction: column; gap: 22px;
}
.opt-group { display: flex; flex-direction: column; gap: 10px; }
.opt-group.is-hidden { display: none; }

.opt-label {
	font-size: 11px; font-weight: 700; text-transform: uppercase;
	letter-spacing: 1.4px; color: var(--muted);
	display: flex; justify-content: space-between; align-items: baseline;
}
.opt-label em { font-style: normal; color: var(--accent); font-weight: 700; letter-spacing: 0; }

.hint { font-size: 13px; line-height: 1.5; color: var(--ink-soft); font-family: var(--font-display); }
.hint--sm { font-size: 12px; font-family: var(--font-ui); color: var(--muted); }

.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; }
.swatch {
	aspect-ratio: 1; border-radius: 7px; border: 2px solid rgba(0,0,0,.12);
	cursor: pointer; padding: 0; transition: transform .12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.is-active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }

.custom-color { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--muted); }
.custom-color input[type=color] {
	width: 38px; height: 30px; padding: 0; border: 1px solid var(--line);
	border-radius: 7px; background: none; cursor: pointer;
}

input[type=range] { width: 100%; accent-color: var(--accent); }
select, input[type=number] {
	font-family: var(--font-ui); font-size: 14px;
	padding: 8px 10px; border: 1px solid var(--line);
	border-radius: 8px; background: var(--paper-2); color: var(--ink);
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.stamps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.stamp-btn {
	aspect-ratio: 1; border: 1px solid var(--line); border-radius: 9px;
	background: var(--paper-2); font-size: 18px; cursor: pointer; color: var(--ink);
	transition: background .15s, border-color .15s;
}
.stamp-btn:hover { border-color: var(--accent); }
.stamp-btn.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------------- Workspace ---------------- */
.workspace {
	flex: 1; min-width: 0; position: relative; overflow: auto;
	padding: 36px;
	background:
		linear-gradient(rgba(0,0,0,.015) 1px, transparent 1px) 0 0 / 100% 28px;
}
.workspace.is-dragover::after {
	content: 'Déposez pour ouvrir';
	position: absolute; inset: 16px; z-index: 50;
	border: 3px dashed var(--accent); border-radius: 18px;
	display: grid; place-items: center;
	font-family: var(--font-display); font-size: 22px; color: var(--accent);
	background: rgba(216,99,47,.06);
}
.workspace.is-loading { cursor: progress; }

.dropzone {
	position: absolute; inset: 0; display: grid; place-items: center; cursor: pointer;
}
.dropzone.is-hidden { display: none; }
.dropzone__inner {
	text-align: center; padding: 60px 70px; border-radius: 20px;
	border: 2px dashed var(--line); background: rgba(251,250,246,.55);
	transition: border-color .2s, transform .2s;
}
.dropzone:hover .dropzone__inner { border-color: var(--accent); transform: translateY(-2px); }
.dropzone__icon {
	font-size: 46px; color: var(--accent);
	width: 86px; height: 86px; margin: 0 auto 18px;
	display: grid; place-items: center; border-radius: 50%;
	background: var(--surface); box-shadow: var(--shadow);
}
.dropzone h2 { font-family: var(--font-display); font-weight: 600; font-size: 26px; margin: 0 0 6px; }
.dropzone p { color: var(--muted); margin: 0; }

/* ---------------- Pile de pages ---------------- */
.page-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 30px; min-width: min-content; }
.page {
	position: relative; background: #fff; box-shadow: var(--shadow);
	border-radius: 2px; margin-inline: auto;
}
.page__base, .page__anno { position: absolute; inset: 0; display: block; border-radius: 2px; }
.page__base { z-index: 1; }
.page__anno { z-index: 2; }
.page__label {
	position: absolute; top: -24px; left: 0;
	font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
	color: var(--muted); font-weight: 600;
}

/* Curseur selon outil (data-cursor posé par UI) */
.page-stack[data-cursor="crosshair"] .page__anno { cursor: crosshair; }
.page-stack[data-cursor="text"] .page__anno { cursor: text; }
.page-stack[data-cursor="cell"] .page__anno { cursor: cell; }
.page-stack[data-cursor="default"] .page__anno { cursor: default; }

/* Overlay de saisie de texte */
.text-overlay {
	position: absolute; z-index: 6;
	margin: 0; padding: 0 2px; border: 1px dashed var(--accent);
	background: rgba(255,255,255,.55); resize: none; overflow: hidden;
	outline: none; white-space: pre; min-width: 40px;
}

/* Zones de texte existant détectées (outil Éditer) */
.tl-box {
	position: absolute; z-index: 4; cursor: text;
	border: 1px solid rgba(27,108,168,.35);
	background: rgba(27,108,168,.08);
	border-radius: 2px; transition: background .12s, border-color .12s;
}
.tl-box:hover { background: rgba(27,108,168,.2); border-color: var(--accent-2); }

/* Séparateur dans le rail d'outils */
.rail__sep { height: 1px; background: rgba(255,255,255,.12); margin: 8px 6px; }

/* Appel à l'OCR sur une page-image */
.ocr-cta {
	position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
	z-index: 5; max-width: 80%;
	font-family: var(--font-ui); font-weight: 600; font-size: 14px;
	padding: 12px 20px; border-radius: 12px; cursor: pointer;
	color: #fff; background: var(--accent-2); border: none;
	box-shadow: 0 10px 26px -10px rgba(27,108,168,.7);
}
.ocr-cta:disabled { background: var(--muted); cursor: default; box-shadow: none; }
.ocr-progress {
	position: absolute; left: 50%; top: calc(50% + 34px); transform: translateX(-50%);
	z-index: 5; width: 60%; max-width: 280px; height: 6px;
	background: rgba(0,0,0,.12); border-radius: 99px; overflow: hidden;
}
.ocr-progress i { display: block; height: 100%; width: 0; background: var(--accent-2); transition: width .2s; }

/* Tactile : on gère défilement ET zoom nous-mêmes (cf. touch.js),
   donc on retire toute action tactile native sur la zone de travail. */
.workspace { touch-action: none; }
.page__anno { touch-action: none; }

/* ---------------- Barre de statut ---------------- */
.statusbar {
	display: flex; align-items: center; justify-content: space-between; gap: 16px;
	background: var(--surface); border-top: 1px solid var(--line);
	padding: 9px 18px; height: 52px;
}
.statusbar__group { display: flex; align-items: center; gap: 8px; }
.statusbar__center {
	flex: 1; justify-content: center;
	font-family: var(--font-display); font-size: 14px; color: var(--ink-soft);
}
.zoom { font-weight: 600; font-size: 13px; min-width: 50px; text-align: center; color: var(--ink-soft); }

/* ---------------- Scrollbars ---------------- */
.workspace::-webkit-scrollbar, .options::-webkit-scrollbar { width: 12px; height: 12px; }
.workspace::-webkit-scrollbar-thumb, .options::-webkit-scrollbar-thumb {
	background: rgba(32,36,46,.22); border-radius: 10px;
	border: 3px solid transparent; background-clip: padding-box;
}
.workspace::-webkit-scrollbar-thumb:hover { background: rgba(32,36,46,.4); background-clip: padding-box; }

/* ---------------- Mobile / tactile ---------------- */
@media (max-width: 820px), (pointer: coarse) {
	body { grid-template-rows: auto 1fr; }   /* topbar + workspace ; le reste est fixé en bas */

	.topbar { height: 52px; padding: 0 10px; gap: 10px; }
	.brand__txt small { display: none; }
	.brand__txt strong { font-size: 17px; }
	.brand__logo { height: 30px; }
	.topbar__file { display: none; }
	.topbar__actions { margin-left: auto; }  /* Ouvrir / Exporter calés à droite */
	.topbar .btn { padding: 7px 11px; font-size: 12px; border-radius: 8px; }
	.hide-sm { display: none; }              /* raccourcit les libellés sur mobile */
	.show-sm { display: inline-block; }

	/* La rangée d'outils, le panneau d'options et la barre de statut
	   passent en bas, empilés et fixés. */
	.app { display: block; height: 100%; min-height: 0; }

	.workspace {
		height: 100%; padding: 16px 12px 150px;  /* place pour les barres du bas */
		-webkit-overflow-scrolling: touch;
	}

	.rail {
		position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
		width: auto; height: auto; min-height: 62px; flex-direction: row;
		gap: 2px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); overflow-x: auto;
		border-top: 1px solid rgba(255,255,255,.12);
	}
	.rail::-webkit-scrollbar { display: none; }
	.rail__sep { display: none; }
	.tool-btn { flex: 0 0 auto; min-width: 58px; padding: 6px 8px; }
	.tool-btn svg { width: 19px; height: 19px; }
	.tool-btn span { font-size: 10px; }

	.statusbar {
		position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 39;
		height: 46px; padding: 6px 10px; gap: 6px;
		border-top: 1px solid var(--line);
		justify-content: space-between;
	}
	.statusbar__group { gap: 6px; flex: 0 0 auto; }
	.statusbar__center { flex: 1; font-size: 12px; text-align: center; min-width: 0; }
	.btn--mini { padding: 6px 9px; font-size: 12px; }
	.btn--icon { width: 32px; height: 32px; font-size: 19px; }

	/* Le panneau d'options devient une feuille coulissante au-dessus des barres */
	.options {
		position: fixed; left: 0; right: 0; bottom: calc(108px + env(safe-area-inset-bottom)); z-index: 38;
		width: auto; max-height: 38vh; padding: 14px 16px;
		border-right: none; border-top: 1px solid var(--line);
		box-shadow: 0 -14px 30px -18px rgba(20,24,30,.4);
		gap: 16px;
		border-radius: 16px 16px 0 0;
		background: var(--surface);
	}
	.swatches { grid-template-columns: repeat(7, 1fr); }

	/* La carte d'accueil est centrée horizontalement mais remontée
	   pour rester dans la zone visible (au-dessus des barres du bas). */
	.dropzone { align-items: start; padding-top: 11vh; }
	.dropzone__inner { padding: 26px 24px; border-radius: 16px; }
	.dropzone__icon { width: 56px; height: 56px; font-size: 30px; margin-bottom: 12px; }
	.dropzone h2 { font-size: 19px; }
	.dropzone p { font-size: 13px; }
}

@media ((max-width: 820px) or (pointer: coarse)) and (orientation: landscape) {
	.options { max-height: 55vh; }
}
