@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap');

:root {
    --bg-color: #fcfcfd;
    --surface-color: #ffffff;
    --text-main: #0f172a;
    --text-muted: #94a3b8;
    
    /* Ultra-minimalist dark primary color (like Apple/Vercel) */
    --primary-color: #0f172a; 
    --primary-hover: #334155;
    
    --border-color: #e2e8f0;
    --border-focus: #cbd5e1;
    
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.02);
    --shadow-sm: 0 2px 8px -1px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 12px 32px -4px rgba(0, 0, 0, 0.06), 0 4px 12px -4px rgba(0, 0, 0, 0.03);
    
    --radius-full: 9999px;
    --radius-lg: 24px;
    --radius-md: 16px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    width: 100%;
    height: 100%;
}

.screen {
    display: none;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.screen.active {
    display: flex;
    opacity: 1;
}

/* Authentication Screen */
.glass-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 3rem 2.5rem;
    width: 380px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    box-shadow: var(--shadow-md);
}

.glass-card h2 {
    text-align: center;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 1.5rem;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

/* Modern Minimalist Inputs */
input {
    background: #f8fafc;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

input:focus {
    background: var(--surface-color);
    border-color: var(--border-focus);
    box-shadow: 0 0 0 4px rgba(15, 23, 42, 0.05);
}

/* Modern Pill Button */
button {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    padding: 1rem;
    font-size: 0.95rem;
    cursor: pointer;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    align-items: center;
}

button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
}

button:active {
    transform: translateY(1px);
    box-shadow: none;
}

.error {
    color: #ef4444;
    font-size: 0.875rem;
    text-align: center;
    background: #fef2f2;
    padding: 0.75rem;
    border-radius: 12px;
    margin-top: -0.5rem;
}

.hidden {
    display: none !important;
}

/* Chat UI */
#chat-screen {
    flex-direction: column;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    background: var(--surface-color);
    height: 100vh; /* Fallback */
    height: 100dvh;
}

@media (min-width: 940px) {
    #chat-screen {
        height: 90vh;
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-md);
        border: 1px solid var(--border-color);
    }
}

header {
    width: 100%;
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

header h2 {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

header button {
    background: transparent;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    box-shadow: none;
    border-radius: var(--radius-full);
}

header button:hover {
    background: #f1f5f9;
    color: var(--text-main);
    box-shadow: none;
    transform: none;
}

#chat-container {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 2rem 2rem 2rem;
    gap: 1.5rem;
    overflow: hidden;
    background: var(--surface-color);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-right: 0.5rem;
}

/* Custom Scrollbar */
.messages::-webkit-scrollbar {
    width: 4px;
}
.messages::-webkit-scrollbar-track {
    background: transparent;
}
.messages::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}
.messages::-webkit-scrollbar-thumb:hover {
    background: #cbd5e1;
}

.message {
    max-width: 75%;
    padding: 1rem 1.25rem;
    border-radius: 20px;
    animation: fadeUp 0.3s ease forwards;
    line-height: 1.6;
    font-size: 0.95rem;
    opacity: 0;
    transform: translateY(8px);
}

.message.user {
    align-self: flex-end;
    background: var(--bg-color);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom-right-radius: 4px;
}

.message.bot {
    align-self: flex-start;
    background: var(--surface-color);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

/* Markdown Styles inside Bot Message */
.message.bot p {
    margin-bottom: 0.75rem;
}
.message.bot p:last-child {
    margin-bottom: 0;
}
.message.bot strong {
    font-weight: 600;
}
.message.bot ul, .message.bot ol {
    margin: 0.5rem 0 0.5rem 1.5rem;
}
.message.bot li {
    margin-bottom: 0.25rem;
}
.message.bot h1, .message.bot h2, .message.bot h3 {
    margin: 1rem 0 0.5rem 0;
    font-weight: 600;
}
.message.bot h3 {
    font-size: 1.05rem;
}
.message.bot code {
    background: #f1f5f9;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85em;
}
.message.bot pre {
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75rem 0;
}
.message.bot pre code {
    background: transparent;
    padding: 0;
    font-size: 0.9em;
}

.message.system-error {
    align-self: center;
    background: #fef2f2;
    color: #ef4444;
    border: 1px solid #fecaca;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85rem;
    max-width: 90%;
    white-space: pre-wrap;
    word-break: break-all;
}

/* AI Chat Style Input Area */
.input-area {
    display: flex;
    gap: 0.5rem;
    background: var(--surface-color);
    padding: 0.5rem 0.5rem 0.5rem 1.5rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    align-items: center;
}

.input-area:focus-within {
    border-color: var(--text-muted);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

.input-area input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.5rem 0;
    font-size: 1rem;
    color: var(--text-main);
    box-shadow: none;
}

.input-area input:focus {
    box-shadow: none;
    background: transparent;
}

.input-area button {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-full);
    box-shadow: none;
    font-weight: 600;
}

@keyframes fadeUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User Processing Animation */
.message.user.processing {
    animation: fadeUp 0.3s ease forwards, pulseBorder 1.5s infinite;
}

@keyframes pulseBorder {
    0% { box-shadow: 0 0 0 0 rgba(15, 23, 42, 0.1); }
    70% { box-shadow: 0 0 0 6px rgba(15, 23, 42, 0); }
    100% { box-shadow: 0 0 0 0 rgba(15, 23, 42, 0); }
}

/* Bot Thinking Animation */
.message.bot.thinking {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 1.25rem;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}
.intermediate-thought {
  color: #888;
  font-size: 0.9em;
  font-style: italic;
  margin-bottom: 8px;
  padding-left: 10px;
  border-left: 2px solid #ccc;
}

/* Message Metadata */
.msg-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-color);
    text-align: right;
    font-style: italic;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .glass-card {
        width: 90%;
        padding: 2rem 1.5rem;
    }

    header {
        padding: 1rem 1.25rem;
    }

    #chat-container {
        padding: 1rem 1rem 1.5rem 1rem;
        gap: 1rem;
    }

    .messages {
        gap: 1rem;
    }

    .message {
        max-width: 90%;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .message.bot h1, .message.bot h2, .message.bot h3 {
        margin: 0.75rem 0 0.5rem 0;
    }

    .message.bot h3 {
        font-size: 1rem;
    }

    .message.bot pre {
        padding: 0.75rem;
        font-size: 0.85em;
    }

    .input-area {
        padding: 0.25rem 0.25rem 0.25rem 1rem;
    }

    .input-area input {
        font-size: 0.95rem;
    }

    .input-area button {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }
}
