/* Widget de chat del chatbot de ventas. Namespace bajo #sv-chatbot-root para
   no chocar con estilos de maincliente.php ni de otras vistas. Paleta igual
   a la del resto del sitio de clientes (ver cartaview.php / maincliente.php):
   no hay paletas distintas por local, todos comparten --rappi-rojo. */

#sv-chatbot-root {
    --sv-rojo: #FF441F;
    --sv-rojo-oscuro: #E8330E;
    --sv-oscuro: #1a1a1a;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#sv-chatbot-root * {
    box-sizing: border-box;
}

/* Boton flotante */
#sv-chatbot-btn {
    position: fixed;
    right: 16px;
    bottom: 88px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--sv-rojo);
    color: #fff;
    border: none;
    box-shadow: 0 10px 24px rgba(255, 68, 31, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1040;
    transition: transform 0.15s ease;
}
#sv-chatbot-btn:hover { transform: scale(1.06); animation-play-state: paused; }
#sv-chatbot-btn:active { transform: scale(0.96); }

/* Latido suave para llamar la atencion sin ser invasivo: la mayor parte del
   ciclo el boton esta quieto, solo "late" un instante cada ~3.6s. Se pausa
   mientras el panel esta abierto (ver sv-sin-pulse en widget.js). */
@keyframes sv-pulse {
    0%, 86%, 100% { transform: scale(1); box-shadow: 0 10px 24px rgba(255, 68, 31, 0.4); }
    91% { transform: scale(1.1); box-shadow: 0 12px 30px rgba(255, 68, 31, 0.55); }
    96% { transform: scale(1); box-shadow: 0 10px 24px rgba(255, 68, 31, 0.4); }
}
#sv-chatbot-btn { animation: sv-pulse 3.6s ease-in-out infinite; }
#sv-chatbot-btn.sv-sin-pulse { animation: none; }

/* Mientras el globo de atencion esta visible, un glow mas notorio (reemplaza
   el latido base) para que el boton se note mas junto con el mensaje. */
@keyframes sv-glow-atento {
    0%, 100% { box-shadow: 0 10px 24px rgba(255, 68, 31, 0.4), 0 0 0 0 rgba(255, 68, 31, 0.55); transform: scale(1); }
    50% { box-shadow: 0 10px 24px rgba(255, 68, 31, 0.4), 0 0 0 9px rgba(255, 68, 31, 0); transform: scale(1.05); }
}
#sv-chatbot-btn.sv-atento { animation: sv-glow-atento 1.7s ease-in-out infinite; }

/* Globo de atencion, apunta al boton flotante. Fondo blanco / texto oscuro
   con acento naranja (borde izquierdo + contorno) para combinar con el
   boton sin copiar su color solido. */
#sv-chatbot-tooltip {
    position: fixed;
    right: 16px;
    max-width: 220px;
    background: #fff;
    color: var(--sv-oscuro);
    padding: 12px 32px 12px 16px;
    border-radius: 16px;
    border-left: 4px solid var(--sv-rojo);
    box-shadow: 0 0 0 1px rgba(255, 68, 31, 0.12), 0 14px 32px rgba(0,0,0,0.18);
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1.35;
    cursor: pointer;
    z-index: 1039;
    display: none;
    transform-origin: bottom right;
    animation: sv-tooltip-in 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
}
#sv-chatbot-tooltip.sv-visible { display: block; }
#sv-chatbot-tooltip::after {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 24px;
    width: 13px;
    height: 13px;
    background: #fff;
    border-right: 1px solid rgba(255, 68, 31, 0.12);
    border-bottom: 1px solid rgba(255, 68, 31, 0.12);
    transform: rotate(45deg);
}
#sv-chatbot-tooltip-cerrar {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    color: #b3b3b3;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
}
#sv-chatbot-tooltip-cerrar:hover { color: var(--sv-oscuro); background: #f2f2f2; }

@keyframes sv-tooltip-in {
    from { opacity: 0; transform: translateY(14px) scale(0.85); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Panel de chat */
#sv-chatbot-panel {
    position: fixed;
    right: 16px;
    bottom: 88px;
    width: min(360px, calc(100vw - 24px));
    height: min(560px, calc(100vh - 140px));
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 1041;
}
#sv-chatbot-panel.sv-abierto { display: flex; }

#sv-chatbot-header {
    background: linear-gradient(135deg, #2a2a2a, #0a0a0a);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
#sv-chatbot-header .sv-titulo {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 800;
    font-size: 0.95rem;
}
#sv-chatbot-header .sv-titulo i { color: var(--sv-rojo); }
#sv-chatbot-header .sv-subtitulo {
    font-size: 0.72rem;
    color: #bbb;
    font-weight: 500;
    margin-top: 2px;
}
#sv-chatbot-cerrar, #sv-chatbot-borrar {
    background: none;
    border: none;
    color: #ccc;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
