/* ═══════════════════════════════════════════════════════════════════════════
   Casemira — Visualiseur de tapis
   UI thémable : change les variables ci-dessous pour matcher ta charte exacte.
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  --cm-bg:        #f8f7f5;   /* off-white chaud (fond) */
  --cm-surface:   #ffffff;   /* fond des panneaux      */
  --cm-ink:       #0f1e2e;   /* navy profond (texte)   */
  --cm-muted:     #6f7682;   /* navy-gris secondaire   */
  --cm-line:      #e8e4de;   /* bordures taupe clair   */
  --cm-navy:      #0f1e2e;   /* primaire / CTA         */
  --cm-gold:      #a09584;   /* accent gold-taupe      */
  --cm-accent:    #0f1e2e;   /* actions principales    */
  --cm-accent-ink:#f8f7f5;   /* texte sur navy         */
  --cm-accent-2:  #0f1e2e;   /* (compat) navy          */
  --cm-radius:    16px;
  --cm-shadow:    0 24px 60px -20px rgba(15, 30, 46, .35);
  --cm-font:      "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --cm-serif:     "Instrument Serif", Georgia, "Times New Roman", serif;
}

/* ── Bouton déclencheur sur la fiche produit ───────────────────────────────── */
.cm-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: 100%;                 /* passe en width:auto pour un bouton plus étroit */
  justify-content: center;
  padding: 8px 18px;           /* ← barre fine : ~⅓ de hauteur en moins que le CTA */
  border: 1px solid var(--cm-accent-2);
  border-radius: 4px;          /* coins quasi carrés */
  background: var(--cm-accent-2);
  color: #fff;
  font-family: var(--cm-font);
  font-size: 13px;             /* texte plus discret */
  font-weight: 600;
  letter-spacing: .01em;
  text-transform: none !important;   /* annule la mise en majuscules du thème */
  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease;
}
.cm-trigger:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -12px rgba(15,30,46,.45); }
.cm-trigger:active { transform: translateY(0); }
.cm-trigger svg { width: 16px; height: 16px; }

/* ── Overlay + carte modale ────────────────────────────────────────────────── */
.cm-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(24, 20, 16, .55);
  backdrop-filter: blur(6px);
  font-family: var(--cm-font);
  color: var(--cm-ink);
  animation: cm-fade .2s ease;
}
.cm-modal.is-open { display: flex; }

.cm-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  overflow: hidden auto;
  background: var(--cm-bg);
  border-radius: var(--cm-radius);
  box-shadow: var(--cm-shadow);
  animation: cm-rise .28s cubic-bezier(.2,.8,.2,1);
}

.cm-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.85);
  color: var(--cm-ink);
  cursor: pointer;
  z-index: 5;
  transition: background .15s ease;
}
.cm-close:hover { background: #fff; }

.cm-head {
  padding: 24px 30px 0;
  text-align: center;
}
.cm-brand-badge {
  display: block;
  max-width: 168px;
  width: 100%;
  height: auto;
  margin: 0 auto 14px;
}
.cm-title {
  font-family: var(--cm-font);     /* Instrument Sans, comme la charte Casemira */
  font-size: 27px;
  font-weight: 600;                /* "Visualisez ce tapis" en gras */
  line-height: 1.15;
  letter-spacing: -.01em;
  color: var(--cm-ink);
  margin: 0;
  padding: 0 24px;                 /* pour ne pas passer sous la croix de fermeture */
}
.cm-title em {                     /* "chez vous" en serif italique */
  font-family: var(--cm-serif);
  font-style: italic;
  font-weight: 400;
}
.cm-sub { color: var(--cm-muted); font-size: 13.5px; line-height: 1.45; margin: 9px 0 0; padding: 0 6px; }

.cm-body { padding: 22px 30px 30px; }

/* ── Étapes (on n'affiche qu'une à la fois) ────────────────────────────────── */
.cm-step { display: none; }
.cm-step.is-active { display: block; animation: cm-fade .25s ease; }

/* Aperçu du tapis sélectionné */
.cm-rug-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--cm-surface);
  border: 1px solid var(--cm-line);
  border-radius: 12px;
  margin-bottom: 22px;
}
.cm-rug-chip img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; }
.cm-rug-chip .l { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--cm-gold); font-weight: 600; }
.cm-rug-chip .n { font-weight: 600; font-size: 14px; }

