/* --- Main Content Container --- */
#content-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Chat Section --- */
#chat-section {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

#chat-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
}

/* Update message styling to accommodate avatars */
.message {
    margin-bottom: 10px;
    padding: 10px;
    max-width: 80%;
    border: 1px solid var(--border-light);
    word-wrap: break-word;
    display: flex;
    align-items: flex-start;
    position: relative;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    margin-right: 10px;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-message {
    background-color: var(--message-user-bg);
    align-self: flex-end;
    flex-direction: row-reverse;
}

.user-message .message-avatar {
    margin-right: 0;
    margin-left: 10px;
}

.user-message .message-label {
    text-align: right;
}

.bot-message {
    background-color: var(--message-bot-bg);
    align-self: flex-start;
}

.bot-message .message-label {
    text-align: left;
}

.tool-result-message,
.tool-call-message {
    background-color: var(--message-tool-result-bg);
    align-self: flex-start;
    border: 1px solid var(--border-light);
    font-style: normal;
}

.message-label {
    font-size: 0.8em;
    color: var(--text-medium);
    margin-bottom: 3px;
    display: block;
}

.user-message .message-label {
    text-align: right;
}

.bot-message .message-label,
.tool-result-message .message-label,
.tool-call-message .message-label {
    text-align: left;
}

.image-preview {
    max-width: 100%;
    height: auto;
    margin-top: 5px;
}

#tool-call-indicator {
    color: var(--tool-call-text);
    font-style: normal;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

#tool-call-indicator::before {
    content: '⚙️';
    font-size: 1em;
    display: inline-block;
}

/* --- Input Container --- */
#input-container {
    display: flex;
    padding: 10px;
    border-top: 1px solid var(--border-medium);
    background-color: var(--app-bg);
    position: relative; /* Changed from sticky to relative */
    bottom: 0;
    transition: background-color 0.3s;
}

/* Add resize handle styling */
#input-resize-handle {
    width: 100%;
    height: 16px;
    cursor: ns-resize;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--app-bg);
    user-select: none;
    touch-action: none;
    z-index: 5;
}

.handle-bar {
    width: 40px;
    height: 4px;
    background-color: var(--border-medium);
    border-radius: 2px;
}

body.dark-theme .handle-bar {
    background-color: var(--dark-medium-gray);
}

#user-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid var(--input-border);
    margin-right: 10px;
    background-color: var(--input-bg);
    color: var(--input-text);
    transition: background-color 0.3s, color 0.3s;
    resize: vertical;
    min-height: 20px;
    max-height: 200px;
    height: 40px;
    overflow-y: auto;
    font-family: inherit;
    font-size: inherit;
}

/* Make the user input respond to parent container height */
@media (max-width: 768px) {
    #user-input {
        /* Disable the built-in resize on mobile - we'll use our custom handle instead */
        resize: none;
    }
}

#send-button,
#file-input-label {
    padding: 10px;
    background-color: var(--dark-gray);
    color: var(--white);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 40px;
    height: 40px;
    box-sizing: border-box;
}

#send-button {
    margin-left: 10px;
}

#file-input-label {
    background-color: var(--dark-gray);
    position: relative;
    overflow: hidden;
    display: inline-block;
}

#file-input-label span {
    display: none;
}

#send-button span {
    display: none;
}

#loading-indicator {
    display: none;
    margin-left: 10px;
    font-style: italic;
    color: var(--text-medium);
    align-self: center;
}

#file-input {
    display: none;
}

#uploaded-file-info {
    position: relative; /* Changed from absolute */
    padding: 10px;
    margin: 0 10px;
    background-color: var(--light-gray);
    border: 1px solid var(--border-medium);
    border-radius: 5px;
    font-size: 0.9em;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
    max-height: 100px;
    overflow: auto;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#uploaded-file-info:empty {
    display: none; /* Hide when empty */
}

body.dark-theme #uploaded-file-info {
    background-color: var(--dark-light-gray);
    color: var(--dark-black);
    border-color: var(--dark-medium-gray);
}

#uploaded-file-info::before {
    content: '\e226'; /* Attachment icon */
    font-family: 'Material Icons';
    margin-right: 10px;
    color: var(--dark-gray);
    font-size: 1.2em;
}

body.dark-theme #uploaded-file-info::before {
    color: var(--dark-dark-gray);
}

/* Add clear button for attachment */
#uploaded-file-info::after {
    content: '\e5cd'; /* Close icon */
    font-family: 'Material Icons';
    margin-left: auto;
    color: var(--dark-gray);
    font-size: 1.2em;
    cursor: pointer;
}

