* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

html {
    height: 100%;
    overflow: hidden;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #ffffff;
    --text-primary: #000000;
    --text-secondary: #6e6e80;
    --accent-color: #a6a6a6;
    --accent-hover: #b6b6b6;
    --light-button-color: #9f9f9f;
    --darker-button-color: #757575;
    --border-color: #e5e5e5;
    --message-user: #efefef;
    --message-assistant: #ffffff;
    --user-accent: #d6e6ff;
    --assistant-accent: #898b94;
    --sidebar-bg: #f0f0f5;
    --sidebar-width: 16.66%; /* 1/6 of screen */
    --font-size-x-big: 20px;
    --font-size-big: 18px;
    --font-size-input: 15px;
    --font-size-medium: 14px;
    --font-size-small: 13px;
    --font-size-x-small: 10px;
    --vh: 1vh; /* Custom viewport height variable */
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent scrolling on the body */
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    height: calc(var(--vh, 1vh) * 100); /* Fallback to 100% if var fails */
    position: relative;
    overflow: hidden; /* Prevent overflow */
}

/* Sidebar styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    z-index: 100;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--accent-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: var(--font-size-big);
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-buttons {
    display: flex;
    align-items: left;
    gap: 0px;
    position: relative;
}

.footer {
    /* bottom of the sidebar */
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    font-size: var(--font-size-x-small);
    color: #535353;
    text-align: left;
}

.settings-btn, .new-chat-btn {
    width: 32px;
    height: 32px;
    background-color: transparent;
    color: var(--text-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
}

.settings-btn:hover, .new-chat-btn:hover {
    background-color: rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.settings-btn:active, .new-chat-btn:active {
    transform: translateY(0);
    background-color: rgba(0, 0, 0, 0.12);
}

.settings-btn svg, .new-chat-btn svg {
    width: 16px;
    height: 16px;
    stroke: var(--text-primary);
}

.settings-dropdown {
    position: absolute;
    top: 40px;
    right: 0;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    width: 160px;
    z-index: 1000;
    display: none;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.settings-dropdown.show {
    display: block;
}

.settings-item {
    padding: 12px 16px;
    font-size: var(--font-size-medium);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.2s;
}

.settings-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.sidebar-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Divider styling */
.sidebar-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 5px 0 10px;
    width: 100%;
}

.sidebar-section-title {
    font-size: var(--font-size-small);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* Suggestion buttons styling */
.suggestion-btn {
    width: 100%;
    padding: 10px 12px;
    background-color: transparent;
    color: var(--text-primary);
    border: none;
    border-radius: 6px;
    font-size: var(--font-size-small);
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    white-space: normal;
    line-height: 1.4;
    min-height: 40px;
}

.suggestion-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.suggestion-btn:active {
    background-color: rgba(0, 0, 0, 0.1);
}

/* For positioning the landing container in the center */
.app-container {
    position: relative;
}

/* Initial landing page state - now more rectangular */
.landing-mode {
    width: 600px;
    height: 200px; /* Fixed height for 3:1 ratio */
    max-width: 80%;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px var(--accent-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    
    /* Center in the remaining space */
    position: absolute;
    top: 50%;
    left: calc(50% + (var(--sidebar-width) / 2));
    transform: translate(-50%, -50%);
}

/* Simplified landing layout */
.landing-mode .chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.landing-mode .chat-header h1 {
    font-size: var(--font-size-big);
    color: var(--accent-color);
    
}

/* Hide messages area in landing mode */
.landing-mode .chat-messages {
    display: none;
}

/* Simplify welcome message */
.landing-welcome {
    display: none; /* Hide by default */
}

.landing-mode .landing-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 16px 0;
    text-align: center;
}

.landing-welcome h2 {
    font-size: var(--font-size-big);
    margin-top: 24px;
    margin-bottom: 4px;
    color: var(--text-primary);
    font-weight: 600;
}

.landing-welcome p {
    display: none; /* Hide the paragraph to save space */
}

/* Make input container fill available space */
.landing-mode .chat-input-container {
    flex: 1;
    border-top: none;
    padding: 12px 16px 16px;
    display: flex;
    align-items: center;
}

.landing-mode #user-input {
    font-size: var(--font-size-input);
    padding: 12px 16px;
    border-radius: 8px;
    min-height: 45px;
    max-height: 80px; /* Limit the height */
}

.landing-mode #send-button {
    height: 45px;
    width: 45px;
    font-size: var(--font-size-medium);
    border-radius: 8px;
    background-color: transparent;
}

/* Thread mode styling remains mostly the same */
.thread-mode {
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100% - var(--sidebar-width));
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    border-radius: 0;
    box-shadow: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    background-color: var(--bg-primary);
    margin: 0;
    margin-left: var(--sidebar-width);
    transform: none;
}

