/* ============================================================= */
/* LAUNCHER BUTTON                                                */
/* ============================================================= */
#chat-toggle {
    position: fixed;
    bottom: 30px;
    right: 30px;
    height: 60px;
    width: 60px;
    background: #333333;
    border-radius: 30px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    cursor: pointer;
    z-index: 9999;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: none;
    user-select: none;
    padding: 0;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25), 0 0 12px rgba(255, 255, 255, 0.3);
    overflow: hidden;
}

#chat-toggle:hover {
    width: 210px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 20px rgba(255, 255, 255, 0.6);
}

#chat-toggle .toggle-text {
    white-space: nowrap;
    color: #ffffff;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateX(10px);
    transition: all 0.3s ease;
    padding-left: 20px;
    padding-right: 10px;
    pointer-events: none;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#chat-toggle:hover .toggle-text {
    opacity: 1;
    transform: translateX(0);
}

#chat-toggle .toggle-icon {
    width: 60px;
    height: 60px;
    background: #111111;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    pointer-events: none;
}

#chat-toggle .toggle-icon img {
    width: 95%;
    height: 95%;
    object-fit: contain;
    display: block;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#chat-toggle:not(.open):hover .toggle-icon img {
    transform: scale(1.15) rotate(-8deg);
}

#chat-toggle:active .toggle-icon img {
    transform: scale(0.95);
}

#chat-toggle .close-icon {
    font-size: 24px;
    color: #ffffff !important;
    font-weight: 300;
    pointer-events: none;
    display: none;
    line-height: 1;
    width: 60px;
    height: 60px;
    align-items: center;
    justify-content: center;
    background: #111111;
    border-radius: 50%;
}

#chat-toggle.open {
    width: 60px !important;
    background: #111111;
    justify-content: center;
}

#chat-toggle.open .toggle-icon,
#chat-toggle.open .toggle-text { display: none !important; }

#chat-toggle.open .close-icon { display: flex !important; }

/* ============================================================= */
/* CHAT WINDOW                                                    */
/* ============================================================= */
#chat-window {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 390px;
    height: 540px;
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    z-index: 998;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.92); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

#chat-header {
    background: linear-gradient(135deg, #000000 0%, #1a1a1a 60%, #2c2c2c 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    transition: background 0.3s ease;
}

#chat-header.is-offline {
    background: linear-gradient(135deg, #333333 0%, #555555 100%);
}

#chat-header .info { display: flex; align-items: center; gap: 14px; }

#chat-header .avatar {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
#chat-header .avatar img { width: 100%; height: 100%; object-fit: contain; display: block; }
#chat-header h3 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.3px; }
#chat-header .sub {
    font-size: 12px; opacity: 0.85; font-weight: 400;
    display: inline-flex; align-items: center; gap: 4px; margin-top: 2px;
}

#chat-status.status-online  { display: none; }
#chat-status.status-offline { color: #fca5a5; display: inline-flex; }

#chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message-row { display: flex; align-items: flex-end; gap: 8px; max-width: 85%; }
.message-row.user-row { margin-left: auto; justify-content: flex-end; }
.message-row.bot-row  { margin-right: auto; }