body.dark-theme #uploaded-file-info::after {
    color: var(--dark-dark-gray);
}

/* --- Section Switcher --- */
#section-switcher {
    display: flex;
    justify-content: space-around;
    background-color: var(--section-switcher-bg);
    border-top: 1px solid var(--border-medium);
    padding: 5px 10px;
    position: sticky;
    bottom: 0;
    z-index: 5;
}

.section-button {
    flex-grow: 1;
    padding: 8px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s, color 0.2s;
    font-size: 0.9em;
}

.section-button.active {
    background-color: var(--section-switcher-button-active-bg);
    color: var(--section-switcher-button-active-color);
}

.section-button:not(.active) {
    background-color: var(--section-switcher-button-inactive-bg);
    color: var(--section-switcher-button-inactive-color);
}

.section-button:focus {
    outline: none;
}

/* Image container and ID badge styling */
.image-container {
    position: relative;
    margin-top: 5px;
    display: inline-block;
}

.image-id-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-family: monospace;
    z-index: 1;
}

body.dark-theme .image-id-badge {
    background-color: rgba(255, 255, 255, 0.8);
    color: #222;
}

.image-preview {
    max-width: 100%;
    height: auto;
    display: block;
}

/* --- Chat Menu Panel --- */
#chat-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay-bg);
    z-index: 100;
    display: none;
}

#chat-menu-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 300px;
    height: 100%;
    background-color: var(--app-bg);
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

#chat-menu-overlay.active #chat-menu-panel {
    transform: translateX(0);
}

#chat-menu-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-medium);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

#chat-menu-header h2 {
    margin: 0;
    font-size: 1.2em;
    color: var(--text-dark);
    flex-basis: 100%;
    margin-bottom: 10px;
}

#new-chat-button {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px;
    background-color: var(--dark-gray);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.3s;
}

body.dark-theme #new-chat-button {
    background-color: var(--dark-medium-gray);
    color: var(--dark-black);
}

#new-chat-button:hover {
    background-color: var(--black);
}

body.dark-theme #new-chat-button:hover {
    background-color: var(--dark-dark-gray);
}

#close-chat-menu-button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-medium);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

#close-chat-menu-button:hover {
    background-color: var(--light-gray);
    color: var(--text-dark);
}

body.dark-theme #close-chat-menu-button:hover {
    background-color: var(--dark-light-gray);
    color: var(--dark-black);
}

#chat-list-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
}

#chat-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chat-list-item {
    padding: 12px 15px;
    border-radius: 5px;
    margin-bottom: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.2s;
}

.chat-list-item:hover {
    background-color: var(--light-gray);
}

body.dark-theme .chat-list-item:hover {
    background-color: var(--dark-light-gray);
}

.chat-list-item.active {
    background-color: var(--medium-gray);
}

body.dark-theme .chat-list-item.active {
    background-color: var(--dark-medium-gray);
}

.chat-item-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-actions {
    display: flex;
    gap: 5px;
}

.chat-item-actions button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-medium);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.9em;
    visibility: hidden;
}

.chat-list-item:hover .chat-item-actions button {
    visibility: visible;
}

.chat-item-actions button:hover {
    background-color: var(--medium-gray);
    color: var(--text-dark);
}

body.dark-theme .chat-item-actions button:hover {
    background-color: var(--dark-medium-gray);
    color: var(--dark-black);
}

/* Chat rename input */
.chat-rename-input {
    width: 100%;
    padding: 5px;
    border: 1px solid var(--border-medium);
    border-radius: 3px;
    font-size: 0.9em;
    background-color: var(--input-bg);
    color: var(--input-text);
}

/* Chat Rename Input Styling */
.chat-rename-input {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    width: calc(100% - 16px);
    margin-right: 10px;
    outline: none;
}

.chat-rename-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 3px var(--accent-color);
}

/* Improve style of rename button */
.rename-chat-button {
    opacity: 0.8;
    transition: opacity 0.2s;
}

.rename-chat-button:hover {
    opacity: 1;
}

.chat-rename-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 3px var(--accent-color);
}

/* --- Media Queries --- */
@media (max-width: 768px) {
    .message {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    .message {
        max-width: 95%;
    }
    
    .message-avatar {
        width: 30px;
        height: 30px;
    }
    
    .user-message .message-avatar {
        margin-left: 8px;
    }
    
    .bot-message .message-avatar {
        margin-right: 8px;
    }
}