:root {
    /* Nova Paleta baseada na imagem */
    --primary-blue: rgb(30, 62, 161);
    /* #1E3EA1 */
    --primary-dark: rgb(30, 58, 138);
    /* #1E3A8A */
    --light-gray: rgb(249, 250, 251);
    /* #F9FAFB */
    --dark-slate: rgb(31, 41, 55);
    /* #1F2937 - Usado para textos/fundos escuros */

    /* Mapeamento para o Tema */
    --dark-bg: linear-gradient(135deg, var(--dark-slate), #111827);
    /* Fundo com base no chumbo */
    --header-bg: linear-gradient(135deg, var(--primary-blue), var(--primary-dark));
    --user-bubble: linear-gradient(135deg, var(--primary-blue), var(--primary-dark));
    --bot-bubble: #374151;
    /* Um pouco mais claro que o dark-slate para contraste */
    --accent-color: var(--primary-blue);
    --text-light: var(--light-gray);
    --widget-bg: var(--dark-slate);
    --widget-border: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(30, 58, 138, 0.3);
    /* Azul escuro transparente */
    --shadow-color: rgba(30, 62, 161, 0.2);
    --close-button-hover: #EF4444;
    --link-light-blue: #93C5FD;
    --danger-color: #e84a6f;
    --success-color: #28a745;

    --widget-width: 420px;
    --widget-height: 600px;
    --widget-width-expanded: 90vw;
    --widget-height-expanded: 85vh;
    --widget-bottom-margin: 90px;
    --widget-right-margin: 20px;
    --toggle-button-size: 60px;
}

/* === WIDGET CONTAINER === */

#chat-widget-container .chat-widget {
    position: fixed;
    bottom: var(--widget-bottom-margin);
    right: var(--widget-right-margin);
    z-index: 10000;
    font-family: 'Segoe UI', 'Poppins', system-ui, sans-serif;
}

/* Botao Flutuante */
#chat-widget-container .chat-toggle-button {
    width: var(--toggle-button-size);
    height: var(--toggle-button-size);
    background: #ffffff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--shadow-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 2px solid #e0e0e0;
    overflow: hidden;
}

#chat-widget-container .chat-toggle-button img {
    width: 70%;
    height: 70%;
    object-fit: contain;
}

#chat-widget-container .chat-toggle-button:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 25px var(--shadow-color);
}

/* Container Principal do Chat */
#chat-widget-container .chat-container {
    width: var(--widget-width);
    height: var(--widget-height);
    max-height: calc(100vh - 120px);
    background: var(--widget-bg);
    border-radius: 16px;
    box-shadow: 0 10px 40px var(--shadow-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--widget-border);
    position: absolute;
    bottom: calc(var(--toggle-button-size) + 15px);
    right: 0;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
}

#chat-widget-container .chat-container.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
}

/* Modo Expandido */
#chat-widget-container .chat-container.expanded {
    width: var(--widget-width-expanded);
    height: var(--widget-height-expanded);
    max-height: 90vh;
    max-width: 1200px;
    bottom: 5vh;
    right: 5vw;
    border-radius: 20px;
}

/* === HEADER === */

#chat-widget-container .chat-header {
    background: var(--header-bg);
    color: var(--text-light);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--widget-border);
    flex-shrink: 0;
    min-height: 60px;
}

#chat-widget-container .header-content {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#chat-widget-container .chat-header .bot-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 10px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    padding: 4px;
}

#chat-widget-container .chat-header .bot-icon svg {
    width: 100%;
    height: 100%;
}

#chat-widget-container .chat-header .bot-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#chat-widget-container .chat-header .header-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-light);
    white-space: nowrap;
}

#chat-widget-container .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Seletor de Agente */
#chat-widget-container .agent-selector {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: var(--text-light);
    padding: 8px 12px;
    padding-right: 28px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

#chat-widget-container .agent-selector:hover {
    background-color: rgba(255, 255, 255, 0.18);
    border-color: var(--accent-color);
}

#chat-widget-container .agent-selector:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(108, 142, 191, 0.3);
}

#chat-widget-container .agent-selector option {
    background: #1a2236;
    color: var(--text-light);
    padding: 8px;
}