/* Conseils de prise de vue */
.cm-tips {
  display: grid;
  gap: 13px;
  margin-bottom: 24px;
}
.cm-tip {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 14px;
  color: var(--cm-ink);
}
.cm-tip .dot {
  flex: 0 0 26px; height: 26px;
  display: grid; place-items: center;
  background: #ede9e2;
  color: var(--cm-gold);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 600;
}

/* Boutons de sélection de source */
.cm-actions { display: grid; gap: 12px; }
.cm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-transform: none !important;   /* annule la mise en majuscules du thème */
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
  font-family: var(--cm-font);
}
.cm-btn svg { width: 19px; height: 19px; }
.cm-btn--primary { background: var(--cm-accent); color: var(--cm-accent-ink); }
.cm-btn--primary:hover { transform: translateY(-1px); box-shadow: 0 12px 24px -14px var(--cm-accent); }
.cm-btn--ghost { background: var(--cm-surface); color: var(--cm-ink); border-color: var(--cm-line); }
.cm-btn--ghost:hover { border-color: var(--cm-gold); }
.cm-btn--block { width: 100%; }
.cm-btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.cm-desktop-only { display: none; }
.cm-mobile-only  { display: grid; }
body.cm-is-desktop .cm-desktop-only { display: grid; }
body.cm-is-desktop .cm-mobile-only  { display: none; }

/* QR : relais desktop → mobile */
.cm-qr { margin-top: 18px; }
.cm-qr-sep {
  display: flex; align-items: center; gap: 12px;
  color: var(--cm-muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .12em;
  margin-bottom: 16px;
}
.cm-qr-sep::before, .cm-qr-sep::after { content: ""; flex: 1; height: 1px; background: var(--cm-line); }
.cm-qr-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--cm-surface); border: 1px solid var(--cm-line);
  border-radius: 12px; padding: 12px;
}
.cm-qr-img { width: 124px; height: 124px; flex: 0 0 auto; border-radius: 6px; background: #fff; display: block; }
.cm-qr-txt { display: flex; flex-direction: column; gap: 4px; }
.cm-qr-txt strong { font-size: 13.5px; color: var(--cm-ink); }
.cm-qr-txt span { font-size: 12px; color: var(--cm-muted); line-height: 1.45; }

/* Aperçu de la photo + résultat (aspect naturel, centré, sans rognage) */
.cm-preview {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #efe9e0;
  border: 1px solid var(--cm-line);
  margin-bottom: 20px;
  min-height: 180px;
}
.cm-preview img { width: 100%; height: auto; max-height: 64vh; object-fit: cover; display: block; }
.cm-preview img.is-clickable { cursor: zoom-in; }

/* Bouton « agrandir » sur le rendu */
.cm-expand {
  position: absolute; top: 10px; right: 10px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: rgba(15,30,46,.6);
  color: #fff; border: none; border-radius: 8px;
  cursor: pointer; z-index: 3;
  backdrop-filter: blur(2px);
  transition: background .15s ease;
}
.cm-expand:hover { background: rgba(15,30,46,.88); }
.cm-expand svg { width: 18px; height: 18px; }

/* Plein écran (lightbox) */
.cm-lightbox {
  position: fixed; inset: 0; z-index: 10000;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 24px;
  background: rgba(8,14,22,.92);
  backdrop-filter: blur(4px);
  animation: cm-fade .2s ease;
}
.cm-lightbox img { max-width: 94vw; max-height: 80vh; border-radius: 8px; box-shadow: 0 20px 60px -20px rgba(0,0,0,.6); }
.cm-lightbox-close {
  position: absolute; top: 18px; right: 18px;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.12); color: #fff;
  border: none; border-radius: 50%; cursor: pointer;
  transition: background .15s ease;
}
.cm-lightbox-close:hover { background: rgba(255,255,255,.24); }
.cm-lightbox-dl { text-decoration: none; min-width: 200px; }

