/* styles.css */
:root {
    --primary-color: #0055a5;          /* A deeper yet vibrant blue for primary accents */
    --background-color: #ffffff;       /* Clean white for better contrast and modern look */
    --sidebar-bg: #f3f4f6;             /* Neutral light grey to differentiate the sidebar */
    --message-user-bg: #e6f2ff;        /* A striking blue for user message; highly readable */
    --message-ai-bg: #f5f7fa;          /* Soft blue-grey for AI message to emphasize clarity */
    --border-color: #d1d5db;           /* Subtle grey for borders to maintain structure */
    --table-border-color: #4e5969;     /* Dark slate grey for table borders to give contrast */
    --text-color: #24292e;             /* Dark grey for primary text; professional readability */
    --text-light: #6b7280;             /* Soft muted grey for secondary text */
    --shadow: 0 4px 10px rgba(0, 0, 0, 0.15); /* Slightly bolder shadow for depth and layering */
}

* {
    /* margin: 0;
    padding: 0; */
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--background-color);
    color: var(--text-color);
}

.container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Sidebar styles */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    margin-bottom: 12px;
}

.new-chat-btn {
    width: 100%;
    padding: 8px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.new-chat-btn:hover {
    background-color: #006bc0;
}

.history-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.history-header {
    font-weight: bold;
    margin-bottom: 12px;
    color: var(--text-light);
}

#chat-history {
    display: flex;
    flex-direction: column;
    /* gap: 8px; */
}

.history-item:hover {
    background-color: #e5e5e5;
}

.history-item.active {
    background-color: #e0e0e0;
    font-weight: bold;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.settings-btn {
    width: 100%;
    padding: 8px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.settings-btn:hover {
    background-color: #e5e5e5;
}

/* Main content styles */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* System message styles */
.system-message-container {
    border-bottom: 1px solid var(--border-color);
    background-color: white;
}

.system-message-header {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-weight: bold;
}

.toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
}

.system-message-body {
    padding: 0 16px 16px;
    display: none;
}

.system-message-body.active {
    display: block;
}

#system-message {
    width: 100%;
    min-height: 60px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    resize: vertical;
}

/* Chat container styles */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    text-align: center;
    margin: auto;
    max-width: 500px;
    padding: 24px;
    background-color: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.welcome-message h2 {
    margin-bottom: 12px;
    color: var(--primary-color);
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    /* white-space: pre-wrap; */
}

.message-content {
    padding-left: 24px;
    line-height: 1.5;
}

.message-content img {
    max-width: 100%;
    border-radius: 4px;
    margin: 8px 0;
}

.message-content pre {
    background-color: #f5f5f5;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    /* margin: 8px 0; */
}

.message-content code {
    font-family: 'Courier New', Courier, monospace;
}

.user-message {
    align-self: flex-end;
    background-color: var(--message-user-bg);
    border: 1px solid #cce4ff;
}

.ai-message {
    align-self: flex-start;
    background-color: var(--message-ai-bg);
    border: 1px solid var(--border-color);
}

.message-info {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
    font-size: 0.85em;
    color: var(--text-light);
}

.message-info .timestamp {
    margin-left: auto;
}

/* Input area styles */
.input-container {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background-color: white;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: var(--shadow);
}

#user-input {
    flex: 1;
    border: none;
    resize: none;
    padding: 8px;
    max-height: 120px;
    font-size: 1em;
}

#user-input:focus {
    outline: none;
}

.input-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-upload-btn {
    padding: 8px;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 4px;
}

.file-upload-btn:hover {
    background-color: #f0f0f0;
}

.file-preview-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.file-preview {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.file-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-preview .file-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    font-size: 1.5em;
}

.file-preview .remove-file {
    position: absolute;
    top: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
}

.send-btn {
    padding: 8px 12px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.send-btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background-color: #006bc0;
}

.file-info {
    font-size: 0.75em;
    color: var(--text-light);
    margin-top: 8px;
    text-align: center;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

/* .modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 0;
    width: 500px;
    max-width: 90%;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
} */

.modal-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close {
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: var(--primary-color);
}

.modal-body {
    padding: 16px;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
}

.setting-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.modal-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    text-align: right;
}