/* Botoes do Header */
#chat-widget-container .header-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-light);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#chat-widget-container .header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

#chat-widget-container .header-btn svg {
    width: 18px;
    height: 18px;
}

/* === CHAT WINDOW === */

#chat-widget-container .chat-window {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(0, 0, 0, 0.15);
}

/* Mensagens */
#chat-widget-container .message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 1.05rem;
    line-height: 1.6;
    animation: messageAppear 0.3s ease-out;
    word-wrap: break-word;
    overflow-wrap: break-word;
    color: #ffffff;
}

#chat-widget-container .user-message {
    background: var(--user-bubble);
    margin-left: auto;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#chat-widget-container .bot-message {
    background: var(--bot-bubble);
    margin-right: auto;
    border-radius: 4px 16px 16px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    gap: 10px;
    align-items: flex-start;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

#chat-widget-container .bot-message .bot-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    overflow: hidden;
    padding: 3px;
}

#chat-widget-container .bot-message .bot-icon svg {
    width: 100%;
    height: 100%;
}

#chat-widget-container .bot-message .bot-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#chat-widget-container .message-content {
    flex: 1;
    overflow: hidden;
    color: #ffffff !important;
    font-weight: 500;
}

#chat-widget-container .message-content * {
    color: #ffffff !important;
}

#chat-widget-container .message-content p {
    margin: 0 0 0.5em 0;
    line-height: 1.6;
    color: #ffffff !important;
}

#chat-widget-container .message-content p:last-child {
    margin-bottom: 0;
}

#chat-widget-container .message-content a {
    color: #7CB9E8 !important;
    text-decoration: underline !important;
}

#chat-widget-container .message-content a:hover {
    color: #A3D4FF !important;
}

#chat-widget-container .message-content pre {
    white-space: pre-wrap;
    background: rgba(0, 0, 0, 0.35);
    padding: 10px;
    border-radius: 6px;
    margin: 8px 0;
    font-size: 0.9rem;
    color: #ffffff !important;
}

#chat-widget-container .message-content code {
    background: rgba(0, 0, 0, 0.25);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #ffffff !important;
}

#chat-widget-container .message-content ul,
#chat-widget-container .message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
    color: #ffffff !important;
}

#chat-widget-container .message-content li {
    margin-bottom: 0.3em;
    color: #ffffff !important;
}

/* Typing Indicator */
#chat-widget-container .typing-message {
    background: var(--bot-bubble);
    min-height: 50px;
}

#chat-widget-container .typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 0;
}

#chat-widget-container .typing-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

#chat-widget-container .typing-dot:nth-child(1) {
    animation-delay: 0s;
}

#chat-widget-container .typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

#chat-widget-container .typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* === INPUT AREA === */

#chat-widget-container .input-area {
    display: flex;
    flex-direction: column;
    padding: 12px;
    background: rgba(0, 0, 0, 0.25);
    border-top: 1px solid var(--widget-border);
    gap: 10px;
    flex-shrink: 0;
}

/* Preview de Imagem */
#chat-widget-container .image-preview-container {
    display: none;
    position: relative;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 8px;
    max-width: 150px;
}

#chat-widget-container .image-preview-container.active {
    display: block;
}

#chat-widget-container .image-preview {
    max-width: 100%;
    max-height: 100px;
    border-radius: 8px;
    display: block;
}

#chat-widget-container .image-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--danger-color);
    border: none;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s ease;
    padding: 0;
}

#chat-widget-container .image-preview-remove:hover {
    background: #FF5C77;
    transform: scale(1.1);
}

#chat-widget-container .image-preview-remove svg {
    width: 12px;
    height: 12px;
}

/* Indicador de Gravacao */
#chat-widget-container .recording-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(232, 74, 111, 0.15);
    border: 1px solid rgba(232, 74, 111, 0.3);
    border-radius: 10px;
    color: #FF5C77;
    font-size: 0.85rem;
}

#chat-widget-container .recording-indicator.active {
    display: flex;
}

#chat-widget-container .recording-dot {
    width: 10px;
    height: 10px;
    background: var(--danger-color);
    border-radius: 50%;
    animation: pulse 1s infinite;
}

