#boxy-ai-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 54px;
    height: 54px;
    background: linear-gradient(135deg, #D2691E, #C4943A);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(210,105,30,.4);
    z-index: 900;
    display: none; /* Solo visible en dashboard */
    align-items: center;
    justify-content: center;
    transition: transform .2s, box-shadow .2s;
    animation: bai-float 3s ease-in-out infinite;
}
#boxy-ai-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(210,105,30,.5);
}
#boxy-ai-btn:active { transform: scale(.95); }
#boxy-ai-btn svg { width: 30px; height: 30px; }

/* Badge de notificación */
#boxy-ai-badge {
    position: absolute;
    top: -5px; right: -5px;
    width: 18px; height: 18px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    display: none;
}

@keyframes bai-float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-5px); }
}

/* ── Panel de chat ── */
#boxy-ai-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 370px;
    height: 560px;
    background: var(--card, #fff);
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0,0,0,.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 901;
    opacity: 0;
    transform: translateY(20px) scale(.96);
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
}
#boxy-ai-panel.bai-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Dark mode */
:root.dark-mode #boxy-ai-panel {
    background: #1e1e2e;
    box-shadow: 0 12px 48px rgba(0,0,0,.45);
}

/* ── Header del panel ── */
#bai-header {
    background: linear-gradient(135deg, #C4943A, #D2691E);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
#bai-face {
    width: 42px; height: 42px;
    background: rgba(0,0,0,.15);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    animation: bai-float 3s ease-in-out infinite;
}
#bai-face svg { width: 32px; height: 32px; }
#bai-info { flex: 1; }
#bai-info h3 { color: #fff; font-size: 15px; font-weight: 700; margin: 0; }
#bai-info p  { color: rgba(255,255,255,.8); font-size: 11px; margin: 0; }
#bai-role-badge {
    font-size: 10px; font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    background: rgba(255,255,255,.2);
    color: #fff;
    letter-spacing: .3px;
}
#bai-close {
    background: rgba(255,255,255,.15);
    border: none; border-radius: 8px;
    width: 30px; height: 30px;
    cursor: pointer; color: #fff;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
    flex-shrink: 0;
}
#bai-close:hover { background: rgba(255,255,255,.3); }

/* ── Config (API Key) ── */
#bai-config {
    padding: 8px 12px;
    background: #faf9f7;
    border-bottom: 1px solid #eee;
    display: flex; gap: 6px; align-items: center;
    flex-shrink: 0;
}
:root.dark-mode #bai-config { background: #16162a; border-color: #2a2a3e; }
#bai-key-input {
    flex: 1; font-size: 11px;
    padding: 5px 8px;
    border: 1px solid #ddd;
    border-radius: 8px; outline: none;
    background: #fff; color: #333;
}
:root.dark-mode #bai-key-input { background: #1e1e2e; border-color: #3a3a4e; color: #ddd; }
#bai-key-input:focus { border-color: #D2691E; }
#bai-save-key {
    font-size: 11px; padding: 5px 10px;
    background: #D2691E; color: #fff;
    border: none; border-radius: 8px;
    cursor: pointer; white-space: nowrap;
}
#bai-save-key:hover { background: #B8601A; }
#bai-key-ok {
    font-size: 11px; color: #16a34a; font-weight: 600;
    display: none;
}

/* ── Mensajes ── */
#bai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8f7f4;
    scroll-behavior: smooth;
}
:root.dark-mode #bai-messages { background: #16162a; }
#bai-messages::-webkit-scrollbar { width: 3px; }
#bai-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

.bai-msg { display: flex; gap: 7px; align-items: flex-end; max-width: 90%; }
.bai-msg.bai-user { align-self: flex-end; flex-direction: row-reverse; }

.bai-av {
    width: 26px; height: 26px;
    border-radius: 8px;
    background: #C4943A;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 14px;
}
.bai-av.bai-user-av {
    background: #e8edf8; border-radius: 50%; font-size: 12px;
}
:root.dark-mode .bai-av.bai-user-av { background: #2a2a4e; }

.bai-bubble {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 14px; border-bottom-left-radius: 4px;
    padding: 9px 12px;
    font-size: 13px; line-height: 1.5; color: #333;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
:root.dark-mode .bai-bubble { background: #1e1e2e; border-color: #2a2a3e; color: #ddd; }

.bai-msg.bai-user .bai-bubble {
    background: linear-gradient(135deg, #D2691E, #C4943A);
    color: #fff; border: none;
    border-radius: 14px; border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(210,105,30,.3);
}

/* Quick replies */
.bai-qr-wrap { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.bai-qr {
    font-size: 11px; padding: 4px 9px;
    background: #fff3e8; color: #C4700A;
    border: 1px solid #f5c9a0; border-radius: 20px;
    cursor: pointer; transition: all .15s;
}
.bai-qr:hover { background: #D2691E; color: #fff; border-color: #D2691E; }
:root.dark-mode .bai-qr { background: #2a1a0e; border-color: #6b3a10; color: #f5a060; }

/* Typing indicator */
.bai-typing { display: flex; gap: 4px; align-items: center; padding: 10px 12px; }
.bai-typing span {
    width: 6px; height: 6px;
    background: #ccc; border-radius: 50%;
    animation: bai-bounce 1.2s infinite;
}
.bai-typing span:nth-child(2) { animation-delay: .2s; }
.bai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bai-bounce {
    0%,60%,100% { transform: translateY(0); }
    30%          { transform: translateY(-6px); }
}

/* ── Input ── */
#bai-input-area {
    padding: 10px 12px;
    border-top: 1px solid #eee;
    display: flex; gap: 7px;
    background: #fff;
    flex-shrink: 0;
}
:root.dark-mode #bai-input-area { background: #1e1e2e; border-color: #2a2a3e; }
#bai-input {
    flex: 1;
    border: 1.5px solid #eee; border-radius: 10px;
    padding: 8px 12px; font-size: 13px;
    font-family: inherit; resize: none; outline: none;
    background: #fff; color: #333;
    transition: border-color .2s;
    height: 38px;
}
:root.dark-mode #bai-input { background: #16162a; border-color: #2a2a3e; color: #ddd; }
#bai-input:focus { border-color: #D2691E; }
#bai-send {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, #D2691E, #C4943A);
    border: none; border-radius: 10px;
    cursor: pointer; color: #fff;
    font-size: 16px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(210,105,30,.3);
    transition: transform .15s;
}
#bai-send:hover  { transform: scale(1.07); }
#bai-send:active { transform: scale(.93); }

/* ── Responsive mobile ── */
@media (max-width: 480px) {
    #boxy-ai-panel {
        width: calc(100vw - 24px);
        right: 12px; bottom: 80px;
        height: 70vh;
    }
    #boxy-ai-btn { bottom: 16px; right: 16px; }
}