
/* A2A Chat Widget Styles */
.a2a-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    z-index: 9999;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    transition: all 0.3s ease;
}

.a2a-chat-widget.minimized {
    height: 60px;
}

.a2a-chat-widget.minimized .a2a-chat-container {
    display: none;
}

/* Multi-widget support */
.a2a-chat-widget:not(:first-of-type) {
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
    border: 2px solid #e5e7eb;
}

.a2a-chat-widget:not(:first-of-type).minimized {
    opacity: 0.8;
}

.a2a-chat-widget:not(:first-of-type):hover {
    opacity: 1;
    transform: translateX(-5px);
}

/* Header */
.a2a-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    position: relative;
}

.a2a-chat-title h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.a2a-chat-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.a2a-chat-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.a2a-chat-controls {
    display: flex;
    gap: 8px;
}

.a2a-chat-controls button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.a2a-chat-controls button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Container */
.a2a-chat-container {
    height: 500px;
    display: flex;
    flex-direction: column;
    background: #f9fafb;
}

/* Messages */
.a2a-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
    max-height: 400px;
}

.a2a-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.a2a-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.a2a-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.a2a-message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    animation: messageSlideIn 0.3s ease-out;
}

.a2a-message-user {
    align-items: flex-end;
}

.a2a-message-bot {
    align-items: flex-start;
}

.a2a-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
}

.a2a-message-user .a2a-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.a2a-message-bot .a2a-message-content {
    background: white;
    color: #374151;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 6px;
}

/* Estilos para links nas mensagens do bot */
.a2a-message-content .a2a-link-button {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white !important;
    text-decoration: none;
    padding: 10px 18px;
    border-radius: 25px;
    margin: 6px 4px 6px 0;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    box-shadow: 0 3px 6px rgba(102, 126, 234, 0.3);
    line-height: 1.4;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.a2a-message-content .a2a-link-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(102, 126, 234, 0.4);
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

.a2a-message-content .a2a-link-button:active {
    transform: translateY(0);
    box-shadow: 0 3px 6px rgba(102, 126, 234, 0.3);
}

/* Formatação de texto nas mensagens do bot */
.a2a-message-bot .a2a-message-content {
    line-height: 1.6;
}

.a2a-message-bot .a2a-message-content h2,
.a2a-message-bot .a2a-message-content h3,
.a2a-message-bot .a2a-message-content h4 {
    margin: 16px 0 10px 0;
    color: #1f2937;
    font-weight: 600;
    line-height: 1.3;
}

.a2a-message-bot .a2a-message-content h2:first-child,
.a2a-message-bot .a2a-message-content h3:first-child,
.a2a-message-bot .a2a-message-content h4:first-child {
    margin-top: 0;
}

.a2a-message-bot .a2a-message-content h2 {
    font-size: 18px;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 4px;
}

.a2a-message-bot .a2a-message-content h3 {
    font-size: 16px;
}

.a2a-message-bot .a2a-message-content h4 {
    font-size: 14px;
}

.a2a-message-bot .a2a-message-content strong {
    font-weight: 600;
    color: #1f2937;
}

.a2a-message-bot .a2a-message-content em {
    font-style: italic;
    color: #4b5563;
}

/* Melhor espaçamento para listas */
.a2a-message-bot .a2a-message-content p {
    margin: 8px 0;
}

.a2a-message-bot .a2a-message-content br + br {
    display: block;
    margin: 8px 0;
    content: "";
}

/* Container para grupos de links */
.a2a-message-bot .a2a-message-content .a2a-links-group {
    margin: 12px 0;
    padding: 8px 0;
}

/* Espaçamento melhorado para seções com links */
.a2a-message-bot .a2a-message-content h3 + br,
.a2a-message-bot .a2a-message-content h4 + br {
    display: none;
}

.a2a-message-bot .a2a-message-content h3,
.a2a-message-bot .a2a-message-content h4 {
    margin-bottom: 12px;
}

/* Melhor organização para listas com links */
.a2a-message-bot .a2a-message-content p {
    margin-bottom: 12px;
}

/* Espaçamento específico para links em listas */
.a2a-message-bot .a2a-message-content .a2a-link-button + br {
    margin-bottom: 4px;
}

/* Agrupamento visual de seções */
.a2a-message-bot .a2a-message-content h2 + p,
.a2a-message-bot .a2a-message-content h3 + p,
.a2a-message-bot .a2a-message-content h4 + p {
    margin-top: 8px;
}

/* Melhor espaçamento para texto após links */
.a2a-message-bot .a2a-message-content .a2a-link-button + br + br {
    margin-top: 8px;
    margin-bottom: 8px;
}

/* Seções organizadas de links */
.a2a-message-bot .a2a-message-content .a2a-link-section {
    margin: 10px 0;
    padding: 8px 0;
    border-left: 3px solid #e5e7eb;
    padding-left: 12px;
}

.a2a-message-bot .a2a-message-content .a2a-link-description {
    display: block;
    color: #4b5563;
    font-size: 13px;
    margin-bottom: 6px;
    line-height: 1.4;
}

/* Melhor organização para múltiplos links */
.a2a-message-bot .a2a-message-content .a2a-link-section .a2a-link-button {
    margin-top: 4px;
    margin-bottom: 4px;
}

/* Espaçamento especial para listas numeradas */
.a2a-message-bot .a2a-message-content h3 + .a2a-link-section,
.a2a-message-bot .a2a-message-content h4 + .a2a-link-section {
    margin-top: 8px;
}

/* Destaque visual para seções importantes */
.a2a-message-bot .a2a-message-content .a2a-link-section:hover {
    background-color: #f9fafb;
    border-radius: 6px;
    margin-left: -4px;
    padding-left: 16px;
    transition: all 0.2s ease;
}

.a2a-message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    padding: 0 4px;
}

