/* Import Poppins font for modern typography */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');

/* Global reset to eliminate browser/Bootstrap defaults */
h3, h4, ul, li, br {
    margin: 0;
    padding: 0;
    font-size: inherit;
    font-weight: normal;
    list-style: none;
}

/* Base styles */
body {
    font-family: 'Poppins', sans-serif !important;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: stretch;
    transition: background 0.3s ease, color 0.3s ease;
    color: #1a202c;
    overflow-x: hidden;
}

body.dark-mode {
    background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    color: #e0e0e0;
}

.no-history-msg {
    color: #718096;
}

body.dark-mode .no-history-msg {
    color: #a0aec0;
}

/* App container */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow-x: hidden;
}

/* Sidebar styling */
.sidebar {
    width: 250px;
    background: #2d3748;
    padding: 20px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    position: fixed;
    height: 100%;
    z-index: 1000;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
}

.sidebar.open {
    transform: translateX(0);
}

body.dark-mode .sidebar {
    background: #1a202c;
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        z-index: 1100;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    body.sidebar-overlay::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        backdrop-filter: blur(3px);
    }
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.sidebar-header h3 {
    color: #e0e0e0;
    font-size: 1.5rem;
    font-weight: 600;
}

.btn-close-sidebar {
    background: none;
    border: none;
    color: #a0aec0;
    font-size: 1.5rem;
}

