/* ============================================================
   CDRTECSYSTEM - CHAT IA
   Chat personalizado - Sin Botpress
   ============================================================ */

:root {
    --cdr-chat-primary: #00c79d;
    --cdr-chat-primary-dark: #00a982;
    --cdr-chat-bg: #101419;
    --cdr-chat-panel: #151a20;
    --cdr-chat-panel-2: #1c2229;
    --cdr-chat-border: rgba(255, 255, 255, 0.08);
    --cdr-chat-text: #f5f7f9;
    --cdr-chat-muted: #9ba4ad;
    --cdr-chat-user: #00c79d;
    --cdr-chat-bot: #20262d;
    --cdr-chat-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}


/* ============================================================
   BOTÓN FLOTANTE
   ============================================================ */

.cdr-chat-button {
    position: fixed;
    right: 25px;
    bottom: 25px;

    width: 64px;
    height: 64px;

    border: 0;
    border-radius: 50%;

    background: var(--cdr-chat-primary);
    color: #ffffff;

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;

    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.25),
        0 0 0 0 rgba(0, 199, 157, 0.45);

    z-index: 999999;

    transition:
        transform 0.25s ease,
        box-shadow 0.25s ease,
        background 0.25s ease;
}

.cdr-chat-button:hover {
    transform: translateY(-3px) scale(1.04);

    box-shadow:
        0 12px 35px rgba(0, 0, 0, 0.3),
        0 0 0 8px rgba(0, 199, 157, 0.08);
}

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

.cdr-chat-button .chat-icon {
    font-size: 27px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.cdr-chat-button .chat-icon-close {
    position: absolute;

    font-size: 23px;

    opacity: 0;
    transform: rotate(-90deg) scale(0.5);

    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}

.cdr-chat-button.open .chat-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.cdr-chat-button.open .chat-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}


/* ============================================================
   NOTIFICACIÓN
   ============================================================ */

.cdr-chat-notification {
    position: fixed;

    right: 22px;
    bottom: 80px;

    width: 10px;
    height: 10px;

    background: #ff4d67;

    border: 2px solid #ffffff;
    border-radius: 50%;

    z-index: 1000000;

    opacity: 0;
    transform: scale(0);

    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}

.cdr-chat-notification.show {
    opacity: 1;
    transform: scale(1);
}


/* ============================================================
   VENTANA
   ============================================================ */

.cdr-chat-window {
    position: fixed;

    right: 25px;
    bottom: 100px;

    width: 390px;
    max-width: calc(100vw - 30px);

    height: 600px;
    max-height: calc(100vh - 125px);

    background: var(--cdr-chat-bg);

    border: 1px solid var(--cdr-chat-border);

    border-radius: 18px;

    overflow: hidden;

    box-shadow: var(--cdr-chat-shadow);

    display: flex;
    flex-direction: column;

    z-index: 999998;

    opacity: 0;
    visibility: hidden;

    transform:
        translateY(20px)
        scale(0.96);

    transform-origin: bottom right;

    transition:
        opacity 0.22s ease,
        visibility 0.22s ease,
        transform 0.22s ease;
}

.cdr-chat-window.open {
    opacity: 1;
    visibility: visible;

    transform:
        translateY(0)
        scale(1);
}


/* ============================================================
   HEADER
   ============================================================ */

.cdr-chat-header {
    min-height: 76px;

    padding: 14px 16px;

    display: flex;
    align-items: center;

    background: var(--cdr-chat-panel);

    border-bottom: 1px solid var(--cdr-chat-border);
}

.cdr-chat-avatar {
    width: 46px;
    height: 46px;

    object-fit: cover;

    border-radius: 50%;

    border: 2px solid rgba(0, 199, 157, 0.7);

    flex-shrink: 0;
}

.cdr-chat-header-info {
    flex: 1;

    min-width: 0;

    margin-left: 12px;
}

.cdr-chat-title {
    margin: 0;

    color: var(--cdr-chat-text);

    font-size: 15px;
    font-weight: 700;

    line-height: 1.3;
}

.cdr-chat-status {
    margin-top: 4px;

    color: var(--cdr-chat-muted);

    font-size: 12px;

    display: flex;
    align-items: center;
    gap: 6px;
}

.cdr-chat-status-dot {
    width: 7px;
    height: 7px;

    background: #25d366;

    border-radius: 50%;

    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}

.cdr-chat-close {
    width: 38px;
    height: 38px;

    border: 0;
    border-radius: 50%;

    background: transparent;
    color: var(--cdr-chat-muted);

    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    transition:
        color 0.2s ease,
        background 0.2s ease;
}

.cdr-chat-close:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #ffffff;
}


/* ============================================================
   MENSAJES
   ============================================================ */

