/* ==========================================================================
   Chat de boutique — widget, page par lien, onglet « Messages » (préfixe ch-)
   --------------------------------------------------------------------------
   Spec : output/monniz-business-refonte/CHAT-BOUTIQUES.md §4, §12.
   Jetons de shop.css (--accent, --on-accent, --accent-text, --ink, --muted,
   --line, --ground, --paper, --r-*). Flat : aucune ombre, aucun dégradé.
   Le fil : messages du client à droite en couleur accent, messages de la
   boutique à gauche en neutre, messages système centrés en gris.
   z-index : bouton 33 (sous la barre panier 35, l'en-tête 40, les modales 55+),
   panneau bureau 34, panneau mobile plein écran 60.
   ========================================================================== */

/* ── Bouton flottant ───────────────────────────────────────────────────── */
.ch-launcher {
    position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 33;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    width: 48px; height: 48px; padding: 0;
    border: 1px solid var(--line-strong, #d4d4d4); border-radius: var(--r-pill, 999px);
    background: var(--paper, #fff); color: var(--ink, #171717);
    font: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
    transition: border-color 150ms ease-out, background-color 150ms ease-out;
}
.ch-launcher:hover { border-color: var(--ink, #171717); }
.ch-launcher:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: 2px; }
.ch-launcher i { font-size: 18px; }
.ch-launcher-text { display: none; }
.ch-launcher[hidden], .ch-launcher.is-open { display: none; }
/* Pastille « réponse non lue » : couleur du marchand. */
.ch-dot { position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; border: 2px solid var(--paper, #fff); border-radius: 50%; background: var(--accent, #000); }
.ch-dot[hidden] { display: none; }
@media (min-width: 768px) {
    .ch-launcher { right: 24px; bottom: 24px; width: auto; height: 48px; padding: 0 20px 0 18px; }
    .ch-launcher-text { display: inline; }
    .ch-dot { top: -2px; right: -2px; }
    body.has-cartbar .ch-launcher { bottom: calc(88px + 16px); }
}
/* Mobile : jamais par-dessus une barre d'achat, une feuille ou le clavier ;
   il revient au-dessus de la barre seulement pour une réponse non lue. */
@media (max-width: 767px) {
    body.pd-has-bar .ch-launcher:not(.has-unread),
    body.has-cartbar .ch-launcher:not(.has-unread),
    .ch-launcher.is-suppressed { display: none; }
    body.pd-has-bar .ch-launcher.has-unread { bottom: calc(76px + 12px + env(safe-area-inset-bottom)); }
    body.has-cartbar .ch-launcher.has-unread { bottom: calc(88px + 12px + env(safe-area-inset-bottom)); }
}

/* ── Panneau ───────────────────────────────────────────────────────────── */
.ch-panel {
    position: fixed; inset: 0; z-index: 60;
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;
    background: var(--paper, #fff); color: var(--ink, #171717);
    font-size: 15px; line-height: 1.5;
}
.ch-panel[hidden] { display: none; }
@media (min-width: 768px) {
    .ch-panel {
        inset: auto 24px 24px auto; z-index: 34;
        width: 380px; height: min(640px, calc(100vh - 120px));
        border: 1px solid var(--line-strong, #d4d4d4); border-radius: var(--r-modal, 16px);
        overflow: hidden;
    }
    body.has-cartbar .ch-panel { bottom: calc(88px + 16px); height: min(640px, calc(100vh - 120px - 88px)); }
}
@media (prefers-reduced-motion: no-preference) {
    .ch-panel.is-entering { animation: ch-in 160ms ease-out; }
    @keyframes ch-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

/* En-tête : fermer (à gauche sur mobile), logo + nom, ligne d'état. */
.ch-head { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 4px; border-bottom: 1px solid var(--line, #e3e3e3); padding-top: max(8px, env(safe-area-inset-top)); }
.ch-close { order: -1; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: var(--r-control, 10px); background: none; color: var(--ink, #171717); font-size: 18px; cursor: pointer; }
.ch-close:hover { background: var(--ground, #f7f7f7); }
.ch-close:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: -2px; }
@media (min-width: 768px) {
    .ch-head { padding: 12px 8px 12px 16px; }
    .ch-close { order: 2; margin-left: auto; font-size: 16px; }
}
.ch-logo { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line, #e3e3e3); object-fit: cover; background: var(--paper, #fff); }
.ch-initial { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; background: var(--ground, #f7f7f7); border: 1px solid var(--line, #e3e3e3); font-size: 15px; font-weight: 500; }
.ch-who { flex: 1 1 auto; min-width: 0; }
.ch-title { margin: 0; font-size: 15px; font-weight: 500; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-status { margin: 1px 0 0; color: var(--muted, #626262); font-size: 13px; line-height: 1.4; }
.ch-status b { font-weight: 500; color: var(--ink, #171717); }
.ch-status .ch-online { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--success, #187655); vertical-align: 1px; }
.ch-wa { display: inline-flex; align-items: center; gap: 6px; margin-top: 2px; color: var(--ink, #171717); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.ch-wa i { font-size: 14px; }

/* Corps défilant. */
.ch-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px; -webkit-overflow-scrolling: touch; }
.ch-body:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: -2px; }

/* Accueil et absence : style système, hors du fil. */
.ch-intro { margin: 0 0 16px; padding: 14px 16px; border-radius: var(--r-card, 12px); background: var(--ground, #f7f7f7); color: var(--ink, #171717); font-size: 14px; line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; }
.ch-intro + .ch-intro { margin-top: -8px; }
.ch-intro.is-away { color: var(--ink-2, #3d3d3d); }

/* Questions d'amorce (un appui envoie le texte). */
.ch-starters { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin: 0 0 16px; }
.ch-starter { min-height: 40px; padding: 8px 14px; border: 1px solid var(--line-strong, #d4d4d4); border-radius: var(--r-pill, 999px); background: var(--paper, #fff); color: var(--ink, #171717); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
.ch-starter:hover { border-color: var(--ink, #171717); }
.ch-starter:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: 2px; }

/* Fil des messages. */
.ch-log { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.ch-day { align-self: center; margin: 12px 0 8px; color: var(--muted, #626262); font-size: 12px; font-weight: 500; }
.ch-msg { display: flex; flex-direction: column; max-width: 82%; }
.ch-msg.is-customer { align-self: flex-end; align-items: flex-end; }
.ch-msg.is-merchant { align-self: flex-start; align-items: flex-start; }
.ch-msg + .ch-msg.is-gap { margin-top: 10px; }
.ch-bubble { padding: 9px 14px; border-radius: 18px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.is-customer .ch-bubble { background: var(--accent, #000); color: var(--on-accent, #fff); border-bottom-right-radius: 6px; }
.is-merchant .ch-bubble { background: var(--ground, #f7f7f7); color: var(--ink, #171717); border: 1px solid var(--line, #e3e3e3); border-bottom-left-radius: 6px; }
.ch-bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.ch-meta { margin: 3px 4px 0; color: var(--muted, #626262); font-size: 12px; line-height: 1.4; }
.ch-meta.is-error { color: var(--error, #b42318); display: inline-flex; align-items: center; gap: 6px; }
.ch-retry { min-height: 32px; padding: 0 4px; border: 0; background: none; color: var(--error, #b42318); font: inherit; font-size: 12px; font-weight: 500; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.ch-retry:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: 1px; border-radius: 4px; }
.ch-msg.is-pending .ch-bubble { opacity: .72; }
.ch-sys { align-self: center; max-width: 92%; margin: 10px 0; color: var(--muted, #626262); font-size: 13px; line-height: 1.5; text-align: center; overflow-wrap: anywhere; }

/* Cartes produit / commande dans un message. */
.ch-card { display: flex; align-items: center; gap: 12px; width: 260px; max-width: 100%; margin: 0 0 4px; padding: 10px; border: 1px solid var(--line, #e3e3e3); border-radius: var(--r-card, 12px); background: var(--paper, #fff); color: var(--ink, #171717); text-decoration: none; }
a.ch-card:hover { border-color: var(--ink, #171717); }
a.ch-card:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: 2px; }
.ch-card-img { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: var(--r-media, 10px); background: var(--ground, #f7f7f7); color: var(--muted, #626262); object-fit: cover; overflow: hidden; }
.ch-card-main { flex: 1 1 auto; min-width: 0; }
.ch-card-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0; font-size: 14px; font-weight: 500; line-height: 1.35; }
.ch-card-sub { display: block; margin-top: 2px; color: var(--muted, #626262); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Mini-carte de coordonnées (avant le premier envoi). */
.ch-contact { margin: 8px 0 4px; padding: 16px; border: 1px solid var(--line, #e3e3e3); border-radius: var(--r-card, 12px); background: var(--paper, #fff); }
.ch-contact[hidden] { display: none; }
.ch-contact-title { margin: 0 0 12px; font-size: 14px; font-weight: 500; line-height: 1.45; }
.ch-contact .field { margin: 0 0 12px; }
.ch-contact .field > label { display: block; margin: 0 0 6px; font-size: 14px; font-weight: 500; }
.ch-contact .input { width: 100%; min-height: 44px; font-size: 16px; }
.ch-opt { color: var(--muted, #626262); font-weight: 400; }
.ch-seg { display: flex; gap: 6px; margin: 0 0 10px; }
.ch-seg button { flex: 1 1 0; min-height: 40px; padding: 0 10px; border: 1px solid var(--line-strong, #d4d4d4); border-radius: var(--r-pill, 999px); background: var(--paper, #fff); color: var(--ink, #171717); font: inherit; font-size: 14px; cursor: pointer; }
.ch-seg button[aria-pressed="true"] { border-color: var(--accent, #000); background: var(--accent, #000); color: var(--on-accent, #fff); font-weight: 500; }
.ch-seg button:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: 2px; }
.ch-check { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 12px; font-size: 14px; line-height: 1.45; cursor: pointer; }
.ch-check input { flex: 0 0 auto; width: 20px; height: 20px; margin: 0; accent-color: var(--accent, #000); }
.ch-err { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 12px; color: var(--error, #b42318); font-size: 13px; line-height: 1.45; }
.ch-err[hidden] { display: none; }
.ch-err i { margin-top: 2px; }
.ch-contact .btn { width: 100%; }
/* Leurre anti-robot : hors écran, jamais focalisable. */
.ch-hp { position: absolute !important; left: -10000px !important; width: 1px; height: 1px; overflow: hidden; }

/* Champ WhatsApp avec indicatif : même rendu que shop/partials/phone-country-field
   (styles .bk-* repris ici, la page n'embarque pas forcément modal-sheet-styles). */
.ch-scope .bk-phone { position: relative; display: flex; align-items: stretch; min-height: 44px; background: var(--paper, #fff); border: 1px solid var(--control, #767676); border-radius: var(--r-control, 10px); }
.ch-scope .bk-phone:hover { border-color: var(--ink-2, #3d3d3d); }
.ch-scope .bk-phone:has(.bk-phone-input:focus) { border-color: var(--accent-text, #000); outline: 2px solid var(--accent-text, #000); outline-offset: 0; }
.ch-scope .bk-phone:has([aria-invalid="true"]) { border-color: var(--error, #b42318); }
.ch-scope .bk-phone-country { display: inline-flex; align-items: center; gap: 6px; padding: 0 10px 0 12px; border: 0; border-right: 1px solid var(--line, #e3e3e3); border-radius: var(--r-control, 10px) 0 0 var(--r-control, 10px); background: transparent; color: var(--ink, #171717); font: inherit; font-size: 15px; cursor: pointer; }
.ch-scope .bk-phone-country:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: -2px; }
.ch-scope .bk-dial { color: var(--muted, #626262); font-size: 15px; font-variant-numeric: tabular-nums; }
.ch-scope .bk-phone-input { flex: 1 1 auto; min-width: 0; border: 0; outline: none; background: transparent; padding: 0 14px; color: var(--ink, #171717); font: inherit; font-size: 16px; font-variant-numeric: tabular-nums; }
.ch-scope .bk-flag { width: 24px; height: 16px; object-fit: contain; border-radius: 2px; }
.ch-scope .bk-chevron { font-size: 11px; color: var(--muted, #626262); }
.ch-scope .bk-menu { display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 5; background: var(--paper, #fff); border: 1px solid var(--line-strong, #d4d4d4); border-radius: var(--r-control, 10px); overflow: hidden; }
.ch-scope .bk-menu-search { padding: 8px; border-bottom: 1px solid var(--line, #e3e3e3); }
.ch-scope .bk-menu-search input { width: 100%; min-height: 40px; padding: 0 12px; border: 1px solid var(--control, #767676); border-radius: 8px; background: var(--paper, #fff); color: var(--ink, #171717); font: inherit; font-size: 16px; outline: none; }
.ch-scope .bk-menu-search input:focus { border-color: var(--accent-text, #000); outline: 2px solid var(--accent-text, #000); outline-offset: 0; }
.ch-scope .bk-menu ul { list-style: none; margin: 0; padding: 4px 0; max-height: 200px; overflow-y: auto; }
.ch-scope .bk-option { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border: 0; background: transparent; color: var(--ink, #171717); font: inherit; font-size: 15px; text-align: left; cursor: pointer; }
.ch-scope .bk-option:hover { background: var(--ground, #f7f7f7); }
.ch-scope .bk-option[aria-selected="true"] { background: var(--accent-soft, #f2f2f2); font-weight: 500; }
.ch-scope .bk-option-name { flex: 1 1 auto; min-width: 0; }
.ch-scope .bk-option-aside { color: var(--muted, #626262); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Pied : contexte produit, alerte, saisie, mention. */
.ch-foot { flex: 0 0 auto; padding: 10px 12px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line, #e3e3e3); background: var(--paper, #fff); }
.ch-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; margin: 0 0 8px; padding: 0 0 0 12px; border: 1px solid var(--line, #e3e3e3); border-radius: var(--r-pill, 999px); background: var(--ground, #f7f7f7); font-size: 13px; }
.ch-chip[hidden] { display: none; }
.ch-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-chip button { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 0; border-radius: 50%; background: none; color: var(--muted, #626262); cursor: pointer; }
.ch-chip button:hover { color: var(--ink, #171717); }
.ch-chip button:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: -2px; }
.ch-alert { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 8px; padding: 8px 12px; border-radius: var(--r-control, 10px); background: var(--ground, #f7f7f7); color: var(--ink, #171717); font-size: 13px; line-height: 1.45; }
.ch-alert[hidden] { display: none; }
.ch-alert i { margin-top: 2px; color: var(--muted, #626262); }
.ch-alert[data-tone="error"] i { color: var(--error, #b42318); }
.ch-alert[data-tone="warning"] i { color: var(--warning, #8a5a00); }
.ch-compose { display: flex; align-items: flex-end; gap: 8px; }
.ch-input { flex: 1 1 auto; min-width: 0; min-height: 44px; max-height: 132px; margin: 0; padding: 10px 14px; border: 1px solid var(--control, #767676); border-radius: 22px; background: var(--paper, #fff); color: var(--ink, #171717); font: inherit; font-size: 16px; line-height: 1.4; resize: none; overflow-y: auto; }
.ch-input:focus { outline: 2px solid var(--accent-text, #000); outline-offset: 0; border-color: var(--accent-text, #000); }
.ch-input::placeholder { color: var(--muted, #626262); }
.ch-input:disabled { background: var(--ground, #f7f7f7); cursor: not-allowed; }
.ch-send { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--accent, #000); color: var(--on-accent, #fff); font-size: 16px; cursor: pointer; transition: background-color 150ms ease-out; }
.ch-send:hover { background: var(--accent-hover, #262626); }
.ch-send:focus-visible { outline: 2px solid var(--accent-text, #000); outline-offset: 2px; }
.ch-send:disabled { opacity: .45; cursor: not-allowed; }
.ch-legal { margin: 8px 2px 0; color: var(--muted, #626262); font-size: 12px; line-height: 1.45; }
.ch-legal a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* État indisponible (chat coupé, visiteur bloqué) et chargement. */
.ch-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 100%; padding: 24px; color: var(--ink, #171717); font-size: 15px; text-align: center; }
.ch-empty i { font-size: 22px; color: var(--muted, #626262); }
.ch-empty p { margin: 0; max-width: 300px; }
.ch-loading { display: flex; align-items: center; justify-content: center; min-height: 120px; color: var(--muted, #626262); font-size: 14px; }

/* ── Mode page (lien /{slug}/messages/{token}, onglet Messages) ───────── */
.ch-page { display: flex; flex-direction: column; width: 100%; max-width: 720px; margin: 0 auto; background: var(--paper, #fff); border: 1px solid var(--line, #e3e3e3); border-radius: var(--r-card, 12px); overflow: hidden; }
.ch-page .ch-panel { position: static; inset: auto; z-index: auto; width: auto; height: auto; min-height: 0; border: 0; border-radius: 0; }
.ch-page .ch-body { min-height: 280px; max-height: calc(100dvh - 320px); }
.ch-page .ch-close { display: none; }
.ch-page .ch-head { padding: 12px 16px; }
.ch-page.is-tall .ch-panel { height: min(720px, calc(100dvh - 160px)); }

/* ── Points d'entrée fixes (en-tête, fiche, contact, pied de page) ────── */
.ch-entry[hidden] { display: none !important; }
button.ch-link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ── Onglet « Messages » de l'espace client ───────────────────────────── */
.ch-acc-unread { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; background: var(--accent, #000); }
.ch-acc-back { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin: -8px 0 8px; color: var(--ink, #171717); font-size: 14px; font-weight: 500; text-decoration: none; }
.ch-acc-back:hover { text-decoration: underline; text-underline-offset: 3px; }
.ch-acc-closed { margin: 0; padding: 14px 16px; border-top: 1px solid var(--line, #e3e3e3); color: var(--muted, #626262); font-size: 14px; text-align: center; }

/* Compléments : verrou de défilement (mobile), côté gauche, liens neutres. */
html.ch-lock, html.ch-lock body { overflow: hidden; }
.ch-launcher.is-left { right: auto; left: 16px; }
@media (min-width: 768px) {
    .ch-launcher.is-left { left: 24px; }
    .ch-panel.is-left { right: auto; left: 24px; }
}
.ch-retry.ch-link-ink { color: var(--ink, #171717); font-size: 13px; }
.ch-safety { display: flex; align-items: flex-start; gap: 8px; margin: -4px 0 16px; color: var(--muted, #626262); font-size: 13px; line-height: 1.45; }
.ch-safety i { margin-top: 3px; font-size: 12px; }
