/* Interface de l'outil Brochures — tokens repris du Médipost Design Handover v1.0 */
:root {
  --bordeaux: #96204F;
  --bordeaux-dark: #74183D;
  --ink: #203941;
  --muted: #5A676C;
  --bg: #EFEEEB;
  --cream: #F6F1E8;
  --line: #DDD5C9;
  --white: #FFFFFF;
  --field-line: #B5B7B3;
  --ok-text: #185A32;
  --ok-bg: #EDF8F0;
  --ok-line: #A6D6B5;
  --warn: #AD722A;
  --err-text: #A52838;
  --err-bg: #F9E7E8;
  --badge-text: #74183D;
  --badge-bg: #F3DCE5;
  --badge-line: #E8C8D4;
  --radius: 5px;
  --ease: cubic-bezier(0.22, 0.68, 0, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.wrap { max-width: 1168px; margin: 0 auto; padding: 0 24px; }

.skip {
  position: absolute; left: 16px; top: -60px; z-index: 10;
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--radius);
}
.skip:focus { top: 12px; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* ---------- En-tête ---------- */
.top { background: var(--white); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 96px; }
.brandmark { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; color: var(--ink); border-radius: var(--radius); }
.brandmark img { width: 220px; height: auto; display: block; margin-left: -6px; }
.suffix {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.8px; color: var(--bordeaux);
  padding-left: 14px; border-left: 1px solid var(--line);
}

.tabs { display: flex; gap: 4px; margin: 0 auto 0 20px; }
.tabs a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; border-radius: var(--radius);
  font-size: 14px; font-weight: 700; color: var(--muted); text-decoration: none; transition: background-color 150ms, color 150ms;
}
.tabs a:hover { background: var(--cream); color: var(--bordeaux); }
.tabs a[aria-current="page"] { background: var(--cream); color: var(--bordeaux); }

/* ---------- Typographie ---------- */
.over { margin: 0; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.8px; color: var(--bordeaux); }
h1 { margin: 0; color: var(--ink); font-weight: 700; }
.lead { margin: 0; font-size: 17px; line-height: 1.55; color: var(--ink); }
.lead.small { font-size: 15px; color: var(--muted); }
.help { margin: 6px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.help.center { text-align: center; margin-top: 12px; }
.opt { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 4px; }
.error { margin: 8px 0 0; font-size: 14px; line-height: 1.45; color: var(--err-text); background: var(--err-bg); padding: 10px 12px; border-radius: var(--radius); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 12px 20px; border-radius: var(--radius);
  font: inherit; font-weight: 700; font-size: 15px; line-height: 1.2; text-align: center;
  border: 1px solid transparent; cursor: pointer; transition: background-color 150ms, color 150ms, border-color 150ms;
}
.btn-primary { background: var(--bordeaux); color: #fff; }
.btn-primary:hover { background: var(--bordeaux-dark); }
.btn-secondary, .btn-ghost { background: transparent; color: var(--bordeaux); border-color: var(--bordeaux); }
.btn-secondary:hover, .btn-ghost:hover { background: var(--cream); }
.btn-small { min-height: 44px; padding: 8px 14px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn .spin {
  width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Champs ---------- */
.field { margin: 0 0 18px; }
.field:last-child { margin-bottom: 0; }
label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; color: var(--ink); }
input[type="text"], input[type="url"], input[type="tel"], input[type="email"], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--white); border: 1px solid var(--field-line); border-radius: var(--radius);
}
textarea { resize: vertical; line-height: 1.45; min-height: 46px; display: block; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--bordeaux); box-shadow: 0 0 0 4px #96204F1A;
}
input[aria-invalid="true"] { border-color: var(--err-text); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--bordeaux); margin: 0; flex: none; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 400; font-size: 15px; margin: 0 0 8px; cursor: pointer; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.pair .field { margin: 0; }

.panel { background: var(--white); border-radius: var(--radius); padding: 30px; }

/* ---------- Étape 1 ---------- */
.start { padding: 64px 0 96px; }
.start-grid { display: grid; grid-template-columns: 0.9fr 1.1fr; gap: clamp(42px, 7vw, 96px); align-items: start; }
.start-intro { padding-top: 14px; }
.start-intro h1 { margin: 14px 0 20px; font-size: clamp(39px, 5vw, 58px); line-height: 1.02; letter-spacing: -0.055em; }
.steps { list-style: none; margin: 34px 0 0; padding: 0; border-top: 1px solid var(--line); }
.steps li { display: flex; align-items: baseline; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 15px; color: var(--ink); }
.steps span { font-size: 11px; font-weight: 700; letter-spacing: 1.2px; color: var(--bordeaux); min-width: 14px; }
.start-form { padding: 34px; }
.start-form input[type="url"], .start-form select { min-height: 52px; }
.start-form label { font-size: 13px; }
.start-form .btn { min-height: 52px; margin-top: 6px; }

/* ---------- Étape 2 ---------- */
.editor { padding: 32px 0 80px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr); gap: 32px; align-items: start; }
.editor-head { background: var(--cream); border-radius: var(--radius); padding: 26px 30px; margin-bottom: 16px; }
.editor-head h1 { margin: 8px 0 8px; font-size: clamp(26px, 2.6vw, 34px); line-height: 1.1; letter-spacing: -1px; }
.editor-head h1:focus { outline: none; }

