/**
 * SOLVA - Site assistant (assets/js/chatbot.js)
 * Minimal / Swiss direction (design-system/solva/MASTER.md): navy, borders, no gradients.
 */

/* ---------- floating actions: assistant above WhatsApp ---------- */
.whatsapp-float.fab-stack { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.bot-launcher {
    position: relative; width: 56px; height: 56px; border: 0; border-radius: 50%; cursor: pointer;
    display: grid; place-items: center; background: #1d1d35; color: #fff; font-size: 1.35rem;
    box-shadow: 0 8px 22px rgba(29, 29, 53, .35); transition: transform .2s ease, background .2s ease;
}
.bot-launcher:hover { transform: scale(1.06); background: #2a2a4a; }
.bot-launcher:focus-visible { outline: 3px solid #93c5fd; outline-offset: 3px; }
.bot-launcher i { grid-area: 1 / 1; transition: opacity .2s ease, transform .25s ease; }
.bot-ico-close { opacity: 0; transform: rotate(-90deg); }
.bot-launcher.is-open .bot-ico-open { opacity: 0; transform: rotate(90deg); }
.bot-launcher.is-open .bot-ico-close { opacity: 1; transform: none; }
.bot-dot { position: absolute; top: 3px; right: 3px; width: 12px; height: 12px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; }

.bot-teaser {
    position: absolute; left: calc(100% + 12px); top: 2px; width: max-content; max-width: 240px;
    display: flex; align-items: flex-start; gap: .25rem; padding: .55rem .5rem .55rem .85rem;
    background: #fff; color: #0f172a; border: 1px solid #e3e6ec; border-radius: 10px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .16); animation: botIn .35s ease;
}
html[dir="rtl"] .bot-teaser { padding: .55rem .85rem .55rem .5rem; }
.bot-teaser-text { border: 0; background: none; padding: 0; font: inherit; font-size: .88rem; font-weight: 600; color: inherit; cursor: pointer; text-align: start; line-height: 1.6; }
.bot-teaser-x { border: 0; background: none; color: #94a3b8; cursor: pointer; width: 24px; height: 24px; border-radius: 6px; flex: none; }
.bot-teaser-x:hover { background: #f1f2f5; color: #0f172a; }

/* ---------- panel ---------- */
.bot-panel {
    --ink: #0f172a; --muted: #64748b; --line: #e3e6ec; --soft: #f3f4f7; --brand: #1d1d35;
    position: fixed; z-index: 10020; left: calc(var(--space-xl, 2rem) + 76px); bottom: var(--space-xl, 2rem);
    width: 384px; height: min(640px, calc(100vh - 130px)); display: flex; flex-direction: column;
    background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .22);
    opacity: 0; transform: translateY(12px) scale(.98); transform-origin: bottom left;
    transition: opacity .2s ease, transform .22s ease;
}
.bot-panel.is-open { opacity: 1; transform: none; }
.bot-panel[hidden] { display: none; }

.bot-head { display: flex; align-items: center; gap: .7rem; padding: .8rem .8rem .8rem 1rem; background: var(--brand); color: #fff; }
html[dir="rtl"] .bot-head { padding: .8rem 1rem .8rem .8rem; }
.bot-mark { flex: none; width: 38px; height: 38px; border-radius: 10px; background: rgba(255, 255, 255, .12); display: grid; place-items: center; }
.bot-mark img { width: 24px; height: 24px; object-fit: contain; filter: brightness(0) invert(1); }
.bot-who { flex: 1; min-width: 0; line-height: 1.35; }
.bot-who strong { display: block; font-size: 1rem; }
.bot-status { display: flex; align-items: center; gap: .4rem; font-size: .76rem; color: rgba(255, 255, 255, .72); }
.bot-online { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; flex: none; }
.bot-hbtn { flex: none; width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: rgba(255, 255, 255, .85); cursor: pointer; font-size: .92rem; }
.bot-hbtn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.bot-hbtn:focus-visible { outline: 2px solid #93c5fd; outline-offset: 1px; }

.bot-log { flex: 1; overflow-y: auto; padding: 1rem .9rem .5rem; display: flex; flex-direction: column; gap: .55rem; background: #fafbfc; overscroll-behavior: contain; scrollbar-width: thin; }
.bot-msg { display: flex; flex-direction: column; gap: .45rem; max-width: 100%; }
.bot-msg.is-new { animation: botIn .28s ease both; }
.bot-msg.is-me { align-items: flex-end; }
.bot-msg.is-bot { align-items: flex-start; }
.bot-bubble { max-width: 86%; padding: .6rem .85rem; border-radius: 12px; font-size: .9rem; line-height: 1.75; word-break: break-word; }
.is-bot .bot-bubble { background: #fff; border: 1px solid var(--line); border-start-start-radius: 4px; }
.is-me .bot-bubble { background: var(--brand); color: #fff; border-start-end-radius: 4px; }

.bot-typing .bot-bubble { display: flex; gap: 4px; padding: .75rem .9rem; }
.bot-typing i { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; animation: botDot 1s ease-in-out infinite; }
.bot-typing i:nth-child(2) { animation-delay: .15s; }
.bot-typing i:nth-child(3) { animation-delay: .3s; }

.bot-links { display: flex; flex-wrap: wrap; gap: .4rem; max-width: 92%; }
.bot-link {
    display: inline-flex; align-items: center; gap: .45rem; padding: .45rem .8rem; border-radius: 8px;
    border: 1px solid var(--brand); background: #fff; color: var(--brand); font: inherit; font-size: .84rem; font-weight: 600;
    text-decoration: none; cursor: pointer; transition: background .15s ease, color .15s ease;
}
.bot-link:hover { background: var(--brand); color: #fff; }
.bot-link.is-primary { background: var(--brand); color: #fff; }
.bot-link.is-primary:hover { background: #2a2a4a; }
.bot-link.is-wa { background: #1fa855; border-color: #1fa855; color: #fff; }
.bot-link.is-wa:hover { background: #188a46; border-color: #188a46; }

/* product cards: a sideways row */
.bot-cards { display: flex; gap: .55rem; overflow-x: auto; max-width: 100%; padding-bottom: .3rem; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.bot-pc { flex: none; width: 196px; scroll-snap-align: start; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.bot-pc-img { display: block; aspect-ratio: 4 / 3; background: #fff; border-bottom: 1px solid var(--line); }
.bot-pc-img img { width: 100%; height: 100%; object-fit: contain; padding: .5rem; display: block; }
.bot-pc-body { padding: .55rem .65rem .65rem; display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.bot-pc-body small { color: var(--muted); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-pc-name { color: var(--ink); font-weight: 700; font-size: .84rem; line-height: 1.5; text-decoration: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bot-pc-name:hover { text-decoration: underline; }
.bot-pc-price { font-weight: 700; color: var(--brand); font-size: .88rem; }
.bot-pc-stock { color: #15803d; font-size: .78rem; font-weight: 600; }
.bot-pc-acts { display: flex; gap: .35rem; margin-top: auto; padding-top: .4rem; }
.bot-pc-more, .bot-pc-add { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: .3rem; height: 32px; border-radius: 7px; font: inherit; font-size: .76rem; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.bot-pc-more { border: 1px solid var(--line); color: var(--ink); background: #fff; }
.bot-pc-more:hover { border-color: var(--brand); }
.bot-pc-add { border: 0; background: var(--brand); color: #fff; }
.bot-pc-add:hover { background: #2a2a4a; }
.bot-pc-add.is-in-cart { background: #15803d; }
.bot-pc-add .cart-add-label { overflow: hidden; text-overflow: ellipsis; }

/* contact card */
.bot-contact { width: 92%; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.bot-crow { display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; color: var(--ink); text-decoration: none; }
.bot-crow + .bot-crow { border-top: 1px solid var(--line); }
a.bot-crow:hover { background: var(--soft); }
.bot-crow > i { width: 30px; height: 30px; flex: none; border-radius: 8px; display: grid; place-items: center; background: var(--soft); color: var(--brand); }
.bot-crow small { display: block; color: var(--muted); font-size: .72rem; }
.bot-crow b { display: block; font-size: .86rem; font-weight: 600; line-height: 1.5; }

/* quick replies */
.bot-chips { display: flex; flex-wrap: wrap; gap: .4rem; padding: .55rem .9rem; border-top: 1px solid var(--line); max-height: 136px; overflow-y: auto; background: #fff; scrollbar-width: thin; }
.bot-chips[hidden] { display: none; }
.bot-chip {
    display: inline-flex; align-items: center; gap: .4rem; padding: .38rem .75rem; border-radius: 999px;
    border: 1px solid #cfd4de; background: #fff; color: var(--ink); font: inherit; font-size: .8rem; font-weight: 600;
    cursor: pointer; text-align: start; line-height: 1.5; transition: border-color .15s ease, background .15s ease;
}
.bot-chip i { color: var(--brand); font-size: .8rem; }
.bot-chip:hover { border-color: var(--brand); background: var(--soft); }
.bot-chip:focus-visible, .bot-link:focus-visible, .bot-pc-add:focus-visible, .bot-pc-more:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

.bot-form { display: flex; gap: .45rem; padding: .6rem .7rem; border-top: 1px solid var(--line); background: #fff; }
.bot-input { flex: 1; min-width: 0; height: 42px; padding: 0 .9rem; border: 1px solid #cfd4de; border-radius: 10px; font: inherit; font-size: 16px; color: var(--ink); background: #fff; }
.bot-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29, 29, 53, .12); }
.bot-send { flex: none; width: 42px; height: 42px; border: 0; border-radius: 10px; background: var(--brand); color: #fff; cursor: pointer; }
.bot-send:hover { background: #2a2a4a; }
html[dir="rtl"] .bot-send i { transform: scaleX(-1); }
.bot-foot { margin: 0; padding: 0 .9rem .55rem; background: #fff; color: #94a3b8; font-size: .7rem; text-align: center; }

@keyframes botIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes botDot { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- phones: full screen ---------- */
@media (max-width: 640px) {
    .bot-panel { inset: 0; width: auto; height: auto; border: 0; border-radius: 0; transform: translateY(16px); }
    .bot-head { padding-top: max(.8rem, env(safe-area-inset-top)); }
    .bot-form { padding-bottom: max(.6rem, env(safe-area-inset-bottom)); }
    html.bot-lock, html.bot-lock body { overflow: hidden; }
    .bot-teaser { max-width: calc(100vw - 120px); }
    .bot-launcher { width: 52px; height: 52px; font-size: 1.25rem; }
}

/* ---------- dark mode ---------- */
body.dark-mode .bot-panel { --ink: #e2e8f0; --muted: #94a3b8; --line: rgba(255, 255, 255, .1); --soft: rgba(255, 255, 255, .06); background: #0b1222; }
body.dark-mode .bot-log { background: #070c18; }
body.dark-mode .is-bot .bot-bubble, body.dark-mode .bot-pc, body.dark-mode .bot-contact, body.dark-mode .bot-pc-more { background: #111a2e; }
body.dark-mode .bot-pc-img { background: #fff; }
body.dark-mode .bot-chips, body.dark-mode .bot-form, body.dark-mode .bot-foot { background: #0b1222; }
body.dark-mode .bot-chip, body.dark-mode .bot-input { background: #111a2e; border-color: rgba(255, 255, 255, .16); color: #e2e8f0; }
body.dark-mode .bot-chip i, body.dark-mode .bot-crow > i { color: #e2e8f0; }
body.dark-mode .bot-link { background: transparent; border-color: #e2e8f0; color: #e2e8f0; }
body.dark-mode .bot-link:hover, body.dark-mode .bot-link.is-primary, body.dark-mode .is-me .bot-bubble, body.dark-mode .bot-send, body.dark-mode .bot-pc-add { background: #e2e8f0; color: #0f172a; }
body.dark-mode .bot-link.is-wa { background: #1fa855; border-color: #1fa855; color: #fff; }
body.dark-mode .bot-pc-price { color: #e2e8f0; }
body.dark-mode .bot-teaser { background: #111a2e; color: #e2e8f0; border-color: rgba(255, 255, 255, .12); }

@media (prefers-reduced-motion: reduce) {
    .bot-panel, .bot-launcher, .bot-launcher i { transition: none; }
    .bot-msg.is-new, .bot-teaser { animation: none; }
    .bot-typing i { animation: none; }
}
@media print { .fab-stack, .bot-panel { display: none !important; } }
