/* Composeur planche d'étiquettes A4 — version unifiée (filtre, groupes, mobile) */

.composer-wrap { display: flex; flex-direction: column; gap: 12px; }

.composer__header {
  display: flex; align-items: center; justify-content: space-between;
}
.composer__header h1 { margin: 0; }
.composer__pane-toggle { display: none; }
.composer__hint {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--text-secondary, var(--op-gray-soft, #999));
}

.composer__toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.composer__toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.composer__counter {
  background: var(--bg-secondary, var(--op-bg-alt, #f0f0f0));
  color: var(--text-main, var(--op-gray, #333));
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  border: 1px solid var(--border-color, var(--op-gray-line, #ddd));
}

/* ── Layout grille palette + planche ──────────────────────────────── */
.composer {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  align-items: start;
}

.composer__palette {
  background: var(--bg-secondary, var(--op-bg, #fff));
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color, var(--op-gray-line, rgba(0,0,0,.08)));
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.composer__palette-search { flex: 0 0 auto; }
.composer__palette-search .op-input {
  width: 100%;
  background: var(--bg-main, var(--op-bg-alt, #f9f9f9));
  color: var(--text-main, var(--op-gray, #333));
  border: 1px solid var(--border-color, var(--op-gray-line, rgba(0,0,0,.1)));
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.composer__palette-search .op-input:focus {
  border-color: var(--accent-orange, #F26B36);
}

.composer__palette-list {
  overflow-y: auto;
  flex: 1 1 auto;
  padding-right: 4px;
}

/* Groupes pliables */
.palette-group { margin-bottom: 12px; }
.palette-group__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-header-table, var(--op-bg-alt, #ececec));
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-main, var(--op-gray, #333));
  border: 1px solid transparent;
  transition: border-color 120ms;
}
.palette-group__header:hover { border-color: var(--accent-orange, #F26B36); }
.palette-group__chevron {
  display: inline-block;
  transition: transform 200ms;
  font-size: 11px;
}
.palette-group.is-collapsed .palette-group__chevron { transform: rotate(-90deg); }
.palette-group__label { flex: 1; }
.palette-group__count {
  background: var(--accent-orange, #F26B36);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}
.palette-group__items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0 0 0;
  transition: max-height 200ms ease, opacity 200ms;
  max-height: 600px;
  overflow: hidden;
}
.palette-group.is-collapsed .palette-group__items {
  max-height: 0;
  padding: 0;
  opacity: 0;
}

.palette-item {
  background: var(--bg-main, var(--op-bg-alt, #f4f4f4));
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: grab;
  user-select: none;
  transition: border-color 120ms, background 120ms, transform 120ms;
  color: var(--text-main, var(--op-gray, #333));
}
.palette-item:hover { border-color: var(--accent-orange, #F26B36); }
.palette-item:active { cursor: grabbing; transform: scale(0.98); }
.palette-item.is-dragging { opacity: 0.5; }
.palette-item--ghost { background: var(--accent-orange, #F26B36); color: #fff; opacity: 0.85; }
.palette-item--chosen { border-color: var(--accent-orange, #F26B36); }
.palette-item__name { font-weight: 600; font-size: 13px; line-height: 1.3; word-break: break-word; }
.palette-item__code {
  font-size: 11px;
  color: var(--accent-primary, var(--op-gray-soft, #888));
  font-family: ui-monospace, monospace;
  margin-top: 2px;
}
.palette-item--no-bc {
  border-color: var(--border-color, rgba(255,255,255,.1));
  cursor: not-allowed;
  opacity: 0.55;
}

/* ── Planche A4 ───────────────────────────────────────────────────── */
.composer__sheet {
  background: #fff;
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border-color, rgba(0,0,0,.1));
  overflow-x: auto;
  color: #1a1a1a;
}

.sheet {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: #fff;
  border: 1px dashed #ccc;
  padding: 8mm 6mm;
  display: grid;
  gap: 0;
}
.sheet--avery-l7165 {
  grid-template-columns: repeat(2, 99.1mm);
  grid-template-rows: repeat(4, 67.7mm);
  justify-content: center;
}
.sheet--avery-24 {
  grid-template-columns: repeat(3, 70mm);
  grid-template-rows: repeat(8, 36mm);
}
.sheet--avery-65 {
  grid-template-columns: repeat(5, 38mm);
  grid-template-rows: repeat(13, 21mm);
}

.sheet-cell {
  border: 1px dashed #d0d0d0;
  padding: 2mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 9pt;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: background 120ms;
  color: #1a1a1a;
}
.sheet-cell:hover { background: rgba(242, 107, 54, 0.1); }
.sheet-cell.is-drop-target {
  background: rgba(242, 107, 54, 0.18);
  outline: 2px solid #F26B36;
}
.sheet-cell.is-empty .sheet-cell__hint {
  color: #ccc;
  font-size: 14pt;
  font-weight: 700;
}
.sheet-cell.is-empty:hover .sheet-cell__hint { color: #F26B36; }
.sheet-cell svg, .sheet-cell img {
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

/* Cellule QR-only (CODE128 abandonné) */
.sheet-cell--qr-only {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1mm;
  position: relative;
}
.sheet-cell__qr-full {
  width: 70%;
  max-width: 28mm;
  max-height: 28mm;
  object-fit: contain;
}
.sheet-cell--qr-only .cell-label { font-size: 7pt; line-height: 1.1; max-width: 100%; }
.sheet-cell--qr-only .cell-code  { font-size: 6pt; font-family: ui-monospace, monospace; color: #555; }
.sheet--avery-65 .sheet-cell__qr-full { max-width: 14mm; max-height: 14mm; }
.sheet--avery-l7165 .sheet-cell__qr-full { max-width: 50mm; max-height: 50mm; }

/* Cellule legacy avec QR à côté du code-barre (conservé pour rétrocompat) */
.sheet-cell--with-qr {
  flex-direction: row;
  gap: 1.5mm;
  align-items: center;
  justify-content: center;
}
.sheet-cell--with-qr .sheet-cell__bc {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}
/* L'<img> QR porte la classe .sheet-cell__qr (cf composer.js). On la
   dimensionne en mm pour qu'elle tienne dans la cellule (sinon elle s'affiche
   à la taille native ~240px et déborde / chevauche les voisines). */
.sheet-cell--with-qr .sheet-cell__qr,
.sheet-cell--with-qr .sheet-cell__qr-img {
  flex: 0 0 auto;
  width: 14mm;
  height: 14mm;
  max-width: 14mm;
  max-height: 14mm;
  object-fit: contain;
}
.sheet-cell--with-qr .sheet-cell__bc-img {
  max-width: 100%;
  max-height: 14mm;
}
.sheet-cell--with-qr .cell-label {
  position: absolute;
  bottom: 1mm;
  left: 0;
  right: 0;
  font-size: 6pt;
}

/* Cellule barcode-only (Nouveau défaut) */
.sheet-cell--barcode-only {
  flex-direction: column;
  gap: 1.5mm;
  padding: 4mm 2mm;
}
.sheet-cell__barcode-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin-bottom: 1mm;
}
.sheet-cell__barcode {
  width: 100%;
  max-width: 80mm;
  height: auto;
}
.sheet--avery-65 .sheet-cell__barcode { max-width: 32mm; }
.sheet--avery-24 .sheet-cell__barcode { max-width: 62mm; }

.sheet-cell--barcode-only .cell-content {
  display: flex;
  flex-direction: column;
  gap: 0.5mm;
}

/* Avery 65 (étiquettes minuscules) : QR plus petit */
.sheet--avery-65 .sheet-cell--with-qr .sheet-cell__qr,
.sheet--avery-65 .sheet-cell--with-qr .sheet-cell__qr-img { width: 8mm; height: 8mm; max-width: 8mm; max-height: 8mm; }
.sheet--avery-65 .sheet-cell--with-qr .sheet-cell__bc-img { max-height: 9mm; }
/* Avery L7165 (grandes étiquettes) : QR un peu plus grand */
.sheet--avery-l7165 .sheet-cell--with-qr .sheet-cell__qr,
.sheet--avery-l7165 .sheet-cell--with-qr .sheet-cell__qr-img { width: 24mm; height: 24mm; max-width: 24mm; max-height: 24mm; }

/* Toggle QR */
.composer__qr-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-secondary, var(--op-bg-alt, #f0f0f0));
  border: 1px solid var(--border-color, var(--op-gray-line, #ddd));
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main, var(--op-gray, #333));
  user-select: none;
}
.composer__qr-toggle input { margin: 0; cursor: pointer; }
.composer__qr-toggle:hover { border-color: #F26B36; }
.sheet-cell .cell-label {
  font-size: 7pt;
  margin-top: 1mm;
  font-weight: 600;
  word-break: break-word;
  line-height: 1.1;
  max-width: 100%;
}
.sheet-cell__remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #c0392b;
  color: #fff;
  font-size: 12px;
  border: none;
  display: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.sheet-cell:hover .sheet-cell__remove { display: flex; }

/* ── Mobile ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .composer { grid-template-columns: 1fr; }
  .composer__pane-toggle { display: inline-flex; }
  .composer__palette {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    z-index: 50;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
    border: none;
    box-shadow: 0 -8px 24px rgba(0,0,0,.3);
    transform: translateY(0);
    transition: transform 240ms cubic-bezier(.32,.72,.16,1);
  }
  .composer__palette.is-closed {
    transform: translateY(100%);
  }
  .composer__sheet {
    padding-bottom: 60vh;
  }
  .sheet {
    transform: scale(0.55);
    transform-origin: top left;
    margin-bottom: -45vh; /* compense le scale visuel */
  }
  .composer__toolbar-row { gap: 6px; }
  .composer__toolbar-row .op-btn { padding: 8px 12px; font-size: 13px; }
}

/* ── Print ────────────────────────────────────────────────────────── */
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .composer__header,
  .composer__hint,
  .composer__toolbar,
  .composer__palette,
  .composer__pane-toggle,
  .composer__counter,
  .bottom-nav,
  .tab-bar,
  header,
  .op-header,
  .op-sidebar,
  .op-bottom-nav,
  .op-fab,
  .cb-fab,
  .op-footer,
  #cb-toast-host {
    display: none !important;
  }
  .container { padding: 0 !important; max-width: none !important; }
  .composer { display: block; grid-template-columns: 1fr; }
  .composer__sheet {
    box-shadow: none;
    padding: 0;
    border-radius: 0;
    border: none;
    background: #fff;
  }
  .sheet { border: none; margin: 0; transform: none; }
  .sheet-cell { border: none; }
  .sheet-cell.is-empty .sheet-cell__hint { display: none; }
  .sheet-cell__remove { display: none !important; }
}
