/* ==================== SIDEBAR INTELLIGENTE ==================== */

.sidebar-chat-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 350px;
    height: 500px;
    z-index: 1000;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.intelligent-sidebar {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, 0.1);
    animation: slideInFromRight 0.4s ease-out;
}

@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ==================== HEADER ==================== */

.sidebar-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.sidebar-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    opacity: 0.9;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #00ff88;
    animation: pulse 2s infinite;
}

.status-indicator.online {
    background: #00ff88;
}

.status-indicator.busy {
    background: #ff9500;
}

/* ==================== CONVERSATION AREA ==================== */

.conversation-area {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sidebar-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.sidebar-message.user {
    flex-direction: row-reverse;
}

.ai-avatar,
.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.ai-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.user-avatar {
    background: #e9ecef;
}

.message-content {
    flex: 1;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.4;
    font-size: 14px;
    max-width: 85%;
}

.ai-message {
    background: white;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 4px;
    color: #333;
}

.user-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.welcome-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
    padding: 16px;
    background: white;
    border-radius: 12px;
    border: 2px solid #e9ecef;
}

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

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

/* ==================== SOSTITUZIONE CHAT CON PULSANTE AI ==================== */

.ai-assistant-replacement {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-height: 200px; /* Altezza minima per occupare lo spazio della chat */
}

.ai-assistant-standalone-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 16px 24px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.ai-assistant-standalone-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4);
    border-color: rgba(255, 255, 255, 0.4);
}

.ai-assistant-standalone-button:active {
    transform: translateY(-1px);
}

/* ==================== RESPONSIVE PER SOSTITUZIONE CHAT ==================== */

@media (max-width: 768px) {
    .ai-assistant-replacement {
        padding: 16px;
        min-height: 150px;
    }
    
    .ai-assistant-standalone-button {
        padding: 14px 20px;
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .ai-assistant-replacement {
        padding: 12px;
        min-height: 120px;
    }
    
    .ai-assistant-standalone-button {
        padding: 12px 18px;
        font-size: 14px;
    }
}

/* ==================== STILI PRECEDENTI (BACKUP) ==================== */

.manual-mode-sidebar {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.manual-mode-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    text-align: center;
}

.manual-mode-header h3 {
    margin: 0 0 8px 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.manual-mode-header p {
    margin: 0;
    font-size: 0.9rem;
    opacity: 0.9;
}

.manual-mode-body {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.manual-info {
    margin-bottom: 24px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 14px;
    color: #555;
}

.info-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.ai-suggestion {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border: 2px solid rgba(102, 126, 234, 0.2);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}

.ai-suggestion h4 {
    margin: 0 0 12px 0;
    font-size: 1.1rem;
    color: #333;
    font-weight: 600;
}

.ai-suggestion p {
    margin: 0 0 20px 0;
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}

.ai-assistant-button-full {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 16px 32px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
    width: 100%;
    font-family: inherit;
}

.ai-assistant-button-full:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(102, 126, 234, 0.4);
}

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

/* ==================== RESPONSIVE PER MODALITÀ MANUALE ==================== */

@media (max-width: 768px) {
    .manual-mode-header {
        padding: 16px;
    }
    
    .manual-mode-header h3 {
        font-size: 1.1rem;
    }
    
    .manual-mode-body {
        padding: 20px;
    }
    
    .info-item {
        padding: 10px;
        font-size: 13px;
    }
    
    .ai-suggestion {
        padding: 16px;
    }
    
    .ai-suggestion h4 {
        font-size: 1rem;
    }
    
    .ai-assistant-button-full {
        padding: 14px 24px;
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .manual-mode-body {
        padding: 16px;
    }
    
    .ai-suggestion {
        padding: 14px;
    }
    
    .ai-assistant-button-full {
        padding: 12px 20px;
        font-size: 14px;
    }
}

/* ==================== STILI PRECEDENTI MODALITÀ MANUALE (BACKUP) ==================== */

.manual-mode-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 20px;
    text-align: center;
}

.manual-mode-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
}

.ai-avatar-large {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin-bottom: 16px;
}

.welcome-content h3 {
    margin: 0 0 12px 0;
    font-size: 1.2rem;
    color: #333;
    font-weight: 600;
}

.welcome-content p {
    margin: 0;
    color: #666;
    font-size: 14px;
    line-height: 1.5;
}

.ai-assistant-cta {
    text-align: center;
}

.ai-assistant-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 16px 24px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
    margin-bottom: 12px;
    width: 100%;
    font-family: inherit;
}

.ai-assistant-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(102, 126, 234, 0.4);
}

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

.ai-cta-description {
    margin: 0;
    color: #666;
    font-size: 12px;
    line-height: 1.4;
}

/* ==================== QUICK ACTIONS ==================== */

.quick-actions {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.quick-btn {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #495057;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.quick-btn:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

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

/* ==================== INPUT AREA ==================== */

.input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e9ecef;
}

.input-container {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 24px;
    padding: 4px;
    transition: all 0.2s ease;
}

.input-container:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#sidebarInput {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px 16px;
    background: transparent;
    font-size: 14px;
    color: #333;
    font-family: inherit;
}

#sidebarInput::placeholder {
    color: #999;
}

.send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: white;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

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

/* ==================== SCROLLBAR ==================== */

.conversation-area::-webkit-scrollbar {
    width: 4px;
}

.conversation-area::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-area::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 2px;
}

.conversation-area::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

/* ==================== RESPONSIVE DESIGN ==================== */

