/* ========================================================
   CHATBOT WIDGET - CARLOS FRANCIA
   Estilo Glassmorphism integrado al tema oscuro del sitio
   Optimizado 100% para Mobile (iOS/Android), Tablet y Desktop
   ======================================================== */

:root {
    --chat-bg: rgba(12, 19, 36, 0.95);
    --chat-header: rgba(24, 35, 58, 0.94);
    --chat-border: rgba(255, 255, 255, 0.12);
    --chat-accent: #38bdf8;
    --chat-accent-glow: rgba(56, 189, 248, 0.4);
    --chat-secondary: #818cf8;
    --chat-text: #f8fafc;
    --chat-text-muted: #94a3b8;
    --chat-bubble-bot: rgba(30, 41, 59, 0.78);
    --chat-whatsapp: #25d366;
}

body.chat-fullscreen-open {
    overflow: hidden !important;
}

/* Floating Action Button (FAB) */
.chat-fab {
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
    right: max(20px, env(safe-area-inset-right, 20px));
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-fab.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.85);
}

.chat-fab-tooltip {
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--chat-border);
    color: var(--chat-text);
    padding: 8px 14px;
    border-radius: 9999px;
    font-size: 0.84rem;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    animation: fabBounce 3s infinite ease-in-out;
    pointer-events: none;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 7px;
}

.chat-fab-tooltip span.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    flex-shrink: 0;
}

.chat-fab-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-accent), var(--chat-secondary));
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #090e1a;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px var(--chat-accent-glow);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.chat-fab-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 30px rgba(56, 189, 248, 0.6);
}

.chat-fab-btn svg {
    width: 26px;
    height: 26px;
    transition: transform 0.3s ease;
}

/* Chat Window Container */
.chat-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    background: var(--chat-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.65), 0 0 25px rgba(56, 189, 248, 0.15);
    z-index: 10000;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Chat Header */
.chat-header {
    background: var(--chat-header);
    padding: 14px 18px;
    padding-top: max(14px, env(safe-area-inset-top, 14px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-accent), var(--chat-secondary));
    color: #090e1a;
    font-weight: 800;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 12px var(--chat-accent-glow);
    flex-shrink: 0;
}

.chat-avatar::after {
    content: '';
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid var(--chat-bg);
}

.chat-header-text h4 {
    color: var(--chat-text);
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}

.chat-header-text span {
    color: var(--chat-text-muted);
    font-size: 0.76rem;
}

.chat-close-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--chat-text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-close-btn:hover {
    color: var(--chat-text);
    background: rgba(255, 255, 255, 0.14);
}

/* Messages Body */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

/* Bubbles */
.chat-bubble {
    max-width: 86%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.52;
    position: relative;
    word-break: break-word;
    animation: fadeIn 0.28s ease;
}

.chat-bubble.bot {
    align-self: flex-start;
    background: var(--chat-bubble-bot);
    border: 1px solid var(--chat-border);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
}

.chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--chat-accent), var(--chat-secondary));
    color: #090e1a;
    font-weight: 600;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.25);
}

/* Action Buttons inside Bot message */
.chat-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.chat-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    min-height: 40px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 0.84rem;
    font-weight: 600;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.chat-action-btn:hover {
    transform: translateY(-1px);
    opacity: 0.95;
}

.chat-action-btn.whatsapp {
    background: #25d366;
    color: #ffffff;
}

.chat-action-btn.email {
    background: rgba(129, 140, 248, 0.2);
    color: #a5b4fc;
    border: 1px solid var(--chat-secondary);
}

.chat-action-btn.jump {
    background: rgba(56, 189, 248, 0.14);
    color: var(--chat-accent);
    border: 1px solid rgba(56, 189, 248, 0.4);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.chat-action-btn.jump:hover {
    background: rgba(56, 189, 248, 0.25);
    border-color: var(--chat-accent);
}

/* Efecto de resplandor al saltar a la sección de la página */
.highlight-section {
    animation: highlightPulse 2.8s cubic-bezier(0.16, 1, 0.3, 1);
    border-radius: 16px;
}

@keyframes highlightPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.8);
        outline: 2px solid var(--chat-accent);
    }
    40% {
        box-shadow: 0 0 30px 6px rgba(56, 189, 248, 0.6);
        outline: 2px solid var(--chat-accent);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(56, 189, 248, 0);
        outline: 2px solid transparent;
    }
}

.chat-action-btn.cv {
    background: rgba(56, 189, 248, 0.2);
    color: var(--chat-accent);
    border: 1px solid var(--chat-accent);
}

/* Typing Indicator */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--chat-bubble-bot);
    border: 1px solid var(--chat-border);
    border-radius: 14px;
    width: fit-content;
    border-bottom-left-radius: 4px;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    background: var(--chat-accent);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.chat-typing span:nth-child(1) { animation-delay: -0.32s; }
.chat-typing span:nth-child(2) { animation-delay: -0.16s; }

/* Quick Suggestion Chips */
.chat-chips {
    padding: 9px 14px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(15, 23, 42, 0.65);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.chat-chips::-webkit-scrollbar {
    height: 3px;
}
.chat-chips::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.chat-chip {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--chat-border);
    color: #cbd5e1;
    padding: 6px 12px;
    border-radius: 9999px;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-chip:hover {
    background: rgba(56, 189, 248, 0.16);
    border-color: var(--chat-accent);
    color: var(--chat-text);
}

/* Input Area */
.chat-input-area {
    padding: 12px 14px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    background: var(--chat-header);
    border-top: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid var(--chat-border);
    border-radius: 9999px;
    padding: 10px 16px;
    color: var(--chat-text);
    /* 16px prevents iOS Safari from auto-zooming on input focus */
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

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

.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-accent), var(--chat-secondary));
    border: none;
    color: #090e1a;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.06);
}

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

/* Animations */
@keyframes fabBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Tablet Portrait & Landscape */
@media (max-width: 768px) {
    .chat-window {
        bottom: 16px;
        right: 16px;
        width: 370px;
        height: 540px;
        max-height: calc(100dvh - 32px);
    }
}

/* Mobile Fullscreen Experience */
@media (max-width: 540px) {
    .chat-window {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }

    .chat-fab {
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
        right: 16px;
    }

    .chat-fab-tooltip {
        display: none !important;
    }
}

/* Mobile Landscape */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-window {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }
    .chat-header {
        padding: 8px 14px;
    }
    .chat-messages {
        padding: 10px 14px;
    }
}
