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

/* ── Theme Variables ─────────────────────────────────────── */
:root {
    /* Light theme (default — matches reference image) */
    --bg-color:        #f0f4ff;
    --sidebar-bg:      #ffffff;
    --text-color:      #1e293b;
    --text-muted:      #64748b;
    --border-color:    #e2e8f0;
    --user-bubble-bg:  #e8edf8;
    --input-bg:        #ffffff;
    --input-border:    #dde3f0;
    --accent-color:    #2563eb;
    --accent-hover:    #1d4ed8;
    --accent-light:    rgba(37,99,235,0.10);
    --shadow-color:    rgba(37,99,235,0.08);
    --blob-color:      rgba(147,181,255,0.35);
    --dot-color:       rgba(37,99,235,0.12);
    --sidebar-w:       240px;
}

.dark-theme {
    --bg-color:        #212121;
    --sidebar-bg:      #171717;
    --text-color:      #ececec;
    --text-muted:      #8e8ea0;
    --border-color:    #2f2f2f;
    --user-bubble-bg:  #343541;
    --input-bg:        #2f2f2f;
    --input-border:    #3f3f3f;
    --accent-color:    #3b82f6;
    --accent-hover:    #2563eb;
    --accent-light:    rgba(59,130,246,0.15);
    --shadow-color:    rgba(0,0,0,0.3);
    --blob-color:      transparent;
    --dot-color:       transparent;
}

/* ── Base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
    position: relative;
}

a { color: var(--accent-color); text-decoration: none; }

/* ── Decorative background (light mode) ──────────────────── */
.bg-blob {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    transition: opacity 0.4s;
}
.bg-blob-tr {
    width: 420px; height: 420px;
    top: -120px; right: -100px;
    background: radial-gradient(circle, rgba(147,197,253,0.5) 0%, rgba(196,221,255,0.2) 60%, transparent 80%);
}
.bg-blob-bl {
    width: 380px; height: 380px;
    bottom: -100px; left: -80px;
    background: radial-gradient(circle, rgba(147,197,253,0.45) 0%, rgba(196,221,255,0.15) 60%, transparent 80%);
}
.bg-dots {
    position: fixed;
    bottom: 40px; left: 30px;
    width: 200px; height: 160px;
    pointer-events: none;
    z-index: 0;
    background-image: radial-gradient(circle, rgba(37,99,235,0.18) 1.5px, transparent 1.5px);
    background-size: 18px 18px;
    transition: opacity 0.4s;
}
.dark-theme .bg-blob,
.dark-theme .bg-dots { opacity: 0; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1rem;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
    /* Always fixed overlay — same on desktop and mobile */
    position: fixed;
    top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: none;
}
.sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(37,99,235,0.12);
}
/* collapsed = alias for closed state (for JS compatibility) */
.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.sidebar-header h3 { font-size: 1rem; font-weight: 600; }

#theme-toggle {
    background: transparent; border: none;
    color: var(--text-muted); cursor: pointer;
    padding: 4px; border-radius: 6px;
    transition: color 0.2s, background 0.2s;
    display: flex; align-items: center;
}
#theme-toggle:hover { color: var(--accent-color); background: var(--accent-light); }

.sidebar-btn {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 10px 12px;
    border-radius: 8px; border: 1px solid var(--border-color);
    background: transparent; color: var(--text-color);
    font-size: 0.88rem; font-weight: 500;
    cursor: pointer; transition: background 0.15s, border-color 0.15s;
    margin-bottom: 0.5rem;
}
.sidebar-btn:hover { background: var(--accent-light); border-color: var(--accent-color); }
.sidebar-btn.secondary { opacity: 0.6; }
.sidebar-btn.secondary:not(:disabled):hover { opacity: 1; }
.sidebar-btn:disabled { cursor: not-allowed; opacity: 0.4; }
.sidebar-btn i { width: 16px; height: 16px; }

.sidebar-stats { display: flex; gap: 8px; margin: 1.5rem 0; }
.stat-item {
    flex: 1; background: var(--border-color);
    padding: 10px; border-radius: 10px;
    display: flex; flex-direction: column;
}
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.stat-value  { font-size: 1.1rem; font-weight: 600; }

.sidebar-footer { margin-top: auto; padding-top: 1rem; }

/* ── Main chat area ──────────────────────────────────────── */
.chat-container {
    flex: 1; display: flex; flex-direction: column;
    position: relative; max-width: 100%; z-index: 1;
}

