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

:root {
    --bg-dark: #09090b; /* Zinc 950 */
    --bg-surface: #18181b; /* Zinc 900 */
    --bg-surface-hover: #27272a; /* Zinc 800 */
    
    --primary: #4f46e5; /* Indigo 600 */
    --primary-hover: #4338ca; /* Indigo 700 */
    --danger: #ef4444;
    
    --text-primary: #f4f4f5; /* Zinc 50 */
    --text-secondary: #a1a1aa; /* Zinc 400 */
    
    --border-color: #27272a; /* Zinc 800 */
    --radius: 12px;
    --font-main: 'Inter', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    display: flex;
    /* Mobile fix for address bar / keyboard */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-surface-hover); border-radius: 4px; }

/* Utility classes */
.hidden { display: none !important; }
.w-100 { width: 100%; justify-content: center; }

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-outline:hover { background: var(--bg-surface-hover); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

.btn-text {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    transition: color 0.2s;
}
.btn-text:hover { color: var(--text-primary); }

/* Glassmorphism */
.glass-effect {
    background: rgba(24, 24, 27, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Layout */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
}

.chat-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
}
.chat-item {
    padding: 12px 15px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 5px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
    font-size: 14px;
}
.chat-item i { font-size: 14px; opacity: 0.7; }
.chat-item:hover { background-color: var(--bg-surface-hover); color: var(--text-primary); }
.chat-item.active { background-color: rgba(79, 70, 229, 0.15); color: var(--primary); font-weight: 500; }
.chat-item.active i { color: var(--primary); opacity: 1; }

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}
.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background: var(--bg-dark);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.user-info span { font-weight: 500; display: flex; align-items: center; gap: 8px; }

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.top-bar {
    height: 60px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 10;
}
.mobile-menu-btn { display: none; background: none; border: none; color: var(--text-primary); font-size: 20px; cursor: pointer; }
.top-bar h3 { font-size: 15px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Chat Area */
.chat-window {
    flex-grow: 1;
    overflow-y: auto;
    padding: 80px 20px 20px 20px; /* offset for top-bar */
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}
.messages-container {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-bottom: 20px;
}

.welcome-screen { text-align: center; margin-top: 15vh; color: var(--text-secondary); }
.welcome-screen i { font-size: 48px; color: var(--primary); margin-bottom: 20px; }
.welcome-screen h1 { color: var(--text-primary); margin-bottom: 10px; font-weight: 600; }

/* Messages */
.message {
    display: flex;
    gap: 16px;
    animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}
.message .avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}
.message.user .avatar { background: var(--bg-surface-hover); color: var(--text-primary); }
.message.model .avatar { background: var(--primary); color: white; box-shadow: 0 4px 10px rgba(79,70,229,0.3); }

.message-content {
    background: rgba(39, 39, 42, 0.4);
    border: 1px solid rgba(255,255,255,0.05);
    padding: 14px 18px;
    border-radius: 12px;
    max-width: 100%;
    overflow-x: auto;
    line-height: 1.6;
    color: var(--text-primary);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.message.user .message-content {
    background: var(--bg-surface-hover);
    border: 1px solid transparent;
}

/* Markdown Styles inside message content */
.message-content p { margin-bottom: 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content pre { border-radius: 8px; margin: 15px 0; border: 1px solid rgba(255,255,255,0.1); }
.message-content code { font-family: 'Consolas', 'Monaco', monospace; font-size: 14px; }
.message-content :not(pre) > code { background: rgba(0,0,0,0.3); padding: 3px 6px; border-radius: 4px; color: #a5b4fc; }

/* Typing Indicator */
.typing-indicator {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px;
    color: var(--text-secondary);
    font-size: 14px;
}
.dot { width: 6px; height: 6px; background-color: var(--primary); 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); }
}

/* Input Area */
.input-area {
    padding: 15px 20px 25px 20px;
    border-top: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
}
#chat-form {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    display: flex;
    align-items: flex-end;
    padding: 6px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3);
    transition: border-color 0.2s;
}
#chat-form:focus-within { border-color: var(--primary); }
#message-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 12px;
    resize: none;
    max-height: 200px;
    outline: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
}
#message-input:disabled { opacity: 0.5; }
#send-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    margin: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
#send-btn:hover:not(:disabled) { background: var(--primary-hover); transform: scale(1.05); }
#send-btn:disabled { background: var(--bg-surface-hover); color: var(--text-secondary); cursor: not-allowed; transform: none; }

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s;
}
.modal.hidden {
    opacity: 0;
    pointer-events: none;
}
.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal.hidden .modal-content { transform: translateY(20px); }
.close-btn {
    position: absolute;
    top: 15px; right: 20px;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
}
.close-btn:hover { color: var(--text-primary); }

#auth-title { margin-bottom: 5px; font-weight: 600; }
.auth-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; }

.input-group {
    position: relative;
    margin-bottom: 15px;
}
.input-group i {
    position: absolute;
    left: 14px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}
.input-group input {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 12px 12px 40px;
    border-radius: 8px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}
.input-group input:focus { border-color: var(--primary); }

.auth-error {
    color: var(--danger);
    background: rgba(239,68,68,0.1);
    padding: 10px;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 15px;
    text-align: center;
}
.auth-switch { text-align: center; margin-top: 15px; font-size: 14px; color: var(--text-secondary); }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-switch a:hover { text-decoration: underline; }

/* Responsive */
.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100dvh;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: none;
    backdrop-filter: blur(4px);
}
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu-btn { display: block; }
    .sidebar-overlay.active { display: block; }
    .input-area { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
