/* =====================================================================
   Javier Arias — Chatbot Widget Styling (Modern Glassmorphism + Animado)
   ===================================================================== */

.chatbot-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    font-family: var(--font-body);
}

/* Floating Action Button (FAB) */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--grad);
    color: #04101e;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 10px 30px -10px var(--glow);
    transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease);
    position: relative;
}

.chatbot-toggle:hover {
    transform: scale(1.06) translateY(-2px);
    box-shadow: 0 14px 36px -8px var(--glow);
}

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

.chatbot-toggle svg {
    position: absolute;
    transition: transform 0.3s var(--ease), opacity 0.3s;
    width: 24px;
    height: 24px;
}

.chatbot-toggle .icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}

/* Toggle active states */
.chatbot-container.open .chatbot-toggle .icon-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}

.chatbot-container.open .chatbot-toggle .icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Notification badge */
.chatbot-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 13px;
    height: 13px;
    background: var(--c-violet);
    border: 2px solid var(--bg);
    border-radius: 50%;
    animation: badgePulse 2s infinite;
    display: none;
}

@keyframes badgePulse {
    0% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.7); }
    70% { box-shadow: 0 0 0 8px rgba(139, 92, 246, 0); }
    100% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0); }
}

/* Chat Window */
.chatbot-window {
    width: 380px;
    max-width: 90vw;
    height: 560px;
    max-height: 80vh;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: rgba(8, 12, 26, 0.75);
    backdrop-filter: blur(20px) saturate(140%);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: absolute;
    bottom: 80px;
    right: 0;
    transform-origin: bottom right;
    transition: transform 0.4s var(--ease), opacity 0.4s var(--ease), visibility 0.4s;
    z-index: 10000;
}

.chatbot-window.hidden {
    transform: scale(0.85) translateY(24px);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

/* Light Theme Adapter */
[data-theme="light"] .chatbot-window {
    background: rgba(245, 247, 252, 0.85);
    border-color: rgba(15, 23, 42, 0.12);
}

/* Chat Header */
.chatbot-header {
    padding: 1.1rem 1.3rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .chatbot-header {
    background: rgba(15, 23, 42, 0.02);
}

.chatbot-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chatbot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    box-shadow: 0 4px 10px -4px var(--glow);
}

.chatbot-details h4 {
    font-family: var(--font-head);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    line-height: 1.2;
}

.chatbot-details .status {
    font-size: 0.72rem;
    color: var(--text-soft);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.15rem;
}

.status-dot {
    width: 6px;
    height: 6px;
    background: var(--c-teal);
    border-radius: 50%;
    animation: statusPulse 1.8s infinite;
}

@keyframes statusPulse {
    0% { opacity: 0.4; }
    50% { opacity: 1; }
    100% { opacity: 0.4; }
}

.chatbot-close {
    font-size: 1.8rem;
    color: var(--text-soft);
    cursor: pointer;
    line-height: 1;
    transition: color 0.25s, transform 0.25s;
    background: none;
    border: none;
    padding: 0;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
}

.chatbot-close:hover {
    color: var(--text);
    transform: rotate(90deg);
}

/* Chat Messages */
.chatbot-messages {
    flex: 1;
    padding: 1.2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

/* Custom Scrollbars */
.chatbot-messages::-webkit-scrollbar {
    width: 5px;
}

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

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

/* Message bubbles */
.chatbot-msg {
    max-width: 82%;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    line-height: 1.5;
    word-break: break-word;
    animation: messageIn 0.35s var(--ease) forwards;
    opacity: 0;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chatbot-msg strong {
    color: inherit;
    font-weight: 600;
}

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

[data-theme="light"] .chatbot-msg.bot {
    background: rgba(15, 23, 42, 0.04);
    border-color: rgba(15, 23, 42, 0.08);
}

.chatbot-msg.user {
    align-self: flex-end;
    background: var(--grad);
    color: #04101e;
    border-bottom-right-radius: 4px;
    font-weight: 500;
    box-shadow: 0 4px 12px -5px var(--glow);
}

/* Quick Replies */
.chatbot-quick-replies {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    overflow-x: auto;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.01);
    scrollbar-width: none;
}

.chatbot-quick-replies::-webkit-scrollbar {
    display: none;
}

.quick-reply-btn {
    font-family: var(--font-body);
    font-size: 0.78rem;
    padding: 0.45rem 0.85rem;
    border-radius: 100px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-soft);
    white-space: nowrap;
    transition: all 0.25s var(--ease);
    cursor: pointer;
    flex-shrink: 0;
}

.quick-reply-btn:hover {
    border-color: var(--c-cyan);
    color: var(--text);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px -4px var(--glow);
}

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

/* Chat Input Form */
.chatbot-form {
    padding: 0.8rem 1.2rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    flex-shrink: 0;
}

[data-theme="light"] .chatbot-form {
    background: rgba(15, 23, 42, 0.02);
}

.chatbot-form input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.25s, box-shadow 0.25s;
}

