/* ===========================================
   Sahan AI Chat Widget - Floating Bubble
   =========================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* Widget Container */
.sahan-ai-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Floating Bubble Button */
.sahan-ai-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00B67A 0%, #00D68F 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 182, 122, 0.4),
                0 0 40px rgba(0, 182, 122, 0.15);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: sahan-ai-bounce-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    position: relative;
    overflow: hidden;
}

.sahan-ai-bubble::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
    border-radius: 50%;
}

.sahan-ai-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 182, 122, 0.5),
                0 0 60px rgba(0, 182, 122, 0.2);
}

.sahan-ai-bubble svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: transform 0.3s ease;
}

.sahan-ai-bubble.active svg.chat-icon { display: none; }
.sahan-ai-bubble.active svg.close-icon { display: block; }
.sahan-ai-bubble:not(.active) svg.chat-icon { display: block; }
.sahan-ai-bubble:not(.active) svg.close-icon { display: none; }

/* Pulse ring animation */
.sahan-ai-bubble::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid rgba(0, 182, 122, 0.6);
    animation: sahan-ai-pulse-ring 2s ease-out infinite;
}

.sahan-ai-bubble.active::after {
    display: none;
}

/* Chat Window */
.sahan-ai-chatbox {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    max-height: 520px;
    background: rgba(0, 20, 30, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 182, 122, 0.15);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
                0 0 40px rgba(0, 182, 122, 0.08);
}

.sahan-ai-chatbox.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.sahan-ai-chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(0, 40, 58, 0.9) 0%, rgba(0, 30, 45, 0.95) 100%);
    border-bottom: 1px solid rgba(0, 182, 122, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sahan-ai-chat-header .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00B67A, #00D68F);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 182, 122, 0.3);
}

.sahan-ai-chat-header .avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
    box-sizing: border-box;
    display: block;
}

/* Header action buttons: voice-reply toggle, open in new tab, reset */
.sahan-ai-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 2px;
}

.sahan-ai-hbtn {
    background: transparent;
    border: none;
    color: #8DA4B8;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    text-decoration: none;
    transition: color .2s ease, background .2s ease;
}

.sahan-ai-hbtn:hover {
    color: #00D68F;
    background: rgba(0, 182, 122, 0.12);
}

.sahan-ai-hbtn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    display: block;
}

/* Speaker icon swaps between on and muted */
#sahan-ai-tts .off-icon { display: none; }
#sahan-ai-tts.muted { color: #5d7185; }
#sahan-ai-tts.muted .on-icon { display: none; }
#sahan-ai-tts.muted .off-icon { display: block; }

.sahan-ai-chat-header .info h4 {
    margin: 0;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.sahan-ai-chat-header .info span {
    color: #00D68F;
    font-size: 11px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sahan-ai-chat-header .info span::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #00D68F;
    border-radius: 50%;
    animation: sahan-ai-status-blink 2s ease-in-out infinite;
}

/* Messages Area */
.sahan-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 280px;
    max-height: 340px;
    scroll-behavior: smooth;
}

.sahan-ai-messages::-webkit-scrollbar {
    width: 4px;
}

.sahan-ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.sahan-ai-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 182, 122, 0.3);
    border-radius: 4px;
}

/* Message Bubble */
.sahan-ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    animation: sahan-ai-msg-in 0.3s ease both;
    word-wrap: break-word;
}

.sahan-ai-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #00B67A, #00A06C);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.sahan-ai-msg.bot {
    align-self: flex-start;
    background: rgba(0, 40, 58, 0.8);
    color: #e0e0e0;
    border: 1px solid rgba(0, 182, 122, 0.1);
    border-bottom-left-radius: 6px;
}

.sahan-ai-msg.bot p {
    margin: 0 0 8px 0;
}

.sahan-ai-msg.bot p:last-child {
    margin-bottom: 0;
}

.sahan-ai-msg.bot a {
    color: #00D68F;
    text-decoration: underline;
}

.sahan-ai-msg.bot code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

/* Typing Indicator */
.sahan-ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
}

.sahan-ai-typing span {
    width: 7px;
    height: 7px;
    background: #00B67A;
    border-radius: 50%;
    animation: sahan-ai-typing-bounce 1.4s ease-in-out infinite;
}

.sahan-ai-typing span:nth-child(2) { animation-delay: 0.16s; }
.sahan-ai-typing span:nth-child(3) { animation-delay: 0.32s; }

/* Input Area */
.sahan-ai-input-area {
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 182, 122, 0.1);
    display: flex;
    gap: 8px;
    align-items: center;
    background: rgba(0, 20, 30, 0.5);
}

.sahan-ai-input-area textarea {
    flex: 1;
    background: rgba(0, 40, 58, 0.6);
    border: 1px solid rgba(0, 182, 122, 0.15);
    border-radius: 12px;
    padding: 10px 14px;
    color: #fff;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 80px;
    min-height: 38px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.sahan-ai-input-area textarea:focus {
    border-color: rgba(0, 182, 122, 0.4);
}

.sahan-ai-input-area textarea::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.sahan-ai-input-area button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.sahan-ai-send-btn {
    background: linear-gradient(135deg, #00B67A, #00D68F);
    color: white;
}

.sahan-ai-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 12px rgba(0, 182, 122, 0.4);
}

.sahan-ai-send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
}

.sahan-ai-voice-btn {
    background: rgba(0, 40, 58, 0.8);
    color: #00D68F;
    border: 1px solid rgba(0, 182, 122, 0.2) !important;
}

.sahan-ai-voice-btn:hover {
    background: rgba(0, 60, 80, 0.8);
}

.sahan-ai-voice-btn.recording {
    background: rgba(255, 50, 50, 0.2);
    border-color: rgba(255, 50, 50, 0.4) !important;
    animation: sahan-ai-pulse-ring 1.5s ease-out infinite;
}

.sahan-ai-voice-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Animations */
@keyframes sahan-ai-bounce-in {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes sahan-ai-pulse-ring {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

@keyframes sahan-ai-msg-in {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes sahan-ai-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

@keyframes sahan-ai-status-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Responsive */
@media (max-width: 480px) {
    .sahan-ai-chatbox {
        width: calc(100vw - 32px);
        right: -8px;
        bottom: 70px;
        max-height: 70vh;
    }
}
