/**
 * Chatbot Widget — default styling
 *
 * All colors/sizes are exposed as custom properties on .chatbot-widget so a
 * project's own stylesheet can rebrand the widget without touching this file.
 */

.chatbot-widget {
    --chatbot-widget-accent: #2b6cb0;
    --chatbot-widget-accent-contrast: #ffffff;
    --chatbot-widget-bg: #ffffff;
    --chatbot-widget-text: #26282b;
    --chatbot-widget-muted: #6b7280;
    --chatbot-widget-border: #e5e7eb;
    --chatbot-widget-bot-bubble: #f2f4f7;
    --chatbot-widget-radius: 16px;
    --chatbot-widget-gap: 24px;
    --chatbot-widget-z-index: 999999;
    --chatbot-widget-font: inherit;
    --chatbot-widget-message-font-size: 15px;

    position: fixed;
    z-index: var(--chatbot-widget-z-index);
    font-family: var(--chatbot-widget-font);
    font-size: 15px;
    line-height: 1.5;
}

.chatbot-widget[data-position="bottom-right"] { bottom: var(--chatbot-widget-gap); right: var(--chatbot-widget-gap); }
.chatbot-widget[data-position="bottom-left"]  { bottom: var(--chatbot-widget-gap); left: var(--chatbot-widget-gap); }
.chatbot-widget[data-position="top-right"]    { top: var(--chatbot-widget-gap); right: var(--chatbot-widget-gap); }
.chatbot-widget[data-position="top-left"]     { top: var(--chatbot-widget-gap); left: var(--chatbot-widget-gap); }

.chatbot-widget__toggle {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border: 0;
    cursor: pointer;
    background: var(--chatbot-widget-accent);
    color: var(--chatbot-widget-accent-contrast);
    padding: 0;
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    font: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.chatbot-widget__toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

/* Same cascade-origin caveat as the panel below: author CSS's unconditional
   'display: flex' above would otherwise beat the UA's [hidden] rule. */
.chatbot-widget__toggle[hidden] {
    display: none;
}

.chatbot-widget__toggle-icon {
    width: 26px;
    height: 26px;
    flex: 0 0 auto;
    background-color: currentColor;
    -webkit-mask: var(--chatbot-widget-icon, url(../icons/ai.svg)) center / contain no-repeat;
    mask: var(--chatbot-widget-icon, url(../icons/ai.svg)) center / contain no-repeat;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.chatbot-widget__toggle.is-active .chatbot-widget__toggle-icon {
    transform: rotate(90deg);
    opacity: 0.85;
}

.chatbot-widget__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #e53e3e;
    border: 2px solid var(--chatbot-widget-bg);
}

.chatbot-widget__panel {
    position: absolute;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: min(380px, calc(100vw - 2 * var(--chatbot-widget-gap)));
    height: min(560px, calc(100vh - 2 * var(--chatbot-widget-gap)));
    max-height: 80vh;
    background: var(--chatbot-widget-bg);
    color: var(--chatbot-widget-text);
    border-radius: var(--chatbot-widget-radius);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.22);
    opacity: 0;
    transform: scale(0.35);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.chatbot-widget__panel.is-open {
    opacity: 1;
    transform: scale(1);
}

/* Author CSS always wins over the UA stylesheet's [hidden] { display: none }
   regardless of specificity, so the plain 'display: flex' above would keep
   the panel laid out (just invisible via opacity) while hidden is set.
   This restores real display:none for the closed state. */
.chatbot-widget__panel[hidden] {
    display: none;
}

.chatbot-widget[data-position$="right"] .chatbot-widget__panel { right: 0; transform-origin: bottom right; }
.chatbot-widget[data-position$="left"] .chatbot-widget__panel { left: 0; transform-origin: bottom left; }
.chatbot-widget[data-position^="bottom"] .chatbot-widget__panel { bottom: calc(100% + 12px); }
.chatbot-widget[data-position^="top"] .chatbot-widget__panel { top: calc(100% + 12px); }
.chatbot-widget[data-position="top-right"] .chatbot-widget__panel { transform-origin: top right; }
.chatbot-widget[data-position="top-left"] .chatbot-widget__panel { transform-origin: top left; }

@media (prefers-reduced-motion: reduce) {
    .chatbot-widget__panel {
        transition: none;
        transform: none;
    }
}

.chatbot-widget__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    padding: 16px 20px;
    background: var(--chatbot-widget-accent);
    color: var(--chatbot-widget-accent-contrast);
}

.chatbot-widget__header-title {
    font-weight: 700;
}