.fold { padding: 0; margin-bottom: 12px; }
.fold > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 16px 22px; min-height: 56px; font-weight: 700; font-size: 17px; color: var(--bordeaux); border-radius: var(--radius);
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after {
  content: ""; margin-left: auto; width: 9px; height: 9px; border-right: 2px solid var(--bordeaux); border-bottom: 2px solid var(--bordeaux);
  transform: rotate(45deg) translate(-2px, -2px); transition: transform 450ms var(--ease);
}
.fold[open] > summary::after { transform: rotate(225deg) translate(-2px, -2px); }
.fold-body { padding: 4px 22px 24px; }
.count { font-size: 12px; font-weight: 400; color: var(--muted); }

/* Listes modifiables (points clés, caractéristiques) */
.rows { display: grid; gap: 8px; margin-bottom: 14px; }
.rows:empty::before { content: "Aucun élément repris de la fiche. Vous pouvez en ajouter."; font-size: 14px; color: var(--muted); }
.rowi { display: grid; grid-template-columns: 26px minmax(0, 0.75fr) minmax(0, 1.25fr) 36px; gap: 8px; align-items: start; }
.rowi > input[type="checkbox"] { margin-top: 12px; }
.rowi textarea { min-height: 42px; padding: 10px; font-size: 14px; line-height: 1.4; resize: none; overflow: hidden; }
.rowi.off textarea { color: var(--muted); background: #FAF9F7; border-color: var(--line); }
.icon-btn {
  width: 36px; height: 42px; border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: var(--radius);
  cursor: pointer; font-size: 15px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--cream); color: var(--bordeaux); }
.icon-btn[disabled] { opacity: .3; cursor: default; }

/* Images */
.imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin: 14px 0 12px; }
.imgs:empty::before { content: "Cette fiche ne contient pas d’image."; font-size: 14px; color: var(--muted); }
.imgi { display: grid; gap: 4px; }
.imgi button {
  position: relative; aspect-ratio: 1; width: 100%; padding: 6px; background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
}
.imgi button img { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); object-fit: contain; display: block; }
.imgi button[aria-pressed="true"] { border: 2px solid var(--bordeaux); padding: 5px; }
.imgi button[aria-pressed="true"]::after {
  content: "Principale"; position: absolute; left: 5px; bottom: 5px; font-size: 11px; font-weight: 700; line-height: 1; padding: 5px 7px;
  border-radius: 4px; color: var(--badge-text); background: var(--badge-bg); border: 1px solid var(--badge-line);
}
.imgi .check { min-height: 32px; margin: 0; font-size: 13px; gap: 8px; }

