/* =====================================================================
   Signature sur place · relance en un geste · certificat de ramonage (features.js)
   Classes préfixées .fx- · uniquement des jetons de tokens.css (voir DESIGN.md)
   ===================================================================== */
html.fx-open, html.fx-open body { overflow: hidden; }
#fx-layer[hidden] { display: none; }
#fx-layer { position: fixed; inset: 0; z-index: var(--z-sheet); font-family: var(--font-sans); color: var(--text); }
#fx-layer button { font-family: var(--font-sans); cursor: pointer; -webkit-tap-highlight-color: transparent; }
#fx-layer .ic { width: 18px; height: 18px; flex: none; }
#toast { z-index: var(--z-toast); }
.tp-prev.fx-top { z-index: var(--z-modal); }

/* ---------- écran plein cadre (signature) ---------- */
.fx-full { display: flex; flex-direction: column; background: var(--surface-2); animation: fx-in var(--dur-slow) var(--ease-out) both; }
.fx-bar {
  flex: none; display: flex; align-items: center; gap: var(--space-3); min-height: 56px;
  padding: var(--space-2) var(--space-4); padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
  background: var(--surface); border-bottom: var(--border-w) solid var(--border);
}
.fx-bar strong { flex: 1; text-align: center; font: var(--fw-semibold) var(--fs-lg) / 1.2 var(--font-sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-bar-sp { width: var(--h-md); flex: none; }
.fx-x {
  flex: none; width: var(--h-md); height: var(--h-md); display: grid; place-items: center; border: 0; border-radius: var(--radius-md);
  background: none; color: var(--text-muted);
}
.fx-x:hover { background: var(--surface-3); color: var(--text); }
.fx-body {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: var(--space-3);
  width: 100%; max-width: var(--content-narrow); margin: 0 auto; padding: var(--space-4);
}
.fx-foot { flex: none; padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: var(--border-w) solid var(--border); }
.fx-foot .fx-cta { max-width: calc(var(--content-narrow) - var(--space-8)); margin: 0 auto; }

.fx-recap {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  padding: var(--space-4); background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius-lg);
}
.fx-recap b { display: block; font: var(--fw-semibold) var(--fs-lg) / var(--lh-tight) var(--font-sans); }
.fx-recap span { display: block; color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--space-0-5); }
.fx-recap-amt { text-align: right; flex: none; }
.fx-recap-amt strong { display: block; font: var(--fw-semibold) var(--fs-xl) / 1.2 var(--font-sans); letter-spacing: var(--tracking-tight); color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums; }

.fx-field { display: flex; flex-direction: column; gap: var(--space-1-5); }
.fx-field > span { font: var(--fw-medium) var(--fs-sm) / 1 var(--font-sans); color: var(--text-2); }
.fx-field input, .fx-msg {
  width: 100%; padding: var(--space-3); border: var(--border-w) solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); font: var(--fs-lg) / var(--lh-normal) var(--font-sans); box-shadow: var(--shadow-xs);
  -webkit-appearance: none; appearance: none;
}
.fx-field input { height: var(--h-xl); padding: 0 var(--space-3); }
.fx-field input:focus, .fx-msg:focus { outline: none; border-color: var(--border-strong); box-shadow: var(--focus-ring); }
.fx-msg { resize: vertical; min-height: 84px; font-size: var(--fs-md); }

.fx-check {
  display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius-lg);
  font-size: var(--fs-md); line-height: var(--lh-normal); cursor: pointer; transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.fx-check input { flex: none; width: 22px; height: 22px; margin: var(--space-0-5) 0 0; accent-color: var(--accent); }
