/* CODA Chatbot */

:root {
    --bh-chat-primary: #4f46e5;
    --bh-chat-primary-dark: #4338ca;
    --bh-chat-accent: #6366f1;
    --bh-chat-primary-rgb: 79, 70, 229;
    --bh-chat-accent-rgb: 99, 102, 241;
    --bh-chat-surface: #ffffff;
    --bh-chat-muted: #64748b;
    --bh-chat-border: #e2e8f0;
    --bh-chat-bg: #f1f5f9;
    --bh-chat-overlay: rgba(15, 23, 42, 0.55);
    --bh-chat-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
    --bh-chat-radius: 20px;
}

body.bh-chatbot-open {
    overflow: hidden;
}

/* Backdrop */
#bh-chat-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: var(--bh-chat-overlay);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
}

#bh-chat-backdrop.open {
    opacity: 1;
    visibility: visible;
}

/* Floating button */
#bh-chatbot-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--bh-chat-primary) 0%, var(--bh-chat-accent) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10000;
    box-shadow: 0 8px 28px rgba(var(--bh-chat-primary-rgb), 0.35);
    transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
    border: none;
    outline: none;
}

#bh-chatbot-button .bh-chatbot-icon {
    width: 30px;
    height: 30px;
    display: block;
    pointer-events: none;
}

#bh-chatbot-button:hover {
    transform: scale(1.06) translateY(-2px);
    box-shadow: 0 12px 32px rgba(var(--bh-chat-primary-rgb), 0.45);
}

#bh-chatbot-button:active {
    transform: scale(1.02);
}

body.bh-chatbot-open #bh-chatbot-button {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.9);
}

/* Chat window */
#bh-chat-window {
    display: none;
    flex-direction: column;
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: min(640px, calc(100vh - 48px));
    max-height: calc(100vh - 48px);
    background: var(--bh-chat-surface);
    border-radius: var(--bh-chat-radius);
    overflow: hidden;
    z-index: 10001;
    box-shadow: var(--bh-chat-shadow);
    border: 1px solid rgba(255, 255, 255, 0.8);
    transform: translateY(16px) scale(0.98);
    opacity: 0;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.28s ease;
}

#bh-chat-window.open {
    display: flex;
    transform: translateY(0) scale(1);
    opacity: 1;
}

#bh-chatbot-button.blocked,
#bh-chat-window.blocked {
    opacity: 0.5;
    cursor: not-allowed !important;
    pointer-events: none;
}

#bh-chat-window.blocked {
    background: #f5f5f5;
}

#bh-chat-window.blocked #bh-user-input {
    background: #e8e8e8;
    cursor: not-allowed;
}

#bh-chat-window.blocked #bh-send-btn {
    background: #cccccc;
    cursor: not-allowed;
    opacity: 0.5;
}

/* Header */
#bh-chat-header {
    background: linear-gradient(135deg, var(--bh-chat-primary) 0%, var(--bh-chat-accent) 100%);
    color: white;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset;
}

#bh-chat-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

#bh-chat-title {
    font-weight: 600;
    font-size: 17px;
    line-height: 1.3;
}

#bh-chat-subtitle {
    font-size: 12px;
    opacity: 0.88;
    font-weight: 400;
}

#bh-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#bh-chat-header button {
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    padding: 0;
    font-family: inherit;
}

#bh-clear-chat {
    height: 34px;
    padding: 0 12px;
}

#bh-close-chat {
    width: 34px;
    height: 34px;
    font-size: 22px;
    line-height: 1;
}

#bh-chat-header button:hover {
    background: rgba(255, 255, 255, 0.28);
}

#bh-close-chat:hover {
    transform: scale(1.05);
}

#bh-chat-window.bh-chat-consent-pending #bh-chat-messages,
#bh-chat-window.bh-chat-consent-pending #bh-chat-input {
    display: none;
}

.bh-chat-consent {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bh-chat-bg);
}

.bh-chat-consent-inner {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.bh-chat-consent-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
}

.bh-chat-consent-intro {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: #334155;
}

.bh-chat-consent-list {
    margin: 0;
    padding-left: 20px;
    font-size: 14px;
    line-height: 1.55;
    color: #334155;
}

