/* --- FONTS & VARIABLES --- */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400&display=swap');

/* ======================================================
   PAGE TRANSITIONS (View Transition API)
====================================================== */
@media (prefers-reduced-motion: no-preference) {
    @view-transition {
        navigation: auto;
    }

    @keyframes slide-out {
        to { transform: translateX(-60px); opacity: 0; }
    }
    @keyframes slide-in {
        from { transform: translateX(60px); opacity: 0; }
    }

    /* Freeze the sidebar — it's identical across pages */
    .sidebar-wrapper {
        view-transition-name: sidebar;
    }

    /* Only the main content panel slides */
    .page-slide-in {
        view-transition-name: page-content;
    }

    ::view-transition-group(page-content) {
        animation-duration: 0.35s;
        animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
    }
    ::view-transition-old(page-content) {
        animation-name: slide-out;
    }
    ::view-transition-new(page-content) {
        animation-name: slide-in;
    }

    /* Sidebar snapshot: no animation, just hold position */
    ::view-transition-old(sidebar),
    ::view-transition-new(sidebar) {
        animation: none;
    }
}

/* ======================================================
   ROOT TOKENS
====================================================== */
:root {
    --bg-color: #ffffff;
    --bg-secondary: #f9fafb;
    --sidebar-bg: #fafafa;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: rgba(0,0,0,0.08);
    --hover: rgba(0,0,0,0.04);
    --primary: #000000;
    --blue-glow: linear-gradient(160deg, rgba(219,234,254,0.55) 0%, rgba(248,249,250,0) 60%);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --radius-pill: 9999px;
    --radius-card: 16px;
}

.dark {
    --bg-color: #111113;
    --bg-secondary: #1a1a1d;
    --sidebar-bg: #161618;
    --text-main: #f0f0f1;
    --text-muted: #8a8a8f;
    --border: rgba(255,255,255,0.08);
    --hover: rgba(255,255,255,0.05);
    --primary: #ffffff;
    --blue-glow: linear-gradient(160deg, rgba(37,99,235,0.12) 0%, rgba(17,17,19,0) 60%);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);
}

