/* Chatbot Widget — aligned with editorial design system */
.chatbot-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Adjust position when sticky footer is visible */
body:has(.sticky-cta-footer.visible) .chatbot-widget {
    bottom: 84px;
}

/* Toggle button — squared ink button */
.chatbot-toggle {
    width: 52px;
    height: 52px;
    border-radius: 3px;
    background: var(--ink, #111111);
    border: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.chatbot-toggle:hover {
    background: var(--accent, #1E4D35);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.chatbot-toggle .chatbot-icon,
.chatbot-toggle .chatbot-close-icon {
    width: 22px;
    height: 22px;
    color: var(--bg, #F6F3EE);
    position: absolute;
    transition: all 0.25s ease;
}

.chatbot-toggle .chatbot-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.chatbot-toggle .chatbot-close-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.8);
}

.chatbot-widget.open .chatbot-toggle {
    background: var(--accent, #1E4D35);
}

.chatbot-widget.open .chatbot-toggle .chatbot-icon {
    opacity: 0;
    transform: rotate(-90deg) scale(0.8);
}

.chatbot-widget.open .chatbot-toggle .chatbot-close-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Chat window */
.chatbot-window {
    position: absolute;
    bottom: 68px;
    right: 0;
    width: 360px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--bg, #F6F3EE);
    border: 1px solid var(--border, #D8D3CD);
    border-radius: 4px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(12px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-widget.open .chatbot-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.chatbot-header {
    padding: 18px 20px;
    background: var(--ink, #111111);
    color: var(--bg, #F6F3EE);
    border-radius: 3px 3px 0 0;
    position: relative;
    flex-shrink: 0;
}

.chatbot-header h3 {
    margin: 0;
    font-family: var(--serif, 'Playfair Display', serif) !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    letter-spacing: -0.01em !important;
    color: var(--bg, #F6F3EE) !important;
}

.chatbot-subtitle {
    margin: 3px 0 0 0;
    font-family: var(--mono, 'JetBrains Mono', monospace);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.55;
    color: var(--bg, #F6F3EE);
}

/* Mobile close button in header */
.chatbot-mobile-close {
    display: none;
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: rgba(246, 243, 238, 0.6);
    cursor: pointer;
    padding: 6px;
    width: 32px;
    height: 32px;
    border-radius: 2px;
    transition: color 0.15s ease, background 0.15s ease;
    display: none;
    align-items: center;
    justify-content: center;
}

.chatbot-mobile-close:hover {
    color: var(--bg, #F6F3EE);
    background: rgba(246, 243, 238, 0.1);
}

.chatbot-mobile-close svg {
    width: 16px;
    height: 16px;
}

/* Message area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-alt, #EDE9E3);
}

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

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

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--border-dark, #B0A9A2);
    border-radius: 2px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--ink-3, #99948F);
}

.chatbot-message {
    display: flex;
    margin-bottom: 4px;
}

.message-content {
    max-width: 82%;
    padding: 10px 14px;
    font-family: var(--sans, 'DM Sans', sans-serif);
    font-size: 0.8125rem;
    line-height: 1.55;
    word-wrap: break-word;
}

/* Bot message bubble */
.bot-message .message-content {
    background: var(--bg, #F6F3EE);
    color: var(--ink, #111111);
    border: 1px solid var(--border, #D8D3CD);
    border-radius: 2px 10px 10px 10px;
}

/* User message bubble */
.user-message {
    justify-content: flex-end;
}

.user-message .message-content {
    background: var(--ink, #111111);
    color: var(--bg, #F6F3EE);
    border-radius: 10px 2px 10px 10px;
}

/* Markdown within messages */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 0.5em 0;
    font-weight: 600;
    line-height: 1.3;
    font-family: var(--serif, 'Playfair Display', serif) !important;
    letter-spacing: -0.01em !important;
}

.message-content h1 { font-size: 1.3em; }
.message-content h2 { font-size: 1.15em; }
.message-content h3 { font-size: 1em; }

.message-content p {
    margin: 0.4em 0;
}

.message-content p:first-child { margin-top: 0; }
.message-content p:last-child  { margin-bottom: 0; }

.message-content ul,
.message-content ol {
    margin: 0.4em 0;
    padding-left: 1.4em;
}

.message-content li {
    margin: 0.2em 0;
}

.message-content strong { font-weight: 600; }
.message-content em     { font-style: italic; }

.message-content code {
    background: var(--bg-alt, #EDE9E3);
    padding: 0.15em 0.35em;
    border-radius: 2px;
    font-family: var(--mono, 'JetBrains Mono', monospace);
    font-size: 0.85em;
    color: var(--accent, #1E4D35);
}

.user-message .message-content code {
    background: rgba(246, 243, 238, 0.15);
    color: var(--bg, #F6F3EE);
}

.message-content pre {
    background: var(--bg-alt, #EDE9E3);
    padding: 0.75em;
    border-radius: 2px;
    overflow-x: auto;
    margin: 0.5em 0;
    border-left: 2px solid var(--accent, #1E4D35);
}

.message-content pre code {
    background: transparent;
    padding: 0;
}

.message-content a {
    color: var(--accent, #1E4D35);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.message-content blockquote {
    border-left: 2px solid var(--border-dark, #B0A9A2);
    padding-left: 1em;
    margin: 0.5em 0;
    color: var(--ink-2, #57524D);
}

/* Input area */
.chatbot-input-container {
    display: flex;
    gap: 8px;
    padding: 14px 16px;
    background: var(--bg, #F6F3EE);
    border-top: 1px solid var(--border, #D8D3CD);
    border-radius: 0 0 3px 3px;
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border, #D8D3CD);
    border-radius: 2px;
    font-family: var(--sans, 'DM Sans', sans-serif);
    font-size: 0.8125rem;
    background: var(--bg, #F6F3EE);
    color: var(--ink, #111111);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chatbot-input::placeholder {
    color: var(--ink-3, #99948F);
    font-family: var(--mono, 'JetBrains Mono', monospace);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}

.chatbot-input:focus {
    border-color: var(--ink, #111111);
    box-shadow: 0 0 0 2px rgba(17, 17, 17, 0.07);
}

/* Send button */
.chatbot-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 2px;
    background: var(--ink, #111111);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
    flex-shrink: 0;
}

.chatbot-send-btn:hover {
    background: var(--accent, #1E4D35);
    transform: translateY(-1px);
}

.chatbot-send-btn svg {
    width: 16px;
    height: 16px;
    color: var(--bg, #F6F3EE);
}

/* Typing indicator */
.typing-indicator .message-content {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-items: center;
}

.typing-indicator .message-content span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-3, #99948F);
    animation: typing 1.4s infinite;
}

.typing-indicator .message-content span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator .message-content span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Fade in animation for messages */
.fade-in-message {
    animation: fadeInUp 0.25s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile */
@media (max-width: 640px) {
    .chatbot-window {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        max-height: none;
        right: -12px;
    }

    .chatbot-widget {
        bottom: 16px;
        right: 16px;
    }

    .chatbot-mobile-close {
        display: flex;
    }

    body:has(.sticky-cta-footer.visible) .chatbot-widget {
        bottom: 140px;
    }
}
