/* ==========================================
   CHATBOT WIDGET - FLOATING CHAT ASSISTANT
   ========================================== */

:root {
    --chatbot-primary: var(--primary, #BD3D75);
    --chatbot-primary-hover: var(--primary-hover, #A83366);
    --chatbot-bg: var(--white, #ffffff);
    --chatbot-surface: var(--gray-50, #f9fafb);
    --chatbot-text: var(--text-strong, #1f2a44);
    --chatbot-muted: var(--text-muted, #6b7280);
    --chatbot-border: var(--gray-200, #e5e7eb);
    --chatbot-message-bot-bg: var(--gray-50, #f9fafb);
    --chatbot-message-user-bg: var(--primary, #BD3D75);
    --chatbot-message-user-text: #ffffff;
    --chatbot-shadow: 0 12px 24px rgba(17, 24, 39, 0.08);
    --chatbot-shadow-lg: 0 24px 48px rgba(17, 24, 39, 0.12);
}

.dark-mode {
    --chatbot-bg: #111827;
    --chatbot-surface: #0b1220;
    --chatbot-text: #f9fafb;
    --chatbot-muted: #9ca3af;
    --chatbot-border: #1f2937;
    --chatbot-message-bot-bg: #0f172a;
    --chatbot-message-user-bg: var(--primary, #BD3D75);
    --chatbot-message-user-text: #ffffff;
}

/* Widget Container */
.chatbot-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: var(--font-sans, 'Inter', system-ui, -apple-system, sans-serif);
}

/* Toggle Button */
.chatbot-toggle-btn {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--chatbot-primary);
    border: 1px solid color-mix(in srgb, var(--chatbot-primary) 25%, transparent);
    box-shadow: var(--chatbot-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.chatbot-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--chatbot-shadow-lg);
}

.chatbot-toggle-btn:active {
    transform: scale(0.95);
}

.chatbot-button-content {
    position: relative;
    width: 40px !important;
    height: 40px !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ícono del bot como imagen */
.chatbot-icon-img {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    max-width: none;
    max-height: none;
    filter: brightness(0) invert(1);
    /* Hace el SVG blanco */
    transition: transform 0.3s ease;
}

.chatbot-toggle-btn:hover .chatbot-icon-img {
    transform: scale(1.1);
}

/* Indicador de estado */
.chatbot-status-indicator {
    position: absolute;
    top: 5px;
    right: 11.5px;
    width: 9.5px;
    height: 9.5px;
    background: #ef4444;
    /* Rojo cuando está inactivo */
    border-radius: 50%;
    border: 2px solid white;
    transition: background-color 0.3s ease;
    animation: pulse 2s infinite;
}

/* Indicador verde cuando está activo */
.chatbot-widget.active .chatbot-status-indicator {
    background: #22c55e;
    /* Verde cuando está activo */
    animation: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Chat Window */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--chatbot-bg);
    border-radius: 18px;
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--chatbot-border);
}

.chatbot-widget.active .chatbot-window {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

/* Header */
.chatbot-header {
    background: var(--chatbot-bg);
    color: var(--chatbot-text);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--chatbot-border);
    border-top: 3px solid var(--chatbot-primary);
}

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

.chatbot-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--chatbot-surface);
    border: 1px solid var(--chatbot-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    color: var(--chatbot-primary);
}

.chatbot-avatar-emoji {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-5px);
    }
}

.chatbot-header-text {
    flex: 1;
}

.chatbot-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
}

.chatbot-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--chatbot-muted);
    line-height: 1.2;
}

.chatbot-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--chatbot-surface);
    border: 1px solid var(--chatbot-border);
    color: var(--chatbot-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}

.chatbot-close-btn:hover {
    background: var(--chatbot-primary);
    border-color: var(--chatbot-primary);
    color: #ffffff;
}

.chatbot-close-icon {
    font-size: 18px;
    font-weight: 300;
    line-height: 1;
}

/* Messages Area */
.chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--chatbot-surface);
}

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

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

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chatbot-border);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-primary);
}

/* Message */
.message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    width: 100%;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.message.user {
    flex-direction: row;
    justify-content: flex-end;
}

.message.user .message-avatar-container {
    order: 2;
}

