/* ============================================
   MANUEL DALLA SANTA - AI CHATBOT WIDGET
   ============================================ */

:root {
    --mds-chat-primary: #0a0a0a;
    --mds-chat-primary-hover: #222222;
    --mds-chat-bg: #ffffff;
    --mds-chat-border: rgba(0, 0, 0, 0.08);
    --mds-chat-bubble-user: #111111;
    --mds-chat-bubble-user-text: #ffffff;
    --mds-chat-bubble-bot: #f4f4f6;
    --mds-chat-bubble-bot-text: #1a1a1a;
    --mds-chat-text-muted: #71717a;
    --mds-chat-online: #10b981;
    --mds-chat-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mds-chat-font-display: 'Outfit', 'Inter', sans-serif;
    --mds-chat-shadow: 0 16px 40px -10px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(0, 0, 0, 0.06);
}

/* ── Floating Launcher Button ─────────────────────── */
#mds-chatbot-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background-color: var(--mds-chat-bg);
    box-shadow: 0 10px 28px -4px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 2.5px solid #ffffff;
    cursor: pointer;
    z-index: 9999;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#mds-chatbot-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 14px 34px -4px rgba(0, 0, 0, 0.32), 0 4px 12px rgba(0, 0, 0, 0.12);
}

#mds-chatbot-launcher:active {
    transform: scale(0.96);
}

.mds-launcher-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.mds-launcher-close-icon {
    display: none;
    width: 24px;
    height: 24px;
    color: #ffffff;
}

#mds-chatbot-launcher.is-active {
    background-color: var(--mds-chat-primary);
    border-color: #333333;
}

#mds-chatbot-launcher.is-active .mds-launcher-avatar {
    display: none;
}

#mds-chatbot-launcher.is-active .mds-launcher-close-icon {
    display: block;
}

/* Online Indicator Dot */
.mds-launcher-badge {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 15px;
    height: 15px;
    background-color: var(--mds-chat-online);
    border: 2.5px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.mds-launcher-badge::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    border: 2px solid var(--mds-chat-online);
    animation: mds-pulse-ring 2.2s infinite;
    opacity: 0.7;
}

@keyframes mds-pulse-ring {
    0% {
        transform: scale(0.9);
        opacity: 0.9;
    }
    60% {
        transform: scale(1.7);
        opacity: 0;
    }
    100% {
        transform: scale(1.7);
        opacity: 0;
    }
}

/* Teaser / Welcome tooltip bubble */
.mds-launcher-tooltip {
    position: absolute;
    right: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%);
    background: #111111;
    color: #ffffff;
    font-family: var(--mds-chat-font);
    font-size: 13px;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: 20px;
    white-space: nowrap;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    pointer-events: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mds-launcher-tooltip::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px 0 6px 7px;
    border-style: solid;
    border-color: transparent transparent transparent #111111;
}

.mds-launcher-tooltip.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
}

.mds-tooltip-close {
    background: none;
    border: none;
    color: #888888;
    font-size: 14px;
    margin-left: 4px;
    cursor: pointer;
    line-height: 1;
    padding: 2px;
}
.mds-tooltip-close:hover {
    color: #ffffff;
}

/* ── Chatbot Window ───────────────────────────────── */
#mds-chatbot-window {
    position: fixed;
    bottom: 98px;
    right: 24px;
    width: 385px;
    max-width: calc(100vw - 32px);
    height: 550px;
    max-height: calc(100vh - 130px);
    background-color: var(--mds-chat-bg);
    border-radius: 22px;
    box-shadow: var(--mds-chat-shadow);
    border: 1px solid var(--mds-chat-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    font-family: var(--mds-chat-font);
    opacity: 0;
    visibility: hidden;
    transform: translateY(18px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.3s;
}

#mds-chatbot-window.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.mds-chat-header {
    background: #0f0f11;
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    user-select: none;
}

.mds-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mds-chat-header-avatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: hidden;
    background: #222222;
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

.mds-chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mds-chat-header-titles {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.mds-chat-header-name {
    font-family: var(--mds-chat-font-display);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #ffffff;
}

.mds-chat-header-status {
    font-size: 11.5px;
    color: #a1a1aa;
    display: flex;
    align-items: center;
    gap: 5px;
}

.mds-chat-header-status-dot {
    width: 7px;
    height: 7px;
    background: var(--mds-chat-online);
    border-radius: 50%;
    display: inline-block;
}

.mds-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.mds-chat-header-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #d4d4d8;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.mds-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

/* Chat Messages Area */
.mds-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
    scroll-behavior: smooth;
}

.mds-chat-messages::-webkit-scrollbar {
    width: 5px;
}
.mds-chat-messages::-webkit-scrollbar-thumb {
    background: #d4d4d8;
    border-radius: 4px;
}

