/* ============================================
   TWT AI ASSISTANT - CHAT WIDGET
   ============================================ */

.twt-ai-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ---- Toggle Button ---- */
.twt-ai-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2E7D32, #1B5E20);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 20px rgba(46, 125, 50, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.twt-ai-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(46, 125, 50, 0.5);
}

.twt-ai-toggle__pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(46, 125, 50, 0.3);
    animation: twt-ai-pulse 2s ease-out infinite;
}

@keyframes twt-ai-pulse {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ---- Chat Window ---- */
.twt-ai-chat {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    max-height: 550px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: twt-ai-slideUp 0.3s ease;
}

@keyframes twt-ai-slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Header ---- */
.twt-ai-chat__header {
    background: linear-gradient(135deg, #5C4033, #3E2A22);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.twt-ai-chat__header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.twt-ai-chat__avatar {
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.twt-ai-chat__name {
    font-weight: 600;
    font-size: 0.95rem;
}

.twt-ai-chat__status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    opacity: 0.85;
}

.twt-ai-chat__status-dot {
    width: 7px;
    height: 7px;
    background: #4CAF50;
    border-radius: 50%;
    display: inline-block;
    animation: twt-ai-blink 2s ease infinite;
}

@keyframes twt-ai-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.twt-ai-chat__minimize {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.twt-ai-chat__minimize:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ---- Messages Area ---- */
.twt-ai-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 250px;
    max-height: 320px;
    background: #FAF8F5;
}

.twt-ai-chat__messages::-webkit-scrollbar {
    width: 4px;
}

.twt-ai-chat__messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* Message Bubbles */
.twt-ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.5;
    word-wrap: break-word;
    animation: twt-ai-fadeIn 0.2s ease;
}

@keyframes twt-ai-fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.twt-ai-msg--bot {
    background: #fff;
    color: #1A1A1A;
    border: 1px solid #E5E7EB;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.twt-ai-msg--user {
    background: linear-gradient(135deg, #2E7D32, #1B5E20);
    color: #fff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

/* Markdown in bot messages */
.twt-ai-msg--bot strong {
    font-weight: 700;
    color: #5C4033;
}

.twt-ai-msg--bot a {
    color: #2E7D32;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: rgba(46, 125, 50, 0.3);
    text-underline-offset: 2px;
}

.twt-ai-msg--bot a:hover {
    text-decoration-color: #2E7D32;
}

/* Typing indicator */
.twt-ai-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
}

.twt-ai-typing span {
    width: 8px;
    height: 8px;
    background: #aaa;
    border-radius: 50%;
    animation: twt-ai-bounce 1.4s ease infinite;
}

.twt-ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.twt-ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes twt-ai-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-8px); }
}

/* ---- Quick Actions ---- */
.twt-ai-chat__quick {
    padding: 8px 16px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    border-top: 1px solid #F3F4F6;
    background: #fff;
}

.twt-ai-quick-btn {
    padding: 5px 12px;
    border: 1px solid #E5E7EB;
    background: #fff;
    border-radius: 20px;
    font-size: 0.75rem;
    color: #5C4033;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.twt-ai-quick-btn:hover {
    background: #2E7D32;
    color: #fff;
    border-color: #2E7D32;
}

/* ---- Input Area ---- */
.twt-ai-chat__input {
    display: flex;
    padding: 12px 16px;
    gap: 8px;
    border-top: 1px solid #E5E7EB;
    background: #fff;
}

.twt-ai-chat__input input {
    flex: 1;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #FAF8F5;
    outline: none;
    transition: border-color 0.2s;
}

.twt-ai-chat__input input:focus {
    border-color: #2E7D32;
    box-shadow: 0 0 0 2px rgba(46, 125, 50, 0.1);
}

.twt-ai-chat__send {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #2E7D32;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.twt-ai-chat__send:hover {
    background: #1B5E20;
}

.twt-ai-chat__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .twt-ai-widget {
        bottom: 16px;
        right: 16px;
    }

    .twt-ai-chat {
        width: calc(100vw - 32px);
        max-height: 70vh;
        bottom: 70px;
        right: 0;
    }

    .twt-ai-toggle {
        width: 52px;
        height: 52px;
    }
}