/* Typing indicator */
.a2a-chat-typing {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.a2a-typing-indicator {
    display: flex;
    gap: 4px;
}

.a2a-typing-indicator span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s ease-in-out infinite both;
}

.a2a-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.a2a-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

.a2a-typing-text {
    font-size: 12px;
    color: #6b7280;
}

/* Form */
.a2a-chat-form {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    background: white;
}

.a2a-chat-input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.a2a-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 44px;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.a2a-chat-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.a2a-chat-send {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.2s;
}

.a2a-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.a2a-chat-send:not(:disabled):hover {
    transform: scale(1.05);
}

/* Actions - Maior especificidade para sobrescrever tema */
.a2a-chat-widget .a2a-chat-actions {
    padding: 12px 20px !important;
    border-top: 1px solid #e5e7eb !important;
    background: white !important;
    display: flex !important;
    gap: 8px !important;
    margin: 0 !important;
}

.a2a-chat-widget .a2a-new-conversation,
.a2a-chat-widget .a2a-view-conversations {
    background: #f3f4f6 !important;
    border: 1px solid #d1d5db !important;
    color: #374151 !important;
    padding: 8px 16px !important;
    border-radius: 8px !important;
    font-size: 12px !important;
    cursor: pointer !important;
    transition: all 0.2s !important;
    flex: 1 !important;
    font-family: inherit !important;
    font-weight: 500 !important;
    text-decoration: none !important;
    outline: none !important;
    box-shadow: none !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    line-height: 1.4 !important;
}

.a2a-chat-widget .a2a-new-conversation:hover,
.a2a-chat-widget .a2a-view-conversations:hover {
    background: #e5e7eb !important;
    border-color: #d1d5db !important;
    color: #374151 !important;
    text-decoration: none !important;
    transform: none !important;
}

.a2a-chat-widget .a2a-view-conversations {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    border-color: #667eea !important;
}

.a2a-chat-widget .a2a-view-conversations:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%) !important;
    color: white !important;
    border-color: #5a67d8 !important;
}

/* Reset de estilos que podem vir do tema */
.a2a-chat-widget .a2a-new-conversation:focus,
.a2a-chat-widget .a2a-view-conversations:focus {
    outline: 2px solid #667eea !important;
    outline-offset: 2px !important;
    box-shadow: none !important;
}

.a2a-chat-widget .a2a-new-conversation:active,
.a2a-chat-widget .a2a-view-conversations:active {
    transform: translateY(1px) !important;
}

/* Login required */
.a2a-chat-login-required {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #f59e0b;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 9999;
}

/* Performance optimizations */
.a2a-chat-messages .a2a-message {
    will-change: transform;
    contain: layout style paint;
}

.a2a-chat-widget {
    will-change: transform;
    contain: layout;
}

