:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #EEF2FF;
    --secondary: #10B981;
    --bg-color: #F3F4F6;
    --chat-bg: #FFFFFF;
    --text-main: #1F2937;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --ai-bubble: #F8FAFC;
    --ai-border: #E2E8F0;
    --user-bubble: #4F46E5;
    --user-text: #FFFFFF;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
}

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

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

/* Modal API Key */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 90%;
    text-align: center;
    animation: popIn 0.3s ease-out;
}

.modal-content h2 {
    color: var(--primary);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.modal-content input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 15px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary);
}

.primary-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

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

.primary-btn:active {
    transform: scale(0.98);
}

.small-text {
    margin-top: 15px;
    font-size: 0.8rem;
    color: #9CA3AF;
}

/* App Layout */
.app-container {
    background: var(--chat-bg);
    width: 100%;
    max-width: 900px;
    height: calc(100vh - 40px);
    max-height: 800px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.chat-header {
    padding: 15px 25px;
    background: white;
    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: 15px;
}

.avatar {
    width: 45px;
    height: 45px;
    border-radius: var(--radius-full);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
}

.ai-avatar-header {
    background: var(--primary-light);
    color: var(--primary);
}

.header-info h1 {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 2px;
}

.status {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
}

.dot {
    width: 8px;
    height: 8px;
    background: var(--secondary);
    border-radius: 50%;
    display: inline-block;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-color);
    color: var(--text-main);
}

/* Chat Main Area */
.chat-main {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #FAFAFA;
}

/* Scrollbar styling */
.chat-main::-webkit-scrollbar {
    width: 6px;
}
.chat-main::-webkit-scrollbar-track {
    background: transparent;
}
.chat-main::-webkit-scrollbar-thumb {
    background-color: #D1D5DB;
    border-radius: 10px;
}

/* Welcome Screen */
.welcome-screen {
    text-align: center;
    margin: auto;
    max-width: 600px;
    padding: 20px;
    animation: fadeIn 0.5s ease;
}

.welcome-icon {
    font-size: 3.5rem;
    color: var(--primary);
    margin-bottom: 20px;
}

.welcome-screen h2 {
    font-size: 1.8rem;
    color: var(--text-main);
    margin-bottom: 10px;
}

.welcome-screen p {
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 30px;
}

.quick-questions p {
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 15px;
}

.pill-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.quick-btn {
    background: white;
    border: 1px solid var(--border-color);
    padding: 10px 18px;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}

.quick-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Messages */
.message {
    display: flex;
    gap: 15px;
    max-width: 85%;
    animation: slideUp 0.3s ease;
}

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

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

.msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    font-size: 1rem;
}

.msg-avatar.user-av {
    background: #E0E7FF;
    color: var(--primary);
}

.msg-avatar.ai-av {
    background: var(--primary);
    color: white;
}

.msg-bubble {
    padding: 15px 20px;
    border-radius: 18px;
    font-size: 1rem;
    line-height: 1.6;
}

.message.user .msg-bubble {
    background: var(--user-bubble);
    color: var(--user-text);
    border-top-right-radius: 4px;
}

.message.ai .msg-bubble {
    background: var(--ai-bubble);
    color: var(--text-main);
    border: 1px solid var(--ai-border);
    border-top-left-radius: 4px;
}

.msg-bubble p {
    margin-bottom: 0.75em;
}
.msg-bubble p:last-child {
    margin-bottom: 0;
}

/* Markdown styling inside AI bubble */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 700;
}
.msg-bubble ul, .msg-bubble ol {
    margin-left: 1.5em;
    margin-bottom: 1em;
}
.msg-bubble code {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.msg-bubble pre {
    background: #1e1e1e;
    color: #fff;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin-top: 10px;
    margin-bottom: 10px;
}
.msg-bubble pre code {
    background: none;
    color: inherit;
    padding: 0;
}

/* Typing Indicator */
.typing-indicator {
    padding: 10px 25px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    background: #FAFAFA;
}

.typing-indicator.hidden {
    display: none;
}

.dots span {
    animation: blink 1.4s infinite both;
    font-size: 1.2rem;
    line-height: 0;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

/* Footer & Input */
.chat-footer {
    padding: 15px 25px 25px 25px;
    background: white;
    border-top: 1px solid var(--border-color);
}

.input-container {
    display: flex;
    gap: 15px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 10px 15px;
    align-items: flex-end;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.input-container:focus-within {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    resize: none;
    padding: 8px 5px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-main);
    max-height: 120px;
    outline: none;
    line-height: 1.5;
}

textarea::placeholder {
    color: #9CA3AF;
}

.send-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-bottom: 2px;
    transition: all 0.2s;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: #D1D5DB;
    cursor: not-allowed;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes popIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes blink {
    0% { opacity: 0.2; }
    20% { opacity: 1; }
    100% { opacity: 0.2; }
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    body {
        padding: 0;
    }
    .message {
        max-width: 95%;
    }
    .chat-header h1 {
        font-size: 1.1rem;
    }
}