#sv-chatbot-borrar { font-size: 0.92rem; margin-right: 6px; }
#sv-chatbot-cerrar:hover { color: #fff; }
#sv-chatbot-borrar:hover { color: var(--sv-rojo); }
#sv-chatbot-borrar:disabled { color: #555; cursor: not-allowed; }

#sv-chatbot-mensajes {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f7f8;
}

.sv-msg {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 0.86rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.sv-msg-bot {
    align-self: flex-start;
    background: #fff;
    color: var(--sv-oscuro);
    border: 1px solid #ececec;
    border-bottom-left-radius: 4px;
}
.sv-msg-user {
    align-self: flex-end;
    background: var(--sv-rojo);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.sv-msg-error {
    align-self: center;
    background: #fdecea;
    color: #b3261e;
    border: 1px solid #f6c6c2;
    font-size: 0.8rem;
    text-align: center;
}

/* Links dentro de una respuesta del bot (ej. el link de pago de Wompi que
   Claude escribe como texto plano) -- sin esto se veian como texto suelto,
   no clicables. */
.sv-msg-bot a.sv-msg-link {
    color: var(--sv-rojo);
    font-weight: 600;
    text-decoration: underline;
    word-break: break-all;
}

/* Tarjeta de resumen del pedido (mostrar_resumen_pedido). Solo items,
   subtotales y total -- no hay direccion/domicilio/pago en este flujo aun. */
.sv-resumen-card {
    align-self: flex-start;
    max-width: 92%;
    width: 100%;
    background: #fff;
    border: 1px solid #ececec;
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.06);
}
.sv-resumen-titulo {
    font-weight: 800;
    font-size: 0.84rem;
    color: var(--sv-oscuro);
    margin-bottom: 9px;
    display: flex;
    align-items: center;
    gap: 7px;
}
.sv-resumen-titulo i { color: var(--sv-rojo); }
.sv-resumen-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.sv-resumen-item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.82rem;
    color: #444;
}
.sv-resumen-item-nombre {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sv-resumen-total {
    display: flex;
    justify-content: space-between;
    font-weight: 800;
    font-size: 0.9rem;
    color: var(--sv-oscuro);
    border-top: 1px solid #f1f1f1;
    margin-top: 9px;
    padding-top: 9px;
}

/* Tarjeta de datos de transferencia -- reutiliza .sv-resumen-card/-titulo/
   -items/-item como base, con extras propios para valor destacado, QR y nota. */
.sv-transferencia-valor {
    font-weight: 700;
    color: var(--sv-oscuro);
}
.sv-transferencia-qr {
    display: block;
    width: 150px;
    height: 150px;
    object-fit: contain;
    margin: 12px auto 0 auto;
    border: 1px solid #ececec;
    border-radius: 8px;
    padding: 6px;
}
.sv-transferencia-nota {
    font-size: 0.74rem;
    color: #888;
    text-align: center;
    margin-top: 10px;
    font-style: italic;
}

/* Boton/link al PDF del menu con fotos (ver_menu_pdf). */
.sv-menu-pdf-link {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1.5px solid var(--sv-rojo);
    color: var(--sv-rojo);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;
    max-width: 92%;
}
.sv-menu-pdf-link:hover { background: var(--sv-rojo); color: #fff; text-decoration: none; }
.sv-menu-pdf-link i { font-size: 1rem; }

/* Grid de tarjetas de producto (buscar_menu) con boton "+ Agregar" clicable. */
.sv-menu-grid {
    align-self: flex-start;
    max-width: 92%;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.sv-menu-card {
    background: #fff;
    border: 1px solid #ececec;
    border-radius: 12px;
    padding: 9px;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.06);
    display: flex;
    flex-direction: column;
}
.sv-menu-card-img {
    width: 100%;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 6px;
}
.sv-menu-card-nombre {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--sv-oscuro);
    line-height: 1.25;
    margin-bottom: 3px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.sv-menu-card-precio {
    font-size: 0.78rem;
    font-weight: 800;
    color: #666;
    margin-bottom: 7px;
}
.sv-menu-card-btn {
    background: var(--sv-rojo);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 7px 0;
    font-size: 0.76rem;
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
    margin-top: auto;
    transition: background 0.15s ease;
}
.sv-menu-card-btn:hover { background: var(--sv-rojo-oscuro); }
.sv-menu-card-btn:disabled { cursor: default; }
.sv-menu-card-btn-ok { background: #2e9e5b; }

/* Variantes de un plato agrupado (sola / con papas, ver agruparVariantes en
   chatbot-tools.php) -- ocultas hasta que se toca "Elegir" en la tarjeta. */
.sv-menu-card-variantes {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: auto;
}
.sv-menu-card-variante-btn {
    background: #fff;
    color: var(--sv-rojo);
    border: 1.5px solid var(--sv-rojo);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.72rem;
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    transition: background 0.15s ease, color 0.15s ease;
}
.sv-menu-card-variante-btn span { font-weight: 700; opacity: 0.85; }
.sv-menu-card-variante-btn:hover { background: var(--sv-rojo); color: #fff; }
.sv-menu-card-variante-btn:disabled { cursor: default; }

/* Tarjeta de restaurante (buscar_locales) -- reusa .sv-menu-card, pero es un
   <a> real (no un div), asi que hay que pisar el subrayado/color azul por
   defecto del link. */
.sv-local-card { text-decoration: none; color: inherit; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.sv-local-card:hover { text-decoration: none; color: inherit; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12); }
.sv-local-card-direccion {
    font-size: 0.68rem;
    color: #888;
    line-height: 1.3;
    margin-bottom: 7px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Botones de opcion multiple (preguntar_opciones), estilo "quick reply"
   de chat de WhatsApp: pastillas debajo del mensaje del bot. */
.sv-opciones {
    align-self: flex-start;
    max-width: 92%;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}
.sv-opcion-btn {
    background: #fff;
    color: var(--sv-rojo);
    border: 1.5px solid var(--sv-rojo);
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease;
}
.sv-opcion-btn:hover { background: var(--sv-rojo); color: #fff; }
.sv-opcion-btn:active { background: var(--sv-rojo-oscuro); border-color: var(--sv-rojo-oscuro); }

.sv-typing {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #ececec;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    padding: 11px 15px;
    display: flex;
    gap: 4px;
}
.sv-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #bbb;
    animation: sv-typing-bounce 1.2s infinite ease-in-out;
}
.sv-typing span:nth-child(2) { animation-delay: 0.15s; }
.sv-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sv-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

#sv-chatbot-carrito {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    background: #fff3f0;
    border-top: 1px solid #f3d9d3;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--sv-oscuro);
    flex-shrink: 0;
}
#sv-chatbot-carrito.sv-visible { display: flex; }
#sv-chatbot-carrito a {
    background: var(--sv-rojo);
    color: #fff;
    padding: 6px 12px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 0.74rem;
    font-weight: 800;
}
#sv-chatbot-carrito a:hover { background: var(--sv-rojo-oscuro); color: #fff; text-decoration: none; }

#sv-chatbot-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #ececec;
    background: #fff;
    flex-shrink: 0;
}
#sv-chatbot-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 22px;
    padding: 9px 15px;
    font-size: 0.86rem;
    font-family: inherit;
    outline: none;
}
#sv-chatbot-input:focus { border-color: var(--sv-rojo); }
#sv-chatbot-enviar {
    background: var(--sv-rojo);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.95rem;
}
#sv-chatbot-enviar:hover { background: var(--sv-rojo-oscuro); }
#sv-chatbot-enviar:disabled { background: #ddd; cursor: not-allowed; }

