/* xmchat — widget. Couleurs injectées par variables CSS sur #xmchat-root. */
.xmchat {
  --xmchat-primary: #1f4e79;
  --xmchat-on-primary: #fff;
  --xmchat-x: 20px;
  --xmchat-y: 20px;
  --xmchat-bg: #fff;
  --xmchat-fg: #1b1b1b;
  --xmchat-muted: #595959;
  --xmchat-bubble: #f1f3f5;
  --xmchat-border: #d0d5db;
  /* Bulles : couleurs réglables dans Apparence (injectées par le widget). */
  --xmchat-bot-bg: var(--xmchat-bubble);
  --xmchat-bot-fg: var(--xmchat-fg);
  --xmchat-user-bg: var(--xmchat-primary);
  --xmchat-user-fg: var(--xmchat-on-primary);
  /* Tailles : ajustables depuis le « CSS personnalisé » du module. */
  --xmchat-font-size: 15px;
  --xmchat-title-size: 15px;
  --xmchat-btn-size: 32px;
  --xmchat-icon-size: 18px;
  --xmchat-footer-size: 11px;
  position: fixed;
  bottom: var(--xmchat-y);
  z-index: 2147483000;
  font: var(--xmchat-font-size)/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--xmchat-fg);
}
.xmchat--right { right: var(--xmchat-x); }
.xmchat--left { left: var(--xmchat-x); }
.xmchat *, .xmchat *::before, .xmchat *::after { box-sizing: border-box; }

.xmchat__sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.xmchat__launcher {
  display: grid; place-items: center;
  width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--xmchat-primary); color: var(--xmchat-on-primary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}
.xmchat--left .xmchat__launcher { margin-right: auto; }
.xmchat--right .xmchat__launcher { margin-left: auto; }
.xmchat__launcher:hover { transform: scale(1.05); }
.xmchat__launcher--avatar { padding: 0; overflow: hidden; background: var(--xmchat-bg); border: 3px solid var(--xmchat-primary); }
.xmchat button:focus-visible, .xmchat a:focus-visible, .xmchat textarea:focus-visible, .xmchat__log:focus-visible {
  outline: 3px solid var(--xmchat-primary); outline-offset: 2px;
}
.xmchat__launcher:focus-visible { outline-color: var(--xmchat-fg); }

.xmchat__panel {
  display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 2 * var(--xmchat-x)));
  height: min(600px, calc(100vh - var(--xmchat-y) - 100px));
  margin-bottom: 12px;
  background: var(--xmchat-bg);
  border: 1px solid var(--xmchat-border); border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
  overflow: hidden;
}
.xmchat__panel[hidden] { display: none; }