[data-theme="light"] .chatbot-form input {
    background: var(--surface-2);
}

.chatbot-form input:focus {
    outline: none;
    border-color: var(--c-cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

.chatbot-form button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--grad);
    color: #04101e;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.25s var(--ease), box-shadow 0.25s;
    box-shadow: 0 4px 12px -5px var(--glow);
}

.chatbot-form button:hover {
    transform: scale(1.06) translateY(-1px);
    box-shadow: 0 6px 16px -4px var(--glow);
}

.chatbot-form button:active {
    transform: scale(0.95);
}

.chatbot-form button svg {
    width: 18px;
    height: 18px;
    transform: translateX(1px);
}

/* Typing Indicator */
.chatbot-typing {
    align-self: flex-start;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    padding: 0.75rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chatbot-typing span {
    width: 6px;
    height: 6px;
    background: var(--text-soft);
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

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

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

/* Responsive Adaptive Layout */
@media (max-width: 760px) {
    .chatbot-container {
        bottom: 1.5rem;
        right: 1.5rem;
    }
    
    .chatbot-window {
        width: 100vw;
        height: 100%;
        max-height: 100%;
        max-width: 100vw;
        bottom: 0;
        right: 0;
        border-radius: 0;
        border: none;
        position: fixed;
        transform-origin: bottom center;
        transition: transform 0.4s var(--ease), opacity 0.4s;
    }
    
    .chatbot-window.hidden {
        transform: translateY(100%);
        opacity: 0;
    }
    
    .chatbot-container.open {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
    }
    
    .chatbot-container.open .chatbot-toggle {
        display: none;
    }
}

/* Tooltip Speech Bubble */
.chatbot-tooltip {
    position: absolute;
    bottom: 80px;
    right: 5px;
    background: var(--bg-2);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 0.65rem 1rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    white-space: nowrap;
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    animation: tooltipFadeIn 0.5s var(--ease) forwards;
    pointer-events: auto;
}

[data-theme="light"] .chatbot-tooltip {
    background: #fff;
    border-color: rgba(15, 23, 42, 0.12);
}

/* Tooltip Arrow pointing down */
.chatbot-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 22px;
    width: 10px;
    height: 10px;
    background: var(--bg-2);
    border-right: 1px solid var(--border-strong);
    border-bottom: 1px solid var(--border-strong);
    transform: rotate(45deg);
}

[data-theme="light"] .chatbot-tooltip::after {
    background: #fff;
    border-color: rgba(15, 23, 42, 0.12);
}

/* Close button for tooltip */
.chatbot-tooltip-close {
    font-size: 1.1rem;
    color: var(--text-dim);
    cursor: pointer;
    line-height: 1;
    border: none;
    background: none;
    padding: 0;
    order: 2;
    transition: color 0.2s;
}

.chatbot-tooltip-close:hover {
    color: var(--text);
}

/* Tooltip text transition */
.chatbot-tooltip span {
    transition: opacity 0.3s ease;
    display: inline-block;
}

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

.chatbot-tooltip.hidden {
    display: none !important;
}

@media (max-width: 760px) {
    .chatbot-tooltip {
        bottom: 75px;
        right: 0;
    }
}
