/* StudioThink AI Chatbot */
.st-chatbot {
    /* Neutral, readable defaults — deliberately NOT inherited from theme
       preset variables, which can resolve to clashing colors/fonts.
       Overridden via inline <style> from admin color settings. */
    --st-bot-accent: #7B695E;
    --st-bot-accent-contrast: #ffffff;
    --st-bot-bg: #ffffff;
    --st-bot-user-bg: #F8F5F2;
    --st-bot-text: #403D3B;
    --st-bot-border: #C3BAB3;
    --st-bot-radius: 14px;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    font-weight: 400;
    font-style: normal;
    color: var(--st-bot-text);
    text-align: left;
}

/* Reset typography on injected elements so the host theme's global tag
   styles (serif headings, oversized links, etc.) can't bleed in. */
.st-chatbot,
.st-chatbot *,
.st-chatbot *::before,
.st-chatbot *::after {
    box-sizing: border-box;
}
.st-chatbot p,
.st-chatbot li,
.st-chatbot ul,
.st-chatbot span,
.st-chatbot div,
.st-chatbot textarea,
.st-chatbot button,
.st-chatbot input,
.st-chatbot a,
.st-chatbot strong,
.st-chatbot em,
.st-chatbot code {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    font-weight: inherit;
    color: inherit;
    text-decoration: none;
    letter-spacing: normal;
    text-transform: none;
}
.st-chatbot strong { font-weight: 700; }
.st-chatbot em { font-style: italic; }
.st-chatbot code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    background: rgba(0, 0, 0, 0.06);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

/* Floating mode */
.st-chatbot--floating {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.st-chatbot__launcher {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--st-bot-accent);
    color: var(--st-bot-accent-contrast) !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s ease;
}
.st-chatbot__launcher:hover { transform: scale(1.06); }

.st-chatbot--floating .st-chatbot__panel {
    width: min(380px, calc(100vw - 40px));
    height: min(560px, calc(100vh - 120px));
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
}
.st-chatbot--floating.st-chatbot--expanded .st-chatbot__panel {
    width: min(640px, calc(100vw - 40px));
    height: min(85vh, 820px);
}

/* Panel (both modes) */
.st-chatbot__panel {
    display: flex;
    flex-direction: column;
    background: var(--st-bot-bg);
    border: 1px solid var(--st-bot-border);
    border-radius: var(--st-bot-radius);
    overflow: hidden;
    transition: width 0.2s ease, height 0.2s ease;
}
.st-chatbot--inline .st-chatbot__panel {
    height: 480px;
    max-width: 640px;
}
.st-chatbot--inline.st-chatbot--expanded .st-chatbot__panel {
    height: 720px;
    max-width: 900px;
}

.st-chatbot__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--st-bot-accent);
    color: var(--st-bot-accent-contrast) !important;
    flex: 0 0 auto;
}
/* Explicit (not inherited) so a host theme's own button/span color rules
   — which can carry higher specificity or !important — can't win. */
.st-chatbot__title {
    font-weight: 600;
    color: var(--st-bot-accent-contrast) !important;
}
.st-chatbot__header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}
.st-chatbot__expand,
.st-chatbot__close {
    background: none;
    border: none;
    color: var(--st-bot-accent-contrast) !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 6px;
    opacity: 0.9;
}
.st-chatbot__expand:hover,
.st-chatbot__close:hover { opacity: 1; background: rgba(255, 255, 255, 0.15); }
.st-chatbot__close { font-size: 22px; line-height: 1; padding: 0 6px; }

.st-chatbot__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--st-bot-bg);
}

.st-chatbot__msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
}
.st-chatbot__msg p { margin: 0 0 0.6em; }
.st-chatbot__msg p:last-child { margin-bottom: 0; }
.st-chatbot__msg ul { margin: 0.4em 0 0.4em 1.2em; padding: 0; }
.st-chatbot__msg li { margin: 0.15em 0; }

.st-chatbot__msg--user {
    align-self: flex-end;
    background: var(--st-bot-user-bg);
    border: 1px solid var(--st-bot-border);
    color: var(--st-bot-text);
    border-bottom-right-radius: 4px;
}
.st-chatbot__msg--user a { color: var(--st-bot-accent); text-decoration: underline; }

.st-chatbot__msg--bot {
    align-self: flex-start;
    background: var(--st-bot-bg);
    border: 1px solid var(--st-bot-border);
    color: var(--st-bot-text);
    border-bottom-left-radius: 4px;
}
.st-chatbot__msg--bot a { color: var(--st-bot-accent); text-decoration: underline; }

.st-chatbot__typing { color: #64748b; font-style: italic; }
.st-chatbot__error { color: #b91c1c; }

.st-chatbot__sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--st-bot-border);
    font-size: 12.5px;
    color: #64748b;
}
.st-chatbot__sources a { color: var(--st-bot-accent); text-decoration: underline; }

/* Suggested follow-up question buttons (own row after a bot message) */
.st-chatbot__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-self: flex-start;
    max-width: 100%;
}
.st-chatbot__suggestion {
    background: var(--st-bot-bg);
    border: 1px solid var(--st-bot-accent);
    color: var(--st-bot-accent);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.st-chatbot__suggestion:hover:not(:disabled) {
    background: var(--st-bot-accent);
    color: var(--st-bot-accent-contrast) !important;
}
.st-chatbot__suggestion:disabled { opacity: 0.5; cursor: default; }

.st-chatbot__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--st-bot-border);
    background: var(--st-bot-bg);
    flex: 0 0 auto;
}
.st-chatbot__input {
    flex: 1;
    resize: none;
    border: none;
    border-bottom: 1px solid var(--st-bot-border);
    border-radius: 0;
    padding: 9px 4px;
    max-height: 120px;
    background: transparent;
    color: var(--st-bot-text);
    transition: border-color 0.15s ease;
}
.st-chatbot__input:focus { outline: none; border-bottom-color: var(--st-bot-accent); }
.st-chatbot__input::placeholder { color: var(--st-bot-border); }

.st-chatbot__send {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border: 1px solid var(--st-bot-accent);
    border-radius: 10px;
    background: var(--st-bot-accent);
    color: var(--st-bot-accent-contrast) !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease, border-radius 0.2s ease;
}
.st-chatbot__send:hover {
    background: var(--st-bot-bg);
    color: var(--st-bot-accent) !important;
    border-radius: 50%;
}

@media (max-width: 480px) {
    /* Expand is disabled on mobile: hide the control, and make the
       expanded state resolve to the exact same dimensions as normal so a
       lingering --expanded class (e.g. carried over via sessionStorage
       from an earlier desktop session on the same browser) has no visual
       effect either. Covers both floating and inline placements. */
    .st-chatbot__expand {
        display: none;
    }

    .st-chatbot--floating { right: 16px; bottom: 16px; }

    .st-chatbot--floating .st-chatbot__panel,
    .st-chatbot--floating.st-chatbot--expanded .st-chatbot__panel {
        width: calc(100vw - 32px);
        max-width: calc(100vw - 32px);
        height: min(70vh, 520px);
    }

    .st-chatbot--inline .st-chatbot__panel,
    .st-chatbot--inline.st-chatbot--expanded .st-chatbot__panel {
        max-width: calc(100vw - 32px);
        height: 480px;
    }
}