/* ======================================================
   BASE
====================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Manrope', sans-serif; }
body { background-color: var(--bg-color); color: var(--text-main); display: flex; height: 100vh; overflow: hidden; transition: background-color 0.3s ease, color 0.3s ease; }

::-webkit-scrollbar { width: 5px; background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }
.dark ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }

/* Prose / markdown */
.prose pre { background: #f1f5f9; padding: 1rem; border-radius: 0.5rem; border: 1px solid #e2e8f0; }
.dark .prose pre { background: #1e1e24; border: 1px solid rgba(255,255,255,0.08); }
.prose code { color: #2563eb; font-family: 'JetBrains Mono'; font-size: 0.9em; }
.dark .prose code { color: #93c5fd; }
.dark .prose { color: #d1d5db; }
.dark .prose h1, .dark .prose h2, .dark .prose h3, .dark .prose h4 { color: #f3f4f6; }
.dark .prose strong { color: #f3f4f6; }
.dark .prose a { color: #60a5fa; }
.dark .prose blockquote { border-left-color: rgba(255,255,255,0.15); color: #9ca3af; }
.dark .prose hr { border-color: rgba(255,255,255,0.08); }
.dark .prose ul > li::marker { color: #6b7280; }

/* ======================================================
   ANIMATIONS
====================================================== */
@keyframes initialPageLoad { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.page-load-anim { animation: initialPageLoad 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

@keyframes floatUp { from { opacity: 0; transform: translateY(20px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes floatDown { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(20px); } }
.anim-float { animation: floatUp 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.anim-float-up { animation: floatUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) both; }
.module-enter { animation: floatUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.anim-fade { animation: fadeIn 0.6s ease forwards; }
.anim-fade-in { animation: fadeIn 0.5s ease forwards; }

@keyframes msgSlideIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.msg-enter { animation: msgSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both; }

@keyframes libItemIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.lib-item-enter { animation: libItemIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both; }

/* Main content slides in over the previous page on navigation.
   The sidebar is a sibling (z-index 50) and never animates — it stays constant. */
@keyframes slideInPage {
    from { opacity: 0.3; transform: translateX(36px); box-shadow: -16px 0 40px rgba(0,0,0,0.15); }
    to { opacity: 1; transform: translateX(0); box-shadow: 0 0 0 rgba(0,0,0,0); }
}
.page-slide-in {
    animation: slideInPage 0.99s cubic-bezier(0.16, 1, 0.3, 1) both;
    background-color: var(--bg-color);
    position: relative;
    z-index: 10;
}

@keyframes pulse-soft { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* Loading dots */
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
.loading-row { display: flex; align-items: flex-start; gap: 16px; max-width: 768px; width: 100%; margin: 0 auto; }
.loading-bubble { display: flex; gap: 5px; padding: 14px 18px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 20px; }
.loading-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: bounce 1.4s infinite ease-in-out both; }
.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }
/* Spacing below the last message is driven dynamically from the input bar's
   real height (see frontend.js); this stays 0 so the two don't stack up. */
.scroll-bumper { height: 0; }

/* ======================================================
   SIDEBAR
====================================================== */
.sidebar-wrapper {
    height: 100%;
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.25s cubic-bezier(0.16,1,0.3,1);
    z-index: 50;
    border-right: 1px solid var(--border);
}
.sidebar-expanded { width: 256px; }
.sidebar-collapsed { width: 58px; }

.sidebar-header {
    height: 52px;
    display: flex;
    align-items: center;
    padding: 0 14px;
    flex-shrink: 0;
    gap: 8px;
}
.sidebar-logo-group {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    color: var(--text-main);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.025em;
    flex: 1;
}
.sidebar-toggle-btn {
    padding: 6px;
    color: var(--text-muted);
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-toggle-btn:hover { background: var(--hover); color: var(--text-main); }

.sidebar-top-nav { padding: 6px 10px 4px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    width: 100%;
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border: 1px solid transparent;
    background: transparent;
    text-align: left;
    font-weight: 500;
}
.sidebar-item:hover { background: var(--hover); color: var(--text-main); }
.sidebar-item.active { background: var(--hover); color: var(--text-main); font-weight: 600; }
.sidebar-item-icon { width: 15px; height: 15px; opacity: 0.75; flex-shrink: 0; }

.sidebar-new-chat {
    background: var(--hover);
    color: var(--text-main);
    border-color: var(--border);
    margin-bottom: 6px;
    font-weight: 600;
}
.sidebar-new-chat:hover { background: rgba(0,0,0,0.07); }
.dark .sidebar-new-chat:hover { background: rgba(255,255,255,0.08); }

.sidebar-recents-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.sidebar-recents-area::-webkit-scrollbar { display: none; }
.sidebar-recents-header {
    padding: 8px 8px 5px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.recent-chat-item {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 7px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    font-weight: 500;
}
.recent-chat-item:hover { background: var(--hover); color: var(--text-main); }
.recent-chat-item.active { background: var(--hover); color: var(--text-main); font-weight: 600; }
.recent-chat-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer { padding: 10px; flex-shrink: 0; border-top: 1px solid var(--border); }
.profile-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 8px;
    border-radius: 8px;
    transition: background 0.15s;
    text-align: left;
    background: transparent;
    border: none;
    cursor: pointer;
}
.profile-btn:hover { background: var(--hover); }
.sidebar-collapsed .profile-btn { justify-content: center; padding: 7px; }
.profile-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    color: #ffffff;
    flex-shrink: 0;
    letter-spacing: 0.03em;
}

/* ======================================================
   CHAT WRAPPER & THEMES
====================================================== */
.chat-wrapper {
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: background-color 0.4s ease;
    overflow: hidden;
}
.theme-standard { background-color: var(--bg-color); }
.theme-incognito { background-color: #ebebed; }
.dark .theme-incognito { background-color: #18181b; }
.theme-premium { background: var(--blue-glow), var(--bg-color); }

/* ======================================================
   INCOGNITO BUTTON
====================================================== */
.incognito-btn-wrapper { position: absolute; top: 20px; right: 20px; z-index: 20; }
.btn-incognito {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: var(--radius-pill);
    transition: all 0.25s cubic-bezier(0.2,0,0,1);
    cursor: pointer;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.7);
    backdrop-filter: blur(10px);
    color: var(--text-muted);
}
.dark .btn-incognito { background: rgba(255,255,255,0.05); color: var(--text-muted); }
.btn-incognito:hover { color: var(--text-main); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-incognito.active { background: #1f2937; color: #ffffff; border-color: #374151; }
.dark .btn-incognito.active { background: #e5e7eb; color: #111827; border-color: #e5e7eb; }
.btn-incognito svg { width: 15px; height: 15px; }

/* ======================================================
   EMPTY STATE
====================================================== */
.chat-empty-state {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    z-index: 10;
    /* Pointer-events on children only */
}
.greeting-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 32px;
    min-height: 32vh;
    flex-shrink: 0;
}
.greeting-text {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 400;
    letter-spacing: -0.025em;
    text-align: center;
    padding: 0 16px;
    color: var(--text-main);
    line-height: 1.2;
}

/* Starters — pushed below the centered input */
.starter-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 220px 16px 80px;
    flex-shrink: 0;
}
.starter-container { width: 100%; max-width: 700px; display: flex; flex-direction: column; align-items: center; }
.starter-btn-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; width: 100%; }
.btn-starter {
    padding: 9px 18px;
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.2,0,0,1);
    box-shadow: var(--shadow-sm);
}
.btn-starter:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); color: var(--text-main); border-color: rgba(0,0,0,0.15); }
.dark .btn-starter:hover { border-color: rgba(255,255,255,0.15); }
.btn-starter svg { width: 15px; height: 15px; }

.starter-card {
    width: 100%;
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    margin-top: 12px;
    position: relative;
}
.starter-card-close {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 6px;
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s;
    border: none;
    background: transparent;
}
.starter-card-close:hover { background: var(--hover); color: var(--text-main); }
.starter-card-header {
    padding: 14px 18px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}
.starter-card-btn {
    width: 100%;
    text-align: left;
    padding: 13px 18px;
    font-size: 14px;
    color: var(--text-main);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    font-weight: 500;
}
.starter-card-btn:hover { background: var(--hover); }
.starter-card-btn:last-child { border-bottom: none; }

/* Incognito warning */
.incognito-warning {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    opacity: 0.4;
    margin-top: 24px;
    color: var(--text-muted);
}
.incognito-warning svg { width: 56px; height: 56px; margin-bottom: 12px; }

/* ======================================================
   CHAT MESSAGES
====================================================== */
.chat-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
    z-index: 20;
    padding-bottom: 220px;
}
@media (min-width: 768px) { .chat-scroll-area { padding: 32px; padding-bottom: 220px; } }

.chat-message-row { display: flex; width: 100%; max-width: 768px; margin: 0 auto; }
.chat-message-row.user { justify-content: flex-end; }
.chat-message-row.ai { justify-content: flex-start; }

.ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 14px;
    margin-top: 4px;
    background: var(--bg-color);
    box-shadow: var(--shadow-sm);
}
.ai-avatar img { width: 20px; height: 20px; object-fit: contain; }

.message-content-wrapper { position: relative; max-width: 88%; text-align: left; display: flex; align-items: flex-start; gap: 8px; }
.chat-message-row.user .message-content-wrapper { flex-direction: row-reverse; }

.message-bubble { font-size: 15px; line-height: 1.65; display: inline-block; text-align: left; overflow: hidden; }
.message-bubble.user {
    background: var(--bg-secondary);
    color: var(--text-main);
    padding: 11px 18px;
    border-radius: 22px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.dark .message-bubble.user { background: #26262b; border-color: rgba(255,255,255,0.07); }
.theme-incognito .message-bubble.user { background: #d9d9dc; color: #111827; }
.dark .theme-incognito .message-bubble.user { background: #2a2a2e; }
.message-bubble.ai { color: var(--text-main); width: 100%; }

/* Markdown rendered inside an AI message. The Tailwind CDN ships its preflight
   reset but NOT the typography plugin, so the `prose` class on these bubbles is
   inert — headings, lists and paragraphs would otherwise render unstyled. These
   rules restore proper formatting for marked.js output. */
.message-bubble.ai > :first-child { margin-top: 0; }
.message-bubble.ai > :last-child { margin-bottom: 0; }
.message-bubble.ai p { margin: 0.7em 0; }
.message-bubble.ai h1,
.message-bubble.ai h2,
.message-bubble.ai h3,
.message-bubble.ai h4 { font-weight: 800; line-height: 1.25; margin: 1.2em 0 0.5em; }
.message-bubble.ai h1 { font-size: 1.55em; }
.message-bubble.ai h2 { font-size: 1.3em; }
.message-bubble.ai h3 { font-size: 1.13em; }
.message-bubble.ai h4 { font-size: 1em; }
.message-bubble.ai ul,
.message-bubble.ai ol { margin: 0.6em 0; padding-left: 1.5em; }
.message-bubble.ai ul { list-style: disc; }
.message-bubble.ai ol { list-style: decimal; }
.message-bubble.ai li { margin: 0.3em 0; }
.message-bubble.ai li > ul,
.message-bubble.ai li > ol { margin: 0.3em 0; }
.message-bubble.ai a { color: #2563eb; text-decoration: underline; }
.dark .message-bubble.ai a { color: #60a5fa; }
.message-bubble.ai strong { font-weight: 700; color: var(--text-main); }
.message-bubble.ai em { font-style: italic; }
.message-bubble.ai blockquote {
    border-left: 3px solid var(--border); padding-left: 14px;
    color: var(--text-muted); margin: 0.8em 0;
}
.message-bubble.ai hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.message-bubble.ai :not(pre) > code {
    background: var(--bg-secondary); padding: 2px 6px; border-radius: 6px;
    font-family: 'JetBrains Mono', monospace; font-size: 0.88em; color: #2563eb;
}
.dark .message-bubble.ai :not(pre) > code { color: #93c5fd; }
.message-bubble.ai table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 14px; }
.message-bubble.ai th,
.message-bubble.ai td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.message-bubble.ai th { background: var(--bg-secondary); font-weight: 700; }

/* Edit message */
.btn-edit-msg {
    opacity: 0;
    transition: opacity 0.15s;
    padding: 4px;
    border-radius: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-top: 8px;
}
.message-content-wrapper:hover .btn-edit-msg { opacity: 1; }
.btn-edit-msg:hover { background: var(--hover); color: var(--text-main); }
.edit-container { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.edit-textarea {
    width: 100%;
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-main);
    resize: none;
    outline: none;
    min-height: 80px;
    font-family: inherit;
}
.edit-textarea:focus { border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59,130,246,0.15); }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ======================================================
   FLOATING INPUT BAR
====================================================== */
.input-floating-wrapper {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    max-width: 736px;
    z-index: 50;
    transition: all 0.65s cubic-bezier(0.16, 1, 0.3, 1);
}
.input-floating-wrapper.centered { bottom: 52vh; transform: translate(-50%, 50%); }
.input-floating-wrapper.bottom { bottom: 20px; transform: translate(-50%, 0); }

.file-pill-container { display: flex; justify-content: center; margin-bottom: 8px; }
.file-pill {
    background: var(--bg-color);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 7px 14px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-md);
}
.file-pill-text { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-pill-close { cursor: pointer; color: inherit; background: none; border: none; display: flex; align-items: center; }
.file-pill-close:hover { color: #ef4444; }

.input-bar-inner {
    border: 1px solid var(--border);
    border-radius: 28px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    padding: 12px 14px 8px;
    position: relative;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--bg-color);
}
.input-bar-inner:focus-within {
    border-color: rgba(59,130,246,0.5);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1), var(--shadow-md);
}
.theme-incognito .input-bar-inner { background: #f3f4f6; }
.dark .theme-incognito .input-bar-inner { background: #1e1e22; border-color: rgba(255,255,255,0.1); }

.input-controls-row { display: flex; align-items: center; gap: 2px; }
.btn-model-select {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: var(--radius-pill);
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.btn-model-select:hover { background: var(--hover); color: var(--text-main); }
.btn-model-select svg { width: 13px; height: 13px; opacity: 0.65; }

.dropdown-panel {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 0;
    width: 210px;
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-lg);
    padding: 6px 0;
    z-index: 200;
}
.dark .dropdown-panel { background: #1e1e22; }
.dropdown-action {
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.15s;
}
.dropdown-action:hover { background: var(--hover); }
.dropdown-action-title { font-size: 13.5px; font-weight: 700; color: var(--text-main); }
.dropdown-action-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.input-divider { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }

.btn-tools {
    padding: 7px;
    border-radius: 50%;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-tools svg { width: 16px; height: 16px; }
.btn-tools:hover { background: var(--hover); color: var(--text-main); }

.chat-textarea {
    background: transparent;
    color: var(--text-main);
    padding: 0 2px 6px;
    max-height: 150px;
    outline: none;
    resize: none;
    font-size: 15px;
    border: none;
    font-family: inherit;
    overflow-y: auto;
    line-height: 1.5;
    width: 100%;
    min-height: 28px;
}
.chat-textarea::placeholder { color: var(--text-muted); }

/* Send button */
.btn-send {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.2,0,0,1);
    flex-shrink: 0;
}
.btn-send:disabled { background: var(--hover) !important; color: var(--text-muted) !important; cursor: not-allowed; box-shadow: none !important; transform: none !important; }
.btn-send:not(:disabled) { background: var(--text-main); color: var(--bg-color); box-shadow: var(--shadow-sm); }
.btn-send:not(:disabled):hover { transform: scale(1.08); box-shadow: var(--shadow-md); }
.theme-incognito .btn-send:not(:disabled) { background: #374151; color: #ffffff; }

.input-disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    opacity: 0.75;
}
.incognito-disclaimer { color: #6b7280; font-style: italic; }

/* ======================================================
   PAGE LAYOUTS (Settings, Library, Chats)
====================================================== */
.page-container { max-width: 960px; margin: 0 auto; padding: 56px 36px; width: 100%; }
.page-header { margin-bottom: 36px; }
.page-title { font-size: 2rem; font-weight: 800; letter-spacing: -0.025em; margin-bottom: 8px; color: var(--text-main); }
.page-subtitle { color: var(--text-muted); font-size: 1rem; }

.card {
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}
.dark .card { background: var(--bg-secondary); }
.card:hover { box-shadow: var(--shadow-md); }
.card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 14px; color: var(--text-main); }

.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.lib-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s, background 0.2s;
    background: var(--bg-color);
    position: relative;
}
.dark .lib-item { background: var(--bg-secondary); }
.lib-item:hover { border-color: rgba(59,130,246,0.3); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.lib-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(59,130,246,0.08);
    color: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

@view-transition {
  navigation: auto;
}

@keyframes slide-in {
from { transform: translateX(100vw); }
}

::view-transition-group(root) {
animation-duration: 1s;
}

@keyframes slide-out {
to {
translate: -100vw;
}
}
@keyframes slide-in {
from {
translate: 100vw;
}
}

/* ======================================================
   ARTIFACTS — inline chips + side panel
====================================================== */
[x-cloak] { display: none !important; }

/* Inline chip shown inside an AI message */
.adam-artifact-chip {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 440px;
    margin: 14px 0;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    cursor: pointer;
    text-align: left;
    transition: border-color .15s ease, transform .12s ease, box-shadow .2s ease;
}
.adam-artifact-chip:hover {
    border-color: rgba(99,102,241,0.55);
    transform: translateY(-1px);
    box-shadow: 0 8px 24px rgba(99,102,241,0.14);
}
.adam-artifact-chip-icon {
    flex: 0 0 38px;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    color: #fff;
}
.adam-artifact-chip-icon.code { background: linear-gradient(135deg,#6366f1,#4f46e5); }
.adam-artifact-chip-icon.chart { background: linear-gradient(135deg,#0ea5e9,#2563eb); }
.adam-artifact-chip-icon.document { background: linear-gradient(135deg,#a855f7,#ec4899); }
.adam-artifact-chip-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.adam-artifact-chip-title {
    font-size: 13.5px; font-weight: 700; color: var(--text-main);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.adam-artifact-chip-sub { font-size: 11.5px; font-weight: 600; color: var(--text-muted); margin-top: 1px; }
.adam-artifact-chip-arrow { flex: 0 0 16px; color: var(--text-muted); }

/* Split panel — on desktop the artifact is an in-flow column on the right that
   pushes the chat area to the left rather than floating over it. The backdrop is
   only used on narrow screens, where the panel falls back to an overlay drawer. */
.artifact-backdrop {
    position: fixed; inset: 0; z-index: 90;
    background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
}
.artifact-panel {
    flex: 0 0 auto;
    width: 0;
    z-index: 95;
    background: var(--bg-color);
    border-left: 1px solid var(--border);
    overflow: hidden;
    transition: width .34s cubic-bezier(.16,1,.3,1);
    display: flex;
}
.artifact-panel.open { width: min(560px, 46vw); }
/* The inner content keeps a fixed width so it reveals cleanly left-to-right as the
   panel animates open, instead of squishing. */
.artifact-inner { display: flex; flex-direction: column; width: min(560px, 46vw); height: 100%; }

@media (min-width: 900px) {
    .artifact-backdrop { display: none !important; }
}

/* Narrow screens: revert to a floating drawer over the chat. */
@media (max-width: 899px) {
    .artifact-panel {
        position: fixed; top: 0; right: 0; bottom: 0;
        width: min(520px, 94vw);
        box-shadow: -12px 0 40px rgba(0,0,0,0.18);
        transform: translateX(102%);
        transition: transform .32s cubic-bezier(.16,1,.3,1);
    }
    .artifact-panel.open { width: min(520px, 94vw); transform: translateX(0); }
    .artifact-inner { width: 100%; }
}
.artifact-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 18px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.artifact-header-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.artifact-badge {
    font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
    padding: 4px 8px; border-radius: 7px; color: #fff; flex: 0 0 auto;
    background: #6b7280;
}
.artifact-badge.code { background: #4f46e5; }
.artifact-badge.chart { background: #2563eb; }
.artifact-badge.document { background: #a855f7; }
.artifact-badge.image { background: #ec4899; }
.artifact-title-text {
    font-size: 14.5px; font-weight: 700; color: var(--text-main);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.artifact-close {
    flex: 0 0 auto; padding: 6px; border-radius: 9px; color: var(--text-muted);
    background: none; border: none; cursor: pointer; transition: background .15s, color .15s;
}
.artifact-close:hover { background: var(--hover); color: var(--text-main); }
.artifact-body { flex: 1; overflow: auto; padding: 18px; }
.artifact-code {
    background: #0a0a0a; color: #cdd6f4; border-radius: 12px; border: 1px solid rgba(255,255,255,0.08);
    padding: 16px; overflow: auto; font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.6;
    white-space: pre; tab-size: 2;
}
.artifact-code code { font-family: inherit; background: none; padding: 0; color: inherit; white-space: pre; }
.artifact-doc { font-size: 15px; line-height: 1.7; color: var(--text-main); }
.artifact-doc h1, .artifact-doc h2, .artifact-doc h3 { font-weight: 800; margin: 1.1em 0 .5em; line-height: 1.25; }
.artifact-doc h1 { font-size: 1.6em; } .artifact-doc h2 { font-size: 1.3em; } .artifact-doc h3 { font-size: 1.1em; }
.artifact-doc p { margin: .7em 0; }
.artifact-doc ul, .artifact-doc ol { margin: .6em 0; padding-left: 1.4em; }
.artifact-doc li { margin: .25em 0; }
.artifact-doc table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 14px; }
.artifact-doc th, .artifact-doc td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.artifact-doc th { background: var(--bg-secondary); font-weight: 700; }
.artifact-doc code { background: var(--bg-secondary); padding: 2px 6px; border-radius: 6px; font-family: 'JetBrains Mono', monospace; font-size: .9em; }
.artifact-doc blockquote { border-left: 3px solid var(--border); padding-left: 14px; color: var(--text-muted); margin: .8em 0; }
.artifact-chart-wrap { position: relative; height: 60vh; min-height: 320px; width: 100%; }
.artifact-footer {
    flex: 0 0 auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 14px 18px; border-top: 1px solid var(--border);
}
.artifact-btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 15px; border-radius: 11px; font-size: 13px; font-weight: 700;
    border: none; cursor: pointer; transition: filter .15s, background .15s, opacity .15s;
}
.artifact-btn:disabled { opacity: .6; cursor: default; }
.artifact-btn-ghost { background: var(--hover); color: var(--text-main); }
.artifact-btn-ghost:hover { filter: brightness(.97); }
.artifact-btn-primary { background: linear-gradient(135deg,#6366f1,#8b5cf6); color: #fff; margin-left: auto; }
.artifact-btn-primary:hover { filter: brightness(1.05); }

/* ======================================================
   MEMORY POPUP
====================================================== */
.memory-overlay {
    position: fixed; inset: 0; z-index: 98;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.memory-modal {
    width: min(94vw, 560px); max-height: 86vh; display: flex; flex-direction: column;
    background: var(--bg-color); border: 1px solid var(--border);
    border-radius: 20px; box-shadow: 0 28px 80px rgba(0,0,0,0.4); overflow: hidden;
}
.memory-modal-header {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    padding: 20px 22px 16px; border-bottom: 1px solid var(--border);
}
.memory-modal-icon {
    flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px;
    display: flex; align-items: center; justify-content: center; color: #fff;
    background: linear-gradient(135deg,#a855f7,#6366f1);
}
.memory-modal-title { font-size: 17px; font-weight: 800; color: var(--text-main); }
.memory-modal-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.memory-modal-body { padding: 20px 22px; overflow: auto; flex: 1; }
.memory-readonly {
    white-space: pre-wrap; font-size: 14px; line-height: 1.7; color: var(--text-main);
    background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 14px; padding: 16px;
}
.memory-empty { font-size: 14px; line-height: 1.6; color: var(--text-muted); padding: 6px 2px; }
.memory-textarea {
    width: 100%; min-height: 200px; resize: vertical; font-family: inherit; font-size: 14px; line-height: 1.7;
    color: var(--text-main); background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: 14px; padding: 16px; outline: none;
}
.memory-textarea:focus { border-color: rgba(99,102,241,0.6); box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }
.memory-modal-footer {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    padding: 16px 22px; border-top: 1px solid var(--border);
}

/* ======================================================
   LIBRARY PREVIEW MODAL
====================================================== */
.lib-preview-overlay {
    position: fixed; inset: 0; z-index: 98;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.lib-preview-modal {
    width: min(94vw, 760px); max-height: 88vh; display: flex; flex-direction: column;
    background: var(--bg-color); border: 1px solid var(--border);
    border-radius: 20px; box-shadow: 0 28px 80px rgba(0,0,0,0.4); overflow: hidden;
}
.lib-preview-inner { display: flex; flex-direction: column; min-height: 0; }
.lib-preview-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.lib-preview-title-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lib-preview-title {
    font-size: 15px; font-weight: 700; color: var(--text-main);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-preview-body { padding: 18px 20px; overflow: auto; flex: 1; min-height: 120px; }
.lib-preview-image-wrap { display: flex; align-items: center; justify-content: center; }
.lib-preview-image { max-width: 100%; max-height: 60vh; border-radius: 12px; }
.lib-preview-chart-wrap { position: relative; height: 55vh; min-height: 300px; width: 100%; }
.lib-preview-footer {
    flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 20px; border-top: 1px solid var(--border);
}
.lib-preview-hint { font-size: 12px; font-weight: 600; color: var(--text-muted); }

/* Off-screen surface used to rasterize markdown into a PDF (light, print-like). */
.pdf-render-surface {
    position: fixed; left: 0; top: 0; z-index: -1; pointer-events: none; width: 794px; padding: 16px 24px;
    background: #ffffff; color: #111827;
    font-family: 'Manrope', Arial, sans-serif; font-size: 14px; line-height: 1.7;
}
.pdf-render-surface h1 { font-size: 26px; font-weight: 800; margin: 0 0 12px; }
.pdf-render-surface h2 { font-size: 21px; font-weight: 800; margin: 18px 0 10px; }
.pdf-render-surface h3 { font-size: 17px; font-weight: 700; margin: 14px 0 8px; }
.pdf-render-surface p { margin: 10px 0; }
.pdf-render-surface ul, .pdf-render-surface ol { margin: 10px 0; padding-left: 24px; }
.pdf-render-surface li { margin: 4px 0; }
.pdf-render-surface ul { list-style: disc; }
.pdf-render-surface ol { list-style: decimal; }
.pdf-render-surface a { color: #2563eb; text-decoration: underline; }
.pdf-render-surface blockquote { border-left: 3px solid #d1d5db; padding-left: 14px; color: #6b7280; margin: 10px 0; }
.pdf-render-surface table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.pdf-render-surface th, .pdf-render-surface td { border: 1px solid #d1d5db; padding: 8px 10px; text-align: left; }
.pdf-render-surface th { background: #f3f4f6; font-weight: 700; }
.pdf-render-surface pre { background: #f3f4f6; padding: 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; }
.pdf-render-surface code { font-family: 'JetBrains Mono', monospace; font-size: 0.9em; }

/* Settings: non-editable memory display */
.memory-readonly-box {
    white-space: pre-wrap; font-size: 14px; line-height: 1.7; color: var(--text-main);
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: 14px; padding: 16px; min-height: 130px;
}
.memory-readonly-empty { color: var(--text-muted); }

/* ======================================================
   SETTINGS — unlimited (employee) usage rows
====================================================== */
.usage-infinity {
    display: inline-flex; align-items: center; gap: 3px;
    font-weight: 800; color: #a855f7;
}
.usage-bar-unlimited {
    background: linear-gradient(90deg, #6366f1, #a855f7, #ec4899, #6366f1);
    background-size: 300% 100%;
    animation: usageShimmer 3.5s linear infinite;
    opacity: .85;
}
@keyframes usageShimmer { to { background-position: 300% 0; } }