.chat-container {
    display: flex;
    flex-direction: column;
    position: relative;
}

.landing-mode .chat-container {
    height: 100%;
}

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-secondary);
    box-shadow: 0 0.5px 0.5px var(--accent-color);
}

.thread-mode .chat-header {
    position: sticky;
    top: 0;
    z-index: 10;
}

.chat-header h1 {
    font-size: var(--font-size-x-big);
    font-weight: 600;
    color: var(--accent-color);
}

.chat-messages {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    background-color: var(--bg-primary);
    width: 66.6%;
}

.thread-mode .chat-messages {
    padding-bottom: 80px; /* Space for fixed input box */
}

.message {
    padding: 0;
    max-width: 100%;
    width: 100%;
    position: relative;
}

.message::after {
    content: '';
    display: block;
    height: 1px;
    background-color: var(--border-color);
    width: 100%;
    position: absolute;
    bottom: -12px;
    opacity: 0.5;
}

.message:last-child::after {
    display: none;
}

/* User messages - keep as bubbles */
.user-message .message-content {
    margin-left: auto;
    margin-right: 16px;
    margin-top: auto;
    margin-bottom: auto;
    max-width: 75%;
    background-color: var(--message-user);
    border-radius: 12px;
    border-top-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Assistant messages - no bubble style */
.assistant-message .message-content {
    margin-left: 16px;
    margin-right: 16px;
    max-width: 100%;
    background-color: transparent;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
}

.thread-mode .user-message {
    padding: 16px 0;
}

.thread-mode .assistant-message {
    padding: 24px 0 16px;
    background-color: transparent;
}

.user-message {
    background-color: transparent;
}

.assistant-message {
    background-color: transparent;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.message-name {
    font-weight: 600;
    font-size: var(--font-size-medium);
    color: var(--text-primary);
    margin-bottom: 2px;
}

.user-message .message-name {
    color: var(--user-accent);
    display: block;
}

.assistant-message .message-name {
    display: none; /* Hide Maia label */
}

.message-text {
    font-size: var(--font-size-input);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    display: inline-block;
    width: 100%;
}

.assistant-message .message-text {
    font-size: var(--font-size-input);
    line-height: 1.7;
}

.chat-input-container {
    padding: 16px 20px;
    background-color: var(--bg-secondary);
    display: flex;
    gap: 12px;
    /* border-top: 0px solid var(--border-color); */
}

/* Thread input container styling to match answer width */
.thread-mode .chat-input-container {
    background-color: transparent;
    position: fixed;
    bottom: 0;
    /* right: 0; */
    width: calc((100% - var(--sidebar-width))*0.666);
    z-index: 10;
    padding: 16px 0; /* Remove horizontal padding */
    display: flex;
    justify-content: center; /* Center the input wrapper */
    align-self:center;
}

/* .chat-messages {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    background-color: var(--bg-primary);
    width: 66.6%;
} */

/* New wrapper for input elements to control width */
.input-wrapper {
    display: flex;
    width: 100%;
    max-width: 900px; /* Match the messages container width */
    padding: 0 20px; /* Add padding inside the wrapper */
    gap: 12px;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    resize: none;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    font-size: var(--font-size-input);
    line-height: 1.5;
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    min-height: 45px;
}

#user-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

#send-button {
    background-color: transparent;
    color: var(--text-primary);
    border: none;
    border-radius: 8px;
    width: 45px;
    height: 45px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
    padding: 0;
}

#send-button:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

#send-button:active {
    transform: translateY(0);
    background-color: rgba(0, 0, 0, 0.1);
}

#send-button.disabled {
    background-color: transparent;
    cursor: not-allowed;
    transform: none;
    opacity: 0.5;
}

#send-button .send-icon {
    width: 20px;
    height: 20px;
    filter: brightness(0);
}

.icon {
    width: var(--font-size-big);  /* Set the size as needed */
    height: var(--font-size-big);
    margin-left: 2px;  /* Add spacing if needed */
    vertical-align: -webkit-baseline-top;  /* Align with text if present */
}

/* Thread messages container styling */
.thread-mode .chat-messages {
    max-width: 900px;
    margin: 0 auto;
    padding-left: 20px;
    padding-right: 20px;
}

