/* GEMINI DARK THEME */
:root {
    --bg-color: linear-gradient(180deg, #07131a, #0c1e29);
    --sidebar-color: #1E1F20;
    --text-color: #E3E3E3;
    --accent-color: #444746;
    --input-bg: #1E1F20;
    --blue-accent: #4285f4;
}

body {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* SIDEBAR */
.sidebar {
    width: 210px;
    background-color: var(--sidebar-color);
    padding: 10px;
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
    overflow-x: hidden; 
}

.new-chat { background-color: #1A1A1C; border: 3px solid #444; border-radius: 20px; padding: 10px 15px; cursor: pointer; color: #e2e3e2; width: fit-content; margin-left: 40px; margin-bottom: 30px; transition: 0.2s; }
.new-chat:hover { background-color: #333; }

.menu-section { margin-bottom: 25px; }
.menu-title { 
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 10px;
    color: #86c6ee;
    text-transform: uppercase;
    letter-spacing: 1px;
    
    /* ADD THIS LINE to move the text to the right */
    padding-left: 20px; 
}

/* MENU ITEM */
.menu-item { 
    padding: 10px; 
    border-radius: 5px; 
    cursor: pointer; 
    font-size: 17px; 
    color: #D0D0D0; 
    position: relative; 
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.menu-item:hover { background-color: #333; color: white; }
.menu-item.active { background-color: #333; color: white; font-weight: 600; }
.bottom { margin-top: auto; }

/* SOCIAL ICONS */
.social-icons span { font-size: 18px; margin-right: 10px; cursor: pointer; }

/* MAIN CONTENT */
.main-content {
    flex: 1;
    position: relative; 
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* CENTERING WRAPPER */
#centering-wrapper {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 1000px;
    bottom: 30%; 
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 10;
}

/* WELCOME SCREEN */
#welcome-screen {
    text-align: center;
    margin-bottom: 10px;
    transition: opacity 0.5s ease, height 0.5s ease, margin 0.5s ease;
}

h1 {
    font-size: 56px;
    background: linear-gradient(90deg, #6999e7, #75b1d6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0 0 15px 0;
}

.subtitle { font-size: 26px; color: #c4c9c7; margin-top: 5px; }

/* INPUT BAR */
.input-area { width: 100%; margin-top: 20px; }
.input-box {
    background-color: var(--input-bg);
    border-radius: 40px;        
    padding: 25px 30px;         
    display: flex;
    align-items: flex-start;    
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    min-height: 70px;           
    cursor: text;
}
input { background: transparent; border: none; color: white; font-size: 17px; flex: 1; outline: none; padding-left: 10px; }

input::placeholder {
    color: #a8abaa;
    font-size: 18px;
    opacity: 1;
}

/* BUTTON */
button { 
    background: transparent; 
    border: none; 
    color: white; 
    cursor: pointer; 
    font-size: 18px; 
    padding: 0 10px; 
    align-self: center;  
}
button:hover { color: var(--blue-accent); }
.disclaimer { text-align: center; font-size: 11px; color: #666; margin-top: 8px; }

/* CHAT HISTORY */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;       /* Prevent horizontal scrollbar */
    width: 100%;
    max-width: none;          /* Uncap width so scrollbar hits the screen edge */
    margin: 0;                /* Remove auto margin centering */
    
    /* Center the content using calculated padding */
    /* This keeps messages in a 900px central column while the container fills the screen */
    padding-top: 20px;
    padding-bottom: 120px;
    padding-left: max(20px, calc(50% - 450px));
    padding-right: max(20px, calc(50% - 450px));
    
    display: flex;
    flex-direction: column;
    gap: 20px;
    opacity: 0;
    transition: opacity 1s ease;
    box-sizing: border-box;
}

.message { padding: 15px 20px; border-radius: 18px; max-width: 80%; line-height: 1.6; font-size: 17px; }
.user-message { background-color: #2F3031; align-self: flex-end; border-bottom-right-radius: 4px; }
.ai-message { align-self: flex-start; color: #E3E3E3; }
.ai-message strong { color: white; }
.ai-message a { color: #8ab4f8; text-decoration: none; }
.ai-message a:hover { text-decoration: underline; }

/* CHAT MODE ACTIVE STATE */
body.chat-mode #centering-wrapper { 
    /* We keep position: absolute so the 0.8s transition works smoothly */
    position: absolute;
    
    /* We animate 'bottom' from 35% down to 0 */
    bottom: 0;
    
    /* We MUST keep these exactly the same as the starting state to prevent side-flying */
    left: 50%;
    transform: translateX(-50%);
    
    /* Ensure width consistency */
    width: 90%;
    max-width: 1000px;
    
    padding-bottom: 20px;
    margin: 0;
}

body.chat-mode #welcome-screen { 
    opacity: 0; 
    height: 0; 
    margin: 0; 
    overflow: hidden; 
}

body.chat-mode .chat-container { 
    opacity: 1;
    /* CRITICAL CHANGE: Use margin-bottom to stop the container above the input bar. */
    /* 170px accounts for the input box height + padding + disclaimer. */
    margin-bottom: 170px; 
    /* Reset padding to a normal amount since the margin handles the spacing now */
    padding-bottom: 20px;
}

/* ARTICLE PAGE STYLES */
.article-container {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;      /* Prevents horizontal scrollbar */
    padding: 40px 0 35px 0;  /* 35px bottom padding to protect the button */
    color: #E3E3E3;
    display: flex;
    flex-direction: column;
    align-items: center; 
    box-sizing: border-box;  /* Ensures padding doesn't increase width */
}

/* Updated to include box-sizing */
.article-container > * {
    width: 100%;
    max-width: 800px;
    padding-left: 20px;
    padding-right: 20px;
    box-sizing: border-box;  /* CRITICAL FIX: Keeps elements inside the screen */
}

.back-link { display: block; margin-bottom: 20px; color: #888; text-decoration: none; font-size: 14px; transition: 0.2s; }
.back-link:hover { color: #fff; transform: translateX(-5px); }

.article-header { border-bottom: 1px solid #333; padding-bottom: 20px; margin-bottom: 30px; }
.article-title { font-size: 2.5rem; margin: 0; line-height: 1.2; }
.article-meta { color: #888; margin-top: 15px; font-size: 0.9rem; }

.article-body { line-height: 1.8; font-size: 1.1rem; color: #ccc; }
.article-body h3 { color: #fff; margin-top: 40px; font-size: 1.5rem; }
.article-body h4 { color: #ddd; margin-top: 30px; font-size: 1.2rem; }
.article-body p { margin-bottom: 20px; }

/* CTA BOX */
.cta-box {
    background: #1E1F20;
    border: 1px solid #444;
    border-radius: 12px;
    padding: 30px;
    margin-top: 50px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.cta-box h3 { margin-top: 0; color: white; }
.btn-primary {
    background: var(--blue-accent);
    color: white;
    padding: 12px 30px;
    text-decoration: none;
    border-radius: 30px;
    font-weight: 600;
    display: inline-block;
    margin-top: 15px;
    transition: transform 0.2s, background 0.2s;
}
.btn-primary:hover { background: #3367d6; transform: scale(1.05); }

/* MENU STYLES */
.session-title {
    flex: 1;
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis;
}
.options-btn {
    opacity: 0; 
    padding: 0 6px;
    font-size: 16px;
    color: #8E918F;
    border-radius: 4px;
}
.menu-item:hover .options-btn { opacity: 1; } 
.options-btn:hover { background-color: #555; color: white; }

/* DROPDOWN */
.dropdown-menu {
    display: none; 
    position: fixed; /* Changed to fixed so it escapes the scroll container */
    /* Top and Left will be calculated by JS */
    background-color: #2F3031;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 5px 0;
    width: 140px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    z-index: 9999; /* High z-index to ensure it overlays everything */
}
.dropdown-menu div {
    padding: 10px 15px;
    font-size: 15px;
    color: #E3E3E3;
    cursor: pointer;
    display: flex;
    gap: 10px;
}
.dropdown-menu div:hover { background-color: #444; }

/* MODAL STYLES */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6); 
    display: none; 
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-box {
    background-color: #2F3031; 
    padding: 25px;
    border-radius: 12px;
    width: 400px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-box h3 {
    margin: 0;
    color: #E3E3E3;
    font-size: 20px;
    font-weight: 500;
}

/* Updated selector to include share-input */
#rename-input, #share-input {
    background-color: #1E1F20;
    border: 1px solid #444746;
    border-radius: 4px;
    padding: 12px;
    color: white;
    font-size: 16px;
    outline: none;
}

#rename-input:focus, #share-input:focus {
    border-color: var(--blue-accent);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-text {
    background: transparent;
    border: none;
    color: #A8C7FA;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 20px;
    transition: background 0.2s;
}

.btn-text:hover {
    background-color: rgba(168, 199, 250, 0.1);
}

.btn-primary-text {
    color: #A8C7FA; 
}

/* Custom Scrollbar */
.chat-container::-webkit-scrollbar {
    width: 12px;               /* 1. Sets the width */
}

.chat-container::-webkit-scrollbar-track {
    background: #1E1F20;       /* 2. Sets the background color */
}

.chat-container::-webkit-scrollbar-thumb {
    background-color: #171616;    /* 3. Sets the bar color */
    border: 3px solid #242628; /* Creates the spacing around the bar */
    border-radius: 10px;       /* Roundness */
}

/* Custom Scrollbar for Articles */
.article-container::-webkit-scrollbar {
    width: 12px;
}

.article-container::-webkit-scrollbar-track {
    background: #1E1F20;
}

.article-container::-webkit-scrollbar-thumb {
    background-color: #171616;
    border: 3px solid #242628;
    border-radius: 10px;
}

/* Dynamic Menu: Recent Chats grows with content, stops at 30% height */
.recent-chats-section {
    display: flex;
    flex-direction: column;
    flex: 0 1 auto;      
    min-height: 0;    
    max-height: 24vh;    
    margin-bottom: 8px;
    transition: all 0.3s ease;
    
    /* EXISTING Visual Separator */
    border-bottom: 4px solid #333;

    /* --- NEW CODE BELOW --- */
    
    /* 1. Pull the box out to the edges to cover the parent's padding */
    margin-left: -10px;  /* Adjust this value to match parent padding */
    margin-right: -10px; /* Adjust this value to match parent padding */

    /* 2. Push the text back in so it aligns correctly */
    padding-left: 15px;  /* Must match the margin above (positive) */
    padding-right: 15px; /* Must match the margin above (positive) */
    padding-bottom: 10px; /* Keep your existing bottom padding */
}

/* Dynamic Menu: Articles takes all remaining space */
.articles-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;    
    margin-bottom: 15px;
}

/* Allow the lists inside to scroll independently */
.scroll-list {
    overflow-y: auto; 
    flex: 1;
    padding-right: 5px;
}

/* Make the scrollbar look nice */
.scroll-list::-webkit-scrollbar { width: 4px; }
.scroll-list::-webkit-scrollbar-thumb { background-color: #333; border-radius: 4px; }

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    
    /* 1. HIDE SIDEBAR BY DEFAULT */
    .sidebar {
        position: fixed;
        left: -100%; /* Hide off-screen */
        top: 0;
        bottom: 0;
        width: 260px;
        z-index: 2000;
        transition: left 0.3s ease;
        box-shadow: 5px 0 15px rgba(0,0,0,0.5);
    }

    /* SHOW SIDEBAR WHEN OPEN */
    .sidebar.open {
        left: 0;
    }

    /* 2. MAKE CONTENT FULL WIDTH */
    .main-content {
        width: 100%;
        margin: 0;
    }

    /* 3. MOBILE HEADER BAR */
    .mobile-header {
        display: flex;
        align-items: center;
        padding: 15px 20px;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 10;
    }

    .hamburger-btn {
        font-size: 24px;
        background: none;
        color: #E3E3E3;
        padding: 5px;
        cursor: pointer;
        margin-right: 15px;
        border: none;
    }
    
    .mobile-logo {
        font-weight: 600;
        color: #8ab4f8;
        font-size: 18px;
    }

    /* 4. FIX TEXT SIZING */
    h1 { font-size: 36px; padding: 0 15px; }
    .subtitle { font-size: 18px; padding: 0 20px; }

    /* 5. ADJUST INPUT BOX */
    #centering-wrapper {
        width: 100%;
        bottom: 15%; 
    }
    .input-box {
        margin: 0 15px;
        padding: 15px 20px;
    }
    
    /* 6. DARK OVERLAY */
    #mobile-overlay {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.6);
        z-index: 1500;
        display: none;
        backdrop-filter: blur(2px);
    }
    #mobile-overlay.active { display: block; }
}

/* HIDE MOBILE HEADER ON DESKTOP */
@media (min-width: 769px) {
    .mobile-header, #mobile-overlay { display: none; }
}