/* ── Menu button (top-left card) ─────────────────────────── */
.desktop-sidebar-toggle {
    position: absolute;
    top: 16px; left: 16px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    cursor: pointer; z-index: 200;
    width: 44px; height: 44px;
    border-radius: 12px;
    transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 12px rgba(37,99,235,0.10);
}
.desktop-sidebar-toggle:hover {
    background: var(--accent-light);
    border-color: var(--accent-color);
    transform: scale(1.05);
    color: var(--accent-color);
}

/* ── Welcome screen ──────────────────────────────────────── */
.welcome-screen {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    z-index: 10; pointer-events: none;
    transition: opacity 0.4s ease, visibility 0.4s;
}
.welcome-content {
    display: flex; flex-direction: column;
    align-items: center; transform: translateY(-70px);
}

/* Avatar ring */
.avatar-ring-wrapper {
    position: relative;
    width: 120px; height: 120px;
    margin-bottom: 18px;
}
.avatar-ring-wrapper::before {
    content: '';
    position: absolute; inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--accent-color);
    opacity: 0.6;
}
.welcome-avatar {
    width: 120px; height: 120px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    box-shadow: 0 4px 20px rgba(37,99,235,0.15);
}
.online-dot {
    position: absolute;
    bottom: 6px; right: 6px;
    width: 16px; height: 16px;
    background: var(--accent-color);
    border-radius: 50%;
    border: 2.5px solid var(--bg-color);
    animation: pulse-dot 2.4s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.4); }
    50%       { box-shadow: 0 0 0 5px rgba(37,99,235,0); }
}

/* Name */
.welcome-name {
    font-size: 1.4rem; font-weight: 700;
    color: var(--accent-color);
    font-family: 'Outfit', sans-serif;
    letter-spacing: -0.01em;
}

/* Divider */
.welcome-divider {
    width: 36px; height: 3px;
    background: var(--accent-color);
    border-radius: 2px;
    margin: 10px 0 14px;
    opacity: 0.7;
}

/* Tagline */
.welcome-tagline {
    font-size: 2rem; font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
}
.welcome-tagline .highlight {
    color: var(--accent-color);
    font-weight: 800;
}

/* ── Chat messages ───────────────────────────────────────── */
.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 4rem 2rem 10rem 2rem;
    display: flex; flex-direction: column;
    gap: 2rem;
    max-width: 800px; width: 100%; margin: 0 auto;
}

/* ── Input area ──────────────────────────────────────────── */
.input-container-wrapper {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 0 2rem 2.5rem 2rem;
    background: linear-gradient(to top, var(--bg-color) 70%, transparent);
    z-index: 20;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.input-container-wrapper.welcome-mode {
    top: 0; display: flex;
    align-items: center; justify-content: center;
    background: transparent;
    transform: translateY(20px);
}
.chat-input-container {
    max-width: 740px; width: 100%;
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 2rem;
    display: flex; margin: auto; margin-bottom: 40px;
    align-items: center;
    padding: 10px 10px 10px 18px;
    box-shadow: 0 4px 24px rgba(37,99,235,0.08);
    transition: border-color 0.2s, box-shadow 0.2s;
    gap: 10px;
}
.dark-theme .chat-input-container {
    box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
}
.chat-input-container:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* Input icon */
.input-icon {
    width: 20px; height: 20px;
    color: var(--accent-color);
    opacity: 0.7;
    flex-shrink: 0;
}

.chat-input-container textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1rem;
    resize: none;
    padding: 6px 0;
    max-height: 200px;
    line-height: 1.5;
    font-family: 'Inter', sans-serif;
}
.chat-input-container textarea:focus { outline: none; }
.chat-input-container textarea::placeholder { color: var(--text-muted); }

/* Send button — circular blue */
#send-btn {
    background: var(--accent-color);
    color: white; border: none;
    width: 38px; height: 38px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s, transform 0.15s;
}
#send-btn i { width: 18px; height: 18px; }
#send-btn:disabled { opacity: 0.25; cursor: default; background: var(--text-muted); }
#send-btn:not(:disabled):hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

/* ── Messages ────────────────────────────────────────────── */
.message {
    display: flex; gap: 1.2rem;
    max-width: 100%;
    animation: fadeIn 0.3s ease;
}
.message.user { flex-direction: row-reverse; }

