/**
 * LDK AI Assistant - Chat Widget Styles
 * LaserDentKids - Especialistas en Atencion Dental para Ninos
 * Rediseño completo - Moderno y Profesional
 */

/* Variables de colores */
:root {
    --ldk-primary: #8B5CF6;
    --ldk-primary-dark: #7C3AED;
    --ldk-primary-light: #A78BFA;
    --ldk-secondary: #25D366;
    --ldk-accent: #F59E0B;
    --ldk-text: #1F2937;
    --ldk-text-light: #6B7280;
    --ldk-bg: #F3F4F6;
    --ldk-bg-light: #F9FAFB;
    --ldk-white: #FFFFFF;
    --ldk-shadow: 0 10px 40px rgba(139, 92, 246, 0.3);
    --ldk-shadow-sm: 0 4px 15px rgba(0, 0, 0, 0.1);
    --ldk-radius: 20px;
    --ldk-radius-sm: 12px;
}

/* Reset y Base */
.ldk-chat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Widget Container */
.ldk-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2147483647; /* Maximo z-index posible */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Ocultar otros botones flotantes cuando el chat esta abierto */
body.ldk-chat-open .joinchat,
body.ldk-chat-open .joinchat__button,
body.ldk-chat-open .wa-float-button,
body.ldk-chat-open .whatsapp-button,
body.ldk-chat-open [class*="whatsapp"],
body.ldk-chat-open [class*="wa-float"],
body.ldk-chat-open .floating-wpp,
body.ldk-chat-open .btn-whatsapp,
body.ldk-chat-open .qlwapp {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

/* ==========================================
   BOTON FLOTANTE (Toggle)
   ========================================== */
.ldk-chat-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ldk-primary) 0%, var(--ldk-primary-dark) 100%);
    border: none;
    cursor: pointer;
    box-shadow: var(--ldk-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible;
}

.ldk-chat-toggle:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 15px 50px rgba(139, 92, 246, 0.45);
}

.ldk-chat-toggle:active {
    transform: scale(0.95);
}

/* Icono SVG del boton */
.ldk-chat-toggle svg {
    width: 30px;
    height: 30px;
    fill: white;
    display: block;
    transition: transform 0.3s ease;
}

.ldk-chat-toggle:hover svg {
    transform: scale(1.1);
}

/* Efecto de pulso animado */
.ldk-chat-toggle::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--ldk-primary);
    opacity: 0.4;
    animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    z-index: -1;
}

.ldk-chat-toggle::after {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: var(--ldk-accent);
    border-radius: 50%;
    border: 3px solid white;
    animation: bounce-dot 2s ease-in-out infinite;
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.4;
    }
    50% {
        transform: scale(1.4);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

@keyframes bounce-dot {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-3px);
    }
}

.ldk-chat-toggle.active::before,
.ldk-chat-toggle.active::after {
    display: none;
}

/* ==========================================
   VENTANA DE CHAT
   ========================================== */
.ldk-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 550px;
    max-height: calc(100vh - 140px);
    background: var(--ldk-white);
    border-radius: var(--ldk-radius);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(139, 92, 246, 0.1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================
   HEADER
   ========================================== */
.ldk-chat-header {
    background: linear-gradient(135deg, var(--ldk-primary) 0%, var(--ldk-primary-dark) 100%);
    color: var(--ldk-white);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 80px;
    position: relative;
    overflow: hidden;
}

/* Efecto decorativo en header */
.ldk-chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.ldk-chat-header::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -10%;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
}

/* Logo/Avatar */
.ldk-chat-header img {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--ldk-white);
    padding: 3px;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
}