/* Aperçu */
.editor-preview { position: sticky; top: 16px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.bar-error { margin: 0 0 12px; }
.status { margin: 0; font-size: 12px; line-height: 1.3; padding: 6px 10px; border-radius: 4px; border: 1px solid transparent; }
.status:empty { visibility: hidden; }
.status.ok { color: var(--ok-text); background: var(--ok-bg); border-color: var(--ok-line); }
.status.note { color: var(--badge-text); background: var(--badge-bg); border-color: var(--badge-line); }
.status.warn { color: var(--ink); background: var(--cream); border-color: var(--warn); border-left-width: 4px; }
.sheet {
  position: relative; width: min(100%, calc((100vh - 150px) * 0.7071)); min-width: min(100%, 360px); margin: 0 auto;
  aspect-ratio: 210 / 297; background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.frame {
  position: absolute; top: 0; left: 0; width: 794px; height: 1123px; border: 0; transform-origin: 0 0;
  opacity: 0; pointer-events: none; transition: opacity 200ms;
}
.frame.on { opacity: 1; }

/* ---------- Manuels et procédures ---------- */
.start-form textarea { min-height: 260px; font-size: 15px; }
.file-line { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; }
.file-line .help { margin: 0; }
.linkish {
  font: inherit; font-size: 14px; font-weight: 700; color: var(--bordeaux); background: none; border: 0; padding: 0; min-height: 32px;
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px; border-radius: 3px;
}
.linkish:hover { color: var(--bordeaux-dark); }
.mode { margin: 0 0 18px; font-size: 13px; line-height: 1.45; padding: 10px 12px; border-radius: var(--radius); background: var(--cream); color: var(--ink); }
.mode b { color: var(--bordeaux); }
.notice { margin: 0 0 12px; font-size: 14px; line-height: 1.45; padding: 12px 14px; border-radius: var(--radius); color: var(--ink); background: var(--cream); border-left: 4px solid var(--warn); }
textarea.mono { font-family: Consolas, "Courier New", monospace; font-size: 13.5px; line-height: 1.55; min-height: 420px; tab-size: 2; }
.cheat { margin: 12px 0 0; border: 1px solid var(--line); border-radius: var(--radius); }
.cheat > summary { cursor: pointer; padding: 12px 14px; min-height: 44px; font-size: 14px; font-weight: 700; color: var(--bordeaux); border-radius: var(--radius); }
.cheat dl { margin: 0; padding: 0 14px 12px; display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 0 14px; font-size: 13px; line-height: 1.4; }
.cheat dt, .cheat dd { margin: 0; padding: 7px 0; border-top: 1px solid var(--line); }
.cheat dt { font-family: Consolas, "Courier New", monospace; font-size: 12.5px; color: var(--ink); overflow-wrap: anywhere; }
.cheat dd { color: var(--muted); }
.inline-action { display: flex; gap: 8px; align-items: stretch; }
.inline-action input { flex: 1; min-width: 0; }
.inline-action .btn { flex: none; min-height: 46px; padding: 8px 14px; font-size: 14px; white-space: nowrap; }
.btn-secondary .spin, .btn-ghost .spin { border-color: #96204F55; border-top-color: var(--bordeaux); }
.fold-actions { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 14px; }
.sheet.scroll .frame.on { pointer-events: auto; }
.imgi.cover button[aria-pressed="true"]::after { content: "Couverture"; }
.imgi-line { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); }
.imgi-line .linkish { font-size: 12px; min-height: 28px; }
.add-qr { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.add-qr .inline-action input { flex: 1 1 0; }
#raw-links { display: inline-block; margin: 10px 0 0; }

/* ---------- Petits écrans ---------- */
@media (max-width: 960px) {
  .editor-grid { grid-template-columns: 1fr; }
  .editor-preview { position: static; order: 2; }
  .bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; margin: 0; padding: 10px 16px;
    background: var(--white); border-top: 1px solid var(--line);
  }
  .editor { padding-bottom: 110px; }
}
@media (max-width: 840px) {
  .start { padding: 36px 0 64px; }
  .start-grid { grid-template-columns: 1fr; gap: 32px; }
}
@media (max-width: 700px) {
  .wrap { padding: 0 16px; }
  .top-in { min-height: 80px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 10px; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tabs a { flex: 1; justify-content: center; }
  .cheat dl { grid-template-columns: 1fr; }
  .cheat dd { border-top: 0; padding-top: 0; }
  .inline-action { flex-wrap: wrap; }
  .brandmark img { width: 190px; }
  .panel, .start-form { padding: 22px; }
  .fold { padding: 0; }
  .fold > summary { padding: 14px 16px; }
  .fold-body { padding: 4px 16px 20px; }
  .editor-head { padding: 20px 22px; }
  .pair { grid-template-columns: 1fr; }
  .rowi { grid-template-columns: 26px minmax(0, 1fr) 36px; }
  .rowi > :nth-child(3) { grid-column: 2; grid-row: 2; }
  .rowi > .icon-btn { grid-column: 3; grid-row: 1; }
  .bar .btn { flex: none; white-space: nowrap; }
  .bar .status { flex: 1; }
  .rows { gap: 14px; }
  .start-form .btn, .btn-block { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 1.2s !important; }
}