.avatar {
    min-width: 40px; width: auto; height: 40px;
    border-radius: 999px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin-top: 4px;
    font-weight: 600; font-size: 0.8rem;
    padding: 0 10px; white-space: nowrap; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user      .avatar { background: var(--accent-color); color: white; }
.assistant .avatar { background: transparent; padding: 0; width: 40px; min-width: 40px; }

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

.bubble {
    padding: 10px 16px; border-radius: 18px;
    font-size: 1rem; line-height: 1.65;
    max-width: 85%; overflow-wrap: anywhere; word-break: break-word;
}
.bubble a { word-break: break-all; }
.user      .bubble {
    background: var(--user-bubble-bg);
    border-radius: 18px 18px 2px 18px;
    box-shadow: 0 2px 10px var(--shadow-color);
}
.assistant .bubble { background: transparent; }

.message-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 6px; }

/* ── Typing indicator ────────────────────────────────────── */
.typing-bubble { display: flex; gap: 4px; padding: 10px 0; }
.typing-dot {
    width: 6px; height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ── Animations ──────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* ── Markdown in bubbles ─────────────────────────────────── */
.bubble p { margin-bottom: 0.8rem; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code { background: var(--border-color); padding: 2px 5px; border-radius: 4px; font-family: monospace; font-size: 0.88em; }
.bubble pre  { background: #0d0d0d; color: #e6edf3; padding: 1rem; border-radius: 10px; overflow-x: auto; margin: 1rem 0; }
.bubble pre code { background: transparent; padding: 0; }
.bubble ul, .bubble ol { padding-left: 1.4rem; margin-bottom: 0.8rem; }
.bubble li { margin-bottom: 0.3rem; }
.bubble h1,.bubble h2,.bubble h3 { margin: 0.8rem 0 0.4rem; font-family: 'Outfit', sans-serif; }
.bubble strong { font-weight: 700; }
.bubble table { border-collapse: collapse; width: 100%; margin: 0.8rem 0; }
.bubble th, .bubble td { border: 1px solid var(--border-color); padding: 6px 10px; font-size: 0.9rem; }
.bubble th { background: var(--border-color); font-weight: 600; }
.bubble hr { border: none; border-top: 1px solid var(--border-color); margin: 1rem 0; }

/* ── Light mode code blocks ──────────────────────────────── */
.light-theme .bubble pre  { background: #1e293b; }
.light-theme .bubble code { background: #e8edf8; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Mobile header ───────────────────────────────────────── */
.mobile-header {
    display: none; align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky; top: 0; z-index: 50;
}
.mobile-title { font-weight: 700; font-size: 1rem; flex: 1; text-align: center; padding-right: 32px; }
.icon-btn { background: transparent; border: none; color: var(--text-color); cursor: pointer; padding: 4px; display: flex; align-items: center; }

.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90; opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.active { display: block; opacity: 1; }

/* ── Mobile responsive ───────────────────────────────────── */
@media (max-width: 768px) {
    body { flex-direction: column; }
    .desktop-sidebar-toggle { display: none; }
    .mobile-header { display: flex; }

    /* Sidebar same overlay behavior — already handled above */
    .sidebar.open { transform: translateX(0); box-shadow: 2px 0 10px rgba(0,0,0,0.2); }

    .chat-container { width: 100%; height: calc(100vh - 55px); height: calc(100dvh - 55px); }
    .welcome-content { transform: translateY(-40px); }
    .avatar-ring-wrapper { width: 90px; height: 90px; }
    .welcome-avatar { width: 90px; height: 90px; }
    .welcome-tagline { font-size: 1.6rem; text-align: center; padding: 0 20px; }
    .chat-messages { padding: 1.5rem 1rem 8rem 1rem; gap: 1.5rem; }
    .message { gap: 0.8rem; }
    .avatar { width: 32px; min-width: 32px; height: 32px; font-size: 0.7rem; }
    .assistant .avatar { width: 32px; min-width: 32px; }
    .bubble { padding: 8px 14px; font-size: 0.95rem; max-width: 90%; }
    .input-container-wrapper { padding: 0 1rem 1.5rem 1rem; }
    .chat-input-container { padding: 8px 8px 8px 14px; border-radius: 1.5rem; margin-bottom: 25px; }
    .chat-input-container textarea { font-size: 0.95rem; }
    #send-btn { width: 34px; height: 34px; }
}
