/* ============================================================
   Softega AI Chatbot Widget
   ============================================================ */

/* --- FAB Toggle Button --- */
#chat-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9999;
    width: 56px;
    min-width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(160deg, #60C6EF 0%, #3A84C5 30%, #6B2179 70%, #551966 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(85, 25, 102, 0.45);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    outline: none;
}
#chat-fab:hover {
    transform: translateY(-3px) scale(1.06);
    box-shadow: 0 8px 28px rgba(85, 25, 102, 0.55);
}
#chat-fab svg {
    width: 26px;
    height: 26px;
    fill: #fff;
    transition: transform 0.3s ease, opacity 0.2s ease;
}
#chat-fab .icon-close {
    display: none;
}
#chat-fab.is-open .icon-chat {
    display: none;
}
#chat-fab.is-open .icon-close {
    display: block;
}

/* Pulse ring when closed */
#chat-fab:not(.is-open)::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid rgba(107, 33, 121, 0.4);
    animation: chatPulse 2.4s ease-out infinite;
}
@keyframes chatPulse {
    0%   { opacity: 1; transform: scale(1); }
    70%  { opacity: 0; transform: scale(1.5); }
    100% { opacity: 0; }
}

/* --- Chat Window --- */
#chat-window {
    position: fixed;
    bottom: 96px;
    right: 28px;
    z-index: 9998;
    width: 360px;
    max-width: calc(100vw - 32px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(85, 25, 102, 0.12);
    border: 1px solid rgba(107, 33, 121, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0.92) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
    max-height: calc(100vh - 120px);
}
#chat-window.is-visible {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* Header */
#chat-header {
    background: linear-gradient(160deg, #60C6EF 0%, #3A84C5 30%, #6B2179 70%, #551966 100%);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
#chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;

}
#chat-header-avatar i {
    font-size: 1.1rem;
    color: #fff;
}
#chat-header-info {
    flex: 1;
    min-width: 0;
}
#chat-header-name {
    font-family: "Montserrat", sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}
#chat-header-status {
    font-family: "Montserrat", sans-serif;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.75);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}
#chat-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
    animation: statusPulse 2s ease-in-out infinite;
}
@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

/* Messages area */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 200px;
    max-height: 340px;
}
#chat-messages::-webkit-scrollbar {
    width: 4px;
}
#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(107, 33, 121, 0.2);
    border-radius: 4px;
}

/* Message bubbles */
.chat-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: msgIn 0.22s ease forwards;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.chat-msg.user {
    flex-direction: row-reverse;
}
.chat-msg-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-family: "Montserrat", sans-serif;
    font-size: 0.855rem;
    line-height: 1.55;
    word-break: break-word;
}
.chat-msg.bot .chat-msg-bubble {
    background: #f1f5f9;
    color: #1e293b;
    border-radius: 4px 16px 16px 16px;
}
.chat-msg.user .chat-msg-bubble {
    background: linear-gradient(135deg, #6B2179, #3A84C5);
    color: #fff;
    border-radius: 16px 4px 16px 16px;
}

/* Avatar dots */
.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-msg.bot .chat-msg-avatar {
    background: linear-gradient(135deg, #6B2179, #3A84C5);
}
.chat-msg.bot .chat-msg-avatar i {
    font-size: 0.8rem;
    color: #fff;
    --fa-primary-color: white;
}
.chat-msg.user .chat-msg-avatar {
    background: #e2e8f0;
}
.chat-msg.user .chat-msg-avatar svg {
    width: 14px;
    height: 14px;
    fill: #64748b;
}

/* Typing indicator */
#chat-typing {
    display: none;
    gap: 8px;
    align-items: flex-end;
}
#chat-typing.is-visible {
    display: flex;
}
#chat-typing-bubble {
    background: #f1f5f9;
    border-radius: 4px 16px 16px 16px;
    padding: 12px 16px;
    display: flex;
    gap: 4px;
    align-items: center;
}
#chat-typing-bubble span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typing 1.3s ease-in-out infinite;
}
#chat-typing-bubble span:nth-child(2) { animation-delay: 0.18s; }
#chat-typing-bubble span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30%            { opacity: 1;   transform: translateY(-4px); }
}

/* Error message */
.chat-msg-error .chat-msg-bubble {
    background: #fef2f2 !important;
    color: #dc2626 !important;
    border: 1px solid #fecaca;
}

/* Footer / Input */
#chat-footer {
    border-top: 1px solid #e2e8f0;
    padding: 12px 14px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: #fff;
}
#chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px 14px;
    font-family: "Montserrat", sans-serif;
    font-size: 0.855rem;
    color: #1e293b;
    background: #f8fafc;
    resize: none;
    outline: none;
    line-height: 1.4;
    min-height: 42px;
    max-height: 100px;
    transition: border-color 0.2s;
    overflow-y: auto;
}
#chat-input:focus {
    border-color: #6B2179;
    background: #fff;
}
#chat-input::placeholder {
    color: #94a3b8;
}
#chat-send {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6B2179, #3A84C5);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.2s;
    outline: none;
}
#chat-send:hover:not(:disabled) {
    transform: scale(1.05);
    opacity: 0.9;
}
#chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
#chat-send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* Rate limit notice */
#chat-limit-notice {
    display: none;
    padding: 8px 14px;
    background: #fffbeb;
    border-top: 1px solid #fde68a;
    font-family: "Montserrat", sans-serif;
    font-size: 0.75rem;
    color: #92400e;
    text-align: center;
    flex-shrink: 0;
}
#chat-limit-notice.is-visible {
    display: block;
}

/* Disclaimer */
#chat-disclaimer {
    padding: 6px 14px 8px;
    font-family: "Montserrat", sans-serif;
    font-size: 0.68rem;
    color: #94a3b8;
    text-align: center;
    flex-shrink: 0;
    line-height: 1.4;
}

/* Mobile */
@media (max-width: 480px) {
    #chat-window {
        right: 10px;
        bottom: 78px;
        width: calc(100vw - 20px);
    }
    #chat-fab {
        right: 12px;
        bottom: 16px;
        width: 46px;
        min-width: 46px;
        height: 46px;
    }
    #chat-fab svg {
        width: 21px;
        height: 21px;
    }
}
