body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f7f6;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* Changed from height */
    /* overflow: hidden; /* REMOVED: Allow body scroll if needed */
}

/* Add global box-sizing */
*,
*::before,
*::after {
    box-sizing: border-box;
}

.app-container {
    display: flex; /* Use flexbox for layout */
    width: 90%;
    max-width: 1000px; /* Increased max-width for sidebar + chat */
    height: 90vh;
    max-height: 700px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden; /* Contain scrolling within app-container or its children */
}

.sidebar {
    width: 250px; /* Fixed width for the sidebar */
    background-color: #e9ecef; /* Light grey background */
    padding: 15px;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Allow scrolling within the sidebar */
}

.sidebar h2 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.1em;
    color: #333;
}

#conversation-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.conversation-item {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    font-size: 0.9em;
    color: #555;
    transition: background-color 0.2s ease;
}

.conversation-item:hover {
    background-color: #dcdcdc;
}

.conversation-item.active {
    background-color: #007bff; /* Highlight active conversation */
    color: white;
    font-weight: bold;
}

.chat-container {
    flex-grow: 1; /* Allow chat container to take remaining space */
    display: flex;
    flex-direction: column;
    /* overflow: hidden; /* REMOVED: Ensure chat content is contained - Let children handle overflow */
    height: 100%; /* Add: Ensure it tries to fill parent height */
    position: relative; /* Add positioning context for absolute children */
}

.chat-header {
    background-color: #007bff; /* Modern blue */
    color: white;
    padding: 15px 20px;
    border-bottom: 1px solid #0056b3;
    display: flex;
    justify-content: space-between; /* Space out title and actions */
    align-items: center;
}

.chat-header h2 {
    margin: 0;
    font-size: 1.2em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px; /* Space between model selector and new conversation button */
}

.model-selection {
    font-size: 0.9em;
}

.model-selection label {
    margin-right: 5px;
}

#model-selector {
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid #0056b3; /* Darker border for contrast */
    background-color: #fff;
    color: #333;
    font-size: 0.9em;
}

#new-conversation-button {
    background-color: #28a745; /* Green for new action */
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
}

#new-conversation-button:hover {
    background-color: #218838;
}

.chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px; /* Space between messages */
}

.message {
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 75%;
    word-wrap: break-word;
    line-height: 1.4;
}

.user-message {
    background-color: #007bff;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px; /* Bubble tail */
}

.bot-message {
    background-color: #e9ecef;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px; /* Bubble tail */
}

.message p {
    margin: 0;
}

/* Markdown specific styling within .message */
.message p h1, .message p h2, .message p h3, .message p h4, .message p h5, .message p h6 {
    margin-top: 0.5em;
    margin-bottom: 0.3em;
    line-height: 1.2;
}
.message p h1 { font-size: 1.6em; }
.message p h2 { font-size: 1.4em; }
.message p h3 { font-size: 1.2em; }
.message p h4 { font-size: 1.0em; }

.message p ul, .message p ol {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
    padding-left: 20px; /* Indent lists */
}

.message p li {
    margin-bottom: 0.2em;
}

.message p pre {
    background-color: #2d2d2d; /* Darker background for code blocks */
    color: #f0f0f0;
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto; /* Allow horizontal scroll for long code lines */
    font-size: 0.9em;
    margin: 0.5em 0;
}

.message p code {
    background-color: #f0f0f0; /* Lighter background for inline code */
    color: #c7254e; /* Bootstrap-like color for inline code */
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

.message p pre code {
    background-color: transparent; /* Code inside pre should not have its own background */
    color: inherit;
    padding: 0;
    border-radius: 0;
}

.message p blockquote {
    border-left: 3px solid #007bff;
    padding-left: 10px;
    margin-left: 0;
    font-style: italic;
    color: #555;
}

.message p strong, .message p b {
    font-weight: bold;
}

.message p em, .message p i {
    font-style: italic;
}

.message p a {
    color: #0056b3; /* Link color */
    text-decoration: underline;
}
.message p a:hover {
    color: #003d80;
}

.chat-input-area {
    display: flex;
    padding: 15px;
    border-top: 1px solid #ddd;
    background-color: #f8f9fa;
    flex-shrink: 0; /* Prevent input area from shrinking */
    flex-grow: 0; /* Add: Explicitly prevent growing */
}

#user-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 20px;
    resize: none; /* Prevent manual resize */
    min-height: 20px; /* min height of a single line */
    max-height: 100px; /* max height before scroll, e.g. 4-5 lines */
    overflow-y: auto; /* Allow scroll within textarea if content exceeds max-height */
    font-size: 1em;
    line-height: 1.4;
}

