/* ==========================================================================
   Atendente virtual (IA) — botão flutuante e janela de conversa
   Usa as cores da loja (--primary); --aichat-color vem do painel, se definido.
   ========================================================================== */
.aichat {
    --aichat-accent: var(--aichat-color, var(--primary, #0096b7));
    --aichat-bg: #eef3f5;
    --aichat-in: #ffffff;
    --aichat-out: color-mix(in srgb, var(--aichat-accent) 16%, #fff);
    --aichat-text: #1f2328;
    --aichat-muted: #5c6670;
    --aichat-width: 390px;
    --aichat-h: 100vh;
    position: fixed;
    z-index: 900;
    bottom: 18px;
    right: 18px;
    font-family: inherit;
    color: var(--aichat-text);
}
.aichat--left { right: auto; left: 18px; }
.aichat .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Botão flutuante: sobe quando a barra de compra do celular aparece, para não cobrir o botão COMPRAR */
.aichat__launcher {
    position: relative; display: flex; align-items: center; gap: 10px; padding: 6px 18px 6px 6px; border: 0; border-radius: 999px;
    background: var(--aichat-accent); color: #fff; font: inherit; font-weight: 800; font-size: 15px; cursor: pointer;
    box-shadow: 0 8px 26px rgba(0, 0, 0, .22); transition: transform .15s ease, box-shadow .15s ease;
}
.aichat__launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(0, 0, 0, .26); }
.aichat__launcher:focus-visible, .aichat button:focus-visible, .aichat a:focus-visible, .aichat textarea:focus-visible, .aichat__attach:focus-within {
    outline: 3px solid color-mix(in srgb, var(--aichat-accent) 55%, #000); outline-offset: 2px;
}
.aichat.is-open .aichat__launcher { display: none; }
body:has(.buy-bar.is-visible) .aichat { bottom: 86px; }
.aichat__unread { position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: #d93025; color: #fff; font-size: 12px; line-height: 22px; text-align: center; border: 2px solid #fff; }

.aichat__avatar {
    flex: 0 0 auto; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
    background: #fff; color: var(--aichat-accent); font-weight: 900; font-size: 18px;
}
.aichat__avatar img { width: 100%; height: 100%; object-fit: cover; }
.aichat__avatar--launcher { width: 42px; height: 42px; }

/* Janela */
.aichat__panel {
    display: flex; flex-direction: column; width: min(var(--aichat-width), calc(100vw - 36px)); height: min(640px, calc(100vh - 36px));
    border-radius: 18px; overflow: hidden; background: var(--aichat-bg); box-shadow: 0 18px 60px rgba(0, 0, 0, .28);
}
.aichat__panel[hidden] { display: none; }
.aichat.is-wide { --aichat-width: 560px; }
.aichat.is-wide .aichat__panel { height: min(760px, calc(100vh - 36px)); }

.aichat__head { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 12px; background: var(--aichat-accent); color: #fff; }
.aichat__who { flex: 1 1 auto; min-width: 0; display: grid; line-height: 1.2; }
.aichat__who strong { font-size: 16px; font-weight: 900; }
.aichat__sub { font-size: 12.5px; opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aichat__icon-btn { flex: 0 0 auto; display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; }
.aichat__icon-btn:hover { background: rgba(255, 255, 255, .16); }
.aichat__test { margin: 0; padding: 6px 12px; background: #fff3cd; color: #6b5310; font-size: 12px; font-weight: 800; text-align: center; }

.aichat__body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 4px; scroll-behavior: smooth; }
.aichat__notice { margin: 0 auto 8px; max-width: 92%; padding: 8px 12px; border-radius: 10px; background: #fff8dc; color: #5b4a12; font-size: 12.5px; line-height: 1.4; text-align: center; }
.aichat__notice a { color: inherit; font-weight: 800; }
.aichat__day { align-self: center; margin: 6px 0; padding: 3px 10px; border-radius: 8px; background: rgba(255, 255, 255, .85); color: var(--aichat-muted); font-size: 11.5px; font-weight: 700; }

/* Balões */
.aichat__msg { display: flex; flex-direction: column; max-width: 86%; }
.aichat__msg--in { align-self: flex-start; }
.aichat__msg--out { align-self: flex-end; align-items: flex-end; }
.aichat__msg + .aichat__msg--in.is-first, .aichat__msg + .aichat__msg--out.is-first { margin-top: 8px; }
.aichat__bubble {
    position: relative; padding: 8px 10px 6px 12px; border-radius: 12px; background: var(--aichat-in); font-size: 14.5px; line-height: 1.45;
    white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 1px rgba(0, 0, 0, .08);
}
.aichat__msg--out .aichat__bubble { background: var(--aichat-out); }
.aichat__msg--in.is-first .aichat__bubble:first-child { border-top-left-radius: 4px; }
.aichat__msg--out.is-first .aichat__bubble:first-child { border-top-right-radius: 4px; }
.aichat__bubble + .aichat__bubble { margin-top: 4px; }
.aichat__author { margin: 0 0 2px; font-size: 12px; font-weight: 900; color: #b45309; }
.aichat__meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin: 2px -2px 0 10px; float: right; font-size: 11px; color: var(--aichat-muted); white-space: nowrap; }
.aichat__meta svg { width: 15px; height: 15px; }
.aichat__msg.is-failed .aichat__bubble { background: #fde8e8; }
.aichat__retry { margin-top: 4px; padding: 3px 10px; border: 1px solid #d93025; border-radius: 999px; background: #fff; color: #d93025; font: inherit; font-size: 12.5px; font-weight: 800; cursor: pointer; }
.aichat__img { display: block; max-width: 220px; max-height: 220px; margin-bottom: 4px; border-radius: 8px; }

.aichat__typing { align-self: flex-start; display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: var(--aichat-in); color: var(--aichat-muted); font-size: 13px; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); }
.aichat__dots { display: inline-flex; gap: 3px; }
.aichat__dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--aichat-muted); animation: aichat-dot 1.2s infinite ease-in-out; }
.aichat__dots i:nth-child(2) { animation-delay: .15s; }
.aichat__dots i:nth-child(3) { animation-delay: .3s; }
@keyframes aichat-dot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.aichat__system { align-self: center; max-width: 92%; margin: 8px 0; padding: 8px 12px; border-radius: 10px; background: #fff; color: var(--aichat-text); font-size: 13px; text-align: center; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); }

/* Cartões de produto (dados oficiais vindos do servidor) */
.aichat__cards { display: grid; gap: 8px; margin-top: 6px; width: 100%; }
.aichat__card { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px; padding: 10px; border-radius: 12px; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.aichat__card img { width: 76px; height: 76px; object-fit: contain; border-radius: 8px; background: #f6f7f8; }
.aichat__card-name { margin: 0; font-size: 13.5px; font-weight: 800; line-height: 1.3; }
.aichat__card-tags { margin: 3px 0 0; font-size: 12px; color: var(--aichat-muted); }
.aichat__card-price { margin: 4px 0 0; font-size: 16px; font-weight: 900; color: var(--aichat-text); }
.aichat__card-price small { font-size: 11.5px; font-weight: 700; color: var(--aichat-muted); }
.aichat__card-card { margin: 0; font-size: 12px; color: var(--aichat-muted); }
.aichat__card-stock { margin: 2px 0 0; font-size: 12px; font-weight: 800; color: #16812f; }
.aichat__card-stock.is-out { color: #b42318; }
.aichat__card-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.aichat__btn { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 6px 10px; border: 2px solid var(--aichat-accent); border-radius: 10px; background: #fff; color: var(--aichat-accent); font: inherit; font-size: 13px; font-weight: 800; text-align: center; text-decoration: none; cursor: pointer; }
.aichat__btn--solid { background: var(--aichat-accent); color: #fff; }
.aichat__btn--buy { border-color: var(--button, #29aa0b); background: var(--button, #29aa0b); color: #fff; }

/* Resumo de orçamento */
.aichat__quote { margin-top: 6px; width: 100%; padding: 10px 12px; border-radius: 12px; background: #fff; font-size: 13px; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.aichat__quote h4 { margin: 0 0 6px; font-size: 13px; font-weight: 900; text-transform: uppercase; letter-spacing: .03em; color: var(--aichat-muted); }
.aichat__quote dl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; margin: 0; }
.aichat__quote dt { color: var(--aichat-muted); }
.aichat__quote dd { margin: 0; font-weight: 700; text-align: right; }
.aichat__quote .is-total { padding-top: 5px; border-top: 1px solid #e5e8eb; font-size: 14.5px; font-weight: 900; color: var(--aichat-text); }
.aichat__quote-note { margin: 6px 0 0; font-size: 11.5px; color: var(--aichat-muted); }
.aichat__checkout { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; width: 100%; }

/* Respostas rápidas */
.aichat__quick { display: flex; gap: 6px; padding: 0 12px 8px; overflow-x: auto; scrollbar-width: none; }
.aichat__quick:empty { display: none; }
.aichat__quick::-webkit-scrollbar { display: none; }
.aichat__chip { flex: 0 0 auto; padding: 7px 12px; border: 1.5px solid var(--aichat-accent); border-radius: 999px; background: #fff; color: var(--aichat-accent); font: inherit; font-size: 13px; font-weight: 800; white-space: nowrap; cursor: pointer; }
.aichat__chip:hover { background: var(--aichat-out); }

/* Campo de texto */
.aichat__composer { position: relative; display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: #f6f7f8; border-top: 1px solid #e3e6e9; }
.aichat__composer textarea {
    flex: 1 1 auto; min-width: 0; max-height: 120px; padding: 10px 12px; border: 1px solid #d5dade; border-radius: 20px; background: #fff;
    font: inherit; font-size: 16px; line-height: 1.35; resize: none; color: var(--aichat-text);
}
.aichat__attach { color: var(--aichat-muted); }
.aichat__attach:hover { background: #e9ecef; }
.aichat__send { flex: 0 0 auto; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--aichat-accent); color: #fff; cursor: pointer; }
.aichat__send:disabled { opacity: .5; cursor: default; }
.aichat__preview { position: absolute; left: 8px; right: 8px; bottom: 100%; display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px 12px 0 0; background: #fff; box-shadow: 0 -4px 12px rgba(0, 0, 0, .08); font-size: 13px; }
.aichat__preview[hidden] { display: none; }
.aichat__preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; }
.aichat__preview span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Celular: ocupa a área útil da tela e acompanha o teclado (altura vem do visualViewport) */
@media (max-width: 600px) {
    .aichat { bottom: 12px; right: 12px; }
    .aichat--left { left: 12px; }
    body:has(.buy-bar.is-visible) .aichat { bottom: 80px; }
    .aichat__launcher-text { display: none; }
    .aichat__launcher { padding: 5px; }
    .aichat__expand { display: none; }
    .aichat.is-open.is-full { inset: 0; bottom: 0 !important; }
    .aichat.is-full .aichat__panel { width: 100vw; height: var(--aichat-h); border-radius: 0; }
    .aichat:not(.is-full) .aichat__panel { width: calc(100vw - 24px); height: min(560px, calc(var(--aichat-h) - 24px)); }
    .aichat__msg { max-width: 92%; }
}
body.aichat-lock { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
    .aichat__launcher, .aichat__body { transition: none; scroll-behavior: auto; }
    .aichat__dots i { animation: none; opacity: .7; }
}