.fx-check:has(input:checked) { border-color: var(--accent-border); background: var(--accent-soft); }
.fx-link { border: 0; background: none; padding: 0; color: var(--accent-text); font: var(--fw-medium) var(--fs-sm) var(--font-sans); text-decoration: underline; text-underline-offset: 3px; }
.fx-cert { padding: var(--space-3) var(--space-4); background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius-md); font-size: var(--fs-sm); line-height: var(--lh-normal); color: var(--text-2); }
.fx-cert .d-cert { border: 0; padding: 0; margin: 0; font-size: var(--fs-sm); color: var(--text-2); }
.fx-cert .d-lbl { font-size: var(--fs-xs); margin-bottom: var(--space-1); color: var(--text-muted); }
.fx-cert .d-cert-note { font-size: var(--fs-xs); color: var(--text-muted); }

/* pavé de signature : la feuille reste blanche (la signature est encrée en bleu nuit) */
.fx-pad { position: relative; flex: 1 1 200px; min-height: 190px; background: var(--paper); border: var(--border-w) dashed var(--border-strong); border-radius: var(--radius-lg); overflow: hidden; }
.fx-pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.fx-pad-hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-faint); font: var(--fw-medium) var(--fs-lg) / 1 var(--font-sans); pointer-events: none; }
.fx-pad-hint[hidden], .fx-pad-clear[hidden] { display: none; }
.fx-pad-line { position: absolute; left: var(--space-6); right: var(--space-6); bottom: var(--space-10); border-top: var(--border-w) solid var(--border); pointer-events: none; }
.fx-pad-clear {
  position: absolute; top: var(--space-2); right: var(--space-2); height: var(--h-sm); padding: 0 var(--space-3); border: var(--border-w) solid var(--border);
  border-radius: var(--radius-md); background: var(--surface); color: var(--text-2); font: var(--fw-medium) var(--fs-sm) / 1 var(--font-sans); box-shadow: var(--shadow-xs);
}

/* ---------- boutons ---------- */
.fx-cta {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2); width: 100%; min-height: var(--h-xl); padding: 0 var(--space-5);
  border: 0; border-radius: var(--radius-md); background: var(--accent); color: var(--accent-fg); text-align: center;
  font: var(--fw-semibold) var(--fs-lg) / 1.2 var(--font-sans); box-shadow: var(--shadow-xs);
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}
.fx-cta:hover { background: var(--accent-hover); }
.fx-cta:focus-visible, .fx-btn:focus-visible, .fx-send-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.fx-cta:active, .fx-btn:active, .fx-send-btn:active { transform: scale(0.99); }
.fx-cta.off { opacity: 0.45; }
.fx-btn {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2); width: 100%; min-height: var(--h-xl); padding: 0 var(--space-4);
  border: var(--border-w) solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); text-align: center;
  font: var(--fw-medium) var(--fs-md) / 1.2 var(--font-sans); box-shadow: var(--shadow-xs);
}
.fx-btn:hover { background: var(--surface-3); }
.fx-ghost { display: block; width: 100%; padding: var(--space-3); border: 0; border-radius: var(--radius-md); background: none; color: var(--text-2); font: var(--fw-medium) var(--fs-md) / 1 var(--font-sans); text-align: center; }
.fx-ghost:hover { background: var(--surface-3); color: var(--text); }

/* ---------- écran « c'est signé » ---------- */
.fx-done { align-items: stretch; text-align: center; justify-content: center; max-width: 480px; }
.fx-done-ic {
  align-self: center; width: 64px; height: 64px; border-radius: var(--radius-full); display: grid; place-items: center;
  background: var(--success-soft); color: var(--success); box-shadow: inset 0 0 0 var(--border-w) color-mix(in srgb, var(--success) 25%, transparent);
  animation: fx-pop var(--dur-slow) var(--ease-out) both;
}
#fx-layer .fx-done-ic .ic { width: 30px; height: 30px; stroke-width: 2.5; }
.fx-done h2 { font: var(--fw-semibold) var(--fs-2xl) / var(--lh-tight) var(--font-sans); letter-spacing: var(--tracking-tight); margin: var(--space-2) 0 0; }
.fx-done p { color: var(--text-muted); font-size: var(--fs-md); line-height: var(--lh-normal); margin: 0 0 var(--space-2); }
.fx-okline {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md); background: var(--success-soft); color: var(--success-text); font: var(--fw-medium) var(--fs-sm) / var(--lh-snug) var(--font-sans);
}
.fx-modes { padding: var(--space-3); background: var(--surface); border: var(--border-w) solid var(--border); border-radius: var(--radius-lg); }
.fx-modes > span { display: block; font: var(--fw-medium) var(--fs-sm) / 1 var(--font-sans); color: var(--text-2); margin-bottom: var(--space-3); }
.fx-modes > div { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }

