/* AI Chatbot – Frontend Styles */

/* ── Wrapper ─────────────────────────────────────────────── */
#aichat-wrapper {
    position: fixed;
    z-index: 999999;
    bottom: 24px;
    left: 24px;
    right: auto;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-start;
    gap: 12px;
}
#aichat-wrapper.aichat-pos-bottom-right { right: 24px; left: auto; align-items: flex-end; }
#aichat-wrapper.aichat-pos-bottom-left  { left: 24px; right: auto; align-items: flex-start; }

/* ── Toggle buttons ──────────────────────────────────────── */
.aichat-toggle-btn {
    position: relative;
    width: 58px; height: 58px; border-radius: 50%;
    background: var(--aichat-primary, #6C2BD9);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    transition: transform .2s, box-shadow .2s;
    outline: none; z-index: 2;
    opacity: 1; visibility: visible;
}
.aichat-toggle-btn:hover  { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,0.3); }
.aichat-toggle-btn:active { transform: scale(0.96); }

/* ── Unread badge ────────────────────────────────────────── */
.aichat-badge {
    position: absolute; top: -4px; right: -4px;
    background: #EF4444; color: white;
    font-size: 11px; font-weight: 700;
    width: 20px; height: 20px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid white; pointer-events: none;
}

/* ── Contact wrap & action menu ─────────────────────────── */
.aichat-contact-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}
#aichat-wrapper.aichat-pos-bottom-right .aichat-contact-wrap {
    align-items: flex-end;
}

.aichat-action-menu {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity .22s ease, transform .22s ease;
    margin-bottom: 4px;
}

#aichat-wrapper.aichat-pos-bottom-right .aichat-action-menu {
    align-items: flex-end;
}
.aichat-action-menu.aichat-menu-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

