/* 💬 CHAT REAL-TIME CSS */
/* Mobile-First Design com Performance Otimizada */

/* 🎯 CHAT TOGGLE BUTTON */
.chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    background: linear-gradient(45deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
    transition: all 0.3s ease;
    color: white;
    font-size: 24px;
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* 🔧 OCULTAR BOTÃO QUANDO CHAT ESTIVER ABERTO */
.chat-toggle.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
    pointer-events: none;
}

.chat-toggle:hover:not(.hidden) {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.chat-toggle:active:not(.hidden) {
    transform: scale(0.95);
}

/* 🔔 CHAT BADGE */
.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

.chat-badge.show {
    opacity: 1;
    transform: scale(1);
}

/* 💬 CHAT WINDOW */
.chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    z-index: 999;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.chat-window.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

/* 📋 CHAT HEADER */
.chat-header {
    background: linear-gradient(45deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
}

.chat-title i {
    font-size: 18px;
}

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

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff6b6b;
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background: #51cf66;
    animation: none;
}

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

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* 👤 CHAT NAME SECTION */
.chat-name-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #f8f9fa;
}

.chat-name-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 320px;
    width: 100%;
}

.chat-name-header {
    margin-bottom: 25px;
}

.chat-name-header i {
    font-size: 48px;
    color: #e74c3c;
    margin-bottom: 15px;
}

.chat-name-header h3 {
    color: #2c3e50;
    margin-bottom: 8px;
    font-size: 20px;
    font-weight: 600;
}

.chat-name-header p {
    color: #6c757d;
    font-size: 14px;
    margin: 0;
}

.chat-name-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#chat-name-input {
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s ease;
}

#chat-name-input:focus {
    border-color: #e74c3c;
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
}

.chat-name-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.chat-name-btn:hover {
    background: #c0392b;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

.chat-name-btn:active {
    transform: translateY(0);
}

/* 💌 CHAT MESSAGES */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
}

.chat-message {
    display: flex;
    margin-bottom: 8px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.customer {
    justify-content: flex-end;
}

.chat-message.attendant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-message.customer .message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.attendant .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.chat-message.attendant .message-time {
    text-align: left;
}

/* ✏️ CHAT INPUT */
.chat-input-container {
    padding: 16px;
    background: white;
    border-top: 1px solid #e9ecef;
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

#chat-input {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    transition: border-color 0.2s ease;
}

#chat-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.2);
}

#chat-input:disabled {
    background: #f8f9fa;
    color: #6c757d;
}

.chat-send {
    background: var(--primary);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    font-size: 16px;
    transition: all 0.2s ease;
}

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

.chat-send:disabled {
    background: #dee2e6;
    cursor: not-allowed;
    transform: none;
}

/* ⌨️ TYPING INDICATOR */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 12px;
    color: #6c757d;
}

.typing-dots {
    display: flex;
    gap: 2px;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    background: #6c757d;
    border-radius: 50%;
    animation: typing 1.5s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* 🎉 WELCOME MESSAGE */
.welcome-message {
    text-align: center;
    padding: 20px;
    color: #6c757d;
    font-size: 14px;
}

.welcome-message i {
    font-size: 32px;
    color: var(--primary);
    margin-bottom: 12px;
    display: block;
}

/* 📱 MOBILE RESPONSIVENESS */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 10px;
        right: 10px;
        left: 10px;
        border-radius: 12px;
    }

    .chat-toggle {
        bottom: 15px;
        right: 15px;
        width: 55px;
        height: 55px;
        font-size: 22px;
    }
    
    /* 🔧 OCULTAR BOTÃO EM MOBILE QUANDO CHAT ABERTO */
    .chat-toggle.hidden {
        opacity: 0;
        visibility: hidden;
        transform: scale(0.6);
        pointer-events: none;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-messages {
        padding: 12px;
    }

    .message-bubble {
        font-size: 13px;
        padding: 10px 14px;
    }

    .chat-input-container {
        padding: 12px;
    }

    #chat-input {
        padding: 10px 14px;
        font-size: 16px; /* Evita zoom no iOS */
    }
}

/* 🌙 MODO ESCURO (FUTURO) */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #2c3e50;
    }

    .chat-messages {
        background: #34495e;
    }

    .chat-message.attendant .message-bubble {
        background: #3c5b7d;
        color: white;
    }

    .chat-input-container {
        background: #2c3e50;
        border-top-color: #34495e;
    }

    #chat-input {
        background: #34495e;
        border-color: #4a5f7a;
        color: white;
    }

    #chat-input::placeholder {
        color: #8fa2b2;
    }
}

/* 🚀 PERFORMANCE OTIMIZATIONS */
.chat-window {
    /* GPU acceleration para animações suaves */
    transform: translateZ(0);
    will-change: transform, opacity;
    backface-visibility: hidden;
}

