/* ===== ONE4CARS AI Chat Widget ===== */
/* Colores de marca: Azul #0b2a4a | Dorado #d4a017 | Rojo #D9001D */

:root {
    --o4c-blue: #0b2a4a;
    --o4c-blue-dark: #001F4F;
    --o4c-gold: #d4a017;
    --o4c-gold-light: #e9b52c;
    --o4c-red: #D9001D;
    --o4c-white: #ffffff;
    --o4c-gray-light: #f4f6f8;
    --o4c-gray: #6c757d;
    --o4c-shadow: 0 8px 32px rgba(11, 42, 74, 0.25);
}

/* ===== BUBBLE (Botón flotante) ===== */
.o4c-chat-bubble {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 65px;
    height: 65px;
    background: linear-gradient(135deg, var(--o4c-blue) 0%, var(--o4c-blue-dark) 100%);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(11, 42, 74, 0.4);
    transition: all 0.3s ease;
    z-index: 9999;
    border: 3px solid var(--o4c-gold);
}

.o4c-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 28px rgba(11, 42, 74, 0.5);
}

.o4c-chat-bubble svg {
    width: 32px;
    height: 32px;
    fill: var(--o4c-white);
    transition: all 0.3s ease;
}

.o4c-chat-bubble:hover svg {
    transform: scale(1.1);
}

/* Estado cuando el chat está abierto */
.o4c-chat-bubble.active svg.icon-chat {
    display: none;
}

.o4c-chat-bubble:not(.active) svg.icon-close {
    display: none;
}

/* Indicador de "typing" */
.o4c-chat-bubble::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    background: var(--o4c-red);
    border-radius: 50%;
    border: 2px solid var(--o4c-white);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.o4c-chat-bubble.typing::after {
    opacity: 1;
    animation: o4c-pulse 1.5s infinite;
}

@keyframes o4c-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

/* ===== VENTANA DE CHAT ===== */
.o4c-chat-window {
    position: fixed;
    bottom: 110px;
    left: 30px;
    width: 560px;
    max-width: calc(100vw - 30px);
    height: 860px;
    max-height: calc(100vh - 130px);
    background: var(--o4c-white);
    border-radius: 16px;
    box-shadow: var(--o4c-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(11, 42, 74, 0.1);
}

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

/* ===== HEADER ===== */
.o4c-chat-header {
    background: linear-gradient(135deg, var(--o4c-blue) 0%, var(--o4c-blue-dark) 100%);
    color: var(--o4c-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 3px solid var(--o4c-gold);
}

.o4c-chat-header-avatar {
    width: 45px;
    height: 45px;
    background: var(--o4c-gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: var(--o4c-blue);
    flex-shrink: 0;
}

.o4c-chat-header-info {
    flex: 1;
}

.o4c-chat-header-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.o4c-chat-header-subtitle {
    font-size: 12px;
    opacity: 0.85;
    margin: 2px 0 0 0;
}

.o4c-chat-header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}

.o4c-chat-header-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #28a745;
    border-radius: 50%;
    animation: o4c-blink 2s infinite;
}

@keyframes o4c-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== MENSAJES ===== */
.o4c-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--o4c-gray-light);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.o4c-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.o4c-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(11, 42, 74, 0.2);
    border-radius: 3px;
}

/* Mensaje del usuario */
.o4c-msg-user {
    align-self: flex-end;
    max-width: 85%;
}

.o4c-msg-user .o4c-msg-bubble {
    background: linear-gradient(135deg, var(--o4c-blue) 0%, var(--o4c-blue-dark) 100%);
    color: var(--o4c-white);
    padding: 12px 16px;
    border-radius: 16px 16px 4px 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(11, 42, 74, 0.2);
}

/* Mensaje del bot */
.o4c-msg-bot {
    align-self: flex-start;
    max-width: 85%;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.o4c-msg-bot-avatar {
    width: 32px;
    height: 32px;
    background: var(--o4c-gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: var(--o4c-blue);
    flex-shrink: 0;
}

.o4c-msg-bot .o4c-msg-bubble {
    background: var(--o4c-white);
    color: #333;
    padding: 12px 16px;
    border-radius: 16px 16px 16px 4px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(11, 42, 74, 0.08);
}

/* Enlaces dentro de mensajes */
.o4c-msg-bubble a {
    color: var(--o4c-gold);
    text-decoration: underline;
    font-weight: 600;
}

.o4c-msg-bot .o4c-msg-bubble a {
    color: var(--o4c-blue);
}

/* ===== INDICADOR DE ESCRITURA ===== */
.o4c-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 4px;
}

.o4c-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--o4c-gray);
    border-radius: 50%;
    animation: o4c-typing 1.4s infinite;
}

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

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

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

/* ===== INPUT ===== */
.o4c-chat-input {
    padding: 16px;
    background: var(--o4c-white);
    border-top: 1px solid rgba(11, 42, 74, 0.1);
    display: flex;
    gap: 10px;
    align-items: center;
}

.o4c-chat-input input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid rgba(11, 42, 74, 0.15);
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s ease;
    font-family: inherit;
}

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

