/* ============================================================================
   ATLATECH SRL — CHATBOT WIDGET
   ============================================================================
   Widget chat fisso in basso a destra con albero decisionale.
   Usa esclusivamente i design token del sistema.
   ============================================================================ */

/* ---------- Z-index chatbot ---------- */
:root {
    --z-chatbot: 1050;
}

/* ==========================================================================
   Toggle button (icona chat)
   ========================================================================== */
.chatbot-toggle {
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: var(--z-chatbot);
    box-shadow: var(--shadow-glow-soft);
    transition: transform var(--dur-base) var(--ease-out),
                box-shadow var(--dur-base) var(--ease-standard);
}
.chatbot-toggle:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-glow);
}
.chatbot-toggle svg {
    width: 26px;
    height: 26px;
    transition: transform var(--dur-base) var(--ease-standard),
                opacity var(--dur-base) var(--ease-standard);
}
.chatbot-toggle .chatbot-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}
.chatbot-toggle.is-active .chatbot-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}
.chatbot-toggle.is-active .chatbot-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Badge notifica */
.chatbot-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: var(--color-danger);
    border: 2px solid var(--color-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: var(--fw-bold);
    color: #fff;
    opacity: 0;
    transform: scale(0);
    transition: opacity var(--dur-base) var(--ease-spring),
                transform var(--dur-base) var(--ease-spring);
    pointer-events: none;
}
.chatbot-badge.is-visible {
    opacity: 1;
    transform: scale(1);
}

/* ==========================================================================
   Chat window
   ========================================================================== */
.chatbot-window {
    position: fixed;
    bottom: calc(var(--space-5) + 56px + var(--space-3));
    right: var(--space-5);
    width: 380px;
    max-height: 520px;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    z-index: var(--z-chatbot);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity var(--dur-base) var(--ease-out),
                visibility 0s linear var(--dur-base),
                transform var(--dur-base) var(--ease-out);
}
.chatbot-window.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    transition-delay: 0s;
}

/* ---------- Header ---------- */
.chatbot-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.chatbot-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chatbot-header-avatar svg {
    width: 18px;
    height: 18px;
    color: var(--color-bg);
}
.chatbot-header-info {
    flex: 1;
    min-width: 0;
}
.chatbot-header-name {
    font-family: var(--font-display);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--color-text);
    line-height: 1.2;
}
.chatbot-header-status {
    font-size: var(--fs-xs);
    color: var(--color-success);
    display: flex;
    align-items: center;
    gap: 6px;
}
.chatbot-header-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
}

/* ---------- Messages area ---------- */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4) var(--space-4) var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    scroll-behavior: smooth;
    min-height: 0;
    max-height: 340px;
}
/* Custom scrollbar */
.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: var(--r-full);
}

/* Single message */
.chatbot-msg {
    max-width: 85%;
    padding: var(--space-3) var(--space-4);
    font-size: var(--fs-sm);
    line-height: var(--lh-base);
    border-radius: var(--r-lg);
    animation: chatbot-fadeIn var(--dur-base) var(--ease-out) both;
}
@keyframes chatbot-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Bot message (left) */
.chatbot-msg--bot {
    align-self: flex-start;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    border-bottom-left-radius: var(--r-xs);
}
.chatbot-msg--bot a {
    color: var(--color-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.chatbot-msg--bot a:hover {
    color: var(--color-primary-hover);
}

/* User message (right) */
.chatbot-msg--user {
    align-self: flex-end;
    background: var(--gradient-primary);
    color: var(--color-bg);
    border-bottom-right-radius: var(--r-xs);
}

/* Typing indicator */
.chatbot-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--r-lg);
    border-bottom-left-radius: var(--r-xs);
}
.chatbot-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-dim);
    animation: chatbot-bounce 1.2s infinite ease-in-out;
}
.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes chatbot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Quick-reply options (buttons) ---------- */
.chatbot-options {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: 0 var(--space-4) var(--space-3);
    animation: chatbot-fadeIn var(--dur-base) var(--ease-out) 0.15s both;
}
.chatbot-option-btn {
    padding: 0.5em 1em;
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--color-primary);
    background: var(--color-primary-soft);
    border: 1px solid rgba(201, 168, 76, 0.30);
    border-radius: var(--r-full);
    cursor: pointer;
    transition: var(--transition-base);
    white-space: nowrap;
}
.chatbot-option-btn:hover {
    background: rgba(201, 168, 76, 0.18);
    border-color: var(--color-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow-soft);
}

/* ---------- Input area ---------- */
.chatbot-input-area {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    flex-shrink: 0;
}
.chatbot-input {
    flex: 1;
    padding: 0.6em 0.9em;
    font-size: var(--fs-sm);
    color: var(--color-text);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--r-full);
    transition: var(--transition-base);
}
.chatbot-input::placeholder { color: var(--color-text-dim); }
.chatbot-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.chatbot-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.chatbot-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    color: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--transition-base);
}
.chatbot-send-btn:hover {
    box-shadow: var(--shadow-glow-soft);
    transform: scale(1.06);
}
.chatbot-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}
.chatbot-send-btn svg {
    width: 16px;
    height: 16px;
}

/* ==========================================================================
   Responsive — Mobile
   ========================================================================== */
@media (max-width: 480px) {
    .chatbot-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100dvh;
        border-radius: 0;
        transform: translateY(100%);
    }
    .chatbot-window.is-open {
        transform: translateY(0);
    }
    .chatbot-messages {
        max-height: calc(100dvh - 130px);
    }
    .chatbot-toggle {
        bottom: var(--space-4);
        right: var(--space-4);
    }
    .chatbot-toggle.is-active {
        opacity: 0;
        pointer-events: none;
    }
}
@media (min-width: 481px) and (max-width: 767px) {
    .chatbot-window {
        width: calc(100vw - var(--space-6));
        right: var(--space-3);
        bottom: calc(var(--space-4) + 56px + var(--space-2));
        max-height: 70vh;
    }
}

/* ==========================================================================
   Scroll-top repositioning when chat is open
   ========================================================================== */
.chatbot-toggle.is-active ~ .scroll-top {
    bottom: calc(var(--space-5) + 64px);
}

/* ==========================================================================
   Print — hide chatbot
   ========================================================================== */
@media print {
    .chatbot-toggle,
    .chatbot-window { display: none !important; }
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .chatbot-window,
    .chatbot-msg,
    .chatbot-options,
    .chatbot-toggle,
    .chatbot-badge {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }
}