@media (max-width: 768px) {
    .sidebar-chat-container {
        right: 10px;
        bottom: 10px;
        width: 320px;
        height: 450px;
    }
    
    .sidebar-header {
        padding: 14px 16px;
    }
    
    .sidebar-header h3 {
        font-size: 1rem;
    }
    
    .conversation-area {
        padding: 12px;
    }
    
    .message-content {
        font-size: 13px;
        padding: 10px 14px;
    }
    
    .quick-actions {
        padding: 10px 12px;
        gap: 6px;
    }
    
    .quick-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    .input-area {
        padding: 12px;
    }
    
    #sidebarInput {
        padding: 8px 14px;
        font-size: 13px;
    }
    
    .send-btn {
        width: 32px;
        height: 32px;
    }
    
    .ai-assistant-button {
        padding: 14px 20px;
        font-size: 15px;
    }
    
    .manual-mode-content {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .sidebar-chat-container {
        right: 5px;
        bottom: 5px;
        width: calc(100vw - 10px);
        height: 400px;
    }
    
    .quick-actions {
        grid-template-columns: 1fr;
    }
    
    .ai-assistant-button {
        padding: 12px 18px;
        font-size: 14px;
    }
}

/* ==================== ESTADOS ESPECIALES ==================== */

.intelligent-sidebar.minimized {
    height: 60px;
    overflow: hidden;
}

.intelligent-sidebar.minimized .conversation-area,
.intelligent-sidebar.minimized .quick-actions,
.intelligent-sidebar.minimized .input-area {
    display: none;
}

/* ==================== DARK MODE SUPPORT ==================== */

@media (prefers-color-scheme: dark) {
    .intelligent-sidebar {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .conversation-area {
        background: #111;
    }
    
    .ai-message {
        background: #222;
        border-color: #333;
        color: #fff;
    }
    
    .welcome-message {
        background: #222;
        border-color: #333;
    }
    
    .quick-actions {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .quick-btn {
        background: #222;
        border-color: #333;
        color: #ccc;
    }
    
    .quick-btn:hover {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
    }
    
    .input-area {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .input-container {
        background: #222;
        border-color: #333;
    }
    
    #sidebarInput {
        color: #fff;
    }
    
    #sidebarInput::placeholder {
        color: #666;
    }
    
    .manual-mode-content {
        background: #1a1a1a;
    }
    
    .welcome-content h3 {
        color: #fff;
    }
    
    .welcome-content p,
    .ai-cta-description {
        color: #ccc;
    }
}

/* ==================== ACCESSIBILITY ==================== */

.quick-btn:focus,
.send-btn:focus,
#sidebarInput:focus,
.ai-assistant-button:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .intelligent-sidebar {
        animation: none;
    }
    
    .status-indicator {
        animation: none;
    }
    
    * {
        transition: none !important;
    }
}

/* ==================== HIGH CONTRAST MODE ==================== */

@media (prefers-contrast: high) {
    .intelligent-sidebar {
        border: 2px solid #000;
    }
    
    .quick-btn {
        border: 2px solid #000;
    }
    
    .input-container {
        border: 2px solid #000;
    }
    
    .ai-message {
        border: 2px solid #000;
    }
    
    .ai-assistant-button {
        border: 2px solid #fff;
    }
}

/* ==================== PRINT STYLES ==================== */

@media print {
    .sidebar-chat-container {
        display: none;
    }
}

/* ==================== INTEGRATION STYLES ==================== */

/* Stili per integrazione con sidebar esistente */
.sidebar.has-intelligent-chat {
    padding-bottom: 520px;
}

/* Nasconde elementi della sidebar vecchia quando è attiva quella intelligente */
.sidebar.intelligent-mode .old-chat-elements {
    display: none;
}

/* Animazioni di ingresso per i messaggi */
.sidebar-message {
    animation: fadeInUp 0.3s ease-out;
}

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

/* Stili per messaggi con contenuto formattato */
.message-content strong {
    font-weight: 600;
    color: inherit;
}

.message-content em {
    font-style: italic;
}

.user-message strong {
    color: rgba(255, 255, 255, 0.95);
}

/* ==================== LOADING STATES ==================== */

.sidebar-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #666;
    font-size: 14px;
}

.sidebar-loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #e9ecef;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==================== FILTER OPTIONS STYLES ==================== */

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.filter-option-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    font-family: inherit;
}

.filter-option-btn:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.filter-option-btn:active {
    transform: translateY(0);
}

/* ==================== WAITING INPUT STYLES ==================== */

.sidebar.waiting-input #sidebarInput {
    border-color: #28a745 !important;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1) !important;
}

.sidebar.waiting-input #sidebarInput::placeholder {
    color: #28a745 !important;
    font-weight: 500 !important;
}

/* ==================== STATUS INDICATORS ==================== */

.sidebar.processing .quick-actions {
    opacity: 0.5;
    pointer-events: none;
}

.sidebar.processing .input-area {
    opacity: 0.5;
    pointer-events: none;
}

/* ==================== MESSAGE ENHANCEMENTS ==================== */

.ai-message .filter-options {
    background: rgba(102, 126, 234, 0.1);
    padding: 12px;
    border-radius: 8px;
    margin-top: 8px;
}

.sidebar-message.ai .message-content {
    max-width: 100%;
}

/* ==================== MOBILE ADAPTATIONS ==================== */

@media (max-width: 768px) {
    .filter-option-btn {
        padding: 10px 14px;
        font-size: 12px;
    }
    
    .quick-actions {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        padding: 10px 12px;
    }
    
    .quick-btn {
        padding: 6px 8px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .quick-actions {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .filter-options {
        gap: 6px;
    }
    
    .filter-option-btn {
        padding: 8px 12px;
        font-size: 11px;
    }
}