/* --- CSS for Full Page Layout (PURPLE THEME) --- */

/* CRITICAL: Reset and ensure the root elements fill the viewport */
.chat-page, 
.chat-page html, 
.chat-page body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevents scroll ONLY on chat page */
}

body {
    font-family: Arial, sans-serif;
    background-color: #f0f2f5;
    display: block; 
    width: 100%;
}

/* Full-Width Fixed Top Header (Purple Theme) */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px; 
    background-color: #6a1b9a; /* Deep Purple */
    color: white;
    padding: 0 20px;
    display: flex;
    align-items: center; /* Centers items vertically (though title is positioned absolutely) */
    justify-content: center; /* Centers items horizontally */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

/* Style the Title/Home Link */
.app-title-link {
    color: inherit; /* Inherit white color */
    text-decoration: none; /* Remove underline */
    
    /* FIX: Position absolutely and use transform to ensure perfect vertical and horizontal centering */
    position: absolute; 
    left: 50%;
    top: 50%; 
    transform: translate(-50%, -50%); 
}

.app-header h1 {
    font-size: 1.5em;
    margin: 0;
    line-height: 1; 
}

/* Navigation Menu Button (Hamburger) */
.header-actions {
    position: absolute; 
    right: 20px;
    font-weight: bold;
    cursor: pointer;
    
    /* Style the Menu Button */
    font-size: 1.5em; /* Larger icon */
    line-height: 1;
    border: none;
    padding: 0;
}

/* New: Navigation Dropdown Menu */
.nav-menu-dropdown {
    display: none; /* Hidden by default */
    position: absolute;
    top: 55px; /* Position below the header */
    right: 0;
    background-color: white;
    border: 1px solid #ddd;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    min-width: 150px;
    border-radius: 4px;
    z-index: 1000;
}

.nav-menu-dropdown.open {
    display: flex; /* Show when open */
    flex-direction: column;
}

.nav-menu-dropdown a {
    color: #333;
    padding: 10px 15px;
    text-decoration: none;
    font-size: 0.9em;
    border-bottom: 1px solid #eee;
}

.nav-menu-dropdown a:last-child {
    border-bottom: none;
}

.nav-menu-dropdown a:hover {
    background-color: #f0f0f0;
}

/* Main Content Area (Sidebar + Chat) */
.main-content-area {
    padding-top: 60px;
    height: calc(100vh - 60px); 
    width: 100%;
    display: grid;
    grid-template-columns: 250px 1fr; 
    overflow: hidden; 
}

/* Left Sidebar Column */
.sidebar {
    grid-column: 1;
    background-color: #f7f7f7;
    padding: 15px;
    border-right: 1px solid #ddd;
    overflow-y: auto;
    flex-shrink: 0;
    height: 100%; 
}

.sidebar h2 {
    font-size: 1.1em;
    color: #333;
    margin-top: 0;
    margin-bottom: 15px;
}

/* Chat Item Layout */
.chat-item {
    position: relative; 
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    white-space: nowrap;
}

.chat-title {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap; 
    margin-right: 5px; 
}

.chat-item:hover {
    background-color: #e0e0e0;
}

.chat-item.active {
    background-color: #6a1b9a1a; /* Very light purple for active chat */
    font-weight: bold;
    color: #6a1b9a; /* Deep Purple text */
}

/* Three Vertical Dots Menu Button */
.chat-menu-btn {
    opacity: 0; 
    font-weight: bold;
    font-size: 1.2em;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
    flex-shrink: 0; 
    transform: rotate(90deg); /* Vertical dots */
    color: #6a1b9a; /* Deep Purple */
    user-select: none;
}

/* Show dots on hover over the chat item */
.chat-item:hover .chat-menu-btn {
    opacity: 1; 
}

/* Style for the input field when renaming */
.chat-rename-input {
    width: calc(100% - 10px);
    padding: 5px;
    border: 1px solid #6a1b9a; /* Purple border */
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 0.9em;
}

.chat-item.new-chat-btn {
    margin-top: 15px;
    text-align: center;
    justify-content: center;
    border: 1px dashed #6a1b9a;
    color: #6a1b9a;
    font-weight: bold;
}

/* Chat Menu Dropdown (New Element for Rename/Delete) */
.chat-menu-dropdown {
    position: absolute;
    top: 50%; 
    right: 25px;
    transform: translateY(-50%);
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    z-index: 10;
    white-space: nowrap;
}

.chat-menu-dropdown button {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 0.9em;
}

.chat-menu-dropdown button:hover {
    background-color: #f0f0f0;
}

/* --- CHAT SPECIFIC STYLES --- */

.chat-container {
    grid-column: 2;
    display: flex;
    flex-direction: column; 
    overflow: hidden; 
    height: 100%; 
    /* Set the main chat background to the desired lighter grey */
    background-color: #f7f7f7; 
}

.chat-box {
    flex-grow: 1; 
    padding: 20px;
    overflow-y: scroll; 
    display: flex;
    flex-direction: column;
}

/* Custom scrollbar styles for WebKit browsers */
.chat-box::-webkit-scrollbar {
    width: 8px; 
    height: 8px;
}

.chat-box::-webkit-scrollbar-track {
    background: transparent; 
}

.chat-box::-webkit-scrollbar-thumb {
    background-color: #aaa; 
    border-radius: 10px; 
}

.chat-box::-webkit-scrollbar-button {
    display: none; 
}

.message {
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 20px;
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.4;
}

.user-message {
    align-self: flex-end;
    background-color: #007bff;
    color: white;
    border-bottom-right-radius: 5px;
}

.ai-message {
    align-self: flex-start;
    background-color: #e9e9eb;
    color: #333;
    border-bottom-left-radius: 5px;
}

/* INPUT CONTAINER FIXES: Background Match, Width, and Centering */
.input-container {
    flex-shrink: 0; 
    
    /* Match input background color to the main chat area (#f7f7f7) */
    background-color: #f7f7f7; 
    
    border-top: none; 
    
    /* Center the 80% wide content */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0; /* Vertical padding */
    
    width: 100%; /* Take full width of its parent */
}

/* Constraint the input elements to 80% width when they are inside the input-container */
.input-container > textarea,
.input-container > #send-button {
    max-width: 80%; 
}

#user-input {
    flex-grow: 1;
    
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 20px;
    font-size: 1em;
    resize: none; 
    
    /* Enforce single-line height for visual stability */
    line-height: 20px; 
    min-height: 20px; 
    height: 40px; /* Start height (line height + 2 * padding) */
    
    max-height: 100px;
    overflow-y: auto;
}

#send-button {
    background-color: #6a1b9a; 
    color: white;
    border: none;
    padding: 10px 20px;
    margin-left: 10px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s;
    flex-shrink: 0; 
}

#send-button:hover {
    background-color: #5b1585; /* Darker purple on hover */
}

/* KaTeX styling for display mode math */
.katex-display {
    margin-top: 10px;
    margin-bottom: 10px;
    background-color: white;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
}