#send-button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 20px;
    cursor: pointer;
    margin-left: 10px;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

#send-button:hover {
    background-color: #0056b3;
}

/* Scrollbar styling for chat messages (WebKit browsers) */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Ensure conversation item has enough specificity if overridden */
#conversation-list .conversation-item {
    padding: 10px 12px; /* Adjusted padding */
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    font-size: 0.9em;
    color: #555;
    transition: background-color 0.2s ease, color 0.2s ease; /* Added color transition */
    border-radius: 4px; /* Slight rounding */
    margin-bottom: 3px; /* Spacing between items */
}

#conversation-list .conversation-item:hover {
    background-color: #dcdcdc;
    color: #222; /* Darker text on hover */
}
#conversation-list .conversation-item.active {
    background-color: #007bff; /* Highlight active conversation */
    color: white;
    font-weight: bold;
}

/* Hamburger Menu and Overlay */
.hamburger-button {
    display: none; /* Hidden by default, shown in media query */
    background: none;
    border: none;
    color: white;
    font-size: 1.8em;
    cursor: pointer;
    padding: 0 10px;
    margin-right: 10px; /* Space between hamburger and title */
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 999; /* Below sidebar but above chat content */
}


/* Tablet and larger phone landscape */
@media (max-width: 768px) {
    .app-container {
        width: 100%;
        min-height: 100vh; /* Ensure it takes full viewport height */
        height: auto; /* Allow it to grow if content exceeds viewport */
        max-height: none; /* Remove max-height */
        border-radius: 0; /* No rounded corners on full screen */
        /* flex-direction: column; /* Decided against this to use slide-in sidebar */
    }

    .sidebar {
        position: fixed; /* Changed from absolute for better overlay behavior */
        left: -270px; /* Start off-screen (width + some padding) */
        top: 0;
        bottom: 0;
        z-index: 1000;
        width: 250px; 
        transition: left 0.3s ease-in-out;
        background-color: #e9ecef; /* Ensure background is set */
        box-shadow: 2px 0 5px rgba(0,0,0,0.1); /* Add shadow when it slides in */
        /* display: none; will be handled by .visible class toggle if needed, but left transition is better */
    }

    .sidebar.visible {
        left: 0; /* Slide in */
    }
    
    .chat-container {
        width: 100%; /* Take full width */
    }

    .chat-header {
        padding: 10px 15px;
    }

    .chat-header h2 {
        font-size: 1.1em;
    }
    
    .header-actions {
        /* Reverting column stacking for now, let's see if it fits first */
        /* flex-direction: column; */
        /* align-items: flex-end; */
        gap: 10px; /* Reduced gap slightly */
    }

    #model-selector {
        /* width: 100%; */ /* Only if stacked */
        font-size: 0.85em; /* Slightly smaller selector */
        padding: 4px 6px;
    }
    
    .model-selection label {
        font-size: 0.85em;
    }

    #new-conversation-button {
        font-size: 0.85em; /* Slightly smaller button */
        padding: 6px 10px;
    }

    .message {
        max-width: 90%; /* Allow messages to be a bit wider */
    }

    .chat-input-area {
        padding: 12px; /* Slightly increased padding */
        flex-direction: row; /* Ensure it stays row by default */
        /* align-items: stretch; /* REMOVED: Let items size naturally */
    }
    
    #user-input {
        line-height: 1.4; /* Increased from 1.3 */
        padding: 10px 14px; /* Increased padding */
        font-size: 0.95em; /* Increased font size */
    }
    
    #send-button {
        align-self: flex-end; /* Align to bottom if textarea grows */
        margin-bottom: 2px; /* Small adjustment for alignment with border-radius */
        padding: 10px 14px; /* Increased padding */
        font-size: 0.9em; /* Increased font size */
    }
    
    .hamburger-button {
        display: block; /* Show hamburger */
    }

    .overlay.visible {
        display: block;
    }

    /* REMOVED Mobile override - Button is now consistently absolute */
    /* .scroll-to-bottom-button { */
    /*     /* For Mobile: Change position to fixed and adjust placement */ */
    /*     position: fixed; /* Changed from absolute */ */
    /*     bottom: 20px; /* Position from viewport bottom */ */
    /*     right: 20px; /* Position from viewport right */ */
    /*     z-index: 1050; /* Ensure it's above most other elements */ */
    /* } */
}

