/**
 * Chat Widget - UI/UX Pro Max Edition
 * Turismo MT - Assistente Virtual de Inteligência Artificial
 */

:root {
    --chat-primary: #059669;
    --chat-primary-hover: #047857;
    --chat-primary-dark: #064e3b;
    --chat-primary-light: #ecfdf5;
    --chat-accent: #10b981;
    --chat-text-main: #0f172a;
    --chat-text-muted: #64748b;
    --chat-bg-window: #ffffff;
    --chat-bg-body: #f8fafc;
    --chat-border: #e2e8f0;
    --chat-shadow-lg: 0 20px 35px -5px rgba(0, 0, 0, 0.15), 0 10px 15px -5px rgba(0, 0, 0, 0.08);
    --chat-shadow-fab: 0 12px 28px -4px rgba(5, 150, 105, 0.45), 0 4px 10px -2px rgba(5, 150, 105, 0.25);
    --chat-radius-lg: 20px;
    --chat-radius-bubble: 16px;
    --chat-width: 400px;
    --chat-height: min(640px, calc(100vh - 110px));
    --chat-font: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --chat-transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   Widget Container
   ========================================================================== */
.chat-widget-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: var(--chat-font);
    -webkit-font-smoothing: antialiased;
    box-sizing: border-box;
}

.chat-widget-root *, 
.chat-widget-root *::before, 
.chat-widget-root *::after {
    box-sizing: border-box;
}

/* ==========================================================================
   FAB Trigger Button & Docked Pill
   ========================================================================== */
.chat-fab-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 60px;
    min-width: 60px;
    padding: 0 18px;
    border-radius: 9999px;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    cursor: pointer;
    box-shadow: var(--chat-shadow-fab);
    transition: var(--chat-transition);
    user-select: none;
    outline: none;
}

.chat-fab-button:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 16px 32px -4px rgba(5, 150, 105, 0.55);
}

.chat-fab-button:active {
    transform: translateY(0) scale(0.97);
}

.chat-fab-icon {
    width: 26px;
    height: 26px;
    fill: currentColor;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.chat-fab-button:hover .chat-fab-icon {
    transform: scale(1.1);
}

.chat-fab-label {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
    opacity: 1;
    max-width: 140px;
    transition: var(--chat-transition);
}

/* Pulse Glow Indicator */
.chat-fab-pulse {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: #10b981;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: chatPulse 2.2s infinite;
}

@keyframes chatPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Badge Contador */
.chat-fab-badge {
    position: absolute;
    top: -4px;
    left: -4px;
    background: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
}

/* ==========================================================================
   Auto-Hide & Inactivity States (UI/UX Pro Max)
   ========================================================================== */

/* 1. Mode: Minimize to Pill / Compact Dock */
.chat-widget-root.is-docked .chat-fab-button {
    height: 44px;
    min-width: 44px;
    padding: 0 14px;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    transform: translateY(4px);
    opacity: 0.85;
}

.chat-widget-root.is-docked .chat-fab-button:hover {
    opacity: 1;
    transform: translateY(0) scale(1.02);
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
}

.chat-widget-root.is-docked .chat-fab-icon {
    width: 20px;
    height: 20px;
}

.chat-widget-root.is-docked .chat-fab-label {
    font-size: 12px;
    font-weight: 500;
}

.chat-widget-root.is-docked .chat-fab-pulse {
    animation: none;
    opacity: 0.6;
}

/* 2. Mode: Fade Out */
.chat-widget-root.is-faded .chat-fab-button {
    opacity: 0.3;
    filter: grayscale(40%);
    transform: scale(0.92);
}

.chat-widget-root.is-faded .chat-fab-button:hover {
    opacity: 1;
    filter: grayscale(0%);
    transform: scale(1);
}

/* 3. Mode: Hide Completely */
.chat-widget-root.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(30px) scale(0.85);
    transition: var(--chat-transition);
}

/* ==========================================================================
   Chat Window (Modal Card)
   ========================================================================== */
.chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: var(--chat-width);
    max-width: calc(100vw - 32px);
    height: var(--chat-height);
    background: var(--chat-bg-window);
    border-radius: var(--chat-radius-lg);
    box-shadow: var(--chat-shadow-lg);
    border: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.96);
    transform-origin: bottom right;
    transition: var(--chat-transition);
    z-index: 999999;
}

