/*
 * Chatbot flotante para ERP.
 * Variables principales para personalizar colores y medidas.
 */
.erp-chatbot {
    --erp-chat-primary: #2f5bea;
    --erp-chat-primary-dark: #2043bd;
    --erp-chat-surface: #ffffff;
    --erp-chat-page: #f4f6fb;
    --erp-chat-text: #1f2937;
    --erp-chat-muted: #6b7280;
    --erp-chat-border: #e5e7eb;
    --erp-chat-danger: #b42318;
    --erp-chat-success: #22c55e;
    --erp-chat-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
    --erp-chat-radius: 20px;

    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 2147483000;
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    color: var(--erp-chat-text);
}

.erp-chatbot *,
.erp-chatbot *::before,
.erp-chatbot *::after {
    box-sizing: border-box;
}

.erp-chatbot button,
.erp-chatbot textarea {
    font: inherit;
}

.erp-chatbot__launcher {
    width: 60px;
    height: 60px;
    margin-left: auto;
    padding: 0;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: #fff;
    background:
        linear-gradient(
            135deg,
            var(--erp-chat-primary),
            var(--erp-chat-primary-dark)
        );
    box-shadow: 0 14px 32px rgba(47, 91, 234, 0.38);
    transition:
        transform 160ms ease,
        box-shadow 160ms ease;
}

.erp-chatbot__launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 38px rgba(47, 91, 234, 0.45);
}

.erp-chatbot__launcher:focus-visible,
.erp-chatbot__icon-button:focus-visible,
.erp-chatbot__send:focus-visible,
.erp-chatbot__input:focus-visible {
    outline: 3px solid rgba(47, 91, 234, 0.28);
    outline-offset: 2px;
}

.erp-chatbot__launcher-icon {
    width: 27px;
    height: 27px;
    fill: currentColor;
}

.erp-chatbot__launcher-icon--close {
    display: none;
}

.erp-chatbot.is-open .erp-chatbot__launcher-icon--chat {
    display: none;
}

.erp-chatbot.is-open .erp-chatbot__launcher-icon--close {
    display: block;
}

.erp-chatbot__panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: min(390px, calc(100vw - 32px));
    height: min(650px, calc(100vh - 120px));
    min-height: 430px;
    border: 1px solid rgba(229, 231, 235, 0.9);
    border-radius: var(--erp-chat-radius);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    background: var(--erp-chat-surface);
    box-shadow: var(--erp-chat-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(0.97);
    transform-origin: bottom right;
    transition:
        opacity 180ms ease,
        transform 180ms ease,
        visibility 180ms ease;
}

.erp-chatbot.is-open .erp-chatbot__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.erp-chatbot__header {
    min-height: 72px;
    padding: 14px 14px 14px 16px;
    display: flex;
    align-items: center;
    gap: 11px;
    color: #fff;
    background:
        linear-gradient(
            135deg,
            var(--erp-chat-primary),
            var(--erp-chat-primary-dark)
        );
}

.erp-chatbot__avatar {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: var(--erp-chat-primary-dark);
    background: #fff;
}

.erp-chatbot__heading {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.erp-chatbot__heading strong {
    overflow: hidden;
    font-size: 15px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.erp-chatbot__heading span {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.82);
}

.erp-chatbot__status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--erp-chat-success);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}

.erp-chatbot__icon-button {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    border-radius: 10px;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    transition: background 150ms ease;
}

.erp-chatbot__icon-button:hover {
    background: rgba(255, 255, 255, 0.22);
}

.erp-chatbot__icon-button svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.erp-chatbot__messages {
    min-height: 0;
    padding: 18px 15px;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 13px;
    background:
        radial-gradient(
            circle at top right,
            rgba(47, 91, 234, 0.06),
            transparent 34%
        ),
        var(--erp-chat-page);
    scrollbar-width: thin;
    scrollbar-color: #c7cbd4 transparent;
}

.erp-chatbot__message {
    max-width: 86%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: erp-chat-message-in 180ms ease both;
}

.erp-chatbot__message--assistant {
    align-self: flex-start;
}

.erp-chatbot__message--user {
    align-self: flex-end;
    align-items: flex-end;
}

.erp-chatbot__bubble {
    padding: 11px 13px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.52;
    overflow-wrap: anywhere;
}

.erp-chatbot__message--assistant .erp-chatbot__bubble {
    border: 1px solid var(--erp-chat-border);
    border-bottom-left-radius: 5px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
}