/* Linha de Input */
#chat-widget-container .input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Grupo de Botoes */
#chat-widget-container .input-buttons-left {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* Textarea */
#chat-widget-container .input-area textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--widget-border);
    border-radius: 24px;
    font-size: 0.95rem;
    line-height: 1.4;
    transition: all 0.2s ease;
    background: var(--input-bg);
    color: var(--text-light);
    resize: none;
    overflow-y: hidden;
    height: auto;
    min-height: 44px;
    max-height: 120px;
    box-sizing: border-box;
    font-family: inherit;
}

#chat-widget-container .input-area textarea::placeholder {
    color: rgba(240, 244, 249, 0.5);
}

#chat-widget-container .input-area textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(108, 142, 191, 0.25);
    background: rgba(255, 255, 255, 0.1);
}

/* Botoes de Acao */
#chat-widget-container .input-area button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
    padding: 0;
}

#chat-widget-container .input-area button svg {
    width: 18px;
    height: 18px;
}

#chat-widget-container .input-area button:hover {
    transform: scale(1.08);
}

#chat-widget-container .input-area button:active {
    transform: scale(0.95);
}

/* Cores dos Botoes */
#chat-widget-container .clear-button {
    background: var(--danger-color);
}

#chat-widget-container .clear-button:hover {
    background: #FF5C77;
}

#chat-widget-container .copy-button {
    background: #5a6268;
}

#chat-widget-container .copy-button:hover {
    background: #6c757d;
}

#chat-widget-container .copy-button.copied {
    background: var(--success-color) !important;
}

#chat-widget-container .image-button {
    background: #5078b0;
}

#chat-widget-container .image-button:hover {
    background: #6090c8;
}

#chat-widget-container .voice-button {
    background: #7c5cbc;
}

#chat-widget-container .voice-button:hover {
    background: #9070d0;
}

#chat-widget-container .voice-button.recording {
    background: var(--danger-color) !important;
    animation: pulse 1s infinite;
}

#chat-widget-container .send-button {
    background: var(--accent-color);
    width: 44px;
    height: 44px;
}

#chat-widget-container .send-button:hover {
    background: #7a9ccf;
}

#chat-widget-container .send-button svg {
    width: 20px;
    height: 20px;
}

/* === KEYFRAMES === */

@keyframes messageAppear {
    from {
        transform: translateY(10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* === SCROLLBAR === */

#chat-widget-container .chat-window::-webkit-scrollbar {
    width: 6px;
}

#chat-widget-container .chat-window::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

#chat-widget-container .chat-window::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 3px;
}

#chat-widget-container .chat-window::-webkit-scrollbar-thumb:hover {
    background: var(--link-light-blue);
}

/* === RESPONSIVIDADE === */

@media (max-width: 480px) {
    #chat-widget-container .chat-container {
        width: calc(100vw - 16px);
        height: 80vh;
        max-height: calc(100vh - 100px);
        bottom: 75px;
        right: 8px;
        border-radius: 16px;
    }

    #chat-widget-container .chat-container.expanded {
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    #chat-widget-container .chat-widget {
        bottom: 12px;
        right: 12px;
    }

    #chat-widget-container .chat-toggle-button {
        width: 54px;
        height: 54px;
    }

    #chat-widget-container .chat-header {
        padding: 10px 12px;
        gap: 8px;
    }

    #chat-widget-container .agent-selector {
        font-size: 0.75rem;
        padding: 6px 24px 6px 10px;
        max-width: 120px;
    }

    #chat-widget-container .header-btn {
        width: 32px;
        height: 32px;
    }

    #chat-widget-container .message {
        max-width: 90%;
        font-size: 0.9rem;
    }

    #chat-widget-container .input-area button {
        width: 36px;
        height: 36px;
    }

    #chat-widget-container .send-button {
        width: 40px !important;
        height: 40px !important;
    }
}

/* Movidesk Widget Override */
:root {
    --md-widget-visibility: hidden;
}

.md-chat-widget-wrapper {
    visibility: var(--md-widget-visibility) !important;
}

.md-floating-button {
    bottom: 200px !important;
    right: 20px !important;
    z-index: 9999 !important;
}