/* État de chargement */
.cm-loading {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(15,30,46,.55);
  backdrop-filter: blur(3px);
}
.cm-loading .panel { text-align: center; color: #fff; padding: 24px; width: 100%; max-width: 320px; }
.cm-pct {
  font-family: var(--cm-serif);
  font-style: italic;
  font-size: 42px;
  line-height: 1;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}
.cm-loading .msg { font-size: 14px; font-weight: 500; min-height: 20px; opacity: .95; }
.cm-progress {
  height: 5px;
  width: 100%;
  margin: 14px 0 8px;
  background: rgba(255,255,255,.22);
  border-radius: 999px;
  overflow: hidden;
}
.cm-progress-bar {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--cm-gold);
  border-radius: 999px;
  transition: width .3s ease;
}
.cm-loading .hint { font-size: 11.5px; opacity: .7; margin-top: 4px; }

/* Barre de scan animée pendant la génération */
.cm-scan {
  position: absolute; left: 0; right: 0; height: 40%;
  background: linear-gradient(180deg, transparent, rgba(160,149,132,.40), transparent);
  animation: cm-scan 2.2s ease-in-out infinite;
  pointer-events: none;
}

.cm-result-actions { display: grid; gap: 12px; }
.cm-result-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cm-retry-hint { font-size: 12.5px; color: var(--cm-muted); text-align: center; margin: 0 0 2px; line-height: 1.4; }
.cm-error {
  background: #fbeae5; color: #9a3412;
  border: 1px solid #f3c4b4;
  padding: 12px 14px; border-radius: 10px;
  font-size: 13.5px; margin-bottom: 14px;
}
.cm-foot {
  text-align: center; font-size: 12px; color: var(--cm-muted);
  margin-top: 20px;
}
.cm-foot strong { color: var(--cm-ink); }

/* ── Desktop : étape "work" en 2 colonnes (aperçu à gauche | actions à droite) ── */
.cm-card { transition: max-width .35s cubic-bezier(.2,.8,.2,1); }
body.cm-is-desktop .cm-card.cm-wide { max-width: 780px; }
body.cm-is-desktop .cm-card.cm-wide .cm-rug-chip {
  max-width: 480px; margin-left: auto; margin-right: auto;
}
body.cm-is-desktop .cm-card.cm-wide .cm-work-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 28px;
  align-items: center;
}
body.cm-is-desktop .cm-card.cm-wide .cm-preview { margin-bottom: 0; }
body.cm-is-desktop .cm-card.cm-wide .cm-preview img { max-height: 66vh; }
body.cm-is-desktop .cm-card.cm-wide .cm-work-side {
  display: flex; flex-direction: column; gap: 12px;
}
body.cm-is-desktop .cm-card.cm-wide .cm-result-row { grid-template-columns: 1fr; }

@keyframes cm-fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes cm-rise { from { opacity: 0; transform: translateY(16px) scale(.98) } to { opacity: 1; transform: none } }
@keyframes cm-spin { to { transform: rotate(360deg) } }
@keyframes cm-scan { 0% { top: -40% } 100% { top: 100% } }

@media (max-width: 520px) {
  .cm-card { max-height: 94vh; border-radius: 14px; }
  .cm-brand-badge { max-width: 130px; margin-bottom: 10px; }
  .cm-title { font-size: 22px; padding-left: 18px; padding-right: 18px; }
  .cm-sub { font-size: 13px; }
  .cm-body { padding: 16px 20px 24px; }
  .cm-head { padding: 20px 20px 0; }
  .cm-rug-chip { margin-bottom: 16px; padding: 10px; }
  .cm-rug-chip img { width: 46px; height: 46px; }
  .cm-tips { margin-bottom: 18px; gap: 11px; }
  .cm-preview img { max-height: 44vh; }

  /* Étape "work" (photo importée) : en-tête compacté pour voir les boutons sans scroller */
  .cm-card.cm-wide .cm-sub { display: none; }
  .cm-card.cm-wide .cm-brand-badge { max-width: 108px; margin-bottom: 6px; }
  .cm-card.cm-wide .cm-title { font-size: 19px; }
  .cm-card.cm-wide .cm-head { padding-top: 16px; }
  .cm-card.cm-wide .cm-rug-chip { margin-bottom: 12px; }
  .cm-card.cm-wide .cm-preview img { max-height: 40vh; }
}

@media (max-width: 380px) {
  .cm-title { font-size: 20px; }
  .cm-card.cm-wide .cm-title { font-size: 18px; }
  .cm-card.cm-wide .cm-preview img { max-height: 36vh; }
}