/* Action items */
.aichat-action-item {
    display: flex;
    align-items: center;
    gap: 0;
}
#aichat-wrapper.aichat-pos-bottom-right .aichat-action-item {
    flex-direction: row-reverse; justify-content: flex-end;
}
.aichat-action-label {
    display:none;
}
.aichat-action-btn {
    width: 48px; height: 48px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: none; cursor: pointer; text-decoration: none; flex-shrink: 0;
    box-shadow: 0 3px 12px rgba(0,0,0,0.2);
    transition: transform .2s, box-shadow .2s;
}
.aichat-action-btn:hover { transform: scale(1.1); box-shadow: 0 5px 18px rgba(0,0,0,0.25); }
.aichat-btn-whatsapp { background: #25D366; }
.aichat-btn-email    { background: #EF4444; }
.aichat-btn-phone    { background: #22C55E; }

/* ── Chat window ─────────────────────────────────────────── */
.aichat-window {
    position: fixed;
    bottom: 90px; right: 90px;
    width: 360px; max-height: 520px; min-height: 400px;
    background: #ffffff; border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: flex; flex-direction: column; overflow: hidden;
    opacity: 0; visibility: hidden; pointer-events: none;
    transform: translateY(12px) scale(0.97);
    transition: opacity .25s, transform .25s, visibility .25s;
    z-index: 999998;
}
.aichat-pos-bottom-right .aichat-window { right: 90px; }
.aichat-pos-bottom-left  .aichat-window { left: 90px; right: auto; }
.aichat-window.aichat-open {
    opacity: 1; visibility: visible;
    pointer-events: all; transform: translateY(0) scale(1);
}

/* Window header */
.aichat-header {
    background: var(--aichat-primary, #6C2BD9);
    padding: 14px 16px;
    display: flex; align-items: center; justify-content: space-between;
    color: white; flex-shrink: 0;
}
.aichat-header-info { display: flex; align-items: center; gap: 10px; }
.aichat-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center; color: white;
    flex-shrink: 0;
}
.aichat-bot-name  { display: block; font-size: 14px; font-weight: 700; line-height: 1.2; }
.aichat-status    { display: block; font-size: 11px; opacity: .75; }
.aichat-status-dot {
    display: inline-block; width: 7px; height: 7px;
    border-radius: 50%; background: #4ADE80; margin-right: 4px;
}
.aichat-close-btn {
    background: transparent; border: none; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    padding: 4px; transition: background .2s;
}
.aichat-close-btn:hover { background: rgba(255,255,255,0.15); }

/* Messages area */
.aichat-messages {
    flex: 1; overflow-y: auto;
    padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.aichat-messages::-webkit-scrollbar { width: 4px; }
.aichat-messages::-webkit-scrollbar-track { background: transparent; }
.aichat-messages::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 2px; }

/* Bubbles */
.aichat-msg { display: flex; gap: 8px; align-items: flex-end; animation: aichatFadeIn .25s ease; }
@keyframes aichatFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.aichat-msg-bot  { flex-direction: row; }
.aichat-msg-user { flex-direction: row-reverse; }
.aichat-msg-avatar {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    background: var(--aichat-primary, #6C2BD9);
    display: flex; align-items: center; justify-content: center; color: white; font-size: 13px;
}
.aichat-bubble {
    max-width: 80%; padding: 10px 14px; border-radius: 16px;
    font-size: 14px; line-height: 1.55; word-break: break-word;
}
.aichat-msg-bot  .aichat-bubble { background: #F3F4F6; color: #1F2937; border-bottom-left-radius: 4px; }
.aichat-msg-user .aichat-bubble { background: var(--aichat-primary, #6C2BD9); color: white; border-bottom-right-radius: 4px; }
.aichat-msg-error .aichat-bubble { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }

/* Typing indicator */
.aichat-typing .aichat-bubble { background: #F3F4F6; padding: 12px 16px; }
.aichat-typing-dots { display: flex; gap: 4px; align-items: center; }
.aichat-typing-dots span {
    width: 7px; height: 7px; background: #9CA3AF; border-radius: 50%;
    animation: aichatBounce 1.2s infinite ease-in-out;
}
.aichat-typing-dots span:nth-child(1) { animation-delay: 0s; }
.aichat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.aichat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes aichatBounce {
    0%,60%,100% { transform: translateY(0); opacity: .5; }
    30%          { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.aichat-input-wrap {
    padding: 12px 16px;
    border-top: 1px solid #f0f0f0;
    background: #fff; flex-shrink: 0;
}
.aichat-input-row {
    display: flex; align-items: center; gap: 8px;
    background: white; border: 1px solid #E5E7EB;
    border-radius: 12px; padding: 6px 6px 6px 12px;
    transition: border-color .2s;
}
.aichat-input-row:focus-within {
    border-color: var(--aichat-primary, #6C2BD9);
    box-shadow: 0 0 0 3px rgba(108,43,217,0.1);
}
.aichat-input {
    flex: 1; border: none; outline: none; resize: none;
    font-size: 14px; line-height: 1.5; max-height: 100px;
    background: transparent; color: #1F2937; font-family: inherit;
}
.aichat-send-btn {
    width: 36px; height: 36px; border-radius: 8px; border: none;
    background: var(--aichat-primary, #6C2BD9); color: white;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: opacity .2s, transform .15s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.aichat-send-btn svg { display: block; fill: white; width: 18px; height: 18px; pointer-events: none; }
.aichat-send-btn:hover  { opacity: .88; }
.aichat-send-btn:active { transform: scale(0.93); }
.aichat-send-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Links dentro del chat ───────────────────────────────── */
.aichat-link {
    display: inline-block;
    margin-top: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none !important;
    background: rgba(255,255,255,0.2);
    color: inherit !important;
    border: 1px solid rgba(255,255,255,0.3);
    transition: background .2s;
}
.aichat-msg-bot .aichat-link {
    background: rgba(108,43,217,0.08);
    border-color: rgba(108,43,217,0.2);
    color: var(--aichat-primary, #6C2BD9) !important;
}
.aichat-link:hover { opacity: .8; }

/* ── Listas numeradas ────────────────────────────────────── */
.aichat-list-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin: 4px 0;
}
.aichat-list-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--aichat-primary, #6C2BD9);
    color: white;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 1px;
}
.aichat-msg-user .aichat-list-num {
    background: rgba(255,255,255,0.3);
}
@media (max-width: 420px) {
    .aichat-window {
        width: calc(100vw - 24px);
        right: 0 !important; left: 0 !important;
        margin: 0 12px;
        bottom: 80px;
    }
    #aichat-wrapper.aichat-pos-bottom-right,
    #aichat-wrapper.aichat-pos-bottom-left {
        right: 12px; left: 12px;
    }
}

/* ── Icono del botón ─────────────────────────────────────── */
.aichat-toggle-btn svg {
    width: 26px;
    height: 26px;
    display: block;
}
.aichat-icon-open,
.aichat-icon-close {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Botón chatbot dentro del menú ───────────────────────── */
.aichat-btn-chatbot {
    background: var(--aichat-primary, #6C2BD9);
    position: relative;
}
