:root {
  --ui-bg: #1e1d1b;
  --ui-panel: #262421;
  --ui-panel-2: #2d2b27;
  --ui-border: #3a3733;
  --ui-text: #f1ede6;
  --ui-muted: #a89d8f;
  --ui-accent: #d98a5f;

  /* ---- jetons du gabarit, releves au pixel sur le PDF de reference ---- */
  --card-bg: #ffffff;
  --card-black: #000000;
  --card-title-text: #fcf5e4;
  --card-outer-badge: #c2b09c;   /* conteneur taupe */
  --card-inner-badge: #f4f1ee;   /* badge interne (rendu observe) */
  --card-icon-circle: #faebde;
  --card-icon-color: #493233;
  --card-taupe: #c2b09c;
  --card-cream: #fbf5e3;
  --card-label: #372425;
  --card-text-body: #1e1e1e;

  /* Fondu de la photo d'en-tete vers le fond de page.
     Courbe d'alpha mesuree sur le PDF source (opaque jusqu'a 34.7 %
     de la bande, transparente a 86.8 %). */
  --header-fade: linear-gradient(to bottom,
    #000 0%, #000 34.7%,
    rgba(0,0,0,.95) 38.1%, rgba(0,0,0,.91) 42.6%, rgba(0,0,0,.86) 47.1%,
    rgba(0,0,0,.80) 51.5%, rgba(0,0,0,.72) 56.0%, rgba(0,0,0,.64) 60.5%,
    rgba(0,0,0,.54) 65.0%, rgba(0,0,0,.44) 69.5%, rgba(0,0,0,.34) 73.9%,
    rgba(0,0,0,.23) 78.4%, rgba(0,0,0,.10) 82.9%, rgba(0,0,0,0) 86.8%);
}

* { box-sizing: border-box; }

/* Les regles display: des composants (grid/flex) l'emportent sinon
   sur la regle par defaut de l'attribut hidden. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--ui-bg);
  color: var(--ui-text);
}

button, input, textarea {
  font-family: inherit;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- topbar ---------- */
.topbar {
  min-height: 56px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-border);
}
.topbar-title { display: flex; align-items: center; gap: 8px; }
.topbar-title strong { font-size: 15px; }
.project-name-input {
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 14px;
  font-weight: 600;
  min-width: 280px;
}
.project-name-input:focus { outline: none; border-color: var(--ui-accent); }
.muted { color: var(--ui-muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.autosave-status { font-size: 11px; color: var(--ui-muted); margin-right: 6px; min-width: 90px; text-align: right; }

.btn {
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: #37342f; }
.btn-primary {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #1a1208;
  font-weight: 600;
}
.btn-primary:hover { background: #e39a6f; }

/* ---------- home screen ---------- */
.home-screen {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 28px;
}
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 22px;
  max-width: 1300px;
  margin: 0 auto;
}
.project-card {
  background: var(--ui-panel);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}
.project-card:hover { border-color: var(--ui-accent); transform: translateY(-2px); }
.project-thumb {
  width: 100%;
  aspect-ratio: 1080 / 1350;
  position: relative;
  overflow: hidden;
  background: #000;
}
.project-thumb .thumb-scale-wrap {
  position: absolute;
  top: 0; left: 0;
  width: 1080px;
  height: 1350px;
  transform-origin: top left;
}
.project-card-body { padding: 12px 14px 14px; }
.project-card-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-card-meta { font-size: 11px; color: var(--ui-muted); margin-top: 4px; }
.project-card-actions { display: flex; gap: 6px; margin-top: 10px; }
.project-card-actions .mini-btn { flex: 0 0 auto; padding: 4px 8px; }
.home-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 90px 20px;
  color: var(--ui-muted);
}
.home-empty h2 { color: var(--ui-text); font-size: 19px; margin: 0 0 10px; }
.home-empty p { font-size: 14px; margin: 0; }

/* ---------- workspace layout ---------- */
.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 210px 1fr 340px;
  min-height: 0;
  min-width: 900px;
  overflow-x: auto;
}

.pane { min-height: 0; display: flex; flex-direction: column; }
.pane-header {
  padding: 12px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ui-muted);
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--ui-border);
  flex: 0 0 auto;
}