.message {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
    animation: messageIn 0.25s ease-out;
}
@keyframes messageIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.user-message {
    background: #111111;
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.bot-message {
    background: #f1f5f9;
    color: #0f172a;
    border-bottom-left-radius: 4px;
}

.message a { color: #000000; text-decoration: underline; font-weight: 600; word-break: break-all; }
.user-message a { color: #ffffff; text-decoration: underline; }

.typing-indicator-row { display: flex; align-items: flex-end; gap: 8px; }
.typing-indicator {
    background: #f1f5f9;
    padding: 12px 16px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    display: inline-block;
}
.typing-indicator span {
    animation: blink 1.4s infinite both;
    display: inline-block;
    font-size: 16px;
    line-height: 1;
    color: #64748b;
    margin: 0 1px;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
    0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
    40%           { opacity: 1;   transform: scale(1.2); }
}

#chat-input-container {
    display: flex;
    padding: 16px 20px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
    gap: 8px;
    align-items: stretch;
}

#chat-input {
    flex: 1;
    border: 1.5px solid #cbd5e1;
    border-radius: 14px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
    color: #0f172a;
    background: #f8fafc;
    box-sizing: border-box;
}
#chat-input:focus {
    border-color: #000000;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}
#chat-input:disabled { background: #f1f5f9; color: #94a3b8; }

.chat-img-btn {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s, background-color 0.2s;
    flex-shrink: 0;
    border-radius: 12px;
    aspect-ratio: 1 / 1;
    height: auto;
    padding: 0;
    box-sizing: border-box;
}
.chat-img-btn:hover:not(:disabled)  { transform: scale(1.05); opacity: 0.9; }
.chat-img-btn:active:not(:disabled) { transform: scale(0.95); }
.chat-img-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-img-btn svg { display: block; margin: auto; }

#chat-clear { background-color: #111111; border: 1.5px solid #111111; color: #ffffff; }
#chat-send  { background-color: #111111; border: 1.5px solid #111111; color: #ffffff; }
#chat-send svg { transform: translate(-0.5px, 0.5px); }

#chat-messages::-webkit-scrollbar { width: 5px; }
#chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

.bot-message p { margin: 0 0 8px 0; }
.bot-message p:last-child { margin-bottom: 0; }
.bot-message ul, .bot-message ol { margin: 4px 0 8px 0; padding-left: 20px; }
.bot-message li { margin-bottom: 2px; }
.bot-message code { background: #e2e8f0; padding: 2px 5px; border-radius: 4px; font-family: monospace; font-size: 13px; }
.bot-message pre { background: #0f172a; color: #f8fafc; padding: 10px; border-radius: 8px; overflow-x: auto; margin: 6px 0; }
.bot-message pre code { background: transparent; padding: 0; color: inherit; }
.bot-message h1, .bot-message h2, .bot-message h3, .bot-message h4 { margin: 10px 0 4px 0; font-size: 15px; font-weight: 600; }
.bot-message blockquote { border-left: 3px solid #cbd5e1; margin: 6px 0; padding-left: 10px; color: #64748b; }

/* ============================================================= */
/* BODY LOCK (prevents page scroll behind fullscreen chat)        */
/* ============================================================= */
body.chat-mobile-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    top: 0 !important;
    left: 0 !important;
}

/* ============================================================= */
/* MOBILE — True Fullscreen + Smaller Launcher + Top-Right X      */
/* ============================================================= */
@media (max-width: 640px) {
    /* Fullscreen chat window */
    #chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
        max-height: none !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        animation: none !important;
        z-index: 999999 !important;
    }

    #chat-header {
        padding-top: max(16px, calc(env(safe-area-inset-top, 0px) + 12px));
        padding-right: 64px;
        padding-bottom: 16px;
        padding-left: 20px;
    }

    #chat-messages {
        flex: 1;
        overflow-y: auto;
        padding: 16px;
    }

    #chat-input-container {
        padding: 12px 16px;
        padding-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 8px));
        background-color: #fff;
    }

    /* Smaller launcher button, glow kept */
    #chat-toggle {
        bottom: 16px;
        right: 16px;
        height: 48px;
        width: 48px;
        border-radius: 24px;
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25), 0 0 10px rgba(255, 255, 255, 0.35);
        transition: none;
    }
    #chat-toggle:hover {
        width: 48px;
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25), 0 0 10px rgba(255, 255, 255, 0.35);
    }
    #chat-toggle .toggle-text { display: none; }
    #chat-toggle .toggle-icon { width: 48px; height: 48px; }
    #chat-toggle .close-icon  { width: 48px; height: 48px; font-size: 20px; }
    #chat-toggle:not(.open):hover .toggle-icon img { transform: none; }

    /* Close (X) moves to top-right of the fullscreen header */
    #chat-toggle.open {
        position: fixed !important;
        top: max(12px, calc(env(safe-area-inset-top, 0px) + 8px)) !important;
        right: 16px !important;
        bottom: auto !important;
        width: 48px !important;
        height: 48px !important;
        z-index: 1000000 !important;
    }
}