.o4c-chat-input input::placeholder {
    color: var(--o4c-gray);
}

.o4c-chat-input button {
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, var(--o4c-gold) 0%, var(--o4c-gold-light) 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.o4c-chat-input button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(212, 160, 23, 0.4);
}

.o4c-chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.o4c-chat-input button svg {
    width: 20px;
    height: 20px;
    fill: var(--o4c-blue);
}

/* ===== FOOTER ===== */
.o4c-chat-footer {
    padding: 8px 16px;
    background: var(--o4c-white);
    border-top: 1px solid rgba(11, 42, 74, 0.05);
    text-align: center;
    font-size: 11px;
    color: var(--o4c-gray);
}

.o4c-chat-footer a {
    color: var(--o4c-blue);
    text-decoration: none;
    font-weight: 600;
}

/* ===== BIENVENIDA ===== */
.o4c-welcome-card {
    background: linear-gradient(135deg, rgba(11, 42, 74, 0.05) 0%, rgba(212, 160, 23, 0.1) 100%);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 8px;
    border: 1px solid rgba(212, 160, 23, 0.2);
}

.o4c-welcome-card h4 {
    margin: 0 0 8px 0;
    font-size: 15px;
    color: var(--o4c-blue);
}

.o4c-welcome-card p {
    margin: 0;
    font-size: 13px;
    color: #555;
    line-height: 1.5;
}

.o4c-welcome-card .o4c-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    justify-content: center;
}

