/* ============================================================
   Maurice Chatbot Widget — ONPhI
   Palette: red #f56a6a, text #3d4449, background #f5f6f7
   ============================================================ */

:root {
    --cb-red:        #f56a6a;
    --cb-red-hover:  #f67878;
    --cb-red-dark:   #f45c5c;
    --cb-dark:       #3d4449;
    --cb-muted:      #7f888f;
    --cb-light:      #f5f6f7;
    --cb-border:     rgba(210, 215, 217, 0.75);
    --cb-white:      #ffffff;
    --cb-radius:     14px;
}

/* --- Floating toggle button --- */
#chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--cb-red);
    color: var(--cb-white);
    border: none;
    cursor: pointer;
    z-index: 9998;
    box-shadow: 0 4px 16px rgba(245, 106, 106, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

#chatbot-toggle:hover {
    background: var(--cb-red-hover);
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(245, 106, 106, 0.55);
}

#chatbot-toggle:active {
    background: var(--cb-red-dark);
    transform: scale(0.96);
}

#chatbot-toggle .icon-chat,
#chatbot-toggle .icon-close {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    transition: opacity 0.2s ease;
    line-height: 1;
    color: #ffffff !important;
}

#chatbot-toggle .icon-chat i,
#chatbot-toggle .icon-close i {
    color: #ffffff !important;
}

#chatbot-toggle .icon-close {
    display: none;
}

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

#chatbot-toggle.is-open .icon-close {
    display: flex;
}

/* --- Main panel --- */
#chatbot-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: var(--cb-white);
    border-radius: var(--cb-radius);
    box-shadow: 0 8px 32px rgba(61, 68, 73, 0.18);
    border: solid 1px var(--cb-border);
    z-index: 9997;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(12px);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

#chatbot-panel.is-visible {
    display: flex;
}

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

/* --- Header --- */
#chatbot-header {
    background: var(--cb-red);
    color: var(--cb-white);
    padding: 13px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--cb-radius) var(--cb-radius) 0 0;
    flex-shrink: 0;
    border-bottom: solid 3px var(--cb-red-dark);
}

#chatbot-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--cb-white);
}

#chatbot-header .chatbot-subtitle {
    font-size: 0.72rem;
    opacity: 0.85;
    margin-top: 2px;
    color: var(--cb-white);
}

#chatbot-exchanges-badge {
    background: rgba(255, 255, 255, 0.25);
    border: solid 1px rgba(255, 255, 255, 0.4);
    font-size: 0.72rem;
    padding: 3px 9px;
    border-radius: 20px;
    white-space: nowrap;
    color: var(--cb-white);
}

/* --- Message area --- */
#chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    background: var(--cb-light);
}

#chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

#chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--cb-border);
    border-radius: 2px;
}

/* --- Message bubbles --- */
.chatbot-msg {
    max-width: 85%;
    padding: 10px 13px;
    border-radius: var(--cb-radius);
    font-size: 0.875rem;
    line-height: 1.55;
    word-break: break-word;
    animation: chatbot-fadein 0.2s ease;
}

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

.chatbot-msg.user {
    align-self: flex-end;
    background: var(--cb-red);
    color: var(--cb-white);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 6px rgba(245, 106, 106, 0.3);
}

.chatbot-msg.assistant {
    align-self: flex-start;
    background: var(--cb-white);
    color: var(--cb-dark);
    border: solid 1px var(--cb-border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(61, 68, 73, 0.06);
}

/* Credit-status indicator on the welcome bubble */
.chatbot-msg.assistant.credit-ok {
    border-color: #4caf50;
    box-shadow: 0 1px 4px rgba(76, 175, 80, 0.18);
}

.chatbot-msg.assistant.credit-none {
    border-color: #f44336;
    box-shadow: 0 1px 4px rgba(244, 67, 54, 0.18);
}

.chatbot-msg.system-info {
    align-self: center;
    background: transparent;
    color: var(--cb-muted);
    font-size: 0.78rem;
    text-align: center;
    padding: 4px 10px;
    border: none;
}

.chatbot-msg.error {
    align-self: center;
    background: rgba(245, 106, 106, 0.08);
    color: var(--cb-red-dark);
    border: solid 1px rgba(245, 106, 106, 0.3);
    font-size: 0.82rem;
    text-align: center;
    max-width: 95%;
    border-radius: 8px;
}

/* --- Typing indicator --- */
.chatbot-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
}

.chatbot-typing span {
    width: 7px;
    height: 7px;
    background: var(--cb-red);
    border-radius: 50%;
    opacity: 0.6;
    animation: chatbot-bounce 1.2s infinite ease-in-out;
}

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

@keyframes chatbot-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
    40%            { transform: scale(1);   opacity: 1;   }
}

/* --- Footer (input area) --- */
#chatbot-footer {
    padding: 10px 12px;
    background: var(--cb-white);
    border-top: solid 1px var(--cb-border);
    flex-shrink: 0;
}

#chatbot-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#chatbot-input {
    flex: 1;
    border: solid 1px var(--cb-border);
    border-radius: 22px;
    padding: 9px 14px;
    font-size: 0.875rem;
    outline: none;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.4;
    color: var(--cb-dark);
    background: var(--cb-white);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
}

#chatbot-input:focus {
    border-color: var(--cb-red);
    box-shadow: 0 0 0 1px var(--cb-red);
}

#chatbot-input::placeholder {
    color: var(--cb-muted);
}

#chatbot-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--cb-red);
    color: var(--cb-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 2px var(--cb-red);
    transition: background 0.15s ease, transform 0.1s ease;
}

#chatbot-send:hover {
    background: var(--cb-red-hover);
}

#chatbot-send:active {
    transform: scale(0.93);
    background: var(--cb-red-dark);
}

#chatbot-send:disabled {
    background: var(--cb-border);
    box-shadow: none;
    cursor: not-allowed;
}

#chatbot-send i {
    font-size: 15px;
    color: var(--cb-white);
}

/* --- Quota exhausted message --- */
#chatbot-quota-msg {
    text-align: center;
    font-size: 0.78rem;
    color: var(--cb-muted);
    padding: 6px 0 2px;
}

/* --- "Support Maurice" bar --- */
#chatbot-contribute-bar {
    text-align: center;
    padding: 6px 0 2px;
    border-top: 1px solid var(--cb-border);
    margin-top: 4px;
}

#chatbot-contribute-link {
    font-size: 0.75rem;
    color: var(--cb-muted);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

#chatbot-contribute-link:hover {
    opacity: 1;
    color: var(--cb-primary);
}

/* --- Mobile responsive --- */
@media (max-width: 420px) {
    #chatbot-panel {
        right: 12px;
        bottom: 80px;
        width: calc(100vw - 24px);
    }

    #chatbot-toggle {
        right: 12px;
        bottom: 12px;
    }
}