/* Smaller phones */
@media (max-width: 480px) {
    .chat-header h2 {
        font-size: 1em; /* Slightly smaller title */
        margin-left: 5px; /* Give a bit of space from hamburger */
    }
    
    .header-actions {
        gap: 8px; /* Further reduce gap */
        /* If still cramped, consider stacking or hiding model selector by default */
        /* For example, making model selector part of a dropdown */
        /* Hide model selector and its label entirely on smallest screens */
        /* display: none; /* Hide the whole actions container if needed */
    }
    
    .model-selection {
        /* display: none; /* Hide the model selector entirely on small screens */
        /* Restore previous small screen styles */
        max-width: 130px; /* Limit width of model selector div */
    }

    /* Restore hiding the label */
    .model-selection label {
        display: none; /* Hide label to save space, selector might be intuitive enough */
    }

    /* Restore model selector specific styles */
     #model-selector {
         width: 100%; /* Make select element fill its parent */ 
         font-size: 0.8em;
     }

    #new-conversation-button {
        padding: 7px 15px; /* Increased padding for better touch target */
        font-size: 0.85em; /* Slightly larger font */
        /* width: 100%; /* Make button full width if needed */ */
    }
    
    /* Remove padding added previously for fixed input */
    .chat-messages {
        /* padding-bottom: 80px; /* Adjust as needed based on input area height */
    }

    .message {
        padding: 8px 12px;
        font-size: 0.9em; /* Adjusted from 0.95em */
    }

    /* Revert input area to normal flow */
    .chat-input-area {
        /* position: fixed; */
        /* bottom: 0; */
        /* left: 0; */
        /* width: 100%; /* Use 100% width of viewport */
        background-color: #f8f9fa; /* Ensure it has a background */
        border-top: 1px solid #ddd;
        padding: 10px; /* Adjust padding */
        /* z-index: 1001; /* Above overlay/sidebar */
        /* box-sizing: border-box; /* Include padding in width */
        /* Re-add flex properties */
        display: flex;
        flex-shrink: 0;
    }

    #user-input {
        padding: 10px 14px; /* Keep padding consistent */
        font-size: 0.95em; /* Keep font size consistent */
        /* max-height: 80px; /* REMOVED: Rely on default max-height or adjust if needed */ */
        /* Adjust max-height if fixed input area needs it */
        max-height: 80px; 
    }

    #send-button {
        padding: 10px 12px; /* Adjusted padding slightly */
        font-size: 0.9em; /* Keep font size consistent */
        align-self: flex-end; /* Re-apply align-self */
    }
    
    .sidebar {
        width: 80%; /* Sidebar takes more screen percentage */
        left: -85%; /* Adjust off-screen position based on new width */
    }
    .sidebar.visible {
        left: 0;
    }

    /* Adjust button position again if needed for very small screens */
    /* .scroll-to-bottom-button { */
    /*    bottom: 10px; */
    /*    right: 10px; */
    /* } */
}

/* Scroll to Bottom Button Styles */
.scroll-to-bottom-button {
    position: fixed; /* Changed from absolute to fixed */
    top: 75%; /* Position 75% from the top of the viewport */
    left: 50%; /* Position 50% from the left edge */
    /* right: 20px; */ /* REMOVED: Use left for centering */
    transform: translateX(-50%); /* Center the button horizontally */
    /* bottom: 70px; /* REMOVED: Position relative to chat-container */
    background-color: rgba(0, 123, 255, 0.8); /* Semi-transparent blue */
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    line-height: 40px; /* Center the arrow vertically */
    text-align: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1050; /* Ensure it's above most elements */
}

.scroll-to-bottom-button.visible {
    opacity: 1;
    visibility: visible;
}

.scroll-to-bottom-button:hover {
    background-color: rgba(0, 86, 179, 0.9); /* Darker blue on hover */
} 