:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #0f172a;
    --chat-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --user-msg-bg: #4f46e5;
    --ai-msg-bg: #334155;
    --border-color: #334155;
    --success-color: #10b981;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-image: radial-gradient(circle at top right, rgba(99, 102, 241, 0.15), transparent 400px),
        radial-gradient(circle at bottom left, rgba(99, 102, 241, 0.1), transparent 400px);
}

.chat-container {
    width: 100%;
    max-width: 650px;
    height: 85vh;
    background-color: var(--chat-bg);
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    backdrop-filter: blur(10px);
}

.chat-header {
    padding: 20px 24px;
    background-color: rgba(30, 41, 59, 0.95);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.robot-icon {
    font-size: 26px;
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.15);
    padding: 10px;
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.chat-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.status {
    font-size: 0.85rem;
    color: var(--success-color);
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.status::before {
    content: '';
    width: 8px;
    height: 8px;
    background-color: var(--success-color);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--success-color);
}

.chat-history {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.chat-history::-webkit-scrollbar {
    width: 8px;
}

.chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.3);
    border-radius: 10px;
    border: 2px solid var(--chat-bg);
}

.chat-history::-webkit-scrollbar-thumb:hover {
    background-color: rgba(148, 163, 184, 0.5);
}

.message {
    display: flex;
    max-width: 80%;
    animation: slideUpFade 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.user-message {
    align-self: flex-end;
}

.ai-message {
    align-self: flex-start;
}

.message-content {
    padding: 16px 20px;
    border-radius: 24px;
    line-height: 1.6;
    font-size: 0.95rem;
    word-wrap: break-word;
    letter-spacing: 0.01em;
}

.user-message .message-content {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.25);
}

.ai-message .message-content {
    background-color: var(--ai-msg-bg);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.chat-input-area {
    padding: 20px 24px;
    background-color: rgba(30, 41, 59, 0.95);
    border-top: 1px solid var(--border-color);
}

#chat-form {
    display: flex;
    gap: 12px;
    background-color: var(--chat-bg);
    padding: 10px 10px 10px 24px;
    border-radius: 36px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

#chat-form:focus-within {
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15), inset 0 2px 4px rgba(0, 0, 0, 0.1);
    background-color: rgba(30, 41, 59, 0.8);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    line-height: 1.5;
}

#user-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

#send-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-size: 1.25rem;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    position: relative;
    overflow: hidden;
}

#send-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    opacity: 0;
    transition: opacity 0.3s ease;
}

#send-btn:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.5);
}

#send-btn:hover::after {
    opacity: 1;
}

#send-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

#send-btn:disabled {
    background: var(--border-color);
    color: rgba(255, 255, 255, 0.3);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Typing indicator */
.typing-container {
    width: fit-content;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 16px 20px;
    background-color: var(--ai-msg-bg);
    border-radius: 24px;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: var(--primary-color);
    border-radius: 50%;
    animation: typingPulse 1.4s infinite ease-in-out both;
    box-shadow: 0 0 6px rgba(99, 102, 241, 0.4);
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingPulse {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
        box-shadow: 0 0 2px rgba(99, 102, 241, 0.2);
    }

    40% {
        transform: scale(1.1);
        opacity: 1;
        box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
    }
}

/* Formattazione base Markdown */
.message-content strong {
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.02em;
}

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

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

.message-content code {
    background: rgba(0, 0, 0, 0.25);
    padding: 3px 6px;
    border-radius: 6px;
    font-family: 'Fira Code', monospace;
    font-size: 0.85em;
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.message-content pre {
    background: #0f172a;
    padding: 16px;
    border-radius: 12px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.message-content pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    border: none;
    font-size: 0.9em;
}

.message-content ul,
.message-content ol {
    margin-left: 20px;
    margin-top: 8px;
    margin-bottom: 12px;
}

.message-content li {
    margin-bottom: 4px;
}