.bh-chat-consent-list li + li {
    margin-top: 8px;
}

.bh-chat-consent-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
}

.bh-chat-consent-label input {
    margin-top: 3px;
}

.bh-chat-consent-btn {
    align-self: flex-start;
    background: linear-gradient(135deg, var(--bh-chat-primary) 0%, var(--bh-chat-accent) 100%);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.bh-chat-consent-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.bh-chat-consent-btn:not(:disabled):hover {
    transform: translateY(-1px);
}

/* Messages */
#bh-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bh-chat-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

#bh-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#bh-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#bh-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

#bh-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.user-msg,
.bot-msg {
    max-width: 82%;
    word-wrap: break-word;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    animation: bhMessageSlide 0.3s ease-out;
}

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

.user-msg {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--bh-chat-primary) 0%, var(--bh-chat-accent) 100%);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 14px rgba(var(--bh-chat-primary-rgb), 0.22);
}

.bot-msg {
    align-self: flex-start;
    background: white;
    color: #1e293b;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
    border: 1px solid rgba(226, 232, 240, 0.9);
    opacity: 0;
    animation: bhFadeIn 0.35s ease forwards, bhMessageSlide 0.3s ease-out;
}

@keyframes bhFadeIn {
    to {
        opacity: 1;
    }
}

.bot-msg p {
    margin: 0 0 12px 0;
    line-height: 1.6;
    font-size: 14px;
}

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

.bot-msg a {
    color: var(--bh-chat-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
}

.bot-msg a:hover {
    color: var(--bh-chat-primary-dark);
}

.bot-msg ul,
.bot-msg ol {
    margin: 8px 0 0;
    padding-left: 1.25rem;
}

.bot-msg li {
    margin: 0 0 6px;
    line-height: 1.5;
}

.bot-msg li:last-child {
    margin-bottom: 0;
}

.bh-chat-feedback {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--bh-chat-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bh-chat-feedback-label {
    font-size: 12px;
    color: var(--bh-chat-muted);
    font-weight: 600;
}

.bh-chat-feedback-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bh-chat-feedback-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--bh-chat-border);
    border-radius: 999px;
    background: #f8fafc;
    color: #334155;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.bh-chat-feedback-btn:hover {
    background: #eef2ff;
    border-color: #c7d2fe;
}

.bh-chat-feedback-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.bh-chat-feedback-thanks {
    font-size: 12px;
    color: #15803d;
    font-weight: 600;
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
    border: 1px solid rgba(226, 232, 240, 0.9);
    align-self: flex-start;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    animation: bhTyping 1.4s infinite;
}

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

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

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

/* Input */
#bh-chat-input {
    display: flex;
    align-items: center;
    padding: 16px;
    background: white;
    border-top: 1px solid var(--bh-chat-border);
    gap: 10px;
}

#bh-user-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--bh-chat-border);
    border-radius: 999px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
    background: #fafafa;
}

#bh-user-input:focus {
    border-color: var(--bh-chat-accent);
    box-shadow: 0 0 0 3px rgba(var(--bh-chat-accent-rgb), 0.15);
    background: white;
}

#bh-user-input::placeholder {
    color: var(--bh-chat-muted);
}

#bh-send-btn {
    background: linear-gradient(135deg, var(--bh-chat-primary) 0%, var(--bh-chat-accent) 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 14px rgba(var(--bh-chat-primary-rgb), 0.25);
    outline: none;
    font-family: inherit;
}

#bh-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(var(--bh-chat-primary-rgb), 0.32);
}

#bh-send-btn:active {
    transform: translateY(0);
}

#bh-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Mobile */
@media (max-width: 480px) {
    #bh-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: min(92vh, 100dvh);
        max-height: 92dvh;
        border-radius: 20px 20px 0 0;
    }

    #bh-chatbot-button {
        bottom: 20px;
        right: 20px;
    }
}

.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
    #bh-chat-backdrop,
    #bh-chat-window,
    #bh-chatbot-button,
    .user-msg,
    .bot-msg {
        transition: none;
        animation: none;
    }

    .bot-msg {
        opacity: 1;
    }
}
