/* Chat Widget Styles */
#chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

#chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    position: relative;
    transition: transform 0.2s ease;
}

#chat-button:hover {
    transform: scale(1.05);
}

#chat-button svg {
    fill: white;
    width: 24px;
    height: 24px;
}

#chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: red;
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 12px;
    display: none;
    min-width: 20px;
    text-align: center;
}

#teaser-bubble {
    position: absolute;
    bottom: 80px;
    right: 0;
    background: white;
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: none;
    width: 240px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#teaser-bubble::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 20px;
    border: 10px solid transparent;
    border-top-color: white;
}

#teaser-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin-right: 8px;
    object-fit: cover;
}

#teaser-text {
    font-size: 14px;
    color: #333;
    line-height: 1.4;
}

#teaser-close {
    position: absolute;
    top: 8px;
    right: 8px;
    cursor: pointer;
    color: #aaa;
    font-size: 20px;
    line-height: 1;
    font-weight: bold;
}

#teaser-close:hover {
    color: #666;
}

#chat-window {
    display: none;
    width: 320px;
    height: 480px;
    border-radius: 16px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    flex-direction: column;
    overflow: hidden;
    animation: slideIn 0.3s ease;
}

#chat-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 12px;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    display: flex;
    align-items: center;
}

#header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 8px;
    object-fit: cover;
}

#header-name {
    font-size: 16px;
    font-weight: bold;
}

#header-response {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 4px;
}

#header-close {
    margin-left: auto;
    cursor: pointer;
    color: white;
    font-size: 24px;
    line-height: 1;
    font-weight: bold;
}

#header-close:hover {
    opacity: 0.8;
}

#chat-messages {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    background: var(--background-color);
}

#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.message {
    display: flex;
    margin-bottom: 12px;
    animation: messageIn 0.2s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bot-message {
    align-items: flex-start;
}

.bot-message .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    margin-right: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.message-text {
    background: #f1f1f1;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.4;
}

.bot-message .message-text {
    background: #f1f1f1;
    color: #333;
}

/* Markdown styles within message text */
.message-text h1,
.message-text h2,
.message-text h3 {
    font-weight: bold;
    margin-top: 0.5em;
    margin-bottom: 0.5em;
    line-height: 1.2;
}

.message-text h1 {
    font-size: 1.5em;
}

.message-text h2 {
    font-size: 1.3em;
}

.message-text h3 {
    font-size: 1.1em;
}

.message-text h1:first-child,
.message-text h2:first-child,
.message-text h3:first-child {
    margin-top: 0;
}

.message-text strong {
    font-weight: bold;
}

.message-text em {
    font-style: italic;
}

.message-text a {
    color: var(--primary-color);
    text-decoration: underline;
}

.message-text a:hover {
    opacity: 0.8;
}

.message-text ul,
.message-text ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message-text ul {
    list-style-type: disc;
}

.message-text ol {
    list-style-type: decimal;
}

.message-text li {
    margin: 0.25em 0;
}

.message-text p {
    margin: 0.5em 0;
}

.message-text p:first-child {
    margin-top: 0;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text code {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

.message-text pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.5em;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.message-text pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
}

.message-text blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 0.75em;
    margin: 0.5em 0;
    color: #666;
}

.message-text hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 0.75em 0;
}

.user-message {
    justify-content: flex-end;
}

.user-message .message-text {
    background: var(--primary-color);
    color: white;
}

#chat-input {
    display: flex;
    padding: 12px;
    border-top: 1px solid #eee;
    background: var(--background-color);
}

#input-field {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
}

#input-field:focus {
    border-color: var(--primary-color);
}

#send-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    margin-left: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: opacity 0.2s ease;
}

#send-button:hover {
    opacity: 0.9;
}

#send-button:active {
    transform: scale(0.98);
}

#powered-by {
    text-align: center;
    font-size: 12px;
    color: #aaa;
    padding: 8px;
    background: var(--background-color);
}

#powered-by a {
    color: #aaa;
    text-decoration: none;
}

#powered-by a:hover {
    text-decoration: underline;
}

/* Position variants */
#chat-widget-container.position-left {
    left: 20px;
    right: auto;
}

#chat-widget-container.position-left #teaser-bubble {
    left: 0;
    right: auto;
}

#chat-widget-container.position-left #teaser-bubble::after {
    left: 20px;
    right: auto;
}

/* Animated typing indicator dots shown while waiting for bot reply */
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #888;
    display: inline-block;
    animation: typingBounce 1.2s infinite ease-in-out;
}

/* Stagger each dot so they bounce in sequence */
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.30s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* Accessibility: respect reduced-motion preference with a gentle fade instead */
@media (prefers-reduced-motion: reduce) {
    .typing-dot {
        animation: typingFade 1.4s infinite ease-in-out;
    }
}

/* Defined at top level (not nested inside @media) for portability across older browsers */
@keyframes typingFade {
    0%, 100% { opacity: 0.3; }
    50%      { opacity: 1; }
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    #chat-window {
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
    }
    
    #chat-header {
        border-radius: 0;
    }
    
    #teaser-bubble {
        max-width: calc(100vw - 100px);
    }
}

