/* ============================================================
   El Dorado — AI Chatbot widget
   Floating launcher + chat panel. Uses the global design tokens
   defined in style.css (:root).
   ============================================================ */

.chatbot {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1200;
    font-family: 'Inter', system-ui, sans-serif;
    max-width: calc(100vw - 20px);
}

/* ---- Launcher button ---- */
.chatbot__toggle {
    position: relative;
    width: 128px;
    height: 128px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #1a1405;
    font-size: 1.45rem;
    cursor: pointer;
    box-shadow: none;
    transition: transform .2s ease, box-shadow .2s ease;
    display: grid;
    place-items: center;
}
.chatbot__toggle:hover { transform: translateY(-3px) scale(1.04); }

.chatbot__toggle .chatbot__toggle-open,
.chatbot__toggle .chatbot__toggle-close {
    position: absolute;
    transition: opacity .2s ease, transform .2s ease;
}
.chatbot__toggle-open {
    width: 100px;
    height: 100px;
    object-fit: contain;
    filter: drop-shadow(0 10px 18px rgba(212, 175, 55, 0.22));
}
.chatbot__toggle-close {
    font-size: 1.6rem;
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}
.chatbot__toggle-close { opacity: 0; transform: rotate(-90deg) scale(.6); }
.chatbot.is-open .chatbot__toggle-open  { opacity: 0; transform: rotate(90deg) scale(.6); }
.chatbot.is-open .chatbot__toggle-close { opacity: 1; transform: rotate(0) scale(1); }

/* ---- Panel ---- */
.chatbot__panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: min(380px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 120px));
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.98);
    pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
}
.chatbot.is-open .chatbot__panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---- Header ---- */
.chatbot__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    border-bottom: 1px solid var(--line);
}
.chatbot__avatar {
    width: 104px;
    height: 104px;
    border-radius: 50%;
    background: transparent;
    color: #1a1405;
    display: grid;
    place-items: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.chatbot__avatar img {
    width: 104px;
    height: 104px;
    object-fit: contain;
}
.chatbot__title { display: flex; flex-direction: column; line-height: 1.25; }
.chatbot__title strong { font-size: .98rem; color: var(--text); }
.chatbot__title span { font-size: .74rem; color: var(--muted); }

/* ---- Message body ---- */
.chatbot__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
}
.chatbot__msg {
    max-width: 85%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: .9rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.chatbot__msg--bot {
    align-self: flex-start;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
}
.chatbot__msg--user {
    align-self: flex-end;
    background: var(--gold-grad);
    color: #1a1405;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;   /* preserve line breaks the visitor typed */
}

/* inline markdown inside bot replies */
.chatbot__msg--bot strong { color: var(--gold-soft); font-weight: 600; }
.chatbot__msg--bot a { color: var(--gold); text-decoration: underline; }
.chatbot__msg--bot code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .82em;
    background: rgba(97, 214, 255, 0.12);
    border-radius: 5px;
    padding: 1px 5px;
}
/* blinking caret while the reply streams in */
.chatbot__msg--bot.is-streaming::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 1.05em;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--gold);
    animation: chatbot-caret 1s steps(2) infinite;
}
@keyframes chatbot-caret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.chatbot__msg--error {
    align-self: flex-start;
    background: rgba(255, 90, 90, 0.12);
    border: 1px solid rgba(255, 90, 90, 0.35);
    color: #ffb3b3;
}

/* typing dots */
.chatbot__typing { display: inline-flex; gap: 4px; align-items: center; }
.chatbot__typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--muted);
    animation: chatbot-bounce 1.2s infinite ease-in-out;
}
.chatbot__typing span:nth-child(2) { animation-delay: .15s; }
.chatbot__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatbot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ---- Suggestion chips ---- */
.chatbot__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
}
.chatbot__chip {
    font: inherit;
    font-size: .78rem;
    color: var(--gold-soft);
    background: rgba(245, 199, 106, 0.08);
    border: 1px solid var(--line);
    border-radius: 50px;
    padding: 6px 12px;
    cursor: pointer;
    transition: background .2s ease, transform .2s ease;
}
.chatbot__chip:hover { background: rgba(245, 199, 106, 0.16); transform: translateY(-1px); }

/* ---- Input form ---- */
.chatbot__form {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--line);
    background: var(--bg-alt);
}
.chatbot__input {
    flex: 1;
    font: inherit;
    font-size: .9rem;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 50px;
    padding: 10px 16px;
    outline: none;
    transition: border-color .2s ease;
}
.chatbot__input:focus { border-color: var(--gold); }
.chatbot__input::placeholder { color: var(--muted); }
.chatbot__send {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: var(--gold-grad);
    color: #1a1405;
    font-size: 1rem;
    cursor: pointer;
    transition: transform .2s ease, opacity .2s ease;
}
.chatbot__send:hover { transform: scale(1.06); }
.chatbot__send:disabled { opacity: .5; cursor: not-allowed; transform: none; }

@media (max-width: 480px) {
    .chatbot {
        right: max(10px, env(safe-area-inset-right));
        bottom: max(10px, env(safe-area-inset-bottom));
        left: auto;
    }
    .chatbot__toggle {
        width: 72px;
        height: 72px;
    }
    .chatbot__toggle-open {
        width: 60px;
        height: 60px;
    }
    .chatbot__panel {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: calc(88px + env(safe-area-inset-bottom));
        width: auto;
        max-width: none;
        height: min(560px, calc(100vh - 112px - env(safe-area-inset-bottom)));
        max-height: calc(100vh - 112px - env(safe-area-inset-bottom));
        height: min(560px, calc(100dvh - 112px - env(safe-area-inset-bottom)));
        max-height: calc(100dvh - 112px - env(safe-area-inset-bottom));
        border-radius: 20px;
        transform: translateY(20px);
    }
    .chatbot__header {
        padding: 12px 14px;
        gap: 10px;
    }
    .chatbot__avatar {
        width: 54px;
        height: 54px;
    }
    .chatbot__avatar img {
        width: 54px;
        height: 54px;
    }
    .chatbot__body {
        padding: 14px;
    }
    .chatbot__suggestions {
        padding: 0 14px 10px;
    }
    .chatbot__form {
        padding: 10px 12px;
    }
}

@media (max-width: 380px) {
    .chatbot {
        right: max(8px, env(safe-area-inset-right));
        bottom: max(8px, env(safe-area-inset-bottom));
    }
    .chatbot__panel {
        left: 8px;
        right: 8px;
        bottom: calc(82px + env(safe-area-inset-bottom));
        height: calc(100vh - 98px - env(safe-area-inset-bottom));
        max-height: calc(100vh - 98px - env(safe-area-inset-bottom));
        height: calc(100dvh - 98px - env(safe-area-inset-bottom));
        max-height: calc(100dvh - 98px - env(safe-area-inset-bottom));
        border-radius: 18px;
    }
    .chatbot__title strong {
        font-size: .92rem;
    }
    .chatbot__title span {
        font-size: .7rem;
    }
    .chatbot__msg {
        max-width: 92%;
        font-size: .86rem;
    }
    .chatbot__chip {
        font-size: .74rem;
        padding: 6px 10px;
    }
    .chatbot__input {
        padding: 10px 14px;
    }
}