/* Messages */
.mds-message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 88%;
    animation: mds-fade-in 0.25s ease-out;
}

@keyframes mds-fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mds-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.mds-message-bot {
    align-self: flex-start;
}

.mds-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 2px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.mds-message-content {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}

.mds-message-user .mds-message-content {
    background: var(--mds-chat-bubble-user);
    color: var(--mds-chat-bubble-user-text);
    border-bottom-right-radius: 4px;
}

.mds-message-bot .mds-message-content {
    background: var(--mds-chat-bubble-bot);
    color: var(--mds-chat-bubble-bot-text);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-bottom-left-radius: 4px;
}

/* Formattazione testo bot */
.mds-message-content p {
    margin: 0 0 6px 0;
}
.mds-message-content p:last-child {
    margin-bottom: 0;
}
.mds-message-content ul,
.mds-message-content ol {
    margin: 4px 0 6px 18px;
    padding: 0;
}
.mds-message-content li {
    margin-bottom: 3px;
}
.mds-message-content strong {
    font-weight: 600;
}
.mds-message-content a {
    color: #111111;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
}
.mds-message-content a:hover {
    color: #444444;
}

/* Quick Action Chips */
.mds-chat-chips-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.mds-chips-label {
    font-size: 11px;
    color: var(--mds-chat-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.mds-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.mds-chip {
    background: #ffffff;
    border: 1px solid #e4e4e7;
    color: #18181b;
    font-family: var(--mds-chat-font);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 11px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.mds-chip:hover {
    background: #f4f4f5;
    border-color: #d4d4d8;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06);
}

/* ── Thinking Indicator with imgThinking.png ──────── */
.mds-thinking-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 10px 14px;
    align-self: flex-start;
    max-width: 85%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
    animation: mds-fade-in 0.25s ease-out;
}

.mds-thinking-avatar-wrapper {
    position: relative;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mds-thinking-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    animation: mds-thinking-bounce 2s ease-in-out infinite alternate;
}

@keyframes mds-thinking-bounce {
    0% {
        transform: translateY(0) rotate(0deg);
    }
    50% {
        transform: translateY(-3px) rotate(-2deg);
    }
    100% {
        transform: translateY(1px) rotate(2deg);
    }
}

.mds-thinking-text-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mds-thinking-label {
    font-size: 12px;
    font-weight: 600;
    color: #4b5563;
}

/* Animated Thinking Dots */
.mds-thinking-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.mds-thinking-dots span {
    width: 6px;
    height: 6px;
    background-color: #111111;
    border-radius: 50%;
    display: inline-block;
    animation: mds-dot-pulse 1.4s infinite ease-in-out both;
}

.mds-thinking-dots span:nth-child(1) {
    animation-delay: -0.32s;
}
.mds-thinking-dots span:nth-child(2) {
    animation-delay: -0.16s;
}
.mds-thinking-dots span:nth-child(3) {
    animation-delay: 0;
}

@keyframes mds-dot-pulse {
    0%, 80%, 100% {
        transform: scale(0.4);
        opacity: 0.3;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ── Chat Footer / Input Form ─────────────────────── */
.mds-chat-footer {
    padding: 12px 14px 10px;
    background: #ffffff;
    border-top: 1px solid var(--mds-chat-border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mds-chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f4f4f6;
    border: 1px solid #e4e4e7;
    border-radius: 24px;
    padding: 4px 6px 4px 14px;
    transition: border-color 0.2s, background 0.2s;
}

.mds-chat-form:focus-within {
    border-color: #18181b;
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(24, 24, 27, 0.08);
}

.mds-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--mds-chat-font);
    font-size: 13.5px;
    color: #111111;
    outline: none;
    padding: 6px 0;
}

.mds-chat-input::placeholder {
    color: #a1a1aa;
}

.mds-chat-send-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--mds-chat-primary);
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, background-color 0.2s, opacity 0.2s;
}

.mds-chat-send-btn:hover:not(:disabled) {
    background: var(--mds-chat-primary-hover);
    transform: scale(1.05);
}

.mds-chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.mds-chat-send-btn svg {
    width: 15px;
    height: 15px;
    transform: translateX(1px);
}

.mds-chat-disclaimer {
    font-size: 10px;
    color: #a1a1aa;
    text-align: center;
    letter-spacing: 0.01em;
}

/* ── Mobile Responsive ────────────────────────────── */
@media (max-width: 480px) {
    #mds-chatbot-launcher {
        bottom: 18px;
        right: 18px;
        width: 56px;
        height: 56px;
    }

    #mds-chatbot-window {
        bottom: 84px;
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        height: 74vh;
        max-height: 580px;
        border-radius: 20px;
    }

    .mds-launcher-tooltip {
        display: none; /* Nascondi tooltip su schermi molto piccoli */
    }
}