/* ---------- left: page list ---------- */
.pane-list {
  background: var(--ui-panel);
  border-right: 1px solid var(--ui-border);
}
.page-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.page-thumb {
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 6px;
  cursor: pointer;
  background: var(--ui-panel-2);
}
.page-thumb.active {
  border-color: var(--ui-accent);
  background: #33291f;
}
.page-thumb-frame {
  width: 100%;
  aspect-ratio: 1080 / 1350;
  overflow: hidden;
  border-radius: 6px;
  background: #000;
  position: relative;
}
.page-thumb-frame .thumb-scale-wrap {
  position: absolute;
  top: 0; left: 0;
  width: 1080px;
  height: 1350px;
  transform-origin: top left;
}
.page-thumb-label {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--ui-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-thumb-index { color: var(--ui-muted); margin-right: 4px; }
.page-thumb-fixed {
  margin-top: 6px;
  font-size: 10px;
  color: var(--ui-muted);
  font-style: italic;
}

/* page desactivee : conservee dans le projet, exclue du PDF */
.page-thumb.off .page-thumb-frame { opacity: .32; filter: grayscale(.85); }
.page-thumb.off .page-thumb-label { color: var(--ui-muted); text-decoration: line-through; }
.mini-btn-on { color: var(--ui-accent); border-color: #5a4433; }

.toggle-field {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 12px;
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  font-size: 12.5px;
}
.toggle-field.off { border-color: #5a4433; }
.toggle-field input { accent-color: var(--ui-accent); width: 15px; height: 15px; }
.toggle-field label { cursor: pointer; }
.page-thumb-controls {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}
.mini-btn {
  flex: 1;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-muted);
  border-radius: 5px;
  font-size: 11px;
  padding: 3px 0;
  cursor: pointer;
}
.mini-btn:hover { color: var(--ui-text); border-color: var(--ui-accent); }
.mini-btn-danger {
  color: #fff;
  background: #b33a2e;
  border-color: #b33a2e;
}
.mini-btn-danger:hover { background: #cc4536; color: #fff; }

.btn-add {
  margin: 10px;
  flex: 0 0 auto;
}

/* ---------- center: preview ---------- */
.pane-preview {
  background: #14130f;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 24px;
}
.preview-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-stage {
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  flex: 0 0 auto;
}

/* ---------- right: form ---------- */
.pane-form {
  background: var(--ui-panel);
  border-left: 1px solid var(--ui-border);
}
.spot-form {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-muted);
}
.field input[type=text], .field textarea {
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
  resize: vertical;
}
.field textarea { min-height: 64px; line-height: 1.4; }
.field textarea.tall { min-height: 110px; }
.field-hint { font-size: 11px; color: var(--ui-muted); }

.photo-field { display: flex; align-items: center; gap: 10px; }
.photo-thumb {
  width: 56px; height: 42px;
  border-radius: 6px;
  background: #000 center/cover no-repeat;
  border: 1px solid var(--ui-border);
  flex: 0 0 auto;
}
.photo-thumb.header { width: 72px; height: 42px; }
.photo-controls { display: flex; flex-direction: column; gap: 6px; flex: 1 1 auto; }
.photo-controls input[type=file] { font-size: 11px; color: var(--ui-muted); }
.link-btn {
  background: none;
  border: none;
  color: var(--ui-accent);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

/* ---------- row editors (cle/valeur & lignes) ---------- */
.rows-editor { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; gap: 6px; align-items: center; }
.kv-row input {
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  border-radius: 8px;
  padding: 8px 9px;
  font-size: 12.5px;
  min-width: 0;
}
.kv-row input:focus { outline: none; border-color: var(--ui-accent); }
.kv-row .row-key { flex: 0 0 88px; font-weight: 600; }
.kv-row .row-val { flex: 1 1 auto; }
.kv-row .row-del { flex: 0 0 auto; padding: 6px 8px; }
.btn-row-add {
  align-self: flex-start;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--ui-accent);
  border-style: dashed;
}
.static-note {
  font-size: 13px;
  line-height: 1.5;
  color: var(--ui-muted);
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  padding: 14px;
}

hr.sep { border: none; border-top: 1px solid var(--ui-border); margin: 2px 0; }
.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ui-accent);
  margin-top: 4px;
}