.primary-btn {
    padding: 8px 16px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.primary-btn:hover {
    background-color: #006bc0;
}

/* Responsive styles */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .sidebar-header h2 {
        margin-bottom: 0;
    }

    .new-chat-btn {
        width: auto;
    }

    .history-container {
        display: none;
    }

    .sidebar-footer {
        display: none;
    }

    .main-content {
        height: 0;
        flex: 1;
    }

    .message {
        max-width: 90%;
    }
}

/* Animation for the typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background-color: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    width: fit-content;
    margin-bottom: 16px;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    background-color: var(--text-light);
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    animation: typing 1.5s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
    margin-right: 0;
}

@keyframes typing {
    0% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }

    100% {
        transform: translateY(0);
    }
}

/* File upload styles */
.file-pill {
    display: inline-flex;
    align-items: center;
    background-color: #f0f0f0;
    padding: 4px 8px;
    border-radius: 16px;
    margin-right: 8px;
    margin-bottom: 8px;
    font-size: 0.85em;
}

.file-pill .file-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-pill .remove-file {
    margin-left: 4px;
    cursor: pointer;
    color: var(--text-light);
}

.file-pill .remove-file:hover {
    color: #ff4d4d;
}

/*Markdown styling*/
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin-top: 8px;
    margin-bottom: 4px;
}

.markdown-content p {
    margin-bottom: 4px;
}

.markdown-content ul {
    list-style-type: disc; /* Circle bullets */
}

.markdown-content ol {
    list-style-type: decimal; /* Numbered list */
}

/* .markdown-content ul,
.markdown-content ol {
    margin-left: 20px;
} */

.markdown-content blockquote {
    border-left: 4px solid var(--table-border-color);
    padding-left: 8px;
    margin-left: 0;
    color: var(--text-light);
}

.markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 8px;
}

.markdown-content table th,
.markdown-content table td {
    border: 1px solid var(--table-border-color);
    padding: 8px;
    text-align: left;
}

.markdown-content table th {
    background-color: #f5f5f5;
}

.chat-header {
    padding: 15px 30px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.editable-title {
    font-size: 1.5rem;
    font-weight: 600;
    max-width: 500px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 5px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.model-selector select {
    padding: 5px 10px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: white;
}

.modal-content h2 {
    margin-bottom: 20px;
}

.modal-content input {
    width: 100%;
    padding: 10px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}


/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 15% auto;
    padding: 20px;
    border-radius: 8px;
    width: 500px;
    max-width: 90%;
    border-radius: 8px;
    box-shadow: var(--shadow);
    position: relative;
}

.close,
.closeTitle {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 1.5rem;
    cursor: pointer;
}

/* History row styling */
.history-row {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Space between title and delete button */
    padding: 5px; /* Optional: Add padding for better spacing */
    /*border-bottom: 1px solid #ccc;*/ /* Optional: Add a border for visual separation */
    position: relative;
}

.history-row:hover {
    background-color: #f0f0f0; /* Optional: Add hover effect for the row */
}

/* History item styling with message icon color */
.history-item {
    /*padding: 8px 12px;*/
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex: 1; /* Allow the title item to take up the remaining space */
}

.history-item i.fas.fa-message {
    color: #007bff; /* Set the color of the message icon */
}

/* Delete button styling */
.delete-btn {
    background: none;
    border: none;
    font-size: 16px; /* Adjust size of the delete button */
    cursor: pointer;
    color: red; /* Style icon in red */
    width: 0; /* Initially set the width to 0 */
    overflow: hidden; /* Hide content when width is 0 */
    opacity: 0; /* Initially the button is invisible */
    transition: width 0.2s ease, opacity 0.2s ease; /* Smooth transition on hover */
}

/* On hover, expand the width and make visible */
.history-row:hover .delete-btn {
    width: 24px; /* Final width of the bin icon */
    opacity: 1; /* Restore opacity */
}