.chat-messages {
    /* Otimização de scroll */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* 🛡️ PROTEÇÃO CONTRA OVERFLOW */
.message-bubble {
    /* Quebra palavras longas */
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* 🔒 SECURITY: Previne seleção de elementos UI */
.chat-header,
.chat-input-container {
    -webkit-user-select: none;
    user-select: none;
}

/* Permite seleção apenas no conteúdo das mensagens */
.message-bubble {
    -webkit-user-select: text;
    user-select: text;
}

/* 💬 MODAL DE CAPTURA DE NOME PARA CHAT */
/* DECISION: Modal customizado substitui prompt() nativo feio do browser */
/* ALTERNATIVE: Usar alert/prompt nativo mas quebra UX */
/* IMPACT: Interface elegante e consistente com design do site */

.chat-name-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.chat-name-modal-overlay.show {
    display: flex;
}

.chat-name-modal {
    background: white;
    border-radius: 16px;
    padding: 32px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    transform: scale(0.8);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-align: center;
}

.chat-name-modal-overlay.show .chat-name-modal {
    transform: scale(1);
}

.chat-name-modal-header {
    margin-bottom: 24px;
}

.chat-name-modal-header .chat-icon {
    background: linear-gradient(45deg, var(--primary), var(--primary-dark));
    color: white;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin: 0 auto 16px;
    box-shadow: 0 8px 24px rgba(231, 76, 60, 0.3);
}

.chat-name-modal-header h3 {
    color: var(--dark);
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 8px;
}

.chat-name-modal-header p {
    color: var(--text-secondary);
    font-size: 16px;
    margin: 0;
    line-height: 1.5;
}

.chat-name-input-group {
    margin-bottom: 24px;
    text-align: left;
}

.chat-name-input-group label {
    display: block;
    color: var(--dark);
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}

.chat-name-input {
    width: 100%;
    padding: 16px;
    border: 2px solid #e0e7ff;
    border-radius: 12px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: #fafbfc;
    box-sizing: border-box;
}

.chat-name-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(231, 76, 60, 0.1);
}

.chat-name-input::placeholder {
    color: #a0a9b8;
}

.chat-name-modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.chat-name-btn {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 100px;
}

.chat-name-btn-primary {
    background: linear-gradient(45deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

.chat-name-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.chat-name-btn-primary:active {
    transform: translateY(0);
}

.chat-name-btn-secondary {
    background: #f8f9fb;
    color: var(--text-secondary);
    border: 2px solid #e0e7ff;
}

.chat-name-btn-secondary:hover {
    background: #e0e7ff;
    color: var(--dark);
}

/* 📱 RESPONSIVE - MOBILE FIRST */
@media (max-width: 480px) {
    .chat-name-modal {
        padding: 24px;
        margin: 20px;
        width: calc(100% - 40px);
    }
    
    .chat-name-modal-header h3 {
        font-size: 20px;
    }
    
    .chat-name-modal-header p {
        font-size: 14px;
    }
    
    .chat-name-modal-header .chat-icon {
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
    
    .chat-name-modal-actions {
        flex-direction: column;
    }
    
    .chat-name-btn {
        width: 100%;
    }
}

/* 🚫 MODAL DE LOJA FECHADA */
/* DECISION: Usar mesmo estilo do chat-name-modal para consistência visual */
/* ALTERNATIVE: Manter alert() nativo mas quebra UX */
/* IMPACT: Interface elegante e profissional quando loja está fechada */

.store-closed-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.store-closed-modal-overlay.show {
    display: flex;
}

.store-closed-modal {
    background: white;
    border-radius: 16px;
    padding: 32px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    transform: scale(0.8);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-align: center;
}

.store-closed-modal-overlay.show .store-closed-modal {
    transform: scale(1);
}

.store-closed-modal-header {
    margin-bottom: 24px;
}

.store-closed-modal-header .store-icon {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: white;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin: 0 auto 16px;
    box-shadow: 0 8px 24px rgba(231, 76, 60, 0.3);
}

.store-closed-modal-header h3 {
    color: var(--dark);
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 8px;
}

.store-closed-modal-header p {
    color: var(--text-secondary);
    font-size: 16px;
    margin: 0;
    line-height: 1.5;
}

.store-closed-modal-content {
    margin-bottom: 24px;
    text-align: left;
}

.store-closed-modal-content .info-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f0f2f5;
}

.store-closed-modal-content .info-item:last-child {
    border-bottom: none;
}

.store-closed-modal-content .info-icon {
    width: 40px;
    height: 40px;
    background: #f8f9fb;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 16px;
    margin-right: 16px;
}

.store-closed-modal-content .info-text {
    flex: 1;
}

.store-closed-modal-content .info-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.store-closed-modal-content .info-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--dark);
}

.store-closed-modal-actions {
    display: flex;
    justify-content: center;
}

.store-closed-btn {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
    background: linear-gradient(45deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

.store-closed-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.store-closed-btn:active {
    transform: translateY(0);
}

/* 📱 RESPONSIVE - MOBILE FIRST */
@media (max-width: 480px) {
    .store-closed-modal {
        padding: 24px;
        margin: 20px;
        width: calc(100% - 40px);
    }
    
    .store-closed-modal-header h3 {
        font-size: 20px;
    }
    
    .store-closed-modal-header p {
        font-size: 14px;
    }
    
    .store-closed-modal-header .store-icon {
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
    
    .store-closed-modal-content .info-item {
        padding: 10px 0;
    }
    
    .store-closed-modal-content .info-icon {
        width: 36px;
        height: 36px;
        margin-right: 12px;
    }
    
    .store-closed-modal-content .info-value {
        font-size: 14px;
    }
}

/* 🌟 ANIMAÇÕES */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}