/* Adjust for larger screens */
@media (min-width: 1200px) {
    .input-wrapper {
        max-width: 1000px; /* Match the increased width on larger screens */
    }
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 200px;
    }
    
    .landing-mode {
        width: 500px;
        height: 180px;
    }

    .sidebar-header h2 {
        font-size: var(--font-size-big);
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 1px;
    }
    .chat-messages {
        flex: 1;
        padding: 20px 0;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 24px;
        background-color: var(--bg-primary);
        width: calc((100% - var(--sidebar-width))*1.05);
    }

    /* Reduce margins for chat containers on ipad */
    .thread-mode .chat-messages {
        padding-left: 1%;
        padding-right: 1%;
        max-width: 100%;
        flex: 1;
        overflow-y: auto; /* Ensure messages are scrollable */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        margin-bottom: 60px; /* Space for the fixed input container */
    }
    /* Adjust message positioning for ipad */
    .user-message .message-content {
        margin-left: auto;
        margin-right: 1px;
        max-width: 65%;
    }
    
    .assistant-message .message-content {
        margin-left: auto;
        margin-right: auto;
        max-width: 100%;
    }
    /* Thread input container styling to match answer width */
    .thread-mode .chat-input-container {
        background-color: var(--bg-secondary);
        position: fixed;
        bottom: 0;
        left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
        z-index: 100;
        padding: 12px 8px;
        /* -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden; */
    }
    .thread-mode .input-wrapper {
        padding: 0 8px;
        width: 85%;
        max-width: 100%;
        /* -webkit-transform: translateZ(0);
        transform: translateZ(0); */
    }
    
    #user-input {
        -webkit-appearance: none;
        appearance: none;
        cursor: text;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 180px;
    }
    
    .landing-mode {
        width: 450px;
        height: 160px;
    }
    /* Smaller logo font in ipad */
    .sidebar-header h2 {
        font-size: var(--font-size-medium);
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 1px;
    }

    .chat-messages {
        flex: 1;
        padding: 20px 0;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 24px;
        background-color: var(--bg-primary);
        width: 95%;
    }
    .thread-mode {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        height: 100%;
        overflow: hidden; /* Prevent overflow at container level */
        display: flex;
        flex-direction: column;
        padding: 0;
        margin: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    /* Reduce margins for chat containers on ipad */
    .thread-mode .chat-messages {
        padding-left: 1%;
        padding-right: 1%;
        max-width: 100%;
        flex: 1;
        overflow-y: auto; /* Ensure messages are scrollable */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        margin-bottom: 60px; /* Space for the fixed input container */
    }
    /* Adjust message positioning for ipad */
    .user-message .message-content {
        margin-left: auto;
        margin-right: 1px;
        max-width: 85%;
    }
    
    .assistant-message .message-content {
        margin-left: auto;
        margin-right: auto;
        max-width: 100%;
    }
    
}

