/* ============================================
   Peralta Vázquez Automóviles - Chat Widget Styles
   ============================================ */

/* === Burbuja flotante === */
.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 9998;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    animation: chatPulse 2s ease-in-out infinite;
}

.chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.4);
    animation: none;
}

.chat-bubble.open {
    animation: none;
}

@keyframes chatPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); }
    50% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), 0 0 0 8px rgba(255, 255, 255, 0.25); }
}

.chat-bubble svg {
    width: 28px;
    height: 28px;
    transition: transform var(--transition);
}

.chat-bubble.open svg {
    transform: rotate(90deg);
}

/* Badge de mensajes no leidos */
.chat-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--bg-primary);
    display: none;
}

.chat-bubble-badge.visible {
    display: flex;
}

/* === Peek message (proactive teaser) === */
.chat-peek {
    position: fixed;
    bottom: 164px;
    right: 24px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    padding: 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 103, 255, 0.1);
    z-index: 9997;
    cursor: pointer;
    max-width: 320px;
    min-width: 200px;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.chat-peek.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Arrow pointing to bubble */
.chat-peek::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 22px;
    width: 14px;
    height: 14px;
    background: var(--bg-card);
    border-right: 1px solid var(--accent);
    border-bottom: 1px solid var(--accent);
    transform: rotate(45deg);
}

/* Typing dots inside peek */
.chat-peek-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 14px 20px;
}

.chat-peek-typing .chat-typing-dot {
    width: 8px;
    height: 8px;
}

/* Peek content */
.chat-peek-content {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
}

.chat-peek-avatar {
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-peek-avatar .chat-online-dot {
    width: 10px;
    height: 10px;
}

.chat-peek-text {
    font-size: 13px;
    font-weight: 500;
    line-height: 1.45;
    flex: 1;
}

.chat-peek-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s;
}

.chat-peek-close:hover {
    color: var(--text-primary);
}

/* === Quick reply chips === */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
    animation: chatMsgIn 0.25s ease;
}

.chat-quick-reply-btn {
    background: transparent;
    border: 1.5px solid var(--accent);
    color: var(--accent);
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 12px;
    font-family: var(--font-family);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s;
    white-space: nowrap;
}

.chat-quick-reply-btn:hover {
    background: var(--accent);
    color: var(--accent-text);
    transform: scale(1.04);
}

/* === Nudge wobble animation === */
@keyframes chatNudge {
    0%, 100% { transform: rotate(0deg); }
    15%      { transform: rotate(-12deg); }
    30%      { transform: rotate(10deg); }
    45%      { transform: rotate(-8deg); }
    60%      { transform: rotate(5deg); }
    75%      { transform: rotate(-2deg); }
}

.chat-nudge {
    animation: chatNudge 0.6s ease-in-out !important;
}

/* Glow de la burbuja cuando aparece tooltip */
.chat-bubble-glow {
    animation: chatBubbleGlow 2s ease-in-out infinite;
}

@keyframes chatBubbleGlow {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), 0 0 20px var(--accent), 0 0 40px rgba(212, 25, 32, 0.3);
    }
}

@media (max-width: 480px) {
    .chat-tooltip {
        right: 16px;
        bottom: 150px;
        max-width: calc(100vw - 32px);
        font-size: 12px;
    }

    .chat-tooltip::after {
        right: 20px;
    }
}

/* === Panel de chat === */
.chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

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

/* Header del chat */
.chat-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--accent);
    color: var(--accent-text);
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-header-avatar svg {
    width: 20px;
    height: 20px;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-title {
    font-size: var(--font-size-sm);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: var(--font-size-xs);
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-header-status .chat-online-dot {
    width: 7px;
    height: 7px;
    background: #22c55e;
}

.chat-close-btn {
    background: none;
    border: none;
    color: var(--accent-text);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    opacity: 0.8;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}

.chat-close-btn:hover {
    opacity: 1;
}

/* Area de mensajes */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    scroll-behavior: smooth;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Burbujas de mensaje */
.chat-msg {
    max-width: 85%;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    word-wrap: break-word;
    animation: chatMsgIn 0.25s ease;
}

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

.chat-msg-bot {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.chat-msg-visitante {
    align-self: flex-end;
    background: var(--accent);
    color: var(--accent-text);
    border-bottom-right-radius: 4px;
}

.chat-msg-admin {
    align-self: flex-start;
    background: var(--info);
    color: #fff;
    border-bottom-left-radius: 4px;
}

.chat-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 2px;
    display: block;
}

.chat-msg-visitante .chat-msg-time {
    text-align: right;
}

/* Mensaje de sistema (asesor disponible) */
.chat-system-msg {
    align-self: center;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: chatMsgIn 0.3s ease;
}

.chat-online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
    flex-shrink: 0;
    animation: chatOnlinePulse 2s ease-in-out infinite;
}

@keyframes chatOnlinePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Indicador de escribiendo */
.chat-typing {
    align-self: flex-start;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    display: none;
    gap: 4px;
    align-items: center;
}

.chat-typing.visible {
    display: flex;
}

.chat-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: chatTypingBounce 1.4s ease-in-out infinite;
}

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

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

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

/* Input area */
.chat-input-area {
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    resize: none;
    min-height: 38px;
    max-height: 80px;
    line-height: 1.4;
    transition: border-color var(--transition-fast);
}

.chat-input:focus {
    border-color: var(--accent);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition-fast), transform var(--transition-fast);
    align-self: flex-end;
}

.chat-send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

/* Powered by footer */
.chat-footer {
    text-align: center;
    padding: 4px;
    font-size: 10px;
    color: var(--text-muted);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* === Responsive === */
@media (max-width: 480px) {
    .chat-panel {
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }

    .chat-bubble svg {
        width: 24px;
        height: 24px;
    }
}

/* Peek responsive */
@media (max-width: 480px) {
    .chat-peek {
        right: 12px;
        bottom: 140px;
        max-width: calc(100vw - 24px);
        font-size: 12px;
    }
    .chat-peek::after {
        right: 18px;
    }
    .chat-quick-reply-btn {
        font-size: 11px;
        padding: 5px 10px;
    }
}

/* Mover burbuja cuando WhatsApp float esta visible */
.chat-bubble {
    bottom: 92px;
}

@media (max-width: 480px) {
    .chat-bubble {
        bottom: 78px;
    }
}
