.ai-sa-widget {
    position: relative;
    border-radius: 16px;
    padding: 18px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.05);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.ai-sa-input-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 14px;
}

.ai-sa-input {
    flex: 1;
    padding: 10px 12px;
    border-radius: 999px;
    border: 1px solid #cbd5e1;
    background-color: #ffffff;
    font-size: 14px;
    line-height: 1.4;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.ai-sa-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
    background-color: #ffffff;
}

.ai-sa-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
    white-space: nowrap;
}

.ai-sa-button:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    transform: translateY(-1px);
}

.ai-sa-button:active {
    transform: translateY(0);
}

.ai-sa-button-text {
    display: inline-block;
    margin-right: 6px;
}

.ai-sa-button-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #ffffff;
    animation: ai-sa-spin 0.8s linear infinite;
}

.ai-sa-button-loading .ai-sa-button-spinner {
    display: inline-block;
}

.ai-sa-button-loading .ai-sa-button-text {
    opacity: 0.85;
}

@keyframes ai-sa-spin {
    to {
        transform: rotate(360deg);
    }
}

.ai-sa-messages {
    max-height: 320px;
    overflow-y: auto;
    border-radius: 12px;
    background-color: #ffffff;
    padding: 10px;
    border: 1px solid #e2e8f0;
}

.ai-sa-message {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
}

.ai-sa-message-user {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    text-align: right;
    margin-left: 40px;
}

.ai-sa-message-assistant {
    background-color: #f9fafb;
    margin-right: 40px;
}

.ai-sa-message-error {
    background-color: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.ai-sa-message-loading {
    font-style: italic;
    color: #64748b;
}

.ai-sa-sources {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed #e2e8f0;
}

.ai-sa-sources-title {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 2px;
}

.ai-sa-sources ul {
    margin: 0;
    padding-left: 18px;
}

.ai-sa-sources li {
    font-size: 12px;
    margin: 2px 0;
}

.ai-sa-sources a {
    color: #2563eb;
    text-decoration: none;
}

.ai-sa-sources a:hover {
    text-decoration: underline;
}

/* Scrollbar leggera per l’area messaggi */
.ai-sa-messages::-webkit-scrollbar {
    width: 6px;
}

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

.ai-sa-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

/* Layout mobile: tutto in colonna a larghezza piena */
@media (max-width: 767px) {
    .ai-sa-widget {
        padding: 14px;
    }

    .ai-sa-input-row {
        flex-direction: column;
        align-items: stretch;
    }

    .ai-sa-input {
        width: 100%;
    }

    .ai-sa-button {
        width: 100%;
        justify-content: center;
    }

    .ai-sa-messages {
        width: 100%;
        margin-top: 10px;
    }

    .ai-sa-message-user {
        margin-left: 0;
        text-align: left;
    }

    .ai-sa-message-assistant {
        margin-right: 0;
    }
}