/* ---------- feuille (relance, certificat de ramonage) ---------- */
.fx-sheet-wrap { display: flex; align-items: flex-end; justify-content: center; background: var(--overlay); }
.fx-sheet {
  width: 100%; max-width: var(--modal-w); max-height: 92vh; max-height: 92dvh; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-5) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-lg); animation: fx-up var(--dur-slow) var(--ease-out) both;
}
.fx-sheet-h { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.fx-sheet-h h2 { font: var(--fw-semibold) var(--fs-xl) / var(--lh-tight) var(--font-sans); letter-spacing: var(--tracking-tight); margin: 0; }
.fx-sheet-h p { color: var(--text-muted); font-size: var(--fs-sm); margin: var(--space-1) 0 0; }
.fx-send { display: flex; gap: var(--space-2); }
.fx-send-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1-5); min-height: 72px;
  border: var(--border-w) solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
  font: var(--fw-medium) var(--fs-md) / 1 var(--font-sans); box-shadow: var(--shadow-xs);
}
.fx-send-btn i { font-style: normal; line-height: 1; color: var(--text-muted); }
.fx-send-btn:hover { background: var(--surface-3); }
.fx-send-btn.main { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.fx-send-btn.main i { color: inherit; }
.fx-send-btn.main:hover { background: var(--accent-hover); }
.fx-note { color: var(--text-muted); font-size: var(--fs-sm); margin: 0; text-align: center; }
.fx-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.fx-chip {
  height: var(--h-md); padding: 0 var(--space-3); border: var(--border-w) solid var(--border); border-radius: var(--radius-full);
  background: var(--surface); color: var(--text-2); font: var(--fw-medium) var(--fs-sm) / 1 var(--font-sans) !important;
}
.fx-chip:hover { background: var(--surface-3); color: var(--text); }
@media (min-width: 700px) {
  .fx-sheet-wrap { align-items: center; padding: var(--space-4); }
  .fx-sheet { border-radius: var(--radius-lg); padding: var(--space-6); }
}

/* ---------- boutons posés dans les pages ---------- */
.fx-sign-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-width: 240px; height: var(--h-xl); margin-top: var(--space-3); padding: 0 var(--space-6);
  border: var(--border-w) solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); color: var(--text);
  font: var(--fw-semibold) var(--fs-lg) / 1 var(--font-sans); box-shadow: var(--shadow-xs); cursor: pointer;
}
.fx-sign-btn:hover { background: var(--surface-3); }
.fx-sign-btn .ic, .fx-signed .ic { width: 18px; height: 18px; }
.fx-signed {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-width: 240px; min-height: var(--h-xl); margin-top: var(--space-3); padding: var(--space-2) var(--space-5);
  border: 0; border-radius: var(--radius-md); background: var(--success-soft); color: var(--success-text);
  font: var(--fw-medium) var(--fs-md) / 1.3 var(--font-sans); cursor: pointer;
}
@media (max-width: 640px) { .fx-sign-btn, .fx-signed { width: 100%; min-width: 0; } }

@keyframes fx-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fx-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fx-pop { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .fx-full, .fx-sheet, .fx-done-ic { animation: none; } }
@media print { #fx-layer { display: none !important; } }
