:root {
    --kfai-primary: #111111;
    --kfai-bg: #ffffff;
    --kfai-surface: #f6f7f9;
    --kfai-border: #e5e7eb;
    --kfai-text: #111111;
    --kfai-muted: #6b7280;
    --kfai-border-radius: 12px;
}

.kfai-widget { position: fixed; z-index: 99999; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: var(--kfai-font-size, 14px); color: var(--kfai-text, var(--kfai-text)); }
.kfai-pos-bottom { bottom: 20px; }
.kfai-pos-top { top: 20px; }
.kfai-pos-right { right: 20px; }
.kfai-pos-left { right: auto; left: 20px; }

.kfai-toggle { width: 56px; height: 56px; border-radius: 50%; background: var(--kfai-accent, var(--kfai-primary)); color: #fff; border: none; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,0.2); display: flex; align-items: center; justify-content: center; transition: transform 0.2s; }
.kfai-toggle:hover { transform: scale(1.05); }
.kfai-toggle svg { width: 26px; height: 26px; }
.kfai-toggle .kfai-icon-close { display: none; }
.kfai-widget.open .kfai-toggle .kfai-icon-chat { display: none; }
.kfai-widget.open .kfai-toggle .kfai-icon-close { display: block; }

.kfai-panel { position: absolute; width: var(--kfai-width, 360px); max-height: var(--kfai-height, 560px); background: var(--kfai-panel-bg, var(--kfai-bg)); border-radius: var(--kfai-border-radius); box-shadow: 0 10px 40px rgba(0,0,0,0.18); display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--kfai-border); }
.kfai-pos-bottom .kfai-panel { bottom: 72px; top: auto; }
.kfai-pos-top .kfai-panel { top: 72px; bottom: auto; }
.kfai-pos-right .kfai-panel { right: 0; }
.kfai-pos-left .kfai-panel { right: auto; left: 0; }
.kfai-panel[hidden] { display: none; }

.kfai-header { background: var(--kfai-accent, var(--kfai-primary)); color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }
.kfai-header-info { display: flex; align-items: center; gap: 10px; }
.kfai-avatar { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,0.2); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.kfai-header-title { font-weight: 600; font-size: 15px; }
.kfai-header-status { font-size: 12px; opacity: 0.85; }
.kfai-minimize { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; line-height: 1; }

.kfai-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--kfai-msg-bg, var(--kfai-surface)); }
.kfai-msg { max-width: 85%; padding: 10px 14px; font-size: var(--kfai-font-size, 14px); line-height: 1.5; word-wrap: break-word; }
.kfai-bubble-rounded .kfai-msg-user { border-radius: 16px 16px 4px 16px; }
.kfai-bubble-rounded .kfai-msg-bot { border-radius: 16px 16px 16px 4px; }
.kfai-bubble-square .kfai-msg-user { border-radius: 4px; }
.kfai-bubble-square .kfai-msg-bot { border-radius: 4px; }
.kfai-msg-user { align-self: flex-end; background: var(--kfai-accent, var(--kfai-primary)); color: #fff; }
.kfai-msg-bot { align-self: flex-start; background: var(--kfai-panel-bg, var(--kfai-bg)); color: var(--kfai-text, var(--kfai-text)); border: 1px solid var(--kfai-border); }
.kfai-msg-link { color: var(--kfai-accent, var(--kfai-primary)); text-decoration: underline; font-weight: 600; word-break: break-all; }
.kfai-msg-link:hover { opacity: 0.75; }
.kfai-msg-bot strong { font-weight: 700; }
.kfai-msg-bot em { font-style: italic; }
.kfai-typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; background: var(--kfai-panel-bg, var(--kfai-bg)); border: 1px solid var(--kfai-border); border-radius: 16px; }
.kfai-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--kfai-muted); animation: kfai-bounce 1.4s infinite; }
.kfai-typing span:nth-child(2) { animation-delay: 0.2s; }
.kfai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes kfai-bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-6px); opacity: 1; } }

