/* ===========================================================================
   Floating chatbot widget for the portfolio
   Uses the site's CSS variables so it adapts to light/dark theme automatically.
   =========================================================================== */

#chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--main-color-light);
    color: #fff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.3s ease;
}

#chatbot-toggle:hover {
    transform: scale(1.08);
    background: var(--main-color-dark);
}

#chatbot-toggle svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

#chatbot-toggle.is-open svg.chat-icon { display: none; }
#chatbot-toggle svg.close-icon { display: none; }
#chatbot-toggle.is-open svg.close-icon { display: block; }


#chatbot-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: 9999;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 130px);
    background: var(--bg-panel, #EBEBEB);
    color: var(--text-color-dark);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: "Raleway", sans-serif;
    opacity: 0;
    transform: translateY(20px) scale(0.98);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#chatbot-panel.is-open {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

#chatbot-header {
    background: var(--main-color-light);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#chatbot-header .bot-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

#chatbot-header .bot-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-color-2);
    color: var(--main-color-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    overflow: hidden;
    flex-shrink: 0;
}
#chatbot-header .bot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

#chatbot-header .bot-name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.1;
}

#chatbot-header .bot-status {
    font-size: 11px;
    opacity: 0.85;
}

#chatbot-header .header-close {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

#chatbot-header .header-close:hover { background: rgba(255, 255, 255, 0.2); }
#chatbot-header .header-close svg { width: 16px; height: 16px; fill: currentColor; }


#chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg, transparent);
    scrollbar-width: thin;
}

#chatbot-messages::-webkit-scrollbar { width: 6px; }
#chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--grey-color);
    border-radius: 3px;
}

/* Quick question suggestion chips (shown above the input until the
   visitor sends their first message). */
#chatbot-quick-questions {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 0 12px 10px;
    overflow-x: auto;
    scrollbar-width: none;
}
#chatbot-quick-questions::-webkit-scrollbar { display: none; }
#chatbot-quick-questions.is-hidden { display: none; }

.quick-q {
    flex-shrink: 0;
    border: 1px solid var(--main-color-light);
    background: transparent;
    color: var(--main-color-light);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s;
}
.quick-q:hover {
    background: var(--main-color-light);
    color: #fff;
}
.quick-q:active { transform: scale(0.96); }

.chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.45;
    word-wrap: break-word;
    animation: chatFadeIn 0.25s ease;
}

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

.chat-msg.bot {
    align-self: flex-start;
    background: var(--bg-panel-light, #eff0ff);
    color: var(--text-color-dark);
    border-bottom-left-radius: 4px;
}

/* Markdown rendered inside bot messages */
.chat-msg.bot p { margin: 0 0 6px; line-height: 1.4 !important; color: var(--text-color); }
.chat-msg.bot p:last-child { margin-bottom: 0; }
.chat-msg.bot strong { font-weight: 700; }
.chat-msg.bot em { font-style: italic; }
.chat-msg.bot code {
    font-family: "Consolas", "Monaco", monospace;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.08);
    padding: 1px 4px;
    border-radius: 3px;
}
.chat-msg.bot ol,
.chat-msg.bot ul {
    margin: 4px 0 6px;
    padding-left: 20px;
}
.chat-msg.bot ol li,
.chat-msg.bot ul li { margin: 2px 0; }
.chat-msg.bot br + br { display: block; margin-top: 4px; }

.chat-msg.user {
    align-self: flex-end;
    background: var(--main-color-light);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.error {
    align-self: center;
    background: rgba(220, 53, 69, 0.15);
    color: #c0392b;
    font-size: 12px;
    text-align: center;
    max-width: 90%;
}

/* Typing indicator (three bouncing dots) */
.chat-typing {
    align-self: flex-start;
    background: var(--bg-panel-light, #eff0ff);
    padding: 12px 16px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
}
.chat-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--grey-color);
    animation: typingBounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-5px); opacity: 1; }
}


#chatbot-input {
    flex-shrink: 0;
    padding: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--bg-panel, #EBEBEB);
}

#chatbot-text {
    flex: 1;
    border: 1px solid var(--grey-color);
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 13.5px;
    font-family: inherit;
    line-height: 1.4;
    background: var(--bg, #fff);
    color: var(--text-color-dark);
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    /* Hide the scrollbar until the textarea actually overflows (i.e. when
       content exceeds the max height). The JS auto-grow only lets it scroll
       past ~5 lines, so the scrollbar stays hidden for short messages. */
    overflow-y: hidden;
    height: 38px;
    max-height: 110px; /* ~5 lines */
}
/* Once the content grows beyond max-height, show the scrollbar. */
#chatbot-text.is-scrollable { overflow-y: auto; }
#chatbot-text:focus { border-color: var(--main-color-light); }
#chatbot-text::placeholder { color: var(--grey-color); }

#chatbot-send,
#chatbot-mic {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}
#chatbot-send:active, #chatbot-mic:active { transform: scale(0.92); }

#chatbot-send {
    background: var(--main-color-light);
    color: #fff;
}
#chatbot-send:hover { background: var(--main-color-dark); }
#chatbot-send svg { width: 18px; height: 18px; fill: currentColor; }

#chatbot-mic {
    background: var(--bg-panel-light, #eff0ff);
    color: var(--main-color-light);
}
#chatbot-mic:hover { background: var(--accent-color); }
#chatbot-mic svg { width: 18px; height: 18px; fill: currentColor; }

#chatbot-mic.is-recording {
    background: #e74c3c;
    color: #fff;
    animation: micPulse 1.2s infinite;
}
@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.5); }
    50%      { box-shadow: 0 0 0 8px rgba(231, 76, 60, 0); }
}

#chatbot-mic:disabled,
#chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* Small screens: panel goes nearly full-width.
   On notched/Dynamic-Island phones, env(safe-area-inset-*) keeps the panel
   clear of the status bar / home indicator. Requires viewport-fit=cover. */
@media screen and (max-width: 480px) {
    #chatbot-panel {
        right: 8px;
        left: 8px;
        bottom: calc(88px + env(safe-area-inset-bottom, 0px));
        top: calc(env(safe-area-inset-top, 0px) + 8px);
        width: auto;
        height: auto;
    }
    #chatbot-toggle {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }
}