.btn-close-sidebar:hover {
    color: #edf2f7;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 6px; /* Added spacing between icon and label for better readability */
    width: 100%;
    padding: 10px 15px;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #4a5568, #2d3748);
    color: #e0e0e0;
    border: none;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.sidebar-btn:hover {
    background: linear-gradient(90deg, #718096, #4a5568);
    transform: translateX(5px);
}

body.dark-mode .sidebar-btn {
    background: linear-gradient(90deg, #4a5568, #2d3748);
}

body.dark-mode .sidebar-btn:hover {
    background: linear-gradient(90deg, #718096, #4a5568);
}

/* Main content styling */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
    overflow-x: hidden;
}

.main-content.sidebar-open {
    margin-left: 250px;
}

@media (max-width: 768px) {
    .main-content.sidebar-open {
        margin-left: 0;
    }
}

/* Container styling */
.container {
    width: 100%;
    max-width: 800px;
    background: #ffffff;
    border-radius: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 25px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

body.dark-mode .container {
    background: #2d3748;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@media (max-width: 576px) {
    .container {
        max-width: 100%;
        border-radius: 0;
        padding: 15px;
        box-shadow: none;
    }
    body.dark-mode .container {
        box-shadow: none;
    }
}

/* Chat header styling */
.chat-header {
    padding-bottom: 15px;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

body.dark-mode .chat-header {
    border-bottom: 1px solid #4a5568;
}

.chat-header h2 {
    font-size: 1.75rem;
    font-weight: 600;
    color: #1a202c;
}

body.dark-mode .chat-header h2 {
    color: #e0e0e0;
}

.btn-toggle-sidebar {
    background: linear-gradient(90deg, #4f46e5, #4338ca);
    border: none;
    color: #ffffff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.btn-toggle-sidebar:hover {
    background: linear-gradient(90deg, #6b21a8, #4f46e5);
    transform: scale(1.1);
}

body.dark-mode .btn-toggle-sidebar {
    background: linear-gradient(90deg, #6b21a8, #4f46e5);
}

body.dark-mode .btn-toggle-sidebar:hover {
    background: linear-gradient(90deg, #9333ea, #6b21a8);
}

/* Chat box styling */
.chat-box {
    flex-grow: 1;
    max-height: 60vh;
    overflow-y: auto;
    background: #edf2f7;
    padding: 20px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    overflow-x: hidden;
    padding-bottom: 20px;
}

body.dark-mode .chat-box {
    background: #4a5568;
    border-color: #718096;
}

.chat-box .typing-dots {
    display: flex;
    gap: 4px;
}

.chat-box .typing-dots span {
    width: 6px;
    height: 6px;
    background: #4f46e5;
    border-radius: 50%;
    animation: blink 1.2s infinite;
    opacity: 0.3;
}

body.dark-mode .chat-box .typing-dots span {
    background: #9333ea;
}

.chat-box .typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-box .typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* Chat message styling */
.chat-message {
    margin-bottom: 20px;
    font-size: 1rem;
    animation: fadeIn 0.3s ease-in;
}

.chat-user,
.chat-bot {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
}

.chat-user {
    justify-content: flex-end;
}

.chat-bot {
    justify-content: flex-start;
}

/* Style the message content for both user and bot */
.chat-box .chat-message .message-content {
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 75%;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-weight: 500;
    font-size: 0.95rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    line-height: 1.6;
}

/* User message bubble styling */
.chat-box .chat-message.chat-user .message-content {
    background: #2d3748;
    color: #e0e0e0;
    border-bottom-right-radius: 0;
}

/* Bot message bubble styling */
.chat-box .chat-message.chat-bot .message-content {
    background: #4a5568;
    color: #e0e0e0;
    border-bottom-left-radius: 0;
}

@media (max-width: 576px) {
    .chat-box .chat-message .message-content {
        max-width: 90%;
    }
}

/* Markdown styling within message content */
.chat-box .chat-message .message-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: #e0e0e0;
}

.chat-box .chat-message .message-content h4 {
    font-size: 1.15rem;
    font-weight: 500;
    margin: 15px 0 10px 0;
    color: #e0e0e0;
}

.chat-box .chat-message .message-content li strong {
    font-size: 1.25rem;
    font-weight: 600;
    color: #e0e0e0;
}

.chat-box .chat-message .message-content ul {
    padding-left: 25px;
    margin: 8px 0;
    list-style-type: disc;
}

.chat-box .chat-message .message-content li {
    margin-bottom: 5px;
    color: #e0e0e0;
}

.chat-box .chat-message .message-content br {
    margin-bottom: 10px;
    display: block;
    content: "";
}

.chat-box .chat-message .message-content p {
    margin-bottom: 10px;
}

.chat-box .chat-message .message-content p:last-child {
    margin-bottom: 0;
}

/* Icons before messages */
.chat-user::before,
.chat-bot::before {
    font-family: "Bootstrap-icons";
    font-size: 1.3rem;
    margin-top: 4px;
    flex-shrink: 0;
    color: #1a202c;
}

.chat-user::before {
    content: "\f4da";
}

.chat-bot::before {
    content: "\F777";
}

body.dark-mode .chat-user::before,
body.dark-mode .chat-bot::before {
    color: #e0e0e0;
}

/* Dark mode adjustments for message content */
body.dark-mode .chat-box .chat-message.chat-user .message-content {
    background: #2d3748;
    color: #e0e0e0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

body.dark-mode .chat-box .chat-message.chat-bot .message-content {
    background: #4a5568;
    color: #e0e0e0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Chat input styling */
.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-top: 15px;
}

.input-wrapper .form-control {
    border-radius: 25px;
    padding: 10px 15px;
    border: 1px solid #e2e8f0;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    height: 80px;
    resize: none;
    overflow-y: auto;
}

.input-wrapper .form-control:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.25);
}

body.dark-mode .input-wrapper .form-control {
    background: #4a5568;
    border-color: #718096;
    color: #e0e0e0;
}

body.dark-mode .input-wrapper .form-control:focus {
    border-color: #9333ea;
    box-shadow: 0 0 0 0.2rem rgba(147, 51, 234, 0.25);
}

.input-wrapper .form-control::placeholder {
    color: #718096;
}

body.dark-mode .input-wrapper .form-control::placeholder {
    color: #a0aec0;
}

.send-btn {
    background: linear-gradient(90deg, #4f46e5, #4338ca);
    border: none;
    color: #ffffff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.send-btn:hover {
    background: linear-gradient(90deg, #6b21a8, #4f46e5);
    transform: scale(1.1);
}

body.dark-mode .send-btn {
    background: linear-gradient(90deg, #6b21a8, #4f46e5);
}

body.dark-mode .send-btn:hover {
    background: linear-gradient(90deg, #9333ea, #6b21a8);
}

#uploadDocumentBtn.btn-primary {
    background: linear-gradient(90deg, #198754, #157347);
    border: none;
    color: #ffffff;
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

#uploadDocumentBtn.btn-primary:hover {
    background: linear-gradient(90deg, #1ea362, #198754);
    transform: scale(1.05);
}

body.dark-mode #uploadDocumentBtn.btn-primary {
    background: linear-gradient(90deg, #146c43, #126740);
}

body.dark-mode #uploadDocumentBtn.btn-primary:hover {
    background: linear-gradient(90deg, #1a874f, #146c43);
    transform: scale(1.05);
}

#uploadDocumentSubmit.btn-primary {
    background: linear-gradient(90deg, #198754, #157347);
    border: none;
    color: #ffffff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

#uploadDocumentSubmit.btn-primary:hover {
    background: linear-gradient(90deg, #1ea362, #198754);
    transform: scale(1.05);
}

body.dark-mode #uploadDocumentSubmit.btn-primary {
    background: linear-gradient(90deg, #146c43, #126740);
}

body.dark-mode #uploadDocumentSubmit.btn-primary:hover {
    background: linear-gradient(90deg, #1a874f, #146c43);
    transform: scale(1.05);
}

/* Chat-input styling to ensure stacked layout beside input */
.chat-input {
    display: flex;
    flex-direction: column;
    align-items: end;
    gap: 2px;
}

/* Fade-in animation for messages */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar styling */
.chat-box::-webkit-scrollbar,
.input-wrapper .form-control::-webkit-scrollbar,
.code-wrap pre::-webkit-scrollbar {
    width: 6px;
}

.chat-box::-webkit-scrollbar-track,
.input-wrapper .form-control::-webkit-scrollbar-track,
.code-wrap pre::-webkit-scrollbar-track {
    background: #edf2f7;
}

.chat-box::-webkit-scrollbar-thumb,
.input-wrapper .form-control::-webkit-scrollbar-thumb,
.code-wrap pre::-webkit-scrollbar-thumb {
    background: #4f46e5;
    border-radius: 10px;
}

body.dark-mode .chat-box::-webkit-scrollbar-track,
body.dark-mode .input-wrapper .form-control::-webkit-scrollbar-track,
body.dark-mode .code-wrap pre::-webkit-scrollbar-track {
    background: #4a5568;
}

body.dark-mode .chat-box::-webkit-scrollbar-thumb,
body.dark-mode .input-wrapper .form-control::-webkit-scrollbar-thumb,
body.dark-mode .code-wrap pre::-webkit-scrollbar-thumb {
    background: #9333ea;
}

/* Modal styling */
.modal-content {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body.dark-mode .modal-content {
    background: #2d3748;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.dark-mode .modal-header,
.dark-mode .modal-footer {
    border-color: #4a5568;
}

.dark-mode .modal-title {
    color: #e0e0e0;
}

.dark-mode .modal-body {
    color: #e0e0e0;
}

.dark-mode .modal-header .btn-close {
    filter: invert(1);
}

.modal-backdrop.show {
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
}

/* History modal message styling */
.history-message {
    margin-bottom: 20px;
    font-size: 1rem;
}

.history-user,
.history-bot {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.history-user strong,
.history-bot strong {
    font-weight: 600;
    color: #1a202c;
}

body.dark-mode .history-user strong,
body.dark-mode .history-bot strong {
    color: #e0e0e0;
}

.history-user span {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
    color: #1a202c;
}

.history-bot .message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 1rem;
    line-height: 1.6;
    color: #1a202c;
    overflow-x: hidden;
}

.history-bot .message-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: #1a202c;
}

.history-bot .message-content h4 {
    font-size: 1.15rem;
    font-weight: 500;
    margin: 15px 0 10px 0;
    color: #1a202c;
}

.history-bot .message-content li strong {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a202c;
}

.history-bot .message-content ul {
    padding-left: 25px;
    margin: 8px 0;
    list-style-type: disc;
}

.history-bot .message-content li {
    margin-bottom: 5px;
    color: #1a202c;
}

.history-bot .message-content br {
    margin-bottom: 10px;
    display: block;
    content: "";
}

.history-bot .message-content p {
    margin-bottom: 10px;
}

.history-bot .message-content p:last-child {
    margin-bottom: 0;
}

body.dark-mode .history-user span,
body.dark-mode .history-bot .message-content,
body.dark-mode .history-bot .message-content h3,
body.dark-mode .history-bot .message-content h4,
body.dark-mode .history-bot .message-content li,
body.dark-mode .history-bot .message-content li strong {
    color: #e0e0e0;
}

/* Code wrap styling */
.code-wrap {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
    position: relative;
}

.code-wrap button {
    flex-shrink: 0;
    position: relative;
}

.code-wrap button.copied::after {
    content: "Copied...";
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: #4f46e5;
    color: #fff;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.85rem;
    opacity: 0;
    animation: fadeInOut 1.5s ease-in-out;
}

body.dark-mode .code-wrap button.copied::after {
    background: #9333ea;
}

.code-wrap pre {
    flex-grow: 1;
    min-width: 200px;
    max-width: 100%;
    background: #e2e8f0;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    white-space: pre;
    word-wrap: normal;
}

.code-wrap pre code {
    color: #1a202c !important;
}

body.dark-mode .code-wrap pre {
    background: #1a202c;
    color: #e0e0e0;
}

body.dark-mode .code-wrap pre code {
    color: #e0e0e0 !important;
}

@media (max-width: 576px) {
    .code-wrap {
        flex-direction: column;
        align-items: stretch;
    }
    .code-wrap button {
        align-self: flex-start;
    }
}

/* Font size classes */
.font-small {
    font-size: 0.9rem;
}

.font-medium {
    font-size: 1rem;
}

.font-large {
    font-size: 1.1rem;
}

/* Font size inheritance */
.chat-box .chat-message .message-content,
.chat-box,
.input-wrapper .form-control,
.history-message,
.sidebar-btn,
.chat-header h2,
.modal-content,
.footer {
    font-size: inherit;
}

/* Footer styling */
footer {
    background: #e2e8f0;
    color: #1a202c;
    font-size: 0.85rem;
    padding: 10px 0;
    border-top: 1px solid #cbd5e0;
}

body.dark-mode footer {
    background: #2d3748;
    color: #e0e0e0;
    border-top: 1px solid #4a5568;
}

button {
    font-size: 0.9rem;
}
@media (max-width: 767.98px) {
    .container {
        padding-left: 15px;
        padding-right: 15px;
    }
    .card {
        margin-left: 15px;
        margin-right: 15px;
    }
}
@media (max-width: 767.98px) {
    .card {
        margin: 15px;
    }
}