/* ---------- ecran de connexion (cle partagee) ---------- */
.key-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(20, 19, 15, .92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.key-box {
  background: var(--ui-panel);
  border: 1px solid var(--ui-border);
  border-radius: 16px;
  padding: 34px 38px;
  width: min(420px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.key-box h2 { margin: 0; font-size: 19px; }
.key-box p { margin: 0; font-size: 13px; color: var(--ui-muted); line-height: 1.5; }
.key-input {
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 14px;
}
.key-input:focus { outline: none; border-color: var(--ui-accent); }
.key-error { color: #e07a6a; font-size: 12px; min-height: 15px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2d2b27;
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================================================================
   GABARIT DE FICHE — geometrie relevee au point pres sur le PDF source.
   Page source : 810 x 1012.5 pt  ->  canvas 1080 x 1350 px (x1.33333),
   soit exactement 11.25 x 14.0625 pouces a 96 dpi : l'impression tombe
   juste sans mise a l'echelle.
   Toutes les positions ci-dessous sont absolues, comme dans l'original
   (mise en page Canva), afin que chaque fiche soit rigoureusement
   identique quelle que soit la longueur des textes.
================================================================= */
/* Sans ceci, Chrome n'imprime AUCUN aplat ni image de fond tant que
   l'option « Graphiques d'arriere-plan » de la boite de dialogue reste
   decochee (elle l'est par defaut) : la fiche sortirait en texte nu sur
   blanc. La regle force le navigateur a restituer les fonds tels quels. */
.spot-page, .static-page,
.spot-page *, .static-page * {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.spot-page {
  width: 1080px;
  height: 1350px;
  background: var(--card-bg);
  position: relative;
  overflow: hidden;
  font-family: "Open Sans", "Lato", system-ui, sans-serif;
  color: var(--card-text-body);
}

/* Texture papier : juste au-dessus du fond blanc, SOUS tout le contenu.
   (Verifie sur l'original : 0 % de grain sur les blocs taupe/creme,
   4-9 % sur les marges blanches.) */
.sp-texture {
  position: absolute;
  left: -469px; top: -153px;
  width: 1929px; height: 1929px;
  background-image: var(--paper-texture);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  pointer-events: none;
}

/* Photo d'en-tete : pleine largeur, a fond perdu, fondue vers la page. */
.sp-header-photo {
  position: absolute;
  left: 0; top: 0;
  width: 1080px; height: 238px;
  background-color: #9aa3b5;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  -webkit-mask-image: var(--header-fade);
  mask-image: var(--header-fade);
}

.sp-title {
  position: absolute;
  top: 22.9px;
  left: 50%;
  transform: translateX(-50%);
  height: 47.4px;
  max-width: 1004px;
  padding: 0 12px;
  background: var(--card-black);
  color: var(--card-title-text);
  border-radius: 9.6px;
  font-family: "Poppins", system-ui, sans-serif;
  font-weight: 700;
  font-size: 26.4px;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Les 3 photos chevauchent la bande d'en-tete ; celle du centre est
   plus haute et remonte plus haut (comme dans l'original). */
.sp-photo {
  position: absolute;
  border-radius: 15px;
  background: #dedede center/cover no-repeat;
}
.sp-photo-1 { left: 31.3px;  top: 107.9px; width: 325.2px; height: 197.9px; }
.sp-photo-2 { left: 378.8px; top:  86.8px; width: 322.3px; height: 230.8px; }
.sp-photo-3 { left: 723.2px; top: 107.9px; width: 325.3px; height: 197.9px; }

.sp-badges {
  position: absolute;
  left: 55.6px; top: 332.3px;
  width: 966.3px; height: 186.3px;
  background: var(--card-outer-badge);
  border-radius: 10px;
}
.sp-badge {
  position: absolute;
  background: var(--card-inner-badge);
  border-radius: 9px;
}
.sp-badge-1 { left:  12.9px; top:  18.0px; width: 478.4px; height: 68.7px; }
.sp-badge-2 { left: 504.0px; top:  18.0px; width: 445.3px; height: 68.7px; }
.sp-badge-3 { left:  12.9px; top: 104.1px; width: 936.4px; height: 68.7px; }

.sp-badge-ico {
  position: absolute;
  left: 8.3px; top: 10.2px;
  width: 48.7px; height: 48.4px;
  background: var(--card-icon-circle);
  border-radius: 8px;
  color: var(--card-icon-color);
  display: flex; align-items: center; justify-content: center;
}
.sp-badge-ico svg { width: 29.3px; height: 29.3px; }

.sp-badge-txt {
  position: absolute;
  left: 70.4px; right: 14px;
  top: 50%;
  transform: translateY(-50%);
}
.sp-badge-txt strong {
  display: block;
  font-weight: 600;
  font-size: 19.3px;
  line-height: 1.3;
  color: var(--card-label);
}
/* Valeur du badge : tient sur une ligne. Si elle est trop longue,
   fitPage() reduit la taille du texte plutot que de le tronquer. */
.sp-badge-txt span {
  display: block;
  font-weight: 400;
  font-size: 17.6px;
  line-height: 1.3;
  color: var(--card-text-body);
  white-space: nowrap;
  overflow: hidden;
}

.sp-banner {
  position: absolute;
  background: var(--card-taupe);
  color: #fff;
  border-radius: 10px;
  font-family: "League Spartan", system-ui, sans-serif;
  font-weight: 700;
  /* Calibre sur le rendu original (hauteur de capitale 12.96 pt) :
     League Spartan a une capitale de 0.660 em -> 19.64 pt = 26.2 px.
     La taille "16 pt" annoncee par le PDF est exprimee dans une
     matrice de texte mise a l'echelle, elle n'est pas exploitable
     directement. */
  font-size: 26.2px;
  line-height: 1;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.sp-banner-desc { left:  55.6px; top:  535.1px; width: 963.5px; height: 106.7px; }
.sp-colh-1      { left:  55.6px; top: 1007.7px; width: 472.1px; height:  68.8px; }
.sp-colh-2      { left: 547.3px; top: 1008.7px; width: 469.9px; height:  68.8px; }

.sp-box {
  position: absolute;
  background: var(--card-cream);
  border-radius: 9px;
  overflow: hidden;
  color: var(--card-text-body);
}
.sp-box-desc {
  left: 55.6px; top: 673.9px;
  width: 962px; height: 209.7px;
  padding: 30px 18px 14px 14.8px;
  font-size: 21.07px;
  line-height: 1.373;
  /* preserve les retours a la ligne saisis dans l'apercu */
  white-space: pre-line;
}
.sp-colb-1 { left:  56.7px; top: 1092.5px; width: 472.5px; height: 232.1px; padding: 9px 14px 10px 10px; }
.sp-colb-2 { left: 546.1px; top: 1089.5px; width: 475.9px; height: 235.2px; padding: 9px 14px 10px 20px; }
.sp-colb-1 ul, .sp-colb-2 ul {
  margin: 0;
  padding-left: 26px;
  font-size: 17.6px;
  line-height: 1.364;
}
.sp-colb-1 li, .sp-colb-2 li { margin: 0; }
.sp-colb-1 strong, .sp-colb-2 strong,
.sp-colb-1 .kv-sep, .sp-colb-2 .kv-sep { font-weight: 700; }

/* ---------- edition directe dans l'apercu ----------
   Cadre discret au survol pour signaler les blocs modifiables ;
   rien ne doit apparaitre a l'impression. */
.editable { outline: none; cursor: text; border-radius: 4px; }
.editable:hover {
  box-shadow: 0 0 0 2px rgba(217, 138, 95, .45);
}
.editable:focus {
  box-shadow: 0 0 0 2px #d98a5f;
  background: rgba(217, 138, 95, .07);
}
.editable:empty::before {
  content: attr(data-placeholder);
  opacity: .35;
}
@media print {
  .editable, .editable:hover, .editable:focus {
    box-shadow: none !important;
    background: none !important;
  }
}

/* ================================================================
   PAGES STATIQUES (couverture, intro, fin) — images extraites du
   guide original ; la couverture recoit son titre en surimpression.
================================================================= */
.static-page {
  width: 1080px;
  height: 1350px;
  position: relative;
  overflow: hidden;
  /* brun releve sur la couverture d'origine : sert de fond quand
     l'image de couverture est retiree */
  background: #493233;
}
.static-page img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
/* Titre de couverture : zone mesuree sur l'original
   (y 31->133 pt, centre, Leckerli One 37.3 pt blanc). */
.cover-title {
  position: absolute;
  top: 41px;
  left: 50%;
  transform: translateX(-50%);
  width: 640px;   /* reproduit la cesure de l'original ; saut de ligne manuel possible */
  max-height: 200px;
  overflow: hidden;
  text-align: center;
  font-family: "Leckerli One", cursive;
  font-weight: 400;
  font-size: 49.7px;
  line-height: 1.378;
  color: #ffffff;
  white-space: pre-line;
}

/* ---------- zone d'impression (export PDF uniquement) ----------
   Gardee hors ecran plutot qu'en display:none, afin de rester
   mesurable par l'ajustement automatique du texte. */
.print-area {
  position: absolute;
  left: -100000px;
  top: 0;
  width: 1080px;
}

@media print {
  .app-shell { display: none !important; }
  body { background: #fff; margin: 0; }
  .print-area {
    position: static;
    left: auto;
    width: auto;
  }
  .print-page {
    page-break-after: always;
    break-after: page;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .print-page:last-child { page-break-after: auto; break-after: auto; }
  .spot-page { box-shadow: none; }
  /* 810 x 1012.5 pt, exactement le format de la page source */
  @page {
    size: 285.75mm 357.1875mm;
    margin: 0;
  }
}
