/* Chatbot Widget */
.chatbot-toggle {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--cta-primary);
    color: #fff;
    border: 2px solid #fff;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 9999;
    transition: background-color 0.2s, transform 0.2s;
}
.chatbot-toggle:hover {
    background-color: var(--cta-primary-hover);
    transform: scale(1.05);
}
.chatbot-toggle:not(.active) {
    animation: chatbot-nudge-initial 3s 1, chatbot-nudge 10s 3s infinite;
}

@keyframes chatbot-nudge-initial {
    0%, 95%, 100% { transform: scale(1) rotate(0deg); filter: brightness(1); }
    96% { transform: scale(1.2) rotate(-10deg); filter: brightness(1.4); }
    97% { transform: scale(1.2) rotate(10deg); filter: brightness(1.4); }
    98% { transform: scale(1.2) rotate(-8deg); filter: brightness(1.3); }
    99% { transform: scale(1.1) rotate(5deg); filter: brightness(1.2); }
}
.chatbot-toggle .chatbot-icon-close {
    display: none;
}

@keyframes chatbot-nudge {
    0%, 6%, 100% { transform: scale(1) rotate(0deg); filter: brightness(1); }
    1% { transform: scale(1.2) rotate(-10deg); filter: brightness(1.4); }
    2% { transform: scale(1.2) rotate(10deg); filter: brightness(1.4); }
    3% { transform: scale(1.2) rotate(-8deg); filter: brightness(1.3); }
    4% { transform: scale(1.1) rotate(5deg); filter: brightness(1.2); }
    5% { transform: scale(1) rotate(0deg); filter: brightness(1); }
}
.chatbot-toggle.active .chatbot-icon-open {
    display: none;
}
.chatbot-toggle.active .chatbot-icon-close {
    display: flex;
}

/* Chat window */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 32px;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    z-index: 9998;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.chatbot-window.open {
    display: flex;
}

/* Header */
.chatbot-header {
    background-color: var(--cta-primary);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.chatbot-header-title {
    font-size: 16px;
    font-weight: 600;
}
.chatbot-header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}
.chatbot-header-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.chatbot-header-btn:hover {
    opacity: 1;
}

/* Messages */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chatbot-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px !important;
    line-height: 1.5;
    word-wrap: break-word;
}
.chatbot-msg p, .chatbot-msg li {
    font-size: 14px !important;
}
.chatbot-msg a {
    color: var(--cta-primary);
    text-decoration: underline;
}
.chatbot-msg-bot {
    background-color: #f3f4f6;
    color: var(--text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.chatbot-msg-user {
    background-color: var(--cta-primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.chatbot-msg-user a {
    color: #fff;
}
.chatbot-msg-error {
    background-color: #fef2f2;
    color: #991b1b;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.chatbot-typing {
    align-self: flex-start;
    padding: 10px 14px;
    background-color: #f3f4f6;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    display: none;
    gap: 4px;
    align-items: center;
}
.chatbot-typing.visible {
    display: flex;
}
.chatbot-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #9ca3af;
    animation: chatbot-bounce 1.4s infinite ease-in-out both;
}
.chatbot-typing-dot:nth-child(1) { animation-delay: 0s; }
.chatbot-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.chatbot-input-area {
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}
.chatbot-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
    resize: none;
    font-family: inherit;
    max-height: 80px;
    line-height: 1.4;
}
.chatbot-input:focus {
    border-color: var(--cta-primary);
}
.chatbot-input::placeholder {
    color: #9ca3af;
}
.chatbot-send {
    background-color: var(--cta-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.2s;
}
.chatbot-send:hover {
    background-color: var(--cta-primary-hover);
}
.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Retry button inside error messages */
.chatbot-retry {
    background: none;
    border: 1px solid #991b1b;
    color: #991b1b;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    margin-top: 6px;
    display: inline-block;
}
.chatbot-retry:hover {
    background-color: #991b1b;
    color: #fff;
}

/* Maximized state */
.chatbot-window.maximized {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    z-index: 10000;
}

/* Mobile */
@media (max-width: 768px) {
    .chatbot-toggle {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 50px;
        border-radius: 0;
        font-size: 16px;
        gap: 8px;
        border: none;
    }
    .chatbot-toggle .chatbot-label {
        display: inline;
    }
    .chatbot-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
    .chatbot-toggle.active {
        display: none;
    }
}
@media (min-width: 769px) {
    .chatbot-toggle .chatbot-label {
        display: none;
    }
}
