/**
 * AI Sales Assistant - Estilos del Widget de Chat
 *
 * Estilos para el widget de chat en el frontend.
 *
 * @package AI_Sales_Assistant
 * @since 1.0.0
 */

/* Variables CSS personalizables */
:root {
    --aisa-color-primario: #0073aa;
    --aisa-color-secundario: #ffffff;
    --aisa-color-texto: #333333;
    --aisa-color-texto-claro: #666666;
    --aisa-color-fondo: #f5f5f5;
    --aisa-color-borde: #e0e0e0;
    --aisa-sombra: 0 4px 20px rgba(0, 0, 0, 0.15);
    --aisa-radio-borde: 12px;
    --aisa-transicion: all 0.3s ease;
}

/* Contenedor principal del widget */
#aisa-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* Botón flotante del chat */
#aisa-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--aisa-color-primario);
    color: var(--aisa-color-secundario);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--aisa-sombra);
    transition: var(--aisa-transicion);
    position: relative;
}

#aisa-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

#aisa-chat-button.aisa-chat-open {
    transform: rotate(90deg);
}

#aisa-chat-button i {
    font-size: 24px;
}

/* Badge de mensajes no leídos */
.aisa-unread-count {
    position: absolute;
    top: -5px;
    right: -5px; /* default derecha — se sobreescribe por inline CSS según posición */
    background: #dc3232;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    animation: aisa-pulse 2s infinite;
}

@keyframes aisa-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Ventana del chat */
#aisa-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0; /* default derecha — se sobreescribe por inline CSS según posición */
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: var(--aisa-color-secundario);
    border-radius: var(--aisa-radio-borde);
    box-shadow: var(--aisa-sombra);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aisa-slideUp 0.3s ease;
}

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

/* Header del chat */
.aisa-chat-header {
    background: var(--aisa-color-primario);
    color: var(--aisa-color-secundario);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.aisa-agent-avatar-wrapper {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.aisa-agent-avatar-wrapper img,
.aisa-agent-avatar,
.aisa-agent-avatar-default {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.aisa-agent-avatar-wrapper img,
.aisa-agent-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.aisa-agent-avatar-default {
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.aisa-agent-avatar-default i {
    font-size: 20px;
}

.aisa-agent-name {
    flex: 1;
    font-weight: 600;
    font-size: 16px;
}

.aisa-minimize-btn,
.aisa-close-btn {
    background: transparent;
    border: none;
    color: var(--aisa-color-secundario);
    cursor: pointer;
    padding: 5px;
    opacity: 0.8;
    transition: var(--aisa-transicion);
}

.aisa-minimize-btn:hover,
.aisa-close-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.aisa-minimize-btn i,
.aisa-close-btn i {
    font-size: 16px;
}

/* Área de mensajes */
.aisa-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--aisa-color-fondo);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Scrollbar personalizado */
.aisa-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

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

.aisa-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* Mensajes */
.aisa-message {
    max-width: 85%;
    animation: aisa-fadeIn 0.3s ease;
}

@keyframes aisa-fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.aisa-message-user {
    align-self: flex-end;
}

.aisa-message-agent {
    align-self: flex-start;
}

.aisa-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

.aisa-message-user .aisa-message-content {
    background: var(--aisa-color-primario);
    color: var(--aisa-color-secundario);
    border-bottom-right-radius: 4px;
}

.aisa-message-agent .aisa-message-content {
    background: var(--aisa-color-secundario);
    color: var(--aisa-color-texto);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.aisa-message-error .aisa-message-content {
    background: #fff3f3;
    color: #dc3232;
    border: 1px solid #ffcaca;
}

.aisa-message-content a {
    color: inherit;
    text-decoration: underline;
}

.aisa-message-content a:hover {
    text-decoration: none;
}

.aisa-message-time {
    font-size: 11px;
    color: var(--aisa-color-texto-claro);
    margin-top: 4px;
    padding: 0 5px;
}

.aisa-message-user .aisa-message-time {
    text-align: right;
}

/* Indicador de escritura */
.aisa-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--aisa-color-secundario);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin: 0 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.aisa-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--aisa-color-texto-claro);
    border-radius: 50%;
    animation: aisa-typing 1.4s infinite ease-in-out;
}

.aisa-typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

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

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

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

/* Área de input */
.aisa-chat-input {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 20px;
    background: var(--aisa-color-secundario);
    border-top: 1px solid var(--aisa-color-borde);
    flex-shrink: 0;
}

.aisa-chat-input input {
    flex: 1;
    border: 1px solid var(--aisa-color-borde);
    border-radius: 25px;
    padding: 12px 20px;
    font-size: 14px;
    outline: none;
    transition: var(--aisa-transicion);
}

.aisa-chat-input input:focus {
    border-color: var(--aisa-color-primario);
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

.aisa-chat-input input::placeholder {
    color: var(--aisa-color-texto-claro);
}

.aisa-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--aisa-color-primario);
    color: var(--aisa-color-secundario);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--aisa-transicion);
    flex-shrink: 0;
}

.aisa-send-btn:hover {
    background: var(--aisa-color-primario);
    filter: brightness(1.1);
    transform: scale(1.05);
}

.aisa-send-btn:active {
    transform: scale(0.95);
}

.aisa-send-btn i {
    font-size: 16px;
}

