:root {
  --ink: #1f2a33;
  --ink-2: #4a5661;
  --muted: #6b7680;
  --line: #dde2e6;
  --bg: #f4f2ee;
  --card: #ffffff;
  --accent: #b24a20;
  --accent-dark: #8f3a17;
  --accent-soft: #fbeee7;
  --ok: #2f7d4f;
  --ok-soft: #e6f3ea;
  --warn: #a66a00;
  --warn-soft: #fdf3dc;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { background: var(--ink); color: #fff; }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 8px; font-size: 18px; letter-spacing: .2px; }
.brand b { color: #f3a27c; font-weight: 700; }
.brand-mark { display: inline-flex; color: #f3a27c; }
.header-tag { font-size: 13px; color: #c9d1d8; }

/* Hero */
.hero { padding-top: 28px; padding-bottom: 8px; }
.hero h1 { font-size: clamp(24px, 4.2vw, 36px); line-height: 1.15; margin: 0 0 10px; letter-spacing: -.3px; }
.lead { margin: 0; max-width: 720px; color: var(--ink-2); font-size: 16px; }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; padding-top: 20px; padding-bottom: 32px; }
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) 470px; align-items: start; }
  .preview-col { position: sticky; top: 16px; }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  margin: 0 0 16px;
  min-width: 0;
}
legend {
  font-weight: 700; font-size: 17px; padding: 0; margin-bottom: 12px;
  display: flex; align-items: center; gap: 10px; float: left; width: 100%;
}
.card > :not(legend) { clear: both; }
.step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 700;
}

.grid { display: grid; grid-template-columns: 1fr; gap: 12px 14px; }
@media (min-width: 560px) { .grid { grid-template-columns: 1fr 1fr; } .span2 { grid-column: span 2; } }

label { display: block; font-size: 14px; font-weight: 600; color: var(--ink); }
.opt { font-weight: 400; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px;
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink);
  background: #fff; border: 1px solid #c8cfd5; border-radius: 9px;
  padding: 11px 12px; min-height: 46px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 0; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(178, 74, 32, .15); }
input.invalid, textarea.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(179, 38, 30, .12); }

.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; flex: none; accent-color: var(--accent); }
.check.strong { background: var(--ok-soft); border-radius: 9px; padding: 12px; font-weight: 600; margin-bottom: 14px; }
.check.small { font-size: 13px; font-weight: 400; color: var(--ink-2); margin-top: 8px; align-items: center; }
.check.small input { width: 18px; height: 18px; }

.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; font-weight: 400; }
.saved-hint { color: var(--ok); margin: -4px 0 12px; }
.field-label { font-size: 14px; font-weight: 600; margin: 4px 0 8px; }