.xmchat__header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 8px 8px 14px;
  background: var(--xmchat-primary); color: var(--xmchat-on-primary);
}
.xmchat__identity { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; }
.xmchat__avatar { display: block; flex: none; border-radius: 50%; object-fit: cover; background: var(--xmchat-bg); }
.xmchat__avatar--header { width: 30px; height: 30px; }
.xmchat__avatar--launcher { width: 100%; height: 100%; }
.xmchat__avatar--msg { position: absolute; left: -36px; bottom: 0; width: 28px; height: 28px; border: 1px solid var(--xmchat-border); }
.xmchat__msg--avatar { position: relative; margin-left: 36px; max-width: calc(88% - 36px); }
/* Sélecteur renforcé : les thèmes stylent souvent les h2 (taille, police, majuscules). */
.xmchat .xmchat__title {
  margin: 0; padding: 0; font-family: inherit; font-size: var(--xmchat-title-size); font-weight: 600; line-height: 1.25;
  letter-spacing: normal; text-transform: none; color: inherit;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.xmchat__actions { display: flex; gap: 4px; }
.xmchat__icon-btn {
  display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px;
  background: transparent; color: inherit; cursor: pointer;
}
.xmchat__icon-btn:hover { background: rgba(255, 255, 255, .15); }
.xmchat__icon-btn:focus-visible { outline-color: var(--xmchat-on-primary); outline-offset: -3px; }

.xmchat__log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.xmchat__msg { max-width: 88%; padding: 12px 14px; border-radius: 12px; word-wrap: break-word; }
.xmchat__msg--assistant { align-self: flex-start; background: var(--xmchat-bot-bg); color: var(--xmchat-bot-fg); border-bottom-left-radius: 4px; }
.xmchat__msg--user {
  align-self: flex-end; background: var(--xmchat-user-bg); color: var(--xmchat-user-fg);
  border-bottom-right-radius: 4px; white-space: pre-wrap;
}
.xmchat__day {
  display: flex; align-items: center; gap: 10px; margin: 4px 0 0;
  font-size: 12px; font-weight: 600; color: var(--xmchat-muted); text-align: center;
}
.xmchat__day::before, .xmchat__day::after { content: ""; flex: 1; height: 1px; background: var(--xmchat-border); }
.xmchat__time { margin-top: -10px; font-size: 11px; color: var(--xmchat-muted); }
.xmchat__time--user { align-self: flex-end; }
.xmchat__time--assistant { align-self: flex-start; }
.xmchat__time--avatar { margin-left: 36px; }
.xmchat__body { line-height: 1.55; }
.xmchat__body p { margin: 0 0 .75em; }
.xmchat__body > :last-child { margin-bottom: 0; }
.xmchat__body ul { margin: .25em 0 .85em; padding-left: 1.15em; list-style: disc; }
.xmchat__body li { margin: 0 0 .4em; padding-left: .15em; }
.xmchat__body li::marker { color: var(--xmchat-primary); }
.xmchat__facts {
  display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px;
  margin: .2em 0 .85em; padding: 10px 12px;
  background: #fff; color: var(--xmchat-fg); border: 1px solid var(--xmchat-border); border-left: 3px solid var(--xmchat-primary); border-radius: 8px;
}
.xmchat__facts dt { margin: 0; font-weight: 600; color: var(--xmchat-muted); }
.xmchat__facts dd { margin: 0; min-width: 0; overflow-wrap: break-word; }
.xmchat__facts--stacked { grid-template-columns: 1fr; gap: 0; }
.xmchat__facts--stacked dt { color: var(--xmchat-fg); }
.xmchat__facts--stacked dd { margin-bottom: 8px; }
.xmchat__facts--stacked dd:last-child { margin-bottom: 0; }
@media (max-width: 340px) {
  .xmchat__facts { grid-template-columns: 1fr; gap: 0; }
  .xmchat__facts dd { margin-bottom: 6px; }
}
.xmchat__body strong { font-weight: 650; }
.xmchat__body a { color: var(--xmchat-primary); text-decoration: underline; text-underline-offset: 2px; font-weight: 500; overflow-wrap: anywhere; }

.xmchat__rating { display: flex; gap: 4px; margin-top: 6px; }
.xmchat__rate {
  min-width: 32px; min-height: 28px; padding: 0 6px; border: 1px solid transparent; border-radius: 6px;
  background: transparent; cursor: pointer; font-size: 14px; opacity: .65;
}
.xmchat__rate:hover, .xmchat__rate[aria-pressed="true"] { opacity: 1; border-color: var(--xmchat-border); background: #fff; }

.xmchat__cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; align-self: stretch; }
.xmchat__card {
  display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; align-items: center;
  padding: 8px; border: 1px solid var(--xmchat-border); border-radius: 12px; background: #fff;
}
.xmchat__card-media { display: block; width: 96px; height: 96px; border-radius: 8px; overflow: hidden; background: var(--xmchat-bubble); }
.xmchat__card-media img { display: block; width: 100%; height: 100%; object-fit: cover; }
.xmchat__card-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.xmchat__card-title { font-weight: 600; color: var(--xmchat-fg); text-decoration: none; overflow-wrap: anywhere; }
a.xmchat__card-title:hover { text-decoration: underline; }
.xmchat__card-variant { font-size: 13px; color: var(--xmchat-muted); }
.xmchat__card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 2px; }
.xmchat__stock { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--xmchat-bubble); }
.xmchat__stock--in_stock { background: #e3f4e6; color: #1d5b2a; }
.xmchat__stock--on_order { background: #fff3d6; color: #6b4a00; }
.xmchat__stock--low { background: #fff3d6; color: #6b4a00; }
.xmchat__card-note { margin-top: 4px; font-size: 13px; font-weight: 600; color: #8a1f1f; }
.xmchat__stock--out_of_stock { background: #f8e1e1; color: #8a1f1f; }
.xmchat__card .xmchat__cart-btn { grid-column: 1 / -1; }
.xmchat__card-slot { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--xmchat-primary); }
.xmchat__add-all {
  align-self: stretch; min-height: 44px; padding: 10px 14px; border: 0; border-radius: 10px;
  background: var(--xmchat-primary); color: var(--xmchat-on-primary); font: inherit; font-weight: 700; cursor: pointer;
}
.xmchat__add-all:disabled { opacity: .7; cursor: default; }

/* Bouton « Choisir mes coloris » sur la fiche patron (hors widget) */
.xmchat-pattern { margin: 12px 0; }
.xmchat-pattern__hint { margin: 6px 0 0; font-size: 13px; opacity: .8; }
.xmchat__cart-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  padding: 10px 12px; border: 1px solid var(--xmchat-primary); border-radius: 10px;
  background: #fff; color: var(--xmchat-fg); font: inherit; text-align: left; cursor: pointer;
}
.xmchat__cart-btn:hover { background: var(--xmchat-bubble); }
.xmchat__cart-action { font-weight: 700; color: var(--xmchat-primary); }
.xmchat__cart-label { font-size: 13px; color: var(--xmchat-muted); }
.xmchat__cart-btn--done { border-color: var(--xmchat-border); cursor: default; }
.xmchat__cart-btn:disabled { cursor: default; }

.xmchat__confirm {
  align-self: stretch; padding: 12px 14px; border: 1px solid var(--xmchat-border);
  border-left: 3px solid var(--xmchat-primary); border-radius: 10px; background: #fff;
}
.xmchat__confirm-label { margin: 0 0 10px; font-weight: 600; }
.xmchat__confirm-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.xmchat__confirm button {
  min-height: 40px; padding: 0 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
.xmchat__confirm-yes { border: 0; background: var(--xmchat-primary); color: var(--xmchat-on-primary); }
.xmchat__confirm-no { border: 1px solid #8a9199; background: #fff; color: var(--xmchat-fg); }
.xmchat__confirm button:disabled { opacity: .55; cursor: progress; }

.xmchat__suggestions { display: flex; flex-wrap: wrap; gap: 6px; align-self: stretch; margin-top: -4px; }
.xmchat__msg--avatar ~ .xmchat__suggestions { padding-left: 36px; }
.xmchat__suggestion {
  min-height: 34px; padding: 6px 14px; border: 1px solid var(--xmchat-primary); border-radius: 999px;
  background: #fff; color: var(--xmchat-primary); font: inherit; font-size: 14px; font-weight: 600; line-height: 1.2;
  text-align: left; cursor: pointer;
}
.xmchat__suggestion:hover { background: var(--xmchat-primary); color: var(--xmchat-on-primary); }
.xmchat__typing { display: flex; gap: 4px; padding: 14px; }
.xmchat__typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--xmchat-muted);
  animation: xmchat-dot 1.2s infinite ease-in-out;
}
.xmchat__typing span:nth-child(2) { animation-delay: .15s; }
.xmchat__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes xmchat-dot { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.xmchat__status { margin: 0; min-height: 0; padding: 0 16px; font-size: 13px; color: var(--xmchat-muted); }

.xmchat__form { display: flex; align-items: flex-end; gap: 12px; padding: 12px 12px 10px; border-top: 1px solid var(--xmchat-border); }
.xmchat__input {
  flex: 1; min-width: 0; resize: none; min-height: 38px; max-height: 160px; margin: 0; padding: 8px 10px;
  border: 1px solid #8a9199; border-radius: 10px; font: inherit; color: var(--xmchat-fg); background: #fff;
}
/* Boutons compacts (32 px, au-dessus du minimum WCAG de 24 px), alignés sur le bas du champ. */
/* Contour de focus resserré sur le champ : il ne doit pas toucher les boutons voisins. */
.xmchat .xmchat__input:focus-visible { outline-width: 2px; outline-offset: 1px; }
.xmchat__attach, .xmchat__send {
  display: grid; place-items: center; flex: none; width: var(--xmchat-btn-size); height: var(--xmchat-btn-size); margin: 0 0 3px; padding: 0;
  border: 0; border-radius: 8px; cursor: pointer;
}
.xmchat__attach svg, .xmchat__send svg { width: var(--xmchat-icon-size); height: var(--xmchat-icon-size); }
.xmchat__attach { background: transparent; color: var(--xmchat-muted); }
.xmchat__attach:hover { background: var(--xmchat-bubble); color: var(--xmchat-fg); }
.xmchat__attach:disabled { opacity: .5; cursor: progress; }
.xmchat__send { background: var(--xmchat-primary); color: var(--xmchat-on-primary); }
.xmchat__send:disabled { opacity: .5; cursor: progress; }

.xmchat__footer { padding: 0 12px 8px; font-size: var(--xmchat-footer-size); line-height: 1.35; color: var(--xmchat-muted); }
.xmchat__privacy { margin: 0 0 2px; }
.xmchat__contact { color: var(--xmchat-fg); text-decoration: underline; font-weight: 500; }

@media (max-width: 480px) {
  .xmchat--open { left: 0; right: 0; bottom: 0; }
  .xmchat--open .xmchat__panel {
    width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; border: 0;
  }
  .xmchat--open .xmchat__launcher { display: none; }
  .xmchat__input { font-size: 16px; } /* évite le zoom iOS */
}

@media (prefers-reduced-motion: reduce) {
  .xmchat__launcher, .xmchat__typing span { transition: none; animation: none; }
}

@media print { .xmchat { display: none; } }