.message.user .message-bubble {
    order: 1;
}

.message-avatar-container {
    flex-shrink: 0;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--chatbot-message-bot-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.message.user .message-avatar {
    background: var(--chatbot-message-user-bg);
    color: white;
}

.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 14px;
    word-wrap: break-word;
    width: fit-content;
}

.message-bot {
    background: var(--chatbot-message-bot-bg);
    color: var(--chatbot-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--chatbot-border);
}

.message-user {
    background: var(--chatbot-message-user-bg);
    color: var(--chatbot-message-user-text);
    border-bottom-right-radius: 4px;
}

.message-content {
    font-size: 14px;
    line-height: 1.5;
}

.message-content p {
    margin: 0 0 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chatbot-message-bot-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.7;
    }

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

/* Input Area */
.chatbot-input-area {
    border-top: 1px solid var(--chatbot-border);
    padding: 14px 16px 16px;
    background: var(--chatbot-bg);
}

.chatbot-form {
    display: flex;
    width: 100%;
}

.chatbot-input-wrapper {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    width: 100%;
    align-items: end;
}

.chatbot-input {
    flex: 1;
    width: 100%;
    min-width: 0;
    display: block;
    padding: 14px 16px;
    border: 1px solid var(--chatbot-border);
    border-radius: 14px;
    font-size: 16px;
    resize: none;
    max-height: 120px;
    min-height: 52px;
    font-family: inherit;
    color: var(--chatbot-text);
    background: var(--chatbot-bg);
    transition: all 0.2s ease;
    line-height: 1.5;
}

.chatbot-input:focus {
    outline: none;
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--chatbot-primary) 20%, transparent);
}

.chatbot-input::placeholder {
    color: #9ca3af;
}

.chatbot-send-btn {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 14px;
    background: var(--chatbot-primary);
    border: 1px solid color-mix(in srgb, var(--chatbot-primary) 25%, transparent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chatbot-send-btn:hover:not(:disabled) {
    background: var(--chatbot-primary-hover);
    transform: translateY(-2px);
}

.chatbot-send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-send-icon {
    font-size: 20px;
    line-height: 1;
}

/* Error Message */
.message-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.dark-mode .message-error {
    background: #7f1d1d;
    color: #fecaca;
    border-color: #991b1b;
}

/* Responsive */
@media (max-width: 768px) {
    .chatbot-widget {
        bottom: 12px;
        right: 12px;
        left: 12px;
    }

    .chatbot-toggle-btn {
        width: 52px;
        height: 52px;
        position: fixed;
        right: 12px;
        bottom: 12px;
    }

    .chatbot-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 80px);
        max-height: calc(100vh - 80px);
        border-radius: 16px 16px 0 0;
    }

    .chatbot-widget.active .chatbot-window {
        bottom: 0;
    }

    .chatbot-header {
        padding: 14px 16px;
    }

    .chatbot-avatar {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .chatbot-title {
        font-size: 16px;
    }

    .chatbot-subtitle {
        font-size: 12px;
    }

    .chatbot-messages {
        padding: 16px 12px;
        gap: 12px;
    }

    .message-bubble {
        max-width: 82%;
        font-size: 14px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 16px;
    }

    .chatbot-input-area {
        padding: 12px 14px 14px;
    }

    .chatbot-input {
        font-size: 16px;
        /* Prevents zoom on iOS */
        padding: 12px 14px;
        min-height: 52px;
    }

    .chatbot-send-btn {
        width: 48px;
        height: 48px;
    }
}

@media (max-width: 480px) {
    .message-bubble {
        max-width: 80%;
        padding: 10px 14px;
    }

    .message {
        gap: 8px;
    }

    .chatbot-input-wrapper {
        gap: 6px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {

    .chatbot-toggle-btn,
    .chatbot-window,
    .chatbot-icon-chat,
    .chatbot-icon-close,
    .message {
        animation: none;
        transition: none;
    }

    .chatbot-avatar-emoji {
        animation: none;
    }

    .typing-dot {
        animation: none;
    }
}

/* Focus visible for keyboard navigation */
.chatbot-toggle-btn:focus-visible,
.chatbot-close-btn:focus-visible,
.chatbot-send-btn:focus-visible,
.chatbot-input:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}