/* Logo */
.logo-row { display: flex; align-items: center; gap: 14px; }
.logo-preview {
  width: 84px; height: 56px; border: 1px dashed #c8cfd5; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-size: 12px; color: var(--muted); background: #fafbfb; overflow: hidden;
}
.logo-preview img { max-width: 100%; max-height: 100%; }
.btn-file { position: relative; overflow: hidden; }
.btn-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; min-height: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 650; font-size: 15px; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: #fff; color: var(--ink); border-color: #c8cfd5; }
.btn-ghost:hover { border-color: var(--ink-2); }
.btn-link { background: none; border: 0; padding: 4px 0; color: var(--accent); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.btn:disabled { opacity: .6; cursor: progress; }

/* Appareils */
.appareil { border: 1px solid var(--line); border-radius: 10px; padding: 14px 12px 12px; margin-bottom: 12px; background: #fcfcfb; }
.appareil-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 700; font-size: 15px; }

/* État */
.etat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.etat-opt { position: relative; cursor: pointer; }
.etat-opt input { position: absolute; opacity: 0; pointer-events: none; }
.etat-opt span {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 48px;
  border: 1.5px solid #c8cfd5; border-radius: 10px; font-size: 14px; font-weight: 650; padding: 6px; background: #fff;
}
.etat-opt input:focus-visible + span { box-shadow: 0 0 0 3px rgba(178, 74, 32, .2); }
.etat-opt.ok input:checked + span { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.etat-opt.warn input:checked + span { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.etat-opt.bad input:checked + span { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip { position: relative; cursor: pointer; font-weight: 500; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border: 1px solid #c8cfd5; border-radius: 999px; font-size: 14px; background: #fff; }
.chip input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px rgba(178, 74, 32, .2); }
.card > label:not(.check) + label { margin-top: 12px; }

/* Signatures */
.sigs { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 560px) { .sigs { grid-template-columns: 1fr 1fr; } }
.sig-head { display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.sig-pad {
  display: block; width: 100%; height: 160px; border: 1.5px dashed #b9c1c8; border-radius: 10px;
  background: #fff linear-gradient(to top, transparent 34px, #e3e7ea 34px, #e3e7ea 35px, transparent 35px);
  touch-action: none; cursor: crosshair;
}

/* Actions */
.form-error { color: var(--bad); background: var(--bad-soft); border-radius: 9px; padding: 10px 12px; font-size: 14px; margin: 0 0 12px; }
.actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.new-cert { display: block; margin: 14px auto 0; }
@media (max-width: 999px) {
  .actions {
    position: sticky; bottom: 0; z-index: 5; margin: 0 -16px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: rgba(244, 242, 238, .96); backdrop-filter: blur(6px); border-top: 1px solid var(--line);
  }
}
@media (min-width: 1000px) { #goPreview { display: none; } .actions { grid-template-columns: 1fr; } }

/* Aperçu (feuille) */
.preview-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.paper {
  background: #fff; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(31,42,51,.10);
  padding: 22px 20px; font-size: 11.5px; line-height: 1.4; color: #1e2328;
  aspect-ratio: 210 / 297; overflow: hidden; position: relative;
}
@media (max-width: 999px) { .paper { aspect-ratio: auto; min-height: 0; } }
.pv-head { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 2px solid var(--accent); }
.pv-ent { display: flex; gap: 10px; min-width: 0; }
.pv-ent img { max-width: 70px; max-height: 44px; object-fit: contain; }
.pv-ent-name { font-weight: 700; font-size: 13.5px; }
.pv-small { color: #5d6670; font-size: 10.5px; white-space: pre-line; overflow-wrap: anywhere; }
.pv-title { text-align: right; flex: none; }
.pv-title b { display: block; color: var(--accent); font-size: 13px; letter-spacing: .04em; }
.pv-sec { margin-top: 12px; }
.pv-sec h4 { margin: 0 0 5px; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.pv-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pv-k { color: #77808a; font-size: 10px; }
.pv-v { white-space: pre-line; overflow-wrap: anywhere; }
.pv-app { border: 1px solid #e2e5e8; border-radius: 4px; padding: 6px 8px; margin-bottom: 6px; }
.pv-app b { font-size: 11.5px; }
.pv-vac { display: flex; gap: 6px; align-items: flex-start; font-weight: 600; }
.pv-box { width: 12px; height: 12px; border: 1.5px solid #1e2328; border-radius: 2px; flex: none; display: grid; place-items: center; font-size: 10px; line-height: 1; margin-top: 1px; }
.pv-etat { display: inline-block; padding: 2px 8px; border-radius: 4px; font-weight: 700; margin-top: 6px; }
.pv-etat.bon { background: var(--ok-soft); color: var(--ok); }
.pv-etat.surveiller { background: var(--warn-soft); color: var(--warn); }
.pv-etat.non_conforme { background: var(--bad-soft); color: var(--bad); }
.pv-list { margin: 4px 0 0; padding-left: 16px; }
.pv-sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pv-sig { border: 1px solid #e2e5e8; border-radius: 4px; height: 76px; padding: 4px 6px; display: flex; flex-direction: column; }
.pv-sig img { flex: 1; min-height: 0; object-fit: contain; object-position: left center; max-width: 100%; }
.pv-empty { color: #b0b6bc; font-style: italic; }

/* Pro */
.pro {
  display: grid; grid-template-columns: 1fr; gap: 20px; margin: 8px 0 40px;
  background: var(--ink); color: #eef1f3; border-radius: 16px; padding: 24px 20px;
}
@media (min-width: 820px) { .pro { grid-template-columns: 1.4fr 1fr; padding: 32px; align-items: center; } }
.badge { display: inline-block; background: #f3a27c; color: var(--ink); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; padding: 3px 10px; border-radius: 999px; }
.pro h2 { margin: 10px 0 12px; font-size: 22px; line-height: 1.25; color: #fff; }
.pro-list { margin: 0; padding-left: 20px; }
.pro-list li { margin-bottom: 6px; }
.pro-list b { color: #fff; }
.pro-form label { color: #fff; }
.pro-input { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.pro-input input { margin: 0; flex: 1 1 200px; }
.pro-input .btn { flex: 1 0 auto; }
.pro .hint { color: #b7c0c8; }
.pro .hint.ok { color: #9be0b4; font-weight: 600; }

/* SEO */
.seo { max-width: 780px; padding-bottom: 40px; }
.seo h2 { font-size: 24px; margin: 0 0 12px; }
.seo h3 { font-size: 18px; margin: 24px 0 6px; }
.seo p, .seo li { color: var(--ink-2); }
.disclaimer { font-size: 13px; color: var(--muted) !important; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 28px; }

.site-footer { border-top: 1px solid var(--line); padding: 18px 0 28px; font-size: 13px; color: var(--muted); }
.footer-inner { display: flex; flex-wrap: wrap; gap: 10px 24px; justify-content: space-between; }
.footer-links { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.site-footer a, .pro .hint a { color: inherit; text-underline-offset: 3px; }

/* Pages légales */
.legal { max-width: 780px; padding-top: 28px; padding-bottom: 48px; }
.legal h1 { font-size: clamp(24px, 4vw, 32px); margin: 0 0 6px; }
.legal .updated { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.legal h2 { font-size: 19px; margin: 28px 0 8px; }
.legal p, .legal li { color: var(--ink-2); }
.legal .box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.legal a { color: var(--accent); }
.back { display: inline-block; margin-bottom: 18px; color: var(--accent); font-weight: 600; text-decoration: none; }

.preview-dl { width: 100%; margin-top: 14px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100% - 32px);
}

/* Impression (secours) : n'imprimer que le certificat */
@media print {
  body { background: #fff; }
  .site-header, .hero, .form, .pro, .seo, .site-footer, .preview-label, .preview-dl, .toast { display: none !important; }
  .layout { display: block; padding: 0; }
  .paper { box-shadow: none; aspect-ratio: auto; padding: 0; }
}
