/* GPP Flyer — v5 : couche de confort d'édition (ajoutée par-dessus app.css).
   Objectifs : barre unique en bas, canvas net, inspecteur repliable, filtres compacts. */

/* ---------- 1. Le canvas garde SA taille DOM ; le zoom passe par le viewport ---------- */
.stage-inner {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
}
/* Le zoom est un transform CSS sur le wrapper ; le canvas interne garde sa
   résolution native. Fabric reste à l'échelle 1:1 (jamais setZoom). */
#stage .canvas-container {
  position: relative !important;
  margin: 0 !important;
  box-shadow: 0 2px 6px rgba(10, 22, 40, .10), 0 14px 40px rgba(10, 22, 40, .14);
  background: #fff;
  border-radius: 1px;
  transform-origin: 0 0;
  will-change: transform;
}
/* le wrapper HTML de Fabric ne doit pas imposer de taille */
#c { display: block; }
.canvas-container canvas { display: block; }

/* grille de points plus discrète, façon Canva */
#stage {
  background-color: #eceff4;
  background-image:
    radial-gradient(circle at center, #d6dbe4 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;
}

/* ---------- 2. Barre unique en bas : pages + zoom + alignement ---------- */
.bottom-bar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #e3e8f0;
  border-radius: 13px;
  padding: 5px 7px;
  box-shadow: 0 4px 14px rgba(10, 22, 40, .10), 0 14px 40px rgba(10, 22, 40, .10);
  z-index: 30;
  max-width: calc(100% - 28px);
  overflow-x: auto;
  scrollbar-width: none;
}
.bottom-bar::-webkit-scrollbar { height: 0; }
.bottom-bar .bb-sep {
  width: 1px;
  height: 22px;
  background: #e6ebf2;
  margin: 0 3px;
  flex: 0 0 auto;
}
.bottom-bar .bb-btn {
  border: 0;
  background: transparent;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #33415a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background .12s;
}
.bottom-bar .bb-btn:hover { background: #eef2f8; }
.bottom-bar .bb-btn.active { background: #0A1628; color: #fff; }
.bottom-bar .bb-btn.danger { color: #dc2626; }
.bottom-bar .bb-zoom {
  font-size: 12px;
  font-weight: 700;
  min-width: 44px;
  text-align: center;
  color: #4a5a72;
  cursor: pointer;
  padding: 4px 2px;
  border-radius: 6px;
}
.bottom-bar .bb-zoom:hover { background: #eef2f8; }
.bottom-bar .bb-pages {
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: 240px;
  overflow-x: auto;
  scrollbar-width: none;
}
.bottom-bar .bb-pages::-webkit-scrollbar { height: 0; }
.bottom-bar .bb-page {
  min-width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid #e3e8f0;
  background: #f8fafc;
  font-size: 11.5px;
  font-weight: 700;
  color: #51617a;
  cursor: pointer;
  flex: 0 0 auto;
}
.bottom-bar .bb-page.active {
  background: #0A1628;
  border-color: #0A1628;
  color: #fff;
}

/* ---------- 3. Inspecteur repliable quand rien n'est sélectionné ---------- */
#view-app.insp-collapsed { grid-template-columns: var(--side) 1fr 0; }
#view-app.insp-collapsed .inspector { display: none; }
/* état vide plus utile : carte d'aide */
#insp-empty {
  display: block;
  padding: 14px;
  background: #f7f9fc;
  border: 1px dashed #dbe3ef;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #7b8798;
}
#insp-empty::before {
  content: "—";
  display: block;
  font-size: 20px;
  margin-bottom: 6px;
  color: #c3ccd9;
}

/* ---------- 4. Filtres de catégories : une seule ligne scrollable ---------- */
#cats {
  display: flex !important;
  flex-wrap: nowrap !important;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#cats::-webkit-scrollbar { height: 0; }
#cats .cat {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* ---------- 5. Vignettes de modèles plus lisibles ---------- */
/* l'image garde le ratio du modèle, pas de crop 3/4 forcé */
#tpl-grid .tpl img {
  width: 100%;
  height: auto;
  aspect-ratio: auto;
  object-fit: contain;
  display: block;
  background: #fff;
  padding: 4px;
}
#tpl-grid .tpl {
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  overflow: hidden;
}
#tpl-grid .tpl span {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.3;
  max-height: 2.6em;
  overflow: hidden;
}
#tpl-grid .tpl:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(10, 22, 40, .14);
}

