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

:root {
    /* Professional calming palette */
    --primary-color: #7C3AED;
    --primary-light: #EDE9FE;
    --primary-dark: #6D28D9;
    --secondary-color: #A78BFA;
    --secondary-light: #DDD6FE;
    --accent-color: #8B5CF6;
    
    /* Sophisticated backgrounds */
    --bg-color: #FDFCFE;
    --surface-color: #FFFFFF;
    --message-bg: #F9FAFB;
    --user-message-bg: #EDE9FE;
    --assistant-message-bg: #F9FAFB;
    
    /* Professional text hierarchy */
    --text-primary: #1F2937;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --text-light: #D1D5DB;
    
    /* Refined borders and shadows */
    --border-color: #E5E7EB;
    --border-light: #F3F4F6;
    --shadow-subtle: 0 1px 2px rgba(0, 0, 0, 0.03);
    --shadow-sm: 0 1px 3px rgba(124, 58, 237, 0.06);
    --shadow-md: 0 4px 12px rgba(124, 58, 237, 0.08);
    --shadow-lg: 0 10px 30px rgba(124, 58, 237, 0.12);
    --shadow-xl: 0 20px 40px rgba(124, 58, 237, 0.15);
    
    /* Spacing and radius */
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-xl: 24px;
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'SF Pro Display', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(to bottom right, #FDFCFE 0%, #F9FAFB 40%, #F3F4F6 100%);
    min-height: 100vh;
    color: var(--text-primary);
    overflow-x: hidden;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.011em;
}

/* ==================== LOADING SCREEN ==================== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #FFFFFF 0%, #F9FAFB 40%, #EDE9FE 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity var(--transition-slow), visibility var(--transition-slow);
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.loading-content {
    text-align: center;
    animation: fadeInUp 1s ease;
}

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

.brain-pulse {
    position: relative;
    width: 140px;
    height: 140px;
    margin: 0 auto 3rem;
}

.brain-pulse svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 6px 24px rgba(124, 58, 237, 0.25));
}

.brain-shape {
    animation: gentlePulse 3.5s ease-in-out infinite;
}

@keyframes gentlePulse {
    0%, 100% { 
        transform: scale(1); 
        opacity: 1; 
    }
    50% { 
        transform: scale(1.025); 
        opacity: 0.94; 
    }
}

.pulse-wave {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border: 2.5px solid var(--primary-color);
    border-radius: 50%;
    animation: calmExpand 3.5s ease-out infinite;
}

@keyframes calmExpand {
    0% {
        transform: translate(-50%, -50%) scale(0.88);
        opacity: 0.6;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.65);
        opacity: 0;
    }
}

.loading-title {
    font-size: 2.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.875rem;
    letter-spacing: -0.04em;
}

.loading-subtitle {
    font-size: 1.0625rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
    font-weight: 400;
    letter-spacing: -0.01em;
}

.loading-dots {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.loading-dots span {
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: professionalBounce 1.8s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.25s; }
.loading-dots span:nth-child(3) { animation-delay: 0.5s; }

@keyframes professionalBounce {
    0%, 80%, 100% { 
        transform: scale(0.65); 
        opacity: 0.35; 
    }
    40% { 
        transform: scale(1); 
        opacity: 1; 
    }
}

/* ==================== MAIN CONTAINER ==================== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==================== HEADER ==================== */
.header {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    padding: 1.375rem 3rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-subtle);
}

.header-content {
    flex: 1;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1.125rem;
}

.logo-icon-wrapper {
    position: relative;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--secondary-light) 100%);
    border-radius: 50%;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.logo-icon-wrapper:hover {
    transform: scale(1.05) rotate(-5deg);
    box-shadow: var(--shadow-md);
}

.logo-icon {
    width: 24px;
    height: 24px;
    stroke: var(--primary-color);
    stroke-width: 2.5;
    position: relative;
    z-index: 2;
}

.pulse-ring {
    display: none;
}

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.03em;
}

.header-subtitle {
    display: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.health-indicators {
    display: none;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.125rem;
    background: var(--message-bg);
    border-radius: 24px;
    font-size: 0.875rem;
    transition: all var(--transition-base);
    border: 1px solid var(--border-light);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-light);
    transition: all var(--transition-base);
}

.status-dot.connected {
    background: var(--primary-color);
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.5), 0 0 4px rgba(124, 58, 237, 0.3);
    animation: gentleGlow 2.5s ease-in-out infinite;
}

@keyframes gentleGlow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.status-text {
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: -0.01em;
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.health-decoration {
    display: none;
}

/* ==================== CHAT CONTAINER ==================== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    margin: 0;
    border-radius: 0;
    overflow: hidden;
    position: relative;
    z-index: 2;
}

/* ==================== MESSAGES CONTAINER ==================== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 2.5rem 2rem;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.messages-container > * {
    width: 100%;
    max-width: 760px;
}

.messages-container::-webkit-scrollbar {
    width: 8px;
}

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

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
    transition: background var(--transition-fast);
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 5rem 2.5rem;
    max-width: 100%;
    animation: fadeInScale 1s ease;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.welcome-icon-container {
    position: relative;
    width: 110px;
    height: 110px;
    margin: 0 auto 2.5rem;
    animation: gentleFloat 5s ease-in-out infinite;
}

@keyframes gentleFloat {
    0%, 100% { 
        transform: translateY(0); 
    }
    50% { 
        transform: translateY(-10px); 
    }
}

.welcome-icon {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 6px 20px rgba(124, 58, 237, 0.2));
}

.welcome-pulse {
    display: none;
}

.welcome-message h2 {
    color: var(--text-primary);
    font-size: 2.25rem;
    margin-bottom: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.03em;
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: 1.125rem;
    line-height: 1.75;
    margin-bottom: 2rem;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
    letter-spacing: -0.01em;
}

.welcome-features {
    display: none;
}

/* Messages */
.message {
    display: flex;
    gap: 0.875rem;
    margin-bottom: 1.5rem;
    animation: slideInMessage 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: 0.25rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-base);
}