.chatbot-widget__header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chatbot-widget__font-controls {
    display: flex;
    align-items: center;
    gap: 0;
}

.chatbot-widget__font-btn,
.chatbot-widget__clear,
.chatbot-widget__close {
    -webkit-appearance: none;
    appearance: none;
    border: 0;
    outline: none;
    outline-offset: 2px;
    background: transparent;
    color: inherit;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
}

.chatbot-widget__font-btn {
    display: inline-flex;
    align-items: flex-end;
    justify-content: center;
    width: 22px;
    height: 22px;
    font-family: inherit;
    font-weight: 700;
    opacity: 0.85;
}

.chatbot-widget__font-btn:hover {
    opacity: 1;
}

.chatbot-widget__font-btn--dec {
    font-size: 10px;
}

.chatbot-widget__font-btn--inc {
    font-size: 15px;
}

.chatbot-widget__close:hover,
.chatbot-widget__close:active {
    border: 0;
    outline: none;
    background: transparent;
}

.chatbot-widget__close:focus-visible {
    outline: 2px solid currentColor;
}

.chatbot-widget__clear {
    font-size: 16px;
    opacity: 0.85;
}

.chatbot-widget__clear:hover {
    opacity: 1;
}

.chatbot-widget__close {
    font-size: 22px;
}

.chatbot-widget__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 20px;
}

.chatbot-widget__message {
    display: flex;
}

.chatbot-widget__message--user {
    justify-content: flex-end;
}

.chatbot-widget__message--bot {
    justify-content: flex-start;
}

.chatbot-widget__bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: var(--chatbot-widget-message-font-size);
}

.chatbot-widget__bubble > :first-child {
    margin-top: 0;
}

.chatbot-widget__bubble > :last-child {
    margin-bottom: 0;
}

.chatbot-widget__message--user .chatbot-widget__bubble {
    background: var(--chatbot-widget-accent);
    color: var(--chatbot-widget-accent-contrast);
    border-bottom-right-radius: 4px;
    font-size: calc(var(--chatbot-widget-message-font-size) - 1px);
}

.chatbot-widget__message--bot .chatbot-widget__bubble {
    background: var(--chatbot-widget-bot-bubble);
    color: var(--chatbot-widget-text);
    border-bottom-left-radius: 4px;
}

.chatbot-widget__typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px;
}

.chatbot-widget__typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chatbot-widget-muted);
    animation: chatbot-widget-typing 1s infinite ease-in-out;
}

.chatbot-widget__typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-widget__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatbot-widget-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.chatbot-widget__sources {
    list-style: none;
    margin: 10px 0 0;
    padding: 8px 0 0;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chatbot-widget__sources a {
    font-size: 0.8rem;
    color: inherit;
    opacity: 0.8;
}

.chatbot-widget__suggestions {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    gap: 6px;
    padding: 0 12px 12px;
    flex: 0 0 auto;
}

.chatbot-widget__suggestions[hidden] {
    display: none;
}

.chatbot-widget__suggestion {
    flex: 0 0 auto;
    white-space: nowrap;
    border: 1px solid var(--chatbot-widget-border);
    background: var(--chatbot-widget-bg);
    color: var(--chatbot-widget-accent);
    border-radius: 999px;
    padding: 5px 10px;
    font: inherit;
    font-size: 0.7rem;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chatbot-widget__suggestion:hover {
    background: var(--chatbot-widget-bot-bubble);
    border-color: var(--chatbot-widget-accent);
}

.chatbot-widget__form {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--chatbot-widget-border);
}

.chatbot-widget__input {
    -webkit-appearance: none;
    appearance: none;
    flex: 1 1 auto;
    resize: none;
    max-height: 120px;
    border: 0;
    outline: none;
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    color: var(--chatbot-widget-text);
    background: var(--chatbot-widget-bot-bubble);
}

.chatbot-widget__input:hover {
    border: 0;
    outline: none;
}

.chatbot-widget__input:focus {
    outline: 2px solid var(--chatbot-widget-accent);
    outline-offset: 1px;
}

.chatbot-widget__send {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: var(--chatbot-widget-accent);
    color: var(--chatbot-widget-accent-contrast);
    cursor: pointer;
    font-size: 16px;
}

.chatbot-widget__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-widget__footer {
    flex: 0 0 auto;
    padding: 6px 12px 10px;
    text-align: center;
    font-size: 0.7rem;
    color: var(--chatbot-widget-muted);
}

@media (max-width: 480px) {
    .chatbot-widget__panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }
}