#sv-chatbot-adjuntar {
    background: none;
    color: #888;
    border: 1.5px solid #ddd;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.95rem;
}
#sv-chatbot-adjuntar:hover { border-color: var(--sv-rojo); color: var(--sv-rojo); }
#sv-chatbot-adjuntar:disabled { color: #ccc; border-color: #eee; cursor: not-allowed; }

#sv-chatbot-ubicacion {
    background: none;
    color: #888;
    border: 1.5px solid #ddd;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.95rem;
}
#sv-chatbot-ubicacion:hover { border-color: var(--sv-rojo); color: var(--sv-rojo); }
#sv-chatbot-ubicacion:disabled { color: #ccc; border-color: #eee; cursor: not-allowed; }

/* Burbuja de imagen (comprobante de pago) enviada por el cliente -- reemplaza
   el padding/texto de .sv-msg por una miniatura clicable-friendly. */
.sv-msg-imagen {
    padding: 4px;
    max-width: 65%;
}
.sv-msg-imagen img {
    display: block;
    width: 100%;
    max-height: 220px;
    border-radius: 10px;
    object-fit: cover;
}

/* Botones de estrellas para calificar al repartidor (ver
   agregarBotonesCalificacion en widget.js). */
.sv-calificacion {
    padding: 10px 12px;
}
.sv-calificacion-estrellas {
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-end;
    gap: 4px;
}
.sv-calificacion-btn {
    background: none;
    border: none;
    padding: 2px;
    font-size: 1.5rem;
    line-height: 1;
    color: #e0e0e0;
    cursor: pointer;
    transition: transform 0.1s, color 0.15s;
}
/* El orden en el DOM esta invertido (5..1) a proposito -- ver
   agregarBotonesCalificacion() en widget.js -- para poder resaltar con
   ~ TODAS las estrellas hasta la apuntada (no solo la que esta debajo del
   mouse) usando nada mas que CSS. */
.sv-calificacion-btn:hover:not(:disabled),
.sv-calificacion-btn:hover:not(:disabled) ~ .sv-calificacion-btn:not(:disabled) {
    color: #ffb703;
    transform: scale(1.15);
}
.sv-calificacion-btn:disabled {
    cursor: default;
    opacity: 0.5;
}

@media (max-width: 420px) {
    #sv-chatbot-panel {
        right: 10px;
        left: 10px;
        width: auto;
        bottom: 84px;
        height: min(70vh, calc(100vh - 130px));
    }
    #sv-chatbot-btn { right: 12px; }
}