.erp-chatbot__message--user .erp-chatbot__bubble {
    border-bottom-right-radius: 5px;
    color: #fff;
    background:
        linear-gradient(
            135deg,
            var(--erp-chat-primary),
            var(--erp-chat-primary-dark)
        );
}

.erp-chatbot__bubble p {
    margin: 0 0 8px;
}

.erp-chatbot__bubble p:last-child {
    margin-bottom: 0;
}

.erp-chatbot__bubble ul,
.erp-chatbot__bubble ol {
    margin: 7px 0 7px 19px;
    padding: 0;
}

.erp-chatbot__bubble pre {
    max-width: 100%;
    margin: 9px 0 0;
    padding: 11px;
    border-radius: 10px;
    overflow-x: auto;
    color: #e5e7eb;
    background: #111827;
    font:
        12px/1.5 ui-monospace,
        SFMono-Regular,
        Menlo,
        Monaco,
        Consolas,
        monospace;
}

.erp-chatbot__bubble code:not(pre code) {
    padding: 2px 5px;
    border-radius: 5px;
    color: #7c2d12;
    background: #ffedd5;
    font:
        0.9em ui-monospace,
        SFMono-Regular,
        Menlo,
        Monaco,
        Consolas,
        monospace;
}

.erp-chatbot__message-time {
    padding: 0 4px;
    font-size: 10px;
    color: var(--erp-chat-muted);
}

.erp-chatbot__typing {
    position: absolute;
    left: 18px;
    bottom: 91px;
    width: 54px;
    height: 33px;
    padding: 0 12px;
    border: 1px solid var(--erp-chat-border);
    border-radius: 14px 14px 14px 5px;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: #fff;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.erp-chatbot__typing:not([hidden]) {
    display: flex;
}

.erp-chatbot__typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: erp-chat-typing 1.1s infinite ease-in-out;
}

.erp-chatbot__typing span:nth-child(2) {
    animation-delay: 140ms;
}

.erp-chatbot__typing span:nth-child(3) {
    animation-delay: 280ms;
}

.erp-chatbot__error {
    margin: 8px 12px 0;
    padding: 9px 11px;
    border: 1px solid #fecdca;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--erp-chat-danger);
    background: #fef3f2;
}

.erp-chatbot__composer {
    padding: 12px 12px 8px;
    border-top: 1px solid var(--erp-chat-border);
    display: flex;
    align-items: flex-end;
    gap: 9px;
    background: #fff;
}

.erp-chatbot__input {
    width: 100%;
    min-height: 42px;
    max-height: 125px;
    padding: 10px 12px;
    border: 1px solid #d7dbe3;
    border-radius: 13px;
    resize: none;
    overflow-y: auto;
    color: var(--erp-chat-text);
    background: #fff;
    transition:
        border-color 150ms ease,
        box-shadow 150ms ease;
}

.erp-chatbot__input:focus {
    border-color: var(--erp-chat-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 91, 234, 0.1);
}

.erp-chatbot__input::placeholder {
    color: #9ca3af;
}

.erp-chatbot__input:disabled {
    cursor: not-allowed;
    background: #f9fafb;
}

.erp-chatbot__send {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    border-radius: 13px;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: #fff;
    background: var(--erp-chat-primary);
    transition:
        background 150ms ease,
        transform 150ms ease;
}

.erp-chatbot__send:hover:not(:disabled) {
    background: var(--erp-chat-primary-dark);
    transform: translateY(-1px);
}

.erp-chatbot__send:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.erp-chatbot__send svg {
    width: 19px;
    height: 19px;
    fill: currentColor;
}

.erp-chatbot__footer {
    padding: 0 12px 9px;
    text-align: center;
    font-size: 10px;
    color: var(--erp-chat-muted);
    background: #fff;
}

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

@keyframes erp-chat-typing {
    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.45;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

@media (max-width: 600px) {
    .erp-chatbot {
        right: 14px;
        bottom: 14px;
    }

    .erp-chatbot__launcher {
        width: 56px;
        height: 56px;
    }

    .erp-chatbot__panel {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        min-height: 0;
        border: 0;
        border-radius: 0;
        transform: translateY(18px);
    }

    .erp-chatbot.is-open .erp-chatbot__panel {
        transform: translateY(0);
    }

    .erp-chatbot.is-open .erp-chatbot__launcher {
        display: none;
    }

    .erp-chatbot__header {
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .erp-chatbot__footer {
        padding-bottom: max(9px, env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .erp-chatbot *,
    .erp-chatbot *::before,
    .erp-chatbot *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
