/* ========================================
   Chat Widget - Visitante
   ======================================== */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 24px;
    border-radius: 30px;
    background: linear-gradient(135deg, #e6295f, #ff6b9d);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(230, 41, 95, 0.4);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
    z-index: 9999;
    transition: transform 0.2s, box-shadow 0.2s;
}
.chat-fab i {
    font-size: 1.15rem;
}
.chat-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(230, 41, 95, 0.5);
}
@keyframes chatNudge {
    0%, 100% { transform: translateY(0); }
    15% { transform: translateY(-6px); }
    30% { transform: translateY(0); }
    45% { transform: translateY(-4px); }
    60% { transform: translateY(0); }
}
.chat-fab.nudge {
    animation: chatNudge 0.8s ease;
}
.chat-fab .badge-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}
.chat-fab .badge-dot.active { display: block; }

/* Chat Window */
.chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: none;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    animation: chatSlideUp 0.25s ease-out;
}
.chat-window.open { display: flex; }

@keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.chat-window-header {
    background: linear-gradient(135deg, #c41e4f, #e6295f);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.chat-window-header .chat-title {
    font-weight: 600;
    font-size: 0.95rem;
}
.chat-window-header .chat-subtitle {
    font-size: 0.75rem;
    opacity: 0.8;
}
.chat-window-header .chat-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.2s;
}
.chat-window-header .chat-close:hover {
    background: rgba(255,255,255,0.3);
}

/* Name form */
.chat-name-form {
    padding: 24px 20px;
    text-align: center;
}
.chat-name-form p {
    color: #6b7280;
    font-size: 0.9rem;
    margin-bottom: 16px;
}
.chat-name-form input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 0.9rem;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
}
.chat-name-form input:focus {
    border-color: #e6295f;
}
.chat-name-form button {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #e6295f, #ff6b9d);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    transition: opacity 0.2s;
}
.chat-name-form button:hover { opacity: 0.9; }

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 280px;
    max-height: 340px;
    background: #f9fafb;
}

.chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.85rem;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
}
.chat-msg.visitor {
    align-self: flex-end;
    background: linear-gradient(135deg, #e6295f, #ff6b9d);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.anunciante {
    align-self: flex-start;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}
.chat-msg .msg-time {
    font-size: 0.65rem;
    opacity: 0.6;
    margin-top: 4px;
    display: block;
}
.chat-msg.visitor .msg-time { text-align: right; }

.chat-empty {
    text-align: center;
    color: #9ca3af;
    font-size: 0.85rem;
    padding: 40px 20px;
}
.chat-empty i { font-size: 2rem; display: block; margin-bottom: 8px; }

/* Typing indicator */
.chat-typing { padding: 12px 18px; }
.typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    height: 16px;
}
.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typingBounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #fff;
    flex-shrink: 0;
}
.chat-input-area textarea {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.85rem;
    resize: none;
    max-height: 80px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.2s;
}
.chat-input-area textarea:focus {
    border-color: #e6295f;
}
.chat-input-area .chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e6295f, #ff6b9d);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.chat-input-area .chat-send:hover { opacity: 0.85; }
.chat-input-area .chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Mobile */
@media (max-width: 480px) {
    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }
    .chat-messages {
        max-height: none;
        flex: 1;
    }
    .chat-fab {
        bottom: 80px;
        right: 16px;
        left: 16px;
        justify-content: center;
        font-size: 0.85rem;
    }
}