/* Responsive */
@media (max-width: 480px) {
    #aisa-chat-widget {
        bottom: 10px;
        /* left/right se sobreescriben por inline CSS según posición */
    }

    #aisa-chat-button {
        width: 55px;
        height: 55px;
    }

    #aisa-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 70px;
        /* left/right se sobreescriben por inline CSS según posición */
        border-radius: 16px 16px 0 0;
    }

    .aisa-chat-header {
        padding: 12px 15px;
    }

    .aisa-chat-messages {
        padding: 15px;
    }

    .aisa-chat-input {
        padding: 12px 15px;
    }

    .aisa-message {
        max-width: 90%;
    }
}

/* Modo oscuro (si el tema lo soporta) */
@media (prefers-color-scheme: dark) {
    :root {
        --aisa-color-fondo: #1a1a1a;
        --aisa-color-texto: #e0e0e0;
        --aisa-color-texto-claro: #999999;
        --aisa-color-borde: #333333;
    }

    .aisa-message-agent .aisa-message-content {
        background: #2a2a2a;
    }

    .aisa-chat-input input {
        background: #2a2a2a;
        color: #e0e0e0;
    }

    #aisa-chat-window {
        background: #1a1a1a;
    }

    .aisa-chat-input {
        background: #1a1a1a;
    }
}

/* ── Lista simple de items del agente ── */
.aisa-list {
    list-style: none;
    margin: 6px 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.aisa-list-item {
    padding: 5px 0 5px 14px;
    position: relative;
    font-size: 13px;
    line-height: 1.5;
}

.aisa-list-item::before {
    content: '•';
    position: absolute;
    left: 2px;
    color: var(--aisa-color-primario, #0073aa);
    font-weight: 700;
}

/* ── Botones de acción de producto ── */
.aisa-product-actions {
    display: flex;
    gap: 7px;
    margin-top: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* ── Tarjetas de producto dentro del chat ── */
.aisa-product-card {
    width: 100%;
    max-width: 320px;
    background: #e6dcc7;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    margin: 12px 0;
}

.aisa-product-card-content {
    padding: 16px;
    flex: 1;
}

/* h2 del título */
.aisa-product-card-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #6b1e16;
    line-height: 1.2;
}

/* p de descripción */
.aisa-product-card-desc {
    font-size: 13px;
    color: #6b1e16;
    margin: 10px 0;
    line-height: 1.4;
}

/* Link "Ver Nombre" */
.aisa-product-link {
    display: inline-block;
    margin-bottom: 15px;
    font-size: 13px;
    color: #2a6f6d !important;
    text-decoration: none !important;
    font-weight: bold;
}

.aisa-product-link:hover {
    text-decoration: underline !important;
}

/* Fila precio + rating */
.aisa-product-price-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Precio grande */
.aisa-product-card-price {
    font-size: 32px;
    font-weight: bold;
    color: #6b1e16;
    line-height: 1;
}

/* Rating (estrellas + badge) */
.aisa-product-rating {
    text-align: right;
    font-size: 16px;
    color: #6b1e16;
    line-height: 1.3;
}

/* Badge debajo de las estrellas */
.aisa-product-card-discount {
    font-size: 11px;
    margin-top: 4px;
    color: inherit;
}

/* Footer = <a> de "Agregar al carrito" */
.aisa-product-card-footer {
    display: block;
    background: #58a9a6;
    color: #ffffff !important;
    text-align: center;
    padding: 14px;
    font-weight: bold;
    font-size: 13px;
    text-decoration: none !important;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    transition: filter 0.18s ease;
}

.aisa-product-card-footer:hover {
    filter: brightness(1.08);
    color: #ffffff !important;
}

/* Texto introductorio antes de las cards */
.aisa-intro-text {
    margin-bottom: 8px;
}

.aisa-btn-ver,
.aisa-btn-comprar {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none !important;
    line-height: 1;
    transition: all 0.18s ease;
    white-space: nowrap;
    cursor: pointer;
}

.aisa-btn-ver {
    border: 1.5px solid var(--aisa-color-primario, #0073aa);
    color: var(--aisa-color-primario, #0073aa) !important;
    background: transparent;
}

.aisa-btn-ver:hover {
    background: var(--aisa-color-primario, #0073aa);
    color: #fff !important;
}

.aisa-btn-comprar {
    background: var(--aisa-color-primario, #0073aa);
    color: #fff !important;
    border: 1.5px solid transparent;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}

.aisa-btn-comprar:hover {
    filter: brightness(1.1);
    box-shadow: 0 3px 10px rgba(0,0,0,0.22);
    transform: translateY(-1px);
}

@media (prefers-color-scheme: dark) {
    .aisa-product-card {
        background: #3a3225;
        border-color: #5a4a35;
    }

    .aisa-product-card-price {
        color: #ffb5b5;
    }

    .aisa-product-card-title,
    .aisa-product-card-desc,
    .aisa-product-card-price,
    .aisa-product-rating,
    .aisa-product-card-discount { color: #eadfca; }
    .aisa-product-link { color: #8fd2cf !important; }

    .aisa-list-item::before { color: var(--aisa-color-primario, #4da6d4); }
    .aisa-btn-ver {
        border-color: var(--aisa-color-primario, #4da6d4);
        color: var(--aisa-color-primario, #4da6d4) !important;
    }
    .aisa-btn-ver:hover {
        background: var(--aisa-color-primario, #4da6d4);
        color: #fff !important;
    }
}

@media (min-width: 600px) {
    .aisa-product-card {
        max-width: 360px;
    }
}

@media (min-width: 1024px) {
    .aisa-product-card {
        max-width: 400px;
    }

    .aisa-product-card-content {
        padding: 20px;
    }
}