/* Animations */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.6;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .a2a-chat-widget {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 10px;
    }
    
    .a2a-chat-container {
        height: 400px;
    }
    
    .a2a-chat-messages {
        max-height: 300px;
    }
}

/* Modal de Conversas */
.a2a-conversations-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 999999 !important;
    display: none !important;
    align-items: center !important;
    justify-content: center !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
}

.a2a-conversations-modal[style*="display: flex"] {
    display: flex !important;
}

.a2a-conversations-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.a2a-conversations-content {
    position: relative !important;
    background: white !important;
    border-radius: 12px !important;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04) !important;
    max-width: 500px !important;
    width: 90% !important;
    max-height: 85vh !important;
    overflow: hidden !important;
    z-index: 999999 !important;
    margin: 20px !important;
}

.a2a-conversations-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.a2a-conversations-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.a2a-conversations-close {
    background: none !important;
    border: none !important;
    color: white !important;
    font-size: 28px !important;
    cursor: pointer !important;
    padding: 4px !important;
    width: 36px !important;
    height: 36px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    transition: background-color 0.2s !important;
    line-height: 1 !important;
    font-weight: normal !important;
    position: relative !important;
    z-index: 999999 !important;
    font-family: inherit !important;
}

.a2a-conversations-close:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    color: white !important;
}

.a2a-conversations-close:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5) !important;
    outline-offset: 2px !important;
}

.a2a-conversations-body {
    max-height: calc(85vh - 100px) !important;
    overflow-y: auto !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
}

.a2a-conversations-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    color: #6b7280;
}

.a2a-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e5e7eb;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.a2a-conversations-empty {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
}

/* Lista de Conversas */
.a2a-conversation-item {
    padding: 16px 24px !important;
    border-bottom: 1px solid #f3f4f6 !important;
    cursor: pointer !important;
    transition: background-color 0.2s !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    margin: 0 !important;
    background: white !important;
    color: inherit !important;
    text-decoration: none !important;
    min-height: auto !important;
}

.a2a-conversation-item:hover {
    background: #f9fafb !important;
    color: inherit !important;
    text-decoration: none !important;
}

.a2a-conversation-item:last-child {
    border-bottom: none !important;
    margin-bottom: 16px !important;
}

.a2a-conversation-title {
    font-weight: 600 !important;
    color: #1f2937 !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: inherit !important;
    text-decoration: none !important;
}

.a2a-conversation-preview {
    color: #6b7280 !important;
    font-size: 12px !important;
    line-height: 1.4 !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: inherit !important;
    text-decoration: none !important;
}

.a2a-conversation-meta {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    font-size: 11px !important;
    color: #9ca3af !important;
    margin: 0 !important;
    padding: 0 !important;
}

.a2a-conversation-date {
    font-size: 11px !important;
    color: #9ca3af !important;
    font-family: inherit !important;
}

.a2a-conversation-count {
    background: #e5e7eb !important;
    color: #374151 !important;
    padding: 2px 6px !important;
    border-radius: 10px !important;
    font-size: 10px !important;
    font-weight: 500 !important;
    font-family: inherit !important;
    white-space: nowrap !important;
}

/* Estilos adicionais para sobrescrever temas */
.a2a-conversations-modal * {
    box-sizing: border-box !important;
}

.a2a-conversations-modal h3,
.a2a-conversations-modal h4,
.a2a-conversations-modal p,
.a2a-conversations-modal span {
    margin: 0 !important;
    padding: 0 !important;
    font-family: inherit !important;
    text-decoration: none !important;
    border: none !important;
    background: none !important;
}

.a2a-conversations-modal button {
    font-family: inherit !important;
    text-decoration: none !important;
    border: none !important;
    outline: none !important;
}

/* Garantir que o modal apareça acima de tudo */
.a2a-conversations-content {
    z-index: 999999 !important;
}

/* Responsividade melhorada */
@media (max-width: 600px) {
    .a2a-conversations-content {
        width: 95% !important;
        max-height: 90vh !important;
        margin: 10px !important;
    }

    .a2a-conversations-body {
        max-height: calc(90vh - 80px) !important;
    }

    .a2a-conversation-item {
        padding: 12px 16px !important;
    }
}

/* Print styles */
@media print {
    .a2a-chat-widget,
    .a2a-conversations-modal {
        display: none !important;
    }
}