.chat-window.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ==========================================================================
   Header
   ========================================================================== */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.chat-header-agent {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-avatar-wrapper {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.chat-avatar-icon {
    width: 24px;
    height: 24px;
    fill: #ffffff;
}

.chat-online-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid var(--chat-primary-dark);
}

.chat-header-meta {
    min-width: 0;
}

.chat-header-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-subtitle {
    margin: 3px 0 0 0;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Header Buttons */
.chat-action-btn {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #ffffff;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    padding: 0;
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.chat-action-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Language Selector Dropdown */
.chat-lang-menu {
    position: relative;
}

.chat-lang-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s;
}

.chat-lang-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.chat-lang-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #ffffff;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    min-width: 140px;
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 10;
}

.chat-lang-dropdown.is-active {
    display: flex;
    animation: fadeInDown 0.2s ease;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-lang-option {
    background: transparent;
    border: none;
    padding: 8px 10px;
    text-align: left;
    border-radius: 6px;
    font-size: 13px;
    color: var(--chat-text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}

.chat-lang-option:hover {
    background: #f1f5f9;
}

.chat-lang-option.is-selected {
    background: var(--chat-primary-light);
    color: var(--chat-primary);
    font-weight: 600;
}

/* ==========================================================================
   Messages Area
   ========================================================================== */
.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px;
    background: var(--chat-bg-body);
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.chat-messages-container::-webkit-scrollbar {
    width: 5px;
}

.chat-messages-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* Message Rows */
.chat-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
}

.chat-msg-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-row.assistant {
    align-self: flex-start;
}

.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--chat-primary-light);
    color: var(--chat-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid rgba(5, 150, 105, 0.2);
}

.chat-msg-avatar svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.chat-msg-bubble {
    padding: 12px 16px;
    border-radius: var(--chat-radius-bubble);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.chat-msg-row.user .chat-msg-bubble {
    background: linear-gradient(135deg, var(--chat-primary) 0%, #047857 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-msg-row.assistant .chat-msg-bubble {
    background: #ffffff;
    color: var(--chat-text-main);
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 4px;
}

.chat-msg-bubble a {
    color: var(--chat-primary);
    text-decoration: underline;
    font-weight: 500;
}

.chat-msg-row.user .chat-msg-bubble a {
    color: #ffffff;
}

/* Termos em negrito clicáveis para o prompt */
.chat-msg-row.assistant .chat-msg-bubble strong,
.chat-term-btn {
    color: var(--chat-primary-dark);
    cursor: pointer;
    border-bottom: 1.5px dashed rgba(5, 150, 105, 0.45);
    padding: 0 3px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: inline-block;
}

.chat-msg-row.assistant .chat-msg-bubble strong:hover,
.chat-term-btn:hover {
    background: rgba(5, 150, 105, 0.12);
    border-bottom-color: var(--chat-primary);
    color: var(--chat-primary);
    transform: translateY(-1px);
}

/* Links estruturados com botão rápido de pergunta */
.chat-link-wrap {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    vertical-align: baseline;
}

.chat-ask-link-btn {
    background: rgba(5, 150, 105, 0.08);
    border: 1px solid rgba(5, 150, 105, 0.25);
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 11px;
    cursor: pointer;
    color: var(--chat-primary-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s ease;
}

.chat-ask-link-btn:hover {
    background: var(--chat-primary);
    color: #ffffff;
    border-color: var(--chat-primary);
    transform: scale(1.1);
}

/* Destaque visual no input ao receber texto */
.chat-input-highlight {
    animation: chatInputGlow 1.2s ease-out;
}

@keyframes chatInputGlow {
    0% {
        box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.5);
        background-color: #ecfdf5;
    }
    100% {
        box-shadow: none;
        background-color: #ffffff;
    }
}

.chat-msg-time {
    font-size: 10px;
    color: var(--chat-text-muted);
    margin-top: 4px;
    text-align: right;
}

.chat-msg-row.user .chat-msg-time {
    text-align: right;
    color: rgba(255, 255, 255, 0.8);
}

/* Quick Suggestion Chips */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.chat-chip-btn {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 9999px;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--chat-text-main);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.chat-chip-btn:hover {
    background: var(--chat-primary-light);
    border-color: var(--chat-primary);
    color: var(--chat-primary-dark);
    transform: translateY(-1px);
}

/* Typing indicator */
.chat-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.chat-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Input & Footer Area
   ========================================================================== */
.chat-footer {
    padding: 12px 16px 16px 16px;
    background: #ffffff;
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chat-limit-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--chat-text-muted);
    margin-bottom: 8px;
    padding: 0 4px;
}

.chat-limit-highlight {
    font-weight: 600;
    color: var(--chat-primary);
}

.chat-limit-highlight.is-warning {
    color: #ef4444;
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f1f5f9;
    border: 1.5px solid #cbd5e1;
    border-radius: 24px;
    padding: 4px 6px 4px 14px;
    transition: all 0.2s ease;
}

.chat-input-wrapper:focus-within {
    background: #ffffff;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

.chat-text-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: var(--chat-text-main);
    font-family: inherit;
    padding: 6px 0;
}

.chat-text-input::placeholder {
    color: #94a3b8;
}

.chat-send-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--chat-primary);
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}

.chat-send-button:hover:not(:disabled) {
    background: var(--chat-primary-hover);
    transform: scale(1.06);
}

.chat-send-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: #94a3b8;
}

.chat-send-button svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    margin-left: 2px;
}

/* Disclaimer text */
.chat-disclaimer-text {
    margin: 8px 0 0 0;
    text-align: center;
    font-size: 10px;
    color: #94a3b8;
}

/* ==========================================================================
   Mobile Adjustments
   ========================================================================== */
@media (max-width: 480px) {
    .chat-widget-root {
        bottom: 16px;
        right: 16px;
    }

    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        border: none;
    }

    .chat-header {
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chat-footer {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* ==========================================================================
   V3.3: QUICK RESPONSES (SUGESTÕES DINÂMICAS)
   ========================================================================== */
.chat-suggestions.v33-quick-responses {
    margin-top: 8px;
    margin-bottom: 8px;
}

.chat-chip-btn.v33-chip {
    background-color: #f8f9fa;
    color: #2b6cb0;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-chip-btn.v33-chip:hover {
    background-color: #ebf8ff;
    border-color: #bee3f8;
    color: #2b6cb0;
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.chat-chip-btn.v33-chip::before {
    content: '✨';
    margin-right: 4px;
    font-size: 12px;
}
