/* Caminho: /assets/css/blog/chat-ui-enhancements.css */
/* FASE 26 (Revisão): Corrigido o seletor para ocultar o botão de toggle no desktop. */

#ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

#ai-chat-widget .chat-suggestion-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin-top: auto;
}

#ai-chat-widget .suggestion-btn {
    background-color: rgba(0, 0, 0, 0.05);
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-align: left;
}

#ai-chat-widget .suggestion-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.4);
    color: #000;
}

#ai-chat-widget .typing-indicator {
    display: flex;
    align-items: center;
    padding: 10px 0;
}

#ai-chat-widget .typing-indicator .dot {
    width: 8px;
    height: 8px;
    margin: 0 2px;
    background-color: #aaa;
    border-radius: 50%;
    animation: bounce 1.3s infinite ease-in-out;
}

#ai-chat-widget .typing-indicator .dot:nth-of-type(2) {
    animation-delay: -1.1s;
}

#ai-chat-widget .typing-indicator .dot:nth-of-type(3) {
    animation-delay: -0.9s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1.0);
    }
}

#ai-chat-widget #chat-form button[type="submit"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#ai-chat-widget #chat-form button[type="submit"] .bi-arrow-right {
    display: block;
}

#ai-chat-widget #chat-form button[type="submit"].loading .bi-arrow-right {
    display: none;
}

#ai-chat-widget #chat-form button[type="submit"].loading::after {
    content: '';
    display: block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#ai-chat-widget pre:has(code[class*="language-"]) {
    background: #2d2d2d !important;
    color: #f8f8f2 !important;
    padding: 1em !important;
    margin: .5em 0 !important;
    overflow: auto !important;
    border-radius: 0.3em !important;
    border: none !important;
    text-shadow: none !important;
}

#ai-chat-widget pre:has(code[class*="language-"]) code,
#ai-chat-widget pre:has(code[class*="language-"]) span {
    color: inherit !important;
    background: none !important;
    text-shadow: none !important;
}

#ai-chat-widget .code-block-wrapper {
    position: relative;
}

#ai-chat-widget .copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.8rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    z-index: 1;
}

#ai-chat-widget .code-block-wrapper:hover .copy-code-btn {
    opacity: 1;
}

#ai-chat-widget .copy-code-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

#ai-chat-widget .copy-code-btn.copied {
    background-color: #28a745;
    color: #fff;
}

#chat-window {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(var(--vh, 1vh) * 100);
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    border: 1px solid var(--bs-border-color);
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1010;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    font-size: clamp(0.9rem, 2.5vw, 1.05rem);
}

#chat-window.hidden {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
}

#chat-window #chat-header {
    flex-shrink: 0;
    background-color: #333;
    color: var(--bs-light);
    padding: 0.50rem 0.50rem;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-toggle-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1050;
}

#chat-toggle-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    transition: transform 0.2s ease-in-out;
    background-color: var(--bs-primary);
    color: white;
    border: none;
    cursor: pointer;
}

#chat-toggle-button:hover {
    transform: scale(1.1);
}

.chat-is-open #chat-toggle-button {
    display: none;
}

#chat-header-buttons {
    display: flex;
    gap: 0.5rem;
}

#chat-window #chat-main {
    flex: 1;
    overflow-y: scroll;
    padding: 0.50rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background-color: #f8f9fa;
    min-height: 0;
    white-space: wrap;
    word-break: break-word;
}

#chat-footer {
    flex-shrink: 0;
    padding: 0.75rem;
    border-top: 1px solid var(--bs-border-color);
    background-color: var(--bs-body-bg);
}

#chat-form {
    display: flex;
    align-items: center;
}

.chat-message {
    padding: 0.5rem 0.75rem;
    border-radius: 18px;
    max-width: 90%;
    line-height: 1.4;
    word-wrap: break-word;
}

.user-message {
    background-color: var(--bs-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    font-size: clamp(0.9rem, 2.5vw, 1.05rem);
}

.ai-message {
    background-color: #e9ecef;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    font-size: clamp(0.9rem, 2.5vw, 1.05rem);
}

.chat-message p,
.chat-message ul,
.chat-message li {
    font-size: clamp(0.9rem, 2.5vw, 1.05rem);
    margin-top: 10px;
    margin-bottom: 10px;
    line-height: 1.4;
}

.chat-message ul {
    padding-left: 1rem;
}

.chat-message a {
    color: rgb(13, 110, 253);
    text-decoration: underline;
    cursor: pointer;
    font-size: clamp(0.9rem, 2.5vw, 1.05rem);
    line-height: 1.4;
}

#chat-input,
#chat-form button {
    height: 44px;
}

#chat-input {
    flex-grow: 1;
    border-radius: 22px;
    margin-right: 0.5rem;
}

#chat-input:focus {
    border-color: var(--bs-primary);
}

#chat-form button {
    background-color: var(--bs-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fade-in-slide-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#ai-chat-widget .message-enter-active {
    animation: fade-in-slide-up 0.3s ease-out forwards;
}

#chat-window.is-dragging {
    transition: none;
}

@media (min-width: 768px) {
    #chat-window {
        position: absolute;
        top: auto;
        left: auto;
        bottom: 20px;
        right: 8px;
        width: 400px;
        height: 600px;
        border-radius: 8px;
    }
    #chat-window.maximized {
        position: fixed;
        width: 45%;
        height: 90%;

    }

    /* Oculta o botão flutuante (não o container) quando o chat está aberto no desktop */
    .body-chat-open #chat-toggle-button {
        display: none;
    }
}