.cdr-chat-messages {
    flex: 1;

    overflow-y: auto;

    padding: 18px 15px;

    background:
        radial-gradient(
            circle at top right,
            rgba(0, 199, 157, 0.05),
            transparent 35%
        ),
        var(--cdr-chat-bg);

    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

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

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

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


/* ============================================================
   MENSAJE
   ============================================================ */

.cdr-chat-message {
    width: 100%;

    display: flex;

    margin-bottom: 13px;

    animation: cdrChatMessageIn 0.2s ease;
}

@keyframes cdrChatMessageIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cdr-chat-message.bot {
    justify-content: flex-start;
}

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

.cdr-chat-bubble {
    max-width: 82%;

    padding: 10px 12px 7px;

    border-radius: 15px;

    color: var(--cdr-chat-text);

    font-size: 14px;

    line-height: 1.5;

    overflow-wrap: anywhere;

    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.cdr-chat-message.bot .cdr-chat-bubble {
    background: var(--cdr-chat-bot);

    border-bottom-left-radius: 4px;
}

.cdr-chat-message.user .cdr-chat-bubble {
    background: var(--cdr-chat-user);

    color: #061a15;

    border-bottom-right-radius: 4px;
}

.cdr-chat-time {
    display: block;

    margin-top: 4px;

    font-size: 10px;

    opacity: 0.55;

    text-align: right;
}


/* ============================================================
   TYPING
   ============================================================ */

.cdr-chat-typing {
    display: none;

    padding: 0 15px 10px;

    background: var(--cdr-chat-bg);
}

.cdr-chat-typing.show {
    display: block;
}

.cdr-chat-typing-bubble {
    display: inline-flex;

    align-items: center;

    gap: 4px;

    padding: 11px 13px;

    background: var(--cdr-chat-bot);

    border-radius: 15px;

    border-bottom-left-radius: 4px;
}

.cdr-chat-typing-dot {
    width: 6px;
    height: 6px;

    border-radius: 50%;

    background: var(--cdr-chat-muted);

    animation: cdrTyping 1.2s infinite ease-in-out;
}

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

.cdr-chat-typing-dot:nth-child(3) {
    animation-delay: 0.30s;
}

@keyframes cdrTyping {
    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}


/* ============================================================
   INPUT
   ============================================================ */

.cdr-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;

    padding: 11px 12px;

    background: var(--cdr-chat-panel);

    border-top: 1px solid var(--cdr-chat-border);
}

.cdr-chat-input {
    flex: 1;

    min-width: 0;

    max-height: 110px;

    resize: none;

    padding: 11px 13px;

    border: 1px solid var(--cdr-chat-border);

    border-radius: 13px;

    outline: none;

    background: var(--cdr-chat-panel-2);

    color: var(--cdr-chat-text);

    font-family: inherit;
    font-size: 14px;

    line-height: 1.4;

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.cdr-chat-input::placeholder {
    color: #77818b;
}

.cdr-chat-input:focus {
    border-color: rgba(0, 199, 157, 0.55);

    box-shadow:
        0 0 0 3px rgba(0, 199, 157, 0.08);
}

.cdr-chat-send {
    width: 43px;
    height: 43px;

    flex-shrink: 0;

    border: 0;
    border-radius: 12px;

    background: var(--cdr-chat-primary);

    color: #ffffff;

    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    transition:
        transform 0.2s ease,
        background 0.2s ease,
        opacity 0.2s ease;
}

.cdr-chat-send:hover {
    background: var(--cdr-chat-primary-dark);

    transform: translateY(-1px);
}

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

.cdr-chat-send:disabled {
    opacity: 0.45;

    cursor: not-allowed;

    transform: none;
}


/* ============================================================
   FOOTER
   ============================================================ */

.cdr-chat-footer {
    padding: 7px 10px 9px;

    background: var(--cdr-chat-panel);

    color: #6f7881;

    text-align: center;

    font-size: 10px;
}

.cdr-chat-footer strong {
    color: var(--cdr-chat-muted);
}


/* ============================================================
   COMPATIBILIDAD CON BOTÓN "VOLVER ARRIBA" (.scroll-top)
   El tema base posiciona .scroll-top en bottom:15px / right:35px,
   lo que se superpone con la burbuja de chat (bottom:25px / right:25px).
   Lo subimos para que ambos elementos convivan sin taparse.
   ============================================================ */

.scroll-top.active {
    bottom: 100px;
}


/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 576px) {

    .scroll-top.active {
        bottom: 90px;
    }


    .cdr-chat-button {
        right: 17px;
        bottom: 17px;

        width: 58px;
        height: 58px;
    }

    .cdr-chat-window {
        right: 10px;
        bottom: 85px;

        width: calc(100vw - 20px);

        height: calc(100vh - 105px);
        max-height: calc(100vh - 105px);

        border-radius: 16px;
    }

    .cdr-chat-bubble {
        max-width: 88%;
    }

}


/* ============================================================
   PANTALLAS MUY PEQUEÑAS
   ============================================================ */

@media (max-width: 380px) {

    .cdr-chat-window {
        right: 5px;

        width: calc(100vw - 10px);
    }

    .cdr-chat-header {
        min-height: 68px;
    }

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

}