.o4c-welcome-card .o4c-quick-btn {
    background: var(--o4c-white);
    border: 1px solid var(--o4c-blue);
    color: var(--o4c-blue);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.o4c-welcome-card .o4c-quick-btn:hover {
    background: var(--o4c-blue);
    color: var(--o4c-white);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .o4c-chat-bubble {
        bottom: 20px;
        left: 20px;
        width: 55px;
        height: 55px;
    }

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

    .o4c-chat-window {
        bottom: 90px;
        left: 10px;
        right: 10px;
        width: auto;
        height: calc(100vh - 105px);
        max-height: calc(100vh - 105px);
        border-radius: 12px;
    }

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

    .o4c-chat-header-avatar {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    .o4c-chat-header-title {
        font-size: 14px;
    }

    .o4c-chat-messages {
        padding: 16px;
    }

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

/* ===== ANIMACIÓN DE ENTRADA ===== */
@keyframes o4c-slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.o4c-msg-animate {
    animation: o4c-slideIn 0.3s ease forwards;
}

/* ===== AVISO: LLAMA LA ATENCIÓN SIN ABRIR LA VENTANA ===== */

/* Brillo dorado + anillo pulsante en el botón mientras el aviso está activo */
.o4c-chat-bubble.attention {
    animation: o4c-glow 2.2s ease-in-out infinite;
}

.o4c-chat-bubble.attention::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    border: 3px solid var(--o4c-gold);
    opacity: 0;
    pointer-events: none;
    animation: o4c-ring 2.2s ease-out infinite;
}

/* Punto rojo de notificación mientras hay aviso */
.o4c-chat-bubble.attention::after {
    opacity: 1;
    animation: o4c-pulse 1.5s infinite;
}

@keyframes o4c-glow {
    0%, 100% { box-shadow: 0 6px 20px rgba(11, 42, 74, 0.4), 0 0 0 0 rgba(212, 160, 23, 0.5); }
    50% { box-shadow: 0 6px 20px rgba(11, 42, 74, 0.4), 0 0 0 14px rgba(212, 160, 23, 0); }
}

@keyframes o4c-ring {
    0% { transform: scale(0.9); opacity: 0.9; }
    70% { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* Tarjeta de aviso junto al botón */
.o4c-nudge {
    position: fixed;
    bottom: 105px;
    left: 30px;
    width: 280px;
    max-width: calc(100vw - 60px);
    background: var(--o4c-white);
    border-radius: 14px;
    border: 1px solid rgba(11, 42, 74, 0.12);
    border-left: 4px solid var(--o4c-gold);
    box-shadow: 0 12px 34px rgba(11, 42, 74, 0.28);
    padding: 13px 30px 13px 14px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    z-index: 9997;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(0.96);
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.35s ease;
    font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
    animation: o4c-nudgeIn 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.o4c-nudge.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

@keyframes o4c-nudgeIn {
    from { opacity: 0; transform: translateY(14px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Flechita apuntando al botón */
.o4c-nudge::after {
    content: '';
    position: absolute;
    bottom: -7px;
    left: 24px;
    width: 14px;
    height: 14px;
    background: var(--o4c-white);
    border-right: 1px solid rgba(11, 42, 74, 0.12);
    border-bottom: 1px solid rgba(11, 42, 74, 0.12);
    transform: rotate(45deg);
    border-radius: 0 0 3px 0;
}

.o4c-nudge-emoji {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--o4c-blue) 0%, var(--o4c-blue-dark) 100%);
    border: 2px solid var(--o4c-gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    flex-shrink: 0;
}

.o4c-nudge-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.o4c-nudge-text strong {
    font-size: 13.5px;
    color: var(--o4c-blue);
    line-height: 1.25;
}

.o4c-nudge-text span {
    font-size: 12px;
    color: #555;
    line-height: 1.4;
}

.o4c-nudge-text .o4c-nudge-cta {
    margin-top: 5px;
    color: var(--o4c-red);
    font-weight: 700;
    font-size: 12.5px;
}

.o4c-nudge-close {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: #9aa5b1;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    padding: 0;
    transition: color 0.2s ease, background 0.2s ease;
}

.o4c-nudge-close:hover {
    color: var(--o4c-white);
    background: var(--o4c-red);
}

@media (max-width: 480px) {
    .o4c-nudge {
        bottom: 88px;
        left: 16px;
        width: calc(100vw - 32px);
        max-width: 300px;
        padding: 12px 28px 12px 12px;
    }

    .o4c-nudge::after {
        left: 20px;
    }

    .o4c-nudge-text strong { font-size: 13px; }
    .o4c-nudge-text span { font-size: 11.5px; }
}

/* Se muestra solo cuando este CSS ya cargo (evita parpadeo del widget) */
#o4c-chat-widget { display: block; }

/* ===== TARJETA DE IDENTIDAD (foto del cliente por RIF) ===== */
.o4c-ident {
    display: flex;
    align-items: center;
    gap: 12px;
    align-self: flex-start;
    max-width: 100%;
    background: linear-gradient(135deg, rgba(11, 42, 74, 0.07), rgba(11, 42, 74, 0.02));
    border: 1px solid rgba(11, 42, 74, 0.14);
    border-radius: 14px;
    padding: 10px 14px 10px 10px;
    box-shadow: 0 2px 8px rgba(11, 42, 74, 0.06);
}

.o4c-ident-foto {
    width: 58px;
    height: 58px;
    flex: 0 0 58px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--o4c-blue, #0b2a4a);
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
}

.o4c-ident-foto-sin { object-fit: contain; padding: 6px; }

.o4c-ident-datos { min-width: 0; }

.o4c-ident-nombre {
    font-weight: 800;
    font-size: 13.5px;
    line-height: 1.25;
    color: var(--o4c-blue, #0b2a4a);
    word-break: break-word;
}

.o4c-ident-rif {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
    word-break: break-word;
}

.o4c-ident-ok {
    font-size: 11px;
    font-weight: 800;
    color: #059669;
    margin-top: 3px;
}

/* ===== BARRA FIJA DEL CLIENTE (la foto se mantiene durante todo el chat) ===== */
.o4c-cliente-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    padding: 9px 20px;
    background: linear-gradient(135deg, rgba(11, 42, 74, 0.10), rgba(212, 160, 23, 0.10));
    border-bottom: 1px solid rgba(11, 42, 74, 0.16);
    box-shadow: 0 2px 6px rgba(11, 42, 74, 0.06);
}

.o4c-cliente-bar .o4c-ident {
    border: none;
    background: none;
    box-shadow: none;
    padding: 0;
    max-width: 100%;
}

.o4c-cliente-bar .o4c-ident-foto {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    font-size: 20px;
}

.o4c-cliente-bar .o4c-ident-nombre { font-size: 13px; }
.o4c-cliente-bar .o4c-ident-rif { font-size: 11.5px; margin-top: 1px; }
.o4c-cliente-bar .o4c-ident-ok { font-size: 10.5px; margin-top: 2px; }

/* ===== LISTA DE PRECIOS (una línea por producto con miniatura) ===== */
.o4c-prods {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 4px 0;
}

.o4c-prod {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid rgba(11, 42, 74, 0.10);
    border-radius: 10px;
    padding: 7px 10px;
    box-shadow: 0 1px 3px rgba(11, 42, 74, 0.05);
}

.o4c-prod-img {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    object-fit: contain;
    background: #f8fafc;
    border: 1px solid rgba(11, 42, 74, 0.08);
    border-radius: 6px;
    padding: 2px;
}

.o4c-prod-img.noimg { display: none; }

.o4c-prod-info { flex: 1 1 auto; min-width: 0; }

.o4c-prod-codigo {
    font-weight: 800;
    font-size: 12.5px;
    color: var(--o4c-blue, #0b2a4a);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.o4c-prod-num { color: #94a3b8; font-weight: 700; margin-right: 5px; }

.o4c-prod-desc {
    font-size: 11.5px;
    color: #475569;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.o4c-prod-precio {
    flex: 0 0 auto;
    text-align: right;
    font-weight: 800;
    font-size: 13.5px;
    color: #059669;
    white-space: nowrap;
}

.o4c-prod-stock {
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    color: #94a3b8;
    margin-top: 1px;
}

.o4c-prod-lock {
    flex: 0 0 auto;
    font-size: 10.5px;
    font-weight: 700;
    color: #b45309;
    background: #fef3c7;
    border-radius: 999px;
    padding: 4px 9px;
    white-space: nowrap;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 560px) {
    .o4c-prod-desc { -webkit-line-clamp: 1; }
    .o4c-prod-lock { max-width: 120px; }
}