@media (max-width: 576px) {
    :root {
        --sidebar-width: 0;
    }
    
    body {
        overflow: hidden; /* Prevent body scrolling on mobile */
        position: fixed;
        width: 100%;
        height: 100%;
    }
    
    .app-container {
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transition: transform 0.3s ease;
        width: 250px;
        background-color: var(--sidebar-bg);
        z-index: 200; /* Ensure it's above other elements */
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    /* Consistent header styling in mobile */
    .sidebar-header {
        padding: 20px 16px;
        border-bottom: 1px solid var(--border-color);
    }
    
    /* Make suggestion buttons more tappable on mobile */
    .suggestion-btn {
        min-height: 50px; /* Larger tap target */
        padding: 12px 14px;
        margin-bottom: 5px;
    }
    
    .landing-mode {
        width: 85%;
        height: 150px;
        left: 50%; /* Center on mobile without sidebar */
        position: absolute;
        top: 40%;
        transform: translate(-50%, -50%);
    }
    
    /* Prevent scrolling when keyboard appears */
    .landing-mode .chat-input-container {
        position: relative;
        bottom: auto;
        padding: 12px 8px;
    }
    
    /* Adjust for keyboard appearance */
    .landing-mode.keyboard-active {
        transform: translate(-50%, -80%);
        transition: transform 0.3s ease;
    }
    
    /* Fix common iOS input issues */
    input, textarea, button {
        -webkit-appearance: none;
        border-radius: 0;
        font-size: 16px !important; /* Prevent zooming by ensuring font is 16px or larger */
        -webkit-text-size-adjust: 100%;
    }
    
    input[type="text"], 
    input[type="password"], 
    textarea, 
    select { 
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    /* Prevent viewport jumping when keyboard appears */
    @supports (-webkit-touch-callout: none) {
        .landing-mode {
            transform: translate(-50%, -50%) !important;
            position: absolute !important;
        }
        
        .landing-mode.keyboard-active {
            transform: translate(-50%, -70%) !important;
        }
    }
    
    /* Ensure ALL input elements have at least 16px font size to prevent zoom */
    #user-input {
        font-size: 16px !important; /* Must be at least 16px to prevent iOS zoom */
        -webkit-text-size-adjust: none;
    }
    
    .thread-mode {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        height: 100%;
        overflow: hidden; /* Prevent overflow at container level */
        display: flex;
        flex-direction: column;
        padding: 0;
        margin: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    .chat-messages {
        flex: 1;
        padding: 20px 0;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 24px;
        background-color: var(--bg-primary);
        width: 90%;
    }
    
    .thread-mode .chat-input-container {
        width: 100%;
        max-width: 100%;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: var(--bg-secondary);
        z-index: 10;
        padding: 12px 8px;
        overflow: hidden;
        border-top: 1px solid var(--border-color); /* Add border for visual separation */
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05); /* Subtle shadow for depth */
    }
    
    /* Reduce margins for chat containers on mobile */
    .thread-mode .chat-messages {
        padding-left: 1%;
        padding-right: 1%;
        max-width: 100%;
        flex: 1;
        overflow-y: auto; /* Ensure messages are scrollable */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        margin-bottom: 60px; /* Space for the fixed input container */
    }
    
    .thread-mode .input-wrapper {
        padding: 0 8px;
        width: 100%;
        max-width: 100%;
    }
    
    .chat-input-container {
        padding: 12px 8px;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: var(--bg-secondary);
        z-index: 10;
        width: 100%;
        max-width: 100%;
    }
    
    /* Adjust message positioning for mobile */
    .user-message .message-content {
        margin-left: auto;
        margin-right: 10px;
        max-width: 85%;
        border-top-right-radius: 4px;
        border-top-left-radius: 12px;
        border-bottom-right-radius: 12px;
        border-bottom-left-radius: 12px;
    }
    
    .assistant-message .message-content {
        margin-left: 10px;
        margin-right: auto;
        max-width: 100%;
        padding: 0 0 0 5px; /* Add a slight padding on the left */
    }
    
    /* Add mobile toggle button - default light mode styling */
    .mobile-sidebar-toggle {
        display: block;
        position: fixed;
        top: 20px; /* Higher position from top to stay above browser address bar */
        left: 10px;
        z-index: 150;
        background-color: var(--accent-color);
        color: white;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        border: none;
        cursor: pointer;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.2s;
        padding: 0; /* Remove any padding that might affect centering */
    }

    .mobile-sidebar-toggle:active {
        background-color: var(--accent-hover);
        transform: scale(0.95);
    }

    .mobile-sidebar-toggle svg {
        width: 13px; /* Reduced from 14px (10% smaller) */
        height: 13px; /* Reduced from 14px (10% smaller) */
    }

    .source-link {
        width: 100%;
        min-width: 40%;
        max-width: 100%;
    }

    .source-filename {
        max-width: 48%;
    }

    /* .source-item {
        width: 30%;
        min-width: 40px;
    } */

    /* Update the fill color in dark mode */
    @media (prefers-color-scheme: dark) {
        .mobile-sidebar-toggle svg {
            fill: var(--text-primary);
        }
    }

    /* Hide toggle button when sidebar is shown */
    .sidebar.show ~ .mobile-sidebar-toggle {
        opacity: 0;
        pointer-events: none;
    }

    /* Specific override for mobile #user-input */
    #user-input {
        font-size: 16px !important; /* Force 16px to prevent zoom */
        -webkit-text-size-adjust: 100%; /* Prevent text size adjustment */
        padding: 14px; /* Slightly more padding for better touch */
        border-radius: 18px; /* Rounder corners on mobile */
        min-height: 48px; /* Taller input for easier typing */
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* Subtle shadow */
    }
    
    /* Match send button height to input for alignment */
    #send-button {
        width: 48px;
        height: 48px;
    }
    
    /* Add active state feedback for touch interactions */
    .source-link:active, 
    .suggestion-btn:active,
    .settings-item:active {
        background-color: rgba(0, 0, 0, 0.1);
        transform: scale(0.98);
    }
    
    /* Add feedback class that can be toggled via JS for touch */
    .touch-active {
        background-color: rgba(0, 0, 0, 0.05) !important;
        transform: scale(0.98) !important;
    }
    
    /* Fix source items to display 2 per row on mobile */
    .source-item {
        width: 48%; /* Set to 48% width to fit two side by side */
        min-width: unset;
        max-width: 48%;
        margin-bottom: 0.5px;
    }
    
    .sources-list {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 1px;
        justify-content: space-between;
        width: 100%;
    }
    
    .source-link {
        width: 100%;
        min-width: unset;
        max-width: 100%;
        padding: 1px;
        height: 100%;
    }
    
    .source-filename {
        font-size: var(--font-size-small);
        word-break: break-word;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        max-width: 100%;
    }
}