.message-avatar:hover {
    transform: scale(1.08);
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--user-message-bg) 0%, var(--secondary-light) 100%);
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--assistant-message-bg) 0%, var(--border-light) 100%);
    border: 1px solid var(--border-light);
}

.message-content {
    flex: 1;
    max-width: 70%;
}

.message.user .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message-bubble {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    line-height: 1.65;
    word-wrap: break-word;
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
    letter-spacing: -0.011em;
}

.message-bubble:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

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

/* Error message styling */
.message-bubble.error-bubble {
    background: linear-gradient(135deg, #FEE2E2 0%, #FECACA 100%);
    color: #991B1B;
    border: 1px solid #FCA5A5;
}

/* Markdown content in messages */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    margin: 0.75rem 0 0.5rem 0;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.message-bubble ul,
.message-bubble ol {
    margin: 0.625rem 0;
    padding-left: 1.5rem;
}

.message-bubble li {
    margin: 0.375rem 0;
}

.message-bubble a {
    color: var(--primary-color);
    text-decoration: underline;
    transition: color var(--transition-fast);
}

.message-bubble a:hover {
    color: var(--primary-dark);
}

.message.user .message-bubble a {
    color: rgba(255, 255, 255, 0.95);
    text-decoration: underline;
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-weight: 400;
    letter-spacing: 0;
}

/* ==================== INPUT CONTAINER ==================== */
.input-container {
    padding: 1.25rem 2rem 1.75rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.02);
}

.input-container > * {
    width: 100%;
    max-width: 760px;
}

.typing-indicator {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.125rem;
    margin-bottom: 1rem;
    background: var(--assistant-message-bg);
    border-radius: var(--radius-md);
    width: fit-content;
    align-self: flex-start;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
}

.typing-avatar {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--secondary-light) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.typing-avatar svg {
    width: 14px;
    height: 14px;
    stroke: var(--primary-color);
}

.typing-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: professionalTyping 1.8s infinite;
}

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

.typing-dot:nth-child(3) {
    animation-delay: 0.5s;
}

@keyframes professionalTyping {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

.typing-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-left: 0.375rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    position: relative;
    background: var(--message-bg);
    border-radius: 28px;
    padding: 0.625rem 0.75rem 0.625rem 1.5rem;
    border: 1.5px solid var(--border-color);
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.input-wrapper:focus-within {
    background: #FFFFFF;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.08), var(--shadow-md);
}

.input-icon {
    display: none;
}

.message-input {
    flex: 1;
    padding: 0.75rem 0;
    border: none;
    background: transparent;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 160px;
    color: var(--text-primary);
    line-height: 1.5;
    letter-spacing: -0.011em;
}

.message-input:focus {
    outline: none;
}

.message-input::placeholder {
    color: var(--text-muted);
}

.send-button {
    width: 44px;
    height: 44px;
    border: none;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    flex-shrink: 0;
    box-shadow: var(--shadow-md);
}

.send-button svg {
    width: 20px;
    height: 20px;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.08) rotate(5deg);
    box-shadow: var(--shadow-lg);
}

.send-button:active:not(:disabled) {
    transform: scale(0.96);
}

.send-button:disabled {
    background: linear-gradient(135deg, var(--text-muted) 0%, var(--text-light) 100%);
    cursor: not-allowed;
    opacity: 0.5;
    box-shadow: var(--shadow-subtle);
}

/* ==================== RESPONSIVE DESIGN ==================== */
@media (max-width: 1024px) {
    .health-decoration {
        display: none;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 1.125rem 1.5rem;
    }

    .logo-title {
        font-size: 1.375rem;
    }

    .logo-icon-wrapper {
        width: 40px;
        height: 40px;
    }

    .messages-container {
        padding: 2rem 1.25rem;
    }

    .message-content {
        max-width: 80%;
    }

    .welcome-message {
        padding: 3.5rem 1.75rem;
    }

    .welcome-icon-container {
        width: 95px;
        height: 95px;
    }

    .welcome-message h2 {
        font-size: 1.875rem;
    }

    .welcome-message p {
        font-size: 1.0625rem;
    }

    .loading-title {
        font-size: 1.75rem;
    }

    .brain-pulse {
        width: 120px;
        height: 120px;
    }

    .input-container {
        padding: 1rem 1.25rem 1.25rem;
    }
}

@media (max-width: 480px) {
    .message-content {
        max-width: 84%;
    }

    .message-bubble {
        padding: 0.875rem 1.125rem;
        font-size: 0.9375rem;
    }

    .send-button {
        width: 42px;
        height: 42px;
    }
}