* { box-sizing: border-box; }

:root {
  --bg: #eceeec;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6a726e;
  --line: #d7dbd8;
  --primary: #1a1a1a;
  --radius: 12px;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Helvetica Neue', Arial, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* En mode application (écran d'accueil iPhone), il n'y a plus l'interface de Safari :
   on écarte le contenu de l'encoche et de la barre d'accueil. */
.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 16px 64px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(64px, calc(env(safe-area-inset-bottom) + 24px));
}

.topbar h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.2px; }
.topbar .sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; max-width: 640px; }
.topbar-row { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.topbar-row .btn { flex: 0 0 auto; white-space: nowrap; }

/* Two-column layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 26px;
  align-items: start;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .preview { order: -1; }
}

/* Controls */
.controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.field { margin-bottom: 14px; }
.field.grow { flex: 1 1 auto; }
.field.small { flex: 0 1 120px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

.lab {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 5px;
  color: #333;
}
.lab.thin { font-weight: 400; color: #555; }
.opt { font-weight: 400; color: var(--muted); }

.inp {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #cfd3d1;
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
.inp:focus { outline: 2px solid #9aa3a0; outline-offset: 0; border-color: #9aa3a0; }

.price-inp { position: relative; }
.price-inp .eur {
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px; pointer-events: none;
}
.price-inp .inp { padding-right: 26px; }

/* Tabs (design selector) */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab {
  flex: 1 1 auto;
  padding: 11px 12px;
  border: 1px solid #cfd3d1;
  background: #fff;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
  transition: all .12s;
}
.tab:hover { border-color: #9aa3a0; }
.tab.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Buttons */
.btn {
  padding: 11px 16px;
  border: 1px solid #cfd3d1;
  background: #fff;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
}
.btn:hover { border-color: #9aa3a0; }
.btn.ghost { padding: 9px 12px; font-weight: 600; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { opacity: .9; }
.btn.full { width: 100%; margin-bottom: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.size-row { align-items: flex-end; }
.orient { display: flex; gap: 6px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

.hint { font-size: 12.5px; color: var(--muted); margin: 2px 0 12px; }

/* Fiche edit panel */
.panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px;
  margin-bottom: 14px;
  background: #fbfbfa;
}
.panel-title { font-weight: 700; margin-bottom: 10px; }
.bullet-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.bullet-row .field { margin-bottom: 0; }
.bullet-row .bl-label { flex: 0 1 120px; }
.bullet-row .bl-text { flex: 1 1 220px; }

/* Fiche détaillée : grille de specs + offres */
.specs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.specs-grid .sfield label { font-size: 11.5px; color: #666; display: block; margin-bottom: 2px; }
.offer-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.offer-row .row { align-items: flex-end; }
.offer-row .rm { color: #b23a2e; border-color: #e2c4c0; padding: 8px 10px; align-self: flex-end; }

/* Swatches */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; border: 2px solid transparent; flex: 0 0 auto;
  padding: 0;
}
.swatch.selected { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }

/* Preview */
.preview { position: sticky; top: 16px; }
.preview-inner {
  background: #dfe2e0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 240px;
}
#card {
  display: block;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.14);
  max-width: 100%;
}
.fmt { text-align: center; color: var(--muted); font-size: 12.5px; margin: 14px 0 0; }

/* Mémoire : étiquettes enregistrées */
/* Bloc (pas flex) : le panneau ne peut alors jamais dépasser la largeur de l'écran. */
.lib-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 22, 0.5);
  z-index: 50;
  padding: 24px 16px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.lib-overlay[hidden] { display: none; }
.lib-modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  max-width: 940px;
  margin: 0 auto;
  box-shadow: 0 18px 60px rgba(0,0,0,0.28);
}
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lib-head h2 { margin: 0 0 12px; font-size: 19px; }
.lib-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.lib-tools .inp { flex: 1 1 220px; width: auto; }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 12px;
}
.lib-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbfbfa;
  display: flex;
  flex-direction: column;
}
.lib-del {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  width: 26px;
  height: 26px;
  padding: 0;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.94);
  color: #b23a2e;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.lib-del:hover { border-color: #b23a2e; background: #fff; }
.lib-thumb {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 6px;
  cursor: pointer;
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.lib-thumb:hover { border-color: #9aa3a0; }
.lib-thumb img { max-width: 100%; max-height: 100%; display: block; object-fit: contain; }
.lib-noimg { color: var(--muted); font-size: 12px; }
.lib-name {
  font-weight: 700;
  font-size: 13px;
  margin: 8px 0 2px;
  overflow-wrap: anywhere;
}
.lib-sub { color: var(--muted); font-size: 11.5px; margin-bottom: 8px; }
/* Les boutons passent à la ligne plutôt que de déborder d'une carte étroite. */
.lib-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.lib-btns .btn { flex: 1 1 auto; padding: 7px 8px; font-size: 12px; white-space: nowrap; }
.btn.rm { color: #b23a2e; border-color: #e2c4c0; }

/* Téléphone : vignettes plus petites, 2 par ligne, boutons empilés (cibles larges). */
@media (max-width: 520px) {
  .lib-overlay { padding: 12px 10px; }
  .lib-modal { padding: 13px; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 9px; }
  .lib-thumb { height: 118px; }
  .lib-tools .inp { flex: 1 1 100%; }
  .lib-btns .btn { flex: 1 1 100%; padding: 8px 6px; font-size: 11.5px; }
}

/* Print */
.print-only { display: none; }
@media print {
  .app { display: none !important; }
  .print-only { display: block; }
  .print-only img { display: block; width: 100%; height: 100%; }
}