.kfai-quick-replies { padding: 0 16px 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.kfai-quick-reply { background: transparent; border: 1px solid var(--kfai-accent, var(--kfai-primary)); color: var(--kfai-accent, var(--kfai-primary)); border-radius: 16px; padding: 5px 12px; font-size: 12px; cursor: pointer; }
.kfai-quick-reply:hover { background: var(--kfai-accent, var(--kfai-primary)); color: #fff; }

.kfai-products { display: none; }
.kfai-product-cards { display: flex; flex-direction: column; gap: 10px; align-self: stretch; width: 100%; }
.kfai-product-card { display: flex; gap: 0; border: 1px solid var(--kfai-border); border-radius: 10px; overflow: hidden; background: var(--kfai-panel-bg, var(--kfai-bg)); align-self: flex-start; width: 100%; max-width: 90%; }
.kfai-product-card-img { flex-shrink: 0; width: 80px; height: 80px; background: var(--kfai-surface); overflow: hidden; }
.kfai-product-card-img img { width: 100%; height: 100%; object-fit: cover; }
.kfai-product-card-body { flex: 1; min-width: 0; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.kfai-product-card-name { font-size: 13px; font-weight: 600; color: var(--kfai-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kfai-product-card-price { font-size: 14px; font-weight: 700; color: var(--kfai-accent, var(--kfai-primary)); }
.kfai-product-card-desc { font-size: 11px; color: var(--kfai-muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kfai-product-card-variations { margin-top: 4px; }
.kfai-variation-select { width: 100%; border: 1px solid var(--kfai-border); border-radius: 6px; padding: 4px 6px; font-size: 12px; background: var(--kfai-bg); color: var(--kfai-text); outline: none; cursor: pointer; }
.kfai-variation-select:focus { border-color: var(--kfai-accent, var(--kfai-primary)); }
.kfai-product-card-actions { display: flex; gap: 6px; margin-top: 4px; }
.kfai-product-card-add { background: var(--kfai-accent, var(--kfai-primary)); color: #fff; border: none; border-radius: 6px; padding: 5px 10px; font-size: 11px; cursor: pointer; white-space: nowrap; }
.kfai-product-card-add:disabled { opacity: 0.5; }
.kfai-product-card-view { color: var(--kfai-accent, var(--kfai-primary)); font-size: 11px; font-weight: 600; text-decoration: none; display: flex; align-items: center; padding: 5px 4px; }

.kfai-cart-preview { padding: 8px 16px; background: var(--kfai-msg-bg, var(--kfai-surface)); border-top: 1px solid var(--kfai-border); font-size: 13px; }
.kfai-cart-preview a { color: var(--kfai-accent, var(--kfai-primary)); font-weight: 600; }

.kfai-whatsapp-bar { padding: 8px 16px; border-top: 1px solid var(--kfai-border); }
.kfai-whatsapp-btn { display: flex; align-items: center; justify-content: center; gap: 8px; background: #25D366; color: #fff; text-decoration: none; border-radius: 8px; padding: 10px; font-size: 13px; font-weight: 600; }
.kfai-whatsapp-btn:hover { background: #1eb858; }
.kfai-whatsapp-inline-wrap { align-self: flex-start; width: 100%; margin-top: 2px; }
.kfai-whatsapp-inline-btn { display: flex; align-items: center; justify-content: center; gap: 8px; background: #25D366; color: #fff; text-decoration: none; border-radius: 10px; padding: 12px; font-size: 14px; font-weight: 600; width: 100%; box-sizing: border-box; transition: background 0.2s; }
.kfai-whatsapp-inline-btn:hover { background: #1eb858; }
.kfai-whatsapp-inline-btn svg { fill: #fff; flex-shrink: 0; }
.kfai-whatsapp-btn svg { fill: #fff; }

.kfai-input-row { display: flex; padding: 12px; gap: 8px; border-top: 1px solid var(--kfai-border); }
.kfai-input { flex: 1; border: 1px solid var(--kfai-border); border-radius: 20px; padding: 10px 16px; font-size: var(--kfai-font-size, 14px); outline: none; background: var(--kfai-panel-bg, var(--kfai-bg)); color: var(--kfai-text); }
.kfai-input:focus { border-color: var(--kfai-accent, var(--kfai-primary)); }
.kfai-send { width: 40px; height: 40px; border-radius: 50%; background: var(--kfai-accent, var(--kfai-primary)); color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.kfai-send svg { width: 18px; height: 18px; }
.kfai-send:disabled { opacity: 0.5; }

.kfai-mic { width: 40px; height: 40px; border-radius: 50%; background: var(--kfai-accent, var(--kfai-primary)); color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 0; transition: opacity 0.2s; }
.kfai-mic svg { width: 18px; height: 18px; }
.kfai-mic:hover { opacity: 0.85; }
.kfai-mic.listening { background: #e74c3c; color: #fff; animation: kfai-pulse 1.5s infinite; }
@keyframes kfai-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

@media (max-width: 480px) {
    .kfai-widget.open { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 99999; }
    .kfai-widget.open .kfai-toggle { display: none; }
    .kfai-panel { position: relative !important; top: auto !important; bottom: auto !important; left: auto !important; right: auto !important; width: calc(100vw - 32px) !important; max-width: 400px; max-height: 80vh !important; margin: 0 auto; }
}
