/* Reset e variabili CSS */
:root {
    /* Colori principali */
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --accent-color: #f59e0b;
    
    /* Colori di sfondo */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-chat: #ffffff;
    
    /* Colori del testo */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    /* Colori dei bordi */
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    
    /* Colori di stato */
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --info-color: #3b82f6;
    
    /* Ombre */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Dimensioni */
    --header-height: 80px;
    --status-height: 40px;
    --input-area-height: 120px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    
    /* Font */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    
    /* Transizioni */
    --transition-fast: 0.15s ease-in-out;
    --transition-normal: 0.3s ease-in-out;
    --transition-slow: 0.5s ease-in-out;
}

/* Tema scuro */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-chat: #1e293b;
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --border-color: #334155;
    --border-hover: #475569;
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    overflow: hidden;
}

/* Container principale */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    margin: 0 auto;
    background-color: var(--bg-primary);
    position: relative;
}

/* Header */
.chat-header {
    height: var(--header-height);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
    padding: 0 24px;
    display: flex;
    align-items: center;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 10;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.brand-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-logo {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.brand-text h1 {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin-bottom: 2px;
}

.brand-text p {
    font-size: var(--font-size-sm);
    opacity: 0.9;
    font-weight: 400;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--border-radius-sm);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    font-size: 16px;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

/* Status Bar */
.status-bar {
    height: var(--status-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
}

.status-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success-color);
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background-color: var(--error-color);
}

.qualifications-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* Area messaggi */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background-color: var(--bg-chat);
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* Messaggio di benvenuto */
.welcome-message {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
    padding: 40px 20px;
}

.welcome-content {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    padding: 40px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
}

.welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    font-size: 32px;
    color: white;
}

.welcome-content h2 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.welcome-content p {
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.6;
}

.welcome-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.feature {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.feature i {
    color: var(--primary-color);
    font-size: 18px;
}

.feature span {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.welcome-prompt {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0;
}

/* Messaggi chat */
.message {
    display: flex;
    margin-bottom: 24px;
    animation: slideIn 0.3s ease-out;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    display: flex;
    gap: 12px;
}

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

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

.message.user .avatar {
    background: linear-gradient(135deg, var(--accent-color) 0%, #f97316 100%);
    color: white;
}

.message.assistant .avatar {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
}

.message-bubble {
    padding: 16px 20px;
    border-radius: var(--border-radius-lg);
    position: relative;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.message.assistant .message-bubble {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 6px;
}

.message-text {
    line-height: 1.5;
}

.message-text h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: 12px;
}

.message-text p {
    margin-bottom: 12px;
}

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

.message-text ul, .message-text ol {
    margin: 12px 0;
    padding-left: 20px;
}

.message-text li {
    margin-bottom: 6px;
}

.message-text strong {
    font-weight: 600;
}

.message-text a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: var(--transition-fast);
    word-break: break-all;
}

.message-text a:hover {
    color: var(--primary-hover);
    border-bottom-color: var(--primary-hover);
}

.message.user .message-text a {
    color: rgba(255, 255, 255, 0.9);
    border-bottom-color: rgba(255, 255, 255, 0.3);
}

.message.user .message-text a:hover {
    color: white;
    border-bottom-color: white;
}

/* Stili per immagini cliccabili */
.message-text img {
    transition: var(--transition-fast);
    border-radius: 8px;
}

.message-text img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.message-image-container {
    position: relative;
    display: inline-block;
}

.message-image-container::after {
    content: '🔍';
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    transition: var(--transition-fast);
    pointer-events: none;
}

.message-image-container:hover::after {
    opacity: 1;
}

.message-time {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: 8px;
    text-align: right;
}

.message.assistant .message-time {
    text-align: left;
}

/* Indicatore di digitazione */
.typing-indicator {
    display: none;
    padding: 0 24px 24px;
    animation: slideIn 0.3s ease-out;
}

.typing-indicator.show {
    display: block;
}

.typing-content {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.typing-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    border-bottom-left-radius: 6px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingDots 1.4s infinite ease-in-out;
}

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

.typing-text {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* Area input */
.chat-input-area {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 20px 24px;
}

.input-container {
    max-width: 100%;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 12px 16px;
    transition: var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 120px;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.input-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.input-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.send-btn {
    width: 36px;
    height: 36px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

.char-counter {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: var(--transition-fast);
}

.quick-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.quick-btn i {
    font-size: 12px;
}

/* Pannello impostazioni */
.settings-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: var(--bg-primary);
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    transition: var(--transition-normal);
}

.settings-panel.open {
    right: 0;
}

.settings-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.settings-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.close-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.settings-body {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.setting-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: var(--transition-fast);
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition-fast);
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

.settings-footer {
    padding: 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-primary, .btn-secondary {
    padding: 8px 16px;
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
}

/* Overlay di caricamento */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-normal);
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loading-content {
    background: var(--bg-primary);
    padding: 40px;
    border-radius: var(--border-radius-lg);
    text-align: center;
    box-shadow: var(--shadow-xl);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

.loading-content p {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

/* Toast errore */
.error-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--error-color);
    color: white;
    padding: 16px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 1500;
    max-width: 350px;
    transform: translateX(calc(100% + 40px));
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.error-toast.show {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

/* Toast successo */
.success-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--success-color);
    color: white;
    padding: 16px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 1500;
    max-width: 350px;
    transform: translateX(calc(100% + 40px));
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.success-toast.show {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast-close {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--border-radius-sm);
    transition: var(--transition-fast);
}

.toast-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Animazione per quick replies dinamiche */
@keyframes quickReplySlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.quick-btn.dynamic {
    animation: quickReplySlideIn 0.3s ease-out;
}

.quick-btn.dynamic.new {
    animation-delay: var(--animation-delay, 0ms);
}

/* Animazioni */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

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

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

/* Responsive */
@media (max-width: 768px) {
    .chat-header {
        padding: 0 16px;
        height: 70px;
    }
    
    .brand-text h1 {
        font-size: var(--font-size-lg);
    }
    
    .brand-text p {
        display: none;
    }
    
    .status-bar {
        padding: 0 16px;
    }
    
    .chat-messages {
        padding: 16px;
    }
    
    .chat-input-area {
        padding: 16px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .welcome-content {
        padding: 24px;
    }
    
    .welcome-features {
        grid-template-columns: 1fr;
    }
    
    .quick-actions {
        display: none;
    }
    
    .settings-panel {
        width: 100%;
        right: -100%;
    }
    
    .input-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .brand-logo {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .action-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .welcome-icon {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }
    
    .welcome-content h2 {
        font-size: var(--font-size-xl);
    }
}

/* Utility classes */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Accessibilità */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .chat-header,
    .status-bar,
    .chat-input-area,
    .settings-panel,
    .loading-overlay,
    .error-toast {
        display: none !important;
    }
    
    .chat-container {
        height: auto;
    }
    
    .chat-messages {
        overflow: visible;
        height: auto;
    }
}