/* Increase width on larger screens */
@media (min-width: 1200px) {
    .thread-mode .chat-messages {
        max-width: 1000px; /* Even wider on large screens */
    }
}

/* Enhanced styling for source citations */
.sources-container {
    margin-top: 16px;
    font-size: var(--font-size-medium);
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

/* Images container styling */
.images-container {
    margin-top: 16px;
    font-size: var(--font-size-medium);
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.images-title {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.images-title::after {
    content: '';
    width: 20px;
    height: 20px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cccccc' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    transition: transform 0.3s ease;
}

.images-container.collapsed .images-title::after {
    transform: rotate(-90deg);
}

.images-container.collapsed .images-list {
    display: none;
}

.images-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 12px;
}

.image-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.related-image {
    max-width: 100%;
    max-height: 50vh; /* 50% of viewport height */
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    object-fit: contain; /* Ensures the image maintains its aspect ratio */
}

.related-image:hover {
    transform: scale(1.02);
}

.image-source {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    font-style: italic;
}

.sources-title {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.sources-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.source-item {
    position: relative;
    line-height: 1.4;
    display: inline-block;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s ease;
    padding: 0;
    width: 30%;
    height: auto;
    min-width: 200px;
    word-wrap: break-word;
    white-space: normal;
}

.source-item:before {
    display: none;
}

.source-link {
    color: var(--text-primary) !important;
    text-decoration: none;
    font-weight: 500;
    padding: 12px;
    font-size: var(--font-size-small);
    display: flex;
    flex-direction: column;
    gap: 4px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s ease;
    width: 100%;
    height: 100%;
    overflow-wrap: break-word;
    cursor: pointer;
}

.source-filename {
    color: #0000EE;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.source-filename::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230000EE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'%3E%3C/path%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'%3E%3C/path%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
}

.source-additional-info {
    color: var(--text-secondary);
    font-size: var(--font-size-x-small);
    font-weight: normal;
}

.source-link:visited {
    color: var(--text-primary) !important;
}

.source-link:hover {
    text-decoration: none;
    background-color: rgba(0, 0, 0, 0.02);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.source-link:active {
    color: var(--text-primary) !important;
    background-color: rgba(0, 0, 0, 0.04);
    transform: translateY(0);
}

/* Loading indicator styles */
.loading-container {
    display: flex;
    align-items: center;
    padding: 24px 16px;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 24px;
    height: 24px;
    margin-right: 12px;
    border: 3px solid rgba(94, 124, 226, 0.2);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s linear infinite;
}

.loading-text {
    font-size: var(--font-size-input);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Adjust for keyboard appearance */
.thread-mode {
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100% - var(--sidebar-width));
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    border-radius: 0;
    box-shadow: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    background-color: var(--bg-primary);
    margin: 0;
    margin-left: var(--sidebar-width);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #121212;
        --bg-secondary: #1e1e1e;
        --text-primary: #e0e0e0;
        --text-secondary: #a0a0a0;
        --accent-color: #808080;
        --accent-hover: #a0a0a0;
        --light-button-color: #707070;
        --darker-button-color: #505050;
        --border-color: #333333;
        --message-user: #2d3748;
        --message-assistant: #1e1e1e;
        --user-accent: #3b5998;
        --assistant-accent: #a0a0a0;
        --sidebar-bg: #1a1a1a;
    }
    
    /* Invert the filter for the send icon in dark mode */
    #send-button .send-icon {
        filter: brightness(2);
    }
    
    /* Adjust the mobile sidebar toggle color for dark mode to match input exactly */
    .mobile-sidebar-toggle {
        background-color: #2a2a2a; /* Match input background color exactly */
        color: var(--text-primary);
        border: 1px solid #444444; /* Match input border color exactly */
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }
    
    .mobile-sidebar-toggle:active {
        background-color: #333333;
    }
    
    /* Ensure input fields have dark background */
    #user-input {
        background-color: #2a2a2a;
        color: var(--text-primary);
        border-color: #444444;
    }
    
    /* Make source links more visible in dark mode */
    .source-filename {
        color: #6b9fff; /* Lighter blue for dark backgrounds */
    }
    
    .source-filename::before {
        filter: none; /* Remove brightness filter */
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b9fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'%3E%3C/path%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'%3E%3C/path%3E%3C/svg%3E");
    }
    
    .source-link {
        background-color: transparent; /* Semi-transparent background */
        backdrop-filter: blur(5px); /* Subtle blur effect for depth */
        -webkit-backdrop-filter: blur(5px); /* For Safari */
        border-color: rgba(68, 68, 68, 0.6);
    }
    
    .source-link:hover {
        background-color: rgba(51, 51, 51, 0.7);
    }
    
    /* Adjust box shadows for dark mode */
    /* .mobile-sidebar-toggle,
    .thread-mode .chat-input-container,
    .landing-mode,
    .settings-dropdown,
    .user-message .message-content,
    #user-input {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    } */
    
    /* Better contrast for user messages */
    .user-message .message-content {
        background-color: var(--message-user);
        color: #f0f0f0;
    }
    
    /* Landing mode background */
    .landing-mode {
        background-color: var(--bg-secondary);
        border: 1px solid var(--border-color);
    }
    
    /* Settings dropdown */
    .settings-dropdown {
        background-color: #2a2a2a;
        border-color: #444444;
    }
    
    /* Chat input container background */
    .chat-input-container {
        background: none;
    }
    
    /* Adjust suggestion buttons for dark mode */
    .suggestion-btn {
        color: var(--text-primary);
    }
    
    .suggestion-btn:hover {
        background-color: rgba(255, 255, 255, 0.08);
    }
    
    .suggestion-btn:active {
        background-color: rgba(255, 255, 255, 0.12);
    }
    
    /* Improve icon visibility */
    .icon {
        filter: brightness(1.2);
    }
    
    /* Improve message dividers */
    .message::after {
        background-color: var(--border-color);
        opacity: 0.3;
    }
    
    /* Adjust source list styling */
    .sources-container,
    .images-container {
        border-top-color: var(--border-color);
    }
    
    /* Loading spinner */
    .loading-spinner {
        border-color: rgba(200, 200, 200, 0.2);
        border-top-color: var(--accent-color);
    }
    
    /* Make additional info text more readable */
    .source-additional-info {
        color: #8a8a8a; /* Slightly brighter than text-secondary for better contrast */
    }
    
    /* Enhance active state feedback */
    .touch-active {
        background-color: rgba(255, 255, 255, 0.1) !important;
    }
    
    /* Sidebar styling */
    .sidebar {
        border-right-color: var(--border-color);
    }
    
    .sidebar-header {
        border-bottom-color: var(--border-color);
    }
    
    /* Improve visibility of dropdown items */
    .settings-item:hover {
        background-color: rgba(255, 255, 255, 0.08);
    }
    
    /* Properly style the chat header */
    .chat-header {
        background-color: var(--bg-secondary);
        border-bottom-color: var(--border-color);
        box-shadow: 0 0.5px 0.5px rgba(0, 0, 0, 0.3);
    }
    
    /* Ensure thread mode has proper background */
    .thread-mode {
        background-color: var(--bg-primary);
    }
    
    /* Improve thread mode input container */
    /* .thread-mode .chat-input-container {
        border-top: 1px solid var(--border-color);
    } */
    
    /* Adding subtle hover effects to links */
    a {
        color: #6b9fff;
    }
    
    a:hover {
        color: #8cb3ff;
    }
    
    /* Fix images container SVG color */
    .images-title::after {
        filter: brightness(0.7);
    }

    /* Mobile-specific transparent source containers */
    @media (max-width: 576px) {
        .source-link {
            background-color: transparent;
            backdrop-filter: none;
            -webkit-backdrop-filter: none;
            border: 1px solid rgba(68, 68, 68, 0.3);
        }
        
        .source-link:hover {
            background-color: rgba(255, 255, 255, 0.05);
        }
    }
}

/* .source-item {
    position: relative;
    line-height: 1.4;
    display: inline-block;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s ease;
    padding: 0;
    width: 30%;
    height: auto;
    min-width: 200px;
    word-wrap: break-word;
    white-space: normal;
} */