/* ---------- 6. Barre supérieure : titre projet bien centré ---------- */
#btn-lang { order: -1; }
.topbar .tb-doc { gap: 8px; align-items: center; }
.doc-title {
  line-height: 1.2;
  padding: 7px 12px;
  height: auto;
  align-self: center;
}
.topbar { align-items: center; }
.topbar > * { display: flex; align-items: center; }
.topbar .tb-right { display: flex; align-items: center; gap: 6px; }

/* ---------- 7. Curseurs de zoom (Ctrl+molette) ---------- */
#stage { cursor: default; }
#stage.panning { cursor: grabbing; }

@media (max-width: 1200px) {
  .bottom-bar .bb-pages { max-width: 140px; }
}

/* ---------- 7bis. Mobile : une seule colonne, inspector replié inclus ---------- */
@media (max-width: 820px) {
  #view-app.active,
  #view-app.insp-collapsed {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: var(--topbar) minmax(0, 1fr) !important;
    overflow: hidden;
  }
  #view-app .topbar {
    grid-column: 1 !important; grid-row: 1 !important;
    min-width: 0; padding: 0 8px; gap: 8px;
  }
  #view-app .stage  { grid-column: 1 !important; grid-row: 2 !important; min-width: 0; width: 100%; overflow: hidden; }
  #view-app .stage-inner { width: 100%; min-width: 0; max-width: 100%; }
  #view-app .sidebar, #view-app .inspector { grid-column: auto !important; grid-row: auto !important; }
  #view-app .inspector { display: none !important; }

  /* la barre du haut doit tenir : on ne garde que l'essentiel */
  .tb-actions { gap: 4px; min-width: 0; flex-shrink: 0; }
  #btn-save, #btn-export, #btn-order { display: none !important; }
  .tb-title, .tb-doc { display: none !important; }
  .doc-title { width: auto; min-width: 0; flex: 1; }
  .avatar { width: 30px; height: 30px; font-size: 12px; margin-left: 0; flex-shrink: 0; }
  body, html { overflow-x: hidden; max-width: 100vw; }
}

/* très petits écrans : on garde uniquement menu + titre + avatar */
@media (max-width: 420px) {
  #btn-lang, #btn-undo, #btn-redo { display: none !important; }
  .doc-title { font-size: 12px; }
}

/* ---------- 8. Drag & drop depuis les panneaux ---------- */
.el[draggable], .asset[draggable], .tpl[draggable] { cursor: grab; }
.el.dragging, .asset.dragging, .tpl.dragging { opacity: .45; cursor: grabbing; }
#stage.drop-active {
  background-color: #e3e9f2;
  box-shadow: inset 0 0 0 3px #F59E0B;
}
.drop-indicator {
  position: absolute;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: rgba(245, 158, 11, .9);
  box-shadow: 0 0 0 6px rgba(245, 158, 11, .22);
  pointer-events: none;
  z-index: 25;
  display: none;
}

/* ---------- 9. Barre d'outils flottante sur l'objet ---------- */
.float-bar {
  position: absolute;
  display: none;
  align-items: center;
  gap: 2px;
  background: #0A1628;
  border-radius: 9px;
  padding: 4px;
  box-shadow: 0 6px 22px rgba(10, 22, 40, .28);
  z-index: 40;
  pointer-events: auto;
}
.float-bar::after {
  content: "";
  position: absolute;
  bottom: -5px; left: 50%;
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #0A1628;
}
.float-bar .fb-btn {
  border: 0;
  background: transparent;
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #dbe4f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .12s;
}
.float-bar .fb-btn:hover { background: rgba(255, 255, 255, .14); }
.float-bar .fb-btn.danger:hover { background: #dc2626; color: #fff; }