.ldk-chat-header-info {
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.ldk-chat-header h4 {
    margin: 0 0 5px 0;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ldk-chat-header span {
    font-size: 13px;
    opacity: 0.95;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

/* Indicador Online */
.ldk-chat-header span::before {
    content: '';
    width: 10px;
    height: 10px;
    background: #34D399;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.3);
    animation: online-pulse 2s ease-in-out infinite;
}

@keyframes online-pulse {
    0%, 100% {
        box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.3);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(52, 211, 153, 0.1);
    }
}

/* Boton Cerrar */
.ldk-chat-close {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: none;
    color: var(--ldk-white);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    font-weight: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    line-height: 1;
}

.ldk-chat-close:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: rotate(90deg) scale(1.1);
}

/* ==========================================
   AREA DE MENSAJES
   ========================================== */
.ldk-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(180deg, var(--ldk-bg-light) 0%, var(--ldk-bg) 100%);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

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

.ldk-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 3px;
}

.ldk-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.5);
}

/* ==========================================
   BURBUJAS DE MENSAJE
   ========================================== */
.ldk-message {
    max-width: 85%;
    animation: message-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ldk-message p {
    margin: 0;
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Mensaje del Bot */
.ldk-message.ldk-bot {
    align-self: flex-start;
}

.ldk-message.ldk-bot p {
    background: var(--ldk-white);
    color: var(--ldk-text);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

/* Mensaje del Usuario */
.ldk-message.ldk-user {
    align-self: flex-end;
}

.ldk-message.ldk-user p {
    background: linear-gradient(135deg, var(--ldk-primary) 0%, var(--ldk-primary-dark) 100%);
    color: var(--ldk-white);
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

/* ==========================================
   INDICADOR DE ESCRIBIENDO
   ========================================== */
.ldk-typing {
    display: flex;
    gap: 5px;
    padding: 16px 22px;
    background: var(--ldk-white);
    border-radius: 20px;
    border-bottom-left-radius: 6px;
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    align-self: flex-start;
}

.ldk-typing span {
    width: 9px;
    height: 9px;
    background: var(--ldk-primary-light);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.ldk-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.ldk-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ==========================================
   AREA DE INPUT
   ========================================== */
.ldk-chat-input-area {
    padding: 16px 18px;
    background: var(--ldk-white);
    display: flex;
    gap: 12px;
    align-items: center;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.ldk-chat-input-area input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid #E5E7EB;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
    background: var(--ldk-bg-light);
    color: var(--ldk-text);
}

.ldk-chat-input-area input:focus {
    border-color: var(--ldk-primary);
    background: var(--ldk-white);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
}

.ldk-chat-input-area input::placeholder {
    color: #9CA3AF;
}

/* Boton Enviar */
.ldk-chat-input-area button {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ldk-primary) 0%, var(--ldk-primary-dark) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.ldk-chat-input-area button svg {
    width: 22px;
    height: 22px;
    fill: white;
    display: block;
    transition: transform 0.2s ease;
}

.ldk-chat-input-area button:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.ldk-chat-input-area button:hover svg {
    transform: translateX(2px);
}

.ldk-chat-input-area button:active {
    transform: scale(0.95);
}

.ldk-chat-input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ==========================================
   FOOTER / WHATSAPP LINK
   ========================================== */
.ldk-chat-footer {
    padding: 12px 18px;
    background: var(--ldk-bg-light);
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
}

.ldk-chat-footer a {
    color: var(--ldk-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(37, 211, 102, 0.1);
}

.ldk-chat-footer a:hover {
    background: rgba(37, 211, 102, 0.2);
    transform: translateY(-1px);
}

/* ==========================================
   RESPUESTAS RAPIDAS (Quick Replies)
   ========================================== */
.ldk-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding-left: 5px;
}

.ldk-quick-reply {
    padding: 10px 16px;
    background: var(--ldk-white);
    border: 2px solid var(--ldk-primary-light);
    border-radius: 20px;
    color: var(--ldk-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ldk-quick-reply:hover {
    background: var(--ldk-primary);
    border-color: var(--ldk-primary);
    color: var(--ldk-white);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

/* ==========================================
   MENSAJE DE WHATSAPP (en chat)
   ========================================== */
.ldk-whatsapp-cta {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    border-radius: 16px;
    margin-top: 10px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ldk-whatsapp-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4);
}

.ldk-whatsapp-cta svg {
    width: 24px;
    height: 24px;
    fill: white;
}

/* ==========================================
   CHAT INLINE (Shortcode)
   ========================================== */
.ldk-chat-inline {
    max-width: 500px;
    margin: 20px auto;
    border-radius: var(--ldk-radius);
    overflow: hidden;
    background: var(--ldk-white);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.ldk-chat-inline-header {
    background: linear-gradient(135deg, var(--ldk-primary) 0%, var(--ldk-primary-dark) 100%);
    color: var(--ldk-white);
    padding: 18px 24px;
}

.ldk-chat-inline-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.ldk-chat-inline .ldk-chat-messages {
    height: 380px;
}

/* ==========================================
   RESPONSIVE - MOBILE (Optimizado para uso tactil)
   ========================================== */
@media (max-width: 480px) {
    /* Widget en esquina inferior */
    .ldk-chat-widget {
        bottom: 20px;
        right: 20px;
        left: auto;
    }

    /* Boton flotante mas grande para tactil */
    .ldk-chat-toggle {
        width: 62px;
        height: 62px;
        box-shadow: 0 6px 25px rgba(139, 92, 246, 0.4);
    }

    .ldk-chat-toggle svg {
        width: 28px;
        height: 28px;
    }

    /* Ventana FULLSCREEN en movil */
    .ldk-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        animation: slideUpMobile 0.3s ease-out;
    }

    @keyframes slideUpMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Header mas compacto pero tocable */
    .ldk-chat-header {
        padding: 16px 16px;
        min-height: 72px;
        padding-top: env(safe-area-inset-top, 16px);
    }

    .ldk-chat-header img {
        width: 48px;
        height: 48px;
    }

    .ldk-chat-header h4 {
        font-size: 16px;
        font-weight: 600;
    }

    .ldk-chat-header span {
        font-size: 13px;
    }

    /* Boton cerrar mas grande y accesible */
    .ldk-chat-close {
        width: 40px;
        height: 40px;
        font-size: 28px;
        background: rgba(255, 255, 255, 0.25);
    }

    /* Area de mensajes optimizada */
    .ldk-chat-messages {
        padding: 16px;
        gap: 14px;
        padding-bottom: 20px;
        -webkit-overflow-scrolling: touch; /* Scroll suave en iOS */
    }

    /* Burbujas de mensaje mas anchas */
    .ldk-message {
        max-width: 88%;
    }

    .ldk-message p {
        padding: 14px 18px;
        font-size: 15px;
        line-height: 1.5;
    }

    /* Input area fija abajo con safe area */
    .ldk-chat-input-area {
        padding: 14px 16px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        gap: 12px;
        background: var(--ldk-white);
        border-top: 1px solid rgba(0, 0, 0, 0.08);
    }

    /* Input mas grande y facil de tocar */
    .ldk-chat-input-area input {
        padding: 14px 18px;
        font-size: 16px; /* Previene zoom en iOS */
        border-radius: 24px;
        border-width: 2px;
        min-height: 50px;
    }

    .ldk-chat-input-area input:focus {
        border-color: var(--ldk-primary);
    }

    /* Boton enviar mas grande */
    .ldk-chat-input-area button {
        width: 50px;
        height: 50px;
        min-width: 50px;
        min-height: 50px;
    }

    .ldk-chat-input-area button svg {
        width: 22px;
        height: 22px;
    }

    /* Footer oculto en movil para mas espacio */
    .ldk-chat-footer {
        display: none;
    }

    /* Quick replies scroll horizontal */
    .ldk-quick-replies {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .ldk-quick-replies::-webkit-scrollbar {
        display: none;
    }

    .ldk-quick-reply {
        flex-shrink: 0;
        padding: 12px 18px;
        font-size: 14px;
    }

    /* Typing indicator */
    .ldk-typing {
        padding: 14px 20px;
    }

    .ldk-typing span {
        width: 10px;
        height: 10px;
    }
}

/* ==========================================
   MOBILE LANDSCAPE (horizontal)
   ========================================== */
@media (max-width: 480px) and (orientation: landscape) {
    .ldk-chat-window {
        height: 100%;
    }

    .ldk-chat-header {
        min-height: 60px;
        padding: 10px 16px;
    }

    .ldk-chat-header img {
        width: 40px;
        height: 40px;
    }

    .ldk-chat-messages {
        padding: 12px;
    }

    .ldk-message p {
        padding: 10px 14px;
        font-size: 14px;
    }
}

/* ==========================================
   SMALL PHONES (iPhone SE, etc)
   ========================================== */
@media (max-width: 375px) {
    .ldk-chat-toggle {
        width: 56px;
        height: 56px;
    }

    .ldk-chat-header {
        padding: 12px 14px;
        gap: 10px;
    }

    .ldk-chat-header img {
        width: 42px;
        height: 42px;
    }

    .ldk-chat-header h4 {
        font-size: 15px;
    }

    .ldk-message p {
        padding: 12px 14px;
        font-size: 14px;
    }

    .ldk-chat-input-area {
        padding: 12px 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .ldk-chat-input-area input {
        padding: 12px 14px;
        min-height: 46px;
    }

    .ldk-chat-input-area button {
        width: 46px;
        height: 46px;
        min-width: 46px;
        min-height: 46px;
    }
}

/* ==========================================
   iOS NOTCH SUPPORT (iPhone X+)
   ========================================== */
@supports (padding-top: env(safe-area-inset-top)) {
    @media (max-width: 480px) {
        .ldk-chat-header {
            padding-top: calc(16px + env(safe-area-inset-top));
        }

        .ldk-chat-input-area {
            padding-bottom: calc(14px + env(safe-area-inset-bottom));
        }
    }
}

/* ==========================================
   TABLETS
   ========================================== */
@media (min-width: 481px) and (max-width: 768px) {
    .ldk-chat-window {
        width: 360px;
        height: 500px;
    }
}

/* ==========================================
   ANIMACIONES ESPECIALES
   ========================================== */

/* Shake para llamar atencion */
@keyframes shake-attention {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.ldk-chat-toggle.shake {
    animation: shake-attention 0.8s ease-in-out;
}

/* Glow effect */
@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(139, 92, 246, 0.4);
    }
    50% {
        box-shadow: 0 0 40px rgba(139, 92, 246, 0.6);
    }
}

.ldk-chat-toggle.glow {
    animation: glow 2s ease-in-out infinite;
}

/* ==========================================
   SOPORTE PARA MODO OSCURO (opcional)
   ========================================== */
@media (prefers-color-scheme: dark) {
    /* Mantener tema claro en el widget */
    .ldk-chat-window {
        background: var(--ldk-white);
    }

    .ldk-chat-messages {
        background: linear-gradient(180deg, var(--ldk-bg-light) 0%, var(--ldk-bg) 100%);
    }
}

/* ==========================================
   ACCESIBILIDAD
   ========================================== */
.ldk-chat-toggle:focus,
.ldk-chat-close:focus,
.ldk-chat-input-area button:focus,
.ldk-chat-input-area input:focus {
    outline: 2px solid var(--ldk-primary);
    outline-offset: 2px;
}

/* Reduce motion para usuarios que lo prefieren */
@media (prefers-reduced-motion: reduce) {
    .ldk-chat-toggle::before,
    .ldk-chat-toggle::after,
    .ldk-chat-header span::before,
    .ldk-typing span {
        animation: none;
    }

    .ldk-chat-window {
        animation: none;
    }

    .ldk-message {
        animation: none;
    }
}
