/* ==========================================================================
   Nelo Chat Widget — NLG Systems
   ========================================================================== */

:root {
    --nelo-primary: #00c896;
    --nelo-primary-dark: #007d63;
    --nelo-bg: #0f0f0f;
    --nelo-bg-elev: #1a1a1a;
    --nelo-bg-input: #121212;
    --nelo-surface: #1e1e1e;
    --nelo-border: rgba(255, 255, 255, 0.08);
    --nelo-border-strong: rgba(255, 255, 255, 0.14);
    --nelo-text: #ffffff;
    --nelo-text-dim: rgba(255, 255, 255, 0.65);
    --nelo-text-muted: rgba(255, 255, 255, 0.4);
    --nelo-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);
    --nelo-shadow-btn: 0 8px 24px rgba(0, 200, 150, 0.35);
}

/* ─── Widget Root ──────────────────────────────────────────────────────── */
.chat-widget {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9998;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ─── Floating Button ──────────────────────────────────────────────────── */
.chat-button {
    position: relative;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--nelo-primary) 0%, var(--nelo-primary-dark) 100%);
    color: #ffffff;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--nelo-shadow-btn);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.chat-button:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 12px 32px rgba(0, 200, 150, 0.5);
}

.chat-button:active {
    transform: scale(0.96);
}

.chat-button.pulse::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--nelo-primary);
    opacity: 0.4;
    z-index: -1;
    animation: nelo-pulse 2.2s ease-out infinite;
}

@keyframes nelo-pulse {
    0% { transform: scale(1); opacity: 0.5; }
    80%, 100% { transform: scale(1.7); opacity: 0; }
}

/* ─── Chat Window ──────────────────────────────────────────────────────── */
.chat-window {
    position: absolute;
    bottom: 78px;
    right: 0;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 120px);
    background: var(--nelo-bg-elev);
    border: 1px solid var(--nelo-border);
    border-radius: 20px;
    box-shadow: var(--nelo-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-window.active {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ─── Header ───────────────────────────────────────────────────────────── */
.chat-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 1rem 1.1rem;
    background: linear-gradient(135deg, var(--nelo-primary) 0%, var(--nelo-primary-dark) 100%);
    flex-shrink: 0;
}

.chat-header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
    background: rgba(0, 0, 0, 0.15);
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.9);
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
    color: #ffffff;
}

.chat-header-info h3 {
    margin: 0;
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.2;
    color: #ffffff;
}

.chat-header-info span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    margin-top: 0.15rem;
}

.chat-header-info span::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
    animation: nelo-status 2s ease-out infinite;
}

@keyframes nelo-status {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

.chat-close {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.15);
    color: #ffffff;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.chat-close:hover {
    background: rgba(0, 0, 0, 0.3);
    transform: rotate(90deg);
}

/* ─── Messages Area ────────────────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    padding: 1.2rem 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: var(--nelo-bg);
    scroll-behavior: smooth;
}

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

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

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ─── Messages ─────────────────────────────────────────────────────────── */
.chat-message {
    max-width: 85%;
    animation: nelo-fadeIn 0.3s ease;
    display: flex;
}

.chat-message.bot {
    align-self: flex-start;
}

.chat-message.user {
    align-self: flex-end;
    justify-content: flex-end;
}

.chat-message p {
    margin: 0;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    font-size: 0.92rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-message.bot p {
    background: var(--nelo-surface);
    color: var(--nelo-text);
    border: 1px solid var(--nelo-border);
    border-bottom-left-radius: 6px;
}

.chat-message.user p {
    background: linear-gradient(135deg, var(--nelo-primary) 0%, var(--nelo-primary-dark) 100%);
    color: #ffffff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 200, 150, 0.2);
}

.chat-message p strong {
    font-weight: 700;
}

.chat-message p a {
    color: var(--nelo-primary);
    text-decoration: underline;
    word-break: break-all;
}

.chat-message.user p a {
    color: #ffffff;
}

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

/* ─── Typing Indicator ─────────────────────────────────────────────────── */
.typing-indicator {
    align-self: flex-start;
    max-width: 85%;
}

.typing-indicator p {
    display: none;
}

.chat-message.typing-indicator {
    background: var(--nelo-surface);
    border: 1px solid var(--nelo-border);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    padding: 0.85rem 1rem;
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
    width: auto;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--nelo-text-dim);
    animation: nelo-typing 1.3s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

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

/* ─── Quick Replies ────────────────────────────────────────────────────── */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0 1rem 0.75rem;
    background: var(--nelo-bg);
}

.chat-quick-replies:empty {
    display: none;
}

.quick-reply {
    background: rgba(0, 200, 150, 0.08);
    border: 1px solid rgba(0, 200, 150, 0.3);
    color: var(--nelo-primary);
    padding: 0.5rem 0.95rem;
    border-radius: 50px;
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-reply:hover {
    background: rgba(0, 200, 150, 0.15);
    border-color: var(--nelo-primary);
    transform: translateY(-1px);
}

.quick-reply:active {
    transform: translateY(0);
}

/* ─── Input Area ───────────────────────────────────────────────────────── */
.chat-input-container {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    background: var(--nelo-bg-elev);
    border-top: 1px solid var(--nelo-border);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    min-width: 0;
    background: var(--nelo-bg-input);
    border: 1px solid var(--nelo-border);
    border-radius: 22px;
    padding: 0.7rem 1.1rem;
    color: var(--nelo-text);
    font-size: 0.92rem;
    font-family: inherit;
    transition: border-color 0.2s ease, background 0.2s ease;
    outline: none;
}

.chat-input::placeholder {
    color: var(--nelo-text-muted);
}

.chat-input:focus {
    border-color: var(--nelo-primary);
    background: #0a0a0a;
}

.chat-send {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--nelo-primary) 0%, var(--nelo-primary-dark) 100%);
    color: #ffffff;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 200, 150, 0.25);
}

.chat-send:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(0, 200, 150, 0.4);
}

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

/* ─── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .chat-widget {
        bottom: 1rem;
        right: 1rem;
    }

    .chat-button {
        width: 56px;
        height: 56px;
        font-size: 1.35rem;
    }

    .chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        border: none;
        transform-origin: center;
    }

    .chat-window:not(.active) {
        transform: translateY(100%);
    }

    .chat-window.active {
        transform: translateY(0);
    }

    .chat-header {
        padding: 1rem 1.1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    .chat-avatar {
        width: 40px;
        height: 40px;
    }

    .chat-header-info h3 {
        font-size: 1rem;
    }

    .chat-close {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }

    .chat-messages {
        padding: 1.1rem 0.9rem;
    }

    .chat-message {
        max-width: 88%;
    }

    .chat-message p {
        font-size: 0.94rem;
    }

    .chat-quick-replies {
        padding: 0 0.9rem 0.75rem;
    }

    .chat-input-container {
        padding: 0.8rem 0.9rem;
        padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
    }

    .chat-input {
        font-size: 16px;
        padding: 0.75rem 1.1rem;
    }

    /* Ocultar botón flotante cuando el chat está abierto en mobile */
    .chat-window.active ~ .chat-button,
    .chat-widget:has(.chat-window.active) .chat-button {
        opacity: 0;
        pointer-events: none;
        transform: scale(0);
    }
}

/* ─── Reduced Motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .chat-button.pulse::before,
    .chat-header-info span::before,
    .typing-dot {
        animation: none;
    }

    .chat-window,
    .chat-button,
    .chat-close,
    .chat-send,
    .quick-reply,
    .chat-message {
        transition: none;
        animation: none;
    }
}
