/* Chat Widget - Agente de IA */

:root {
    --chat-max-height: min(600px, calc(100vh - 120px));
    --chat-width: 380px;
}

.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.chat-button svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.chat-button .badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: var(--chat-width);
    max-width: calc(100vw - 40px);
    height: var(--chat-max-height);
    background: white;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

/* Responsividade mobile */
@media (max-width: 480px) {
    :root {
        --chat-max-height: calc(100vh - 100px);
        --chat-width: calc(100vw - 20px);
    }
    
    .chat-window {
        right: 10px;
        bottom: 80px;
    }
}

/* Tablets */
@media (max-width: 768px) and (min-width: 481px) {
    :root {
        --chat-max-height: calc(100vh - 110px);
        --chat-width: 360px;
    }
}

/* Telas pequenas em altura */
@media (max-height: 700px) {
    :root {
        --chat-max-height: calc(100vh - 100px);
    }
}

@media (max-height: 500px) {
    :root {
        --chat-max-height: calc(100vh - 80px);
    }
    
    .chat-window {
        bottom: 70px;
    }
}

.chat-window.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chat-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-header-text p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

/* Language Selector */
.language-selector {
    position: relative;
}

.language-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    font-size: 20px;
    padding: 6px 10px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.language-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.language-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 150px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
}

.language-dropdown.active {
    display: flex;
}

.language-dropdown button {
    background: none;
    border: none;
    padding: 12px 16px;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    color: #2d3748;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.language-dropdown button:hover {
    background: #f7fafc;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 24px;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    transition: background 0.2s;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    min-height: 200px;
}

@media (max-width: 480px) {
    .chat-messages {
        padding: 15px;
        min-height: 150px;
    }
}

@media (max-height: 500px) {
    .chat-messages {
        min-height: 120px;
        padding: 10px;
    }
}

.chat-message {
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-message.user .message-avatar {
    background: #2ecc71;
}

.message-content {
    max-width: 70%;
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chat-message.user .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    color: #2d3748;
}

.chat-message.user .message-text {
    color: white;
}

/* Formatação Markdown */
.message-text strong {
    font-weight: 700;
    color: inherit;
}

.message-text em {
    font-style: italic;
    color: inherit;
}

.message-text h3,
.message-text h4 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    color: #1a202c;
}

.chat-message.user .message-text h3,
.chat-message.user .message-text h4 {
    color: white;
}

.message-text h3 {
    font-size: 16px;
}

.message-text h4 {
    font-size: 14px;
}

.message-text ul,
.message-text ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-text li {
    margin: 4px 0;
    color: #2d3748;
}

.chat-message.user .message-text li {
    color: white;
}

.message-text a {
    color: #667eea;
    text-decoration: underline;
}

.chat-message.user .message-text a {
    color: #e0e7ff;
}

.message-text code {
    background: #f7fafc;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #e53e3e;
}

.chat-message.user .message-text code {
    background: rgba(255, 255, 255, 0.2);
    color: #fef5e7;
}

.message-text pre {
    background: #2d3748;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-text pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.message-text blockquote {
    border-left: 4px solid #667eea;
    padding-left: 12px;
    margin: 8px 0;
    color: #4a5568;
    font-style: italic;
}

.chat-message.user .message-text blockquote {
    border-left-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.9);
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.chat-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e9ecef;
}

.chat-limit-info {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 8px;
    text-align: center;
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    border: 2px solid #e9ecef;
    border-radius: 24px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #667eea;
}

.chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #667eea;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-send:hover:not(:disabled) {
    background: #5568d3;
    transform: scale(1.05);
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Mobile */
@media (max-width: 768px) {
    .chat-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 100px);
        bottom: 80px;
        right: 20px;
    }
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Cursor de digitação */
.typing-cursor {
    animation: blink 1s infinite;
    font-weight: bold;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}
