:root {
    --bg-body: #f3f4f6;
    --text-color: #1f2937;
    --chat-bg: #ffffff;
    --chat-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    --user-message-bg: linear-gradient(135deg, #3b82f6, #60a5fa);
    --user-message-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
    --bot-message-bg: #f1f5f9;
    --bot-message-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --input-bg: #ffffff;
    --input-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    --input-focus-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    --welcome-gradient: linear-gradient(90deg, #3b82f6, #60a5fa);
    --welcome-shadow: 0 4px 20px rgba(59, 130, 246, 0.15);
    --new-chat-bg: #3b82f6;
    --new-chat-hover: #60a5fa;
    --history-item-bg: #ffffff;
    --history-item-hover: #f1f5f9;
    --history-item-active: #3b82f6;
    --delete-btn-bg: #ef4444;
    --delete-btn-hover: #dc2626;
    --scrollbar-thumb: #9ca3af;
    --scrollbar-thumb-hover: #6b7280;
    --placeholder-color: #6b7280;
    --sidebar-bg: #ffffff;
    --sidebar-text: #1f2937;
}

[data-theme="light"] {
    --bg-body: #f3f4f6;
    --text-color: #1f2937;
    --chat-bg: #ffffff;
    --chat-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    --user-message-bg: linear-gradient(135deg, #3b82f6, #60a5fa);
    --user-message-text: #ffffff;
    --bot-message-bg: #f1f5f9;
    --bot-message-text: #1f2937;
    --input-bg: #ffffff;
    --input-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    --history-item-bg: #ffffff;
    --history-item-hover: #f1f5f9;
    --sidebar-bg: #ffffff;
    --sidebar-text: #1f2937;
}

[data-theme="dark"] {
    --bg-body: #111827;
    --text-color: #f3f4f6;
    --chat-bg: #1f2937;
    --chat-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    --user-message-bg: linear-gradient(135deg, #2563eb, #4b9bff);
    --user-message-text: #f3f4f6;
    --bot-message-bg: #374151;
    --bot-message-text: #f3f4f6;
    --input-bg: #1f2937;
    --input-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    --history-item-bg: #374151;
    --history-item-hover: #4b5563;
    --sidebar-bg: #1f2937;
    --sidebar-text: #f3f4f6;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-body);
    color: var(--text-color);
    min-height: 100vh;
    margin: 0;
    overscroll-behavior: none;
    transition: background 0.3s ease;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

.app-container {
    display: flex;
    min-height: 100vh;
    justify-content: center;
}

.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    transition: left 0.3s ease;
    z-index: 100;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
}

.sidebar.active {
    left: 0;
}

.sidebar-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.sidebar-content {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.sidebar-toggle {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 150;
    background: var(--new-chat-bg);
    color: white;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: var(--new-chat-hover);
    transform: scale(1.05);
}

.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    max-width: 960px;
    width: calc(100% - 280px);
    margin: 0 auto 0 280px;
    transition: margin-left 0.3s ease, width 0.3s ease;
    min-height: 100vh;
    padding-bottom: 80px;
    z-index: 50;
}

.chat-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--chat-bg);
    border-radius: 12px;
    margin: 0;
    box-shadow: var(--chat-shadow);
    position: fixed;
    bottom: 80px;
    left: calc(50% + 140px);
    transform: translateX(-50%);
    width: calc(100% - 280px);
    max-width: 960px;
    height: calc(100vh - 80px);
    z-index: 60;
    padding-bottom: 80px; /* Ensure space for input */
}

.welcome-section {
    text-align: center;
    padding: 2rem 1rem;
    animation: slideIn 0.5s ease-out;
}

.welcome-header {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--welcome-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-subheader {
    font-size: 0.875rem;
    color: var(--placeholder-color);
    margin-top: 0.5rem;
}

.message {
    max-width: 85%;
    margin: 0.75rem 1rem;
    padding: 0.8rem 1.2rem;
    border-radius: 20px;
    line-height: 1.6;
    font-size: 0.95rem;
    position: relative;
    box-shadow: var(--user-message-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.message:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.user-message {
    background: var(--user-message-bg);
    color: var(--user-message-text);
    margin-left: auto;
    border-bottom-right-radius: 6px;
}

.bot-message {
    background: var(--bot-message-bg);
    color: var(--bot-message-text);
    margin-right: auto;
    border-bottom-left-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.fade-in {
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-history {
    flex-grow: 1;
    overflow-y: auto;
}

.history-dropdown-content {
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
}

.new-chat-btn, .theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--new-chat-bg);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 500;
}

.new-chat-btn:hover, .theme-toggle:hover {
    background: var(--new-chat-hover);
}

.chat-history-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-radius: 6px;
    margin: 0.25rem 0;
    background: var(--history-item-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--sidebar-text);
}

.chat-history-item:hover {
    background: var(--history-item-hover);
}

.chat-history-item.active {
    background: var(--history-item-active);
    color: white;
}

.delete-btn {
    opacity: 0;
    padding: 0.5rem;
    border-radius: 50%;
    background: var(--delete-btn-bg);
    transition: all 0.2s ease;
}

.chat-history-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: var(--delete-btn-hover);
}

.input-container {
    position: fixed;
    bottom: 0;
    left: calc(50% + 140px);
    transform: translateX(-50%);
    padding: 0.75rem 1rem;
    background: var(--chat-bg);
    z-index: 70;
    width: calc(100% - 280px);
    max-width: 960px;
    display: flex;
    border-radius: 12px;
    justify-content: center;
    box-sizing: border-box;
    min-height: 56px;
    max-height: 120px;
}

.input-wrapper {
    width: 100%;
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    box-shadow: var(--input-shadow);
    transition: all 0.3s ease;
}

.input-wrapper:focus-within {
    box-shadow: var(--input-focus-shadow);
}

#queryInput {
    color: var(--text-color);
    background: transparent;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    outline: none;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
    min-height: 40px;
    max-height: 100px;
}

#queryInput::placeholder {
    color: var(--placeholder-color);
}

.submit-btn {
    background: var(--new-chat-bg);
    color: white;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
}

.submit-btn:hover {
    background: var(--new-chat-hover);
}

.chat-loading {
    display: flex;
    justify-content: center;
    padding: 0.75rem;
    position: fixed;
    bottom: 5rem;
    left: calc(50% + 140px);
    transform: translateX(-50%);
    width: calc(100% - 280px);
    max-width: 960px;
    z-index: 70;
}

.dot {
    width: 8px;
    height: 8px;
    background: var(--new-chat-bg);
    border-radius: 50%;
    margin: 0 4px;
    animation: bounce 0.4s infinite alternate;
}

.dot:nth-child(2) {
    animation-delay: 0.15s;
}

.dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-5px); }
}

@media (min-width: 769px) {
    .sidebar {
        left: 0;
        width: 280px;
    }
    .main-content {
        margin-left: 280px;
        width: calc(100% - 280px);
    }
    .input-container, .chat-loading, .chat-container {
        width: calc(100% - 280px);
        max-width: 960px;
        left: calc(50% + 140px);
        transform: translateX(-50%);
    }
    .input-wrapper {
        width: calc(100% - 2rem);
    }
    .sidebar-toggle {
        display: none;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 260px;
        left: -260px;
        background: var(--sidebar-bg);
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
        border-right: 1px solid rgba(0, 0, 0, 0.1);
        z-index: 100;
    }
    .sidebar.active {
        left: 0;
    }
    .sidebar-header {
        padding: 1rem;
    }
    .header-title {
        font-size: 1.25rem;
        font-weight: 600;
    }
    .sidebar-content {
        padding: 0.75rem;
        gap: 0.5rem;
    }
    .new-chat-btn, .theme-toggle {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
        border-radius: 6px;
    }
    .chat-history-item {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
        border-radius: 6px;
    }
    .main-content {
        margin-left: 0;
        width: 100%;
        z-index: 50;
    }
    .input-container, .chat-loading, .chat-container {
        width: 100%;
        max-width: none;
        left: 50%;
        transform: translateX(-50%);
    }
    .input-container {
        z-index: 70;
        padding: 0.5rem;
        background: var(--chat-bg);
        border-radius: 10px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    .input-wrapper {
        width: 100%;
        border-radius: 8px;
        padding: 0.5rem;
        box-shadow: none;
    }
    .chat-container {
        bottom: 64px;
        height: calc(100vh - 64px);
        border-radius: 0;
        margin: 0;
        padding: 0.75rem;
        z-index: 60;
        background: var(--chat-bg);
        padding-bottom: 80px; /* Ensure space for input */
    }
    .welcome-section {
        padding: 1.5rem 0.75rem;
    }
    .welcome-header {
        font-size: 1.25rem;
    }
    .welcome-subheader {
        font-size: 0.75rem;
    }
    .message {
        max-width: 88%;
        font-size: 0.875rem;
        padding: 0.6rem 1rem;
        border-radius: 16px;
        margin: 0.5rem 0.75rem;
        transition: all 0.3s ease;
        animation: slideUp 0.4s ease-out;
    }
    .user-message {
        border-bottom-right-radius: 4px;
        background: var(--user-message-bg);
        color: var(--user-message-text);
    }
    .bot-message {
        border-bottom-left-radius: 4px;
        background: var(--bot-message-bg);
        color: var(--bot-message-text);
        border: none;
    }
    .submit-btn {
        width: 36px;
        height: 36px;
        background: var(--new-chat-bg);
    }
    #queryInput {
        font-size: 0.875rem;
        min-height: 36px;
        max-height: 80px;
        padding: 0.5rem;
        color: var(--text-color);
    }
    .chat-loading {
        bottom: 4.5rem;
        z-index: 70;
    }
    @keyframes slideUp {
        from { opacity: 0; transform: translateY(20px); }
        to { opacity: 1; transform: translateY(0); }
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 240px;
        left: -240px;
        z-index: 100;
    }
    .sidebar-header {
        padding: 0.75rem;
    }
    .header-title {
        font-size: 1.125rem;
    }
    .sidebar-content {
        padding: 0.5rem;
    }
    .new-chat-btn, .theme-toggle {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }
    .chat-history-item {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }
    .main-content {
        margin-left: 0;
        width: 100%;
        z-index: 50;
    }
    .input-container {
        padding: 0.5rem;
        min-height: 56px;
        z-index: 70;
    }
    .chat-container {
        padding: 0.5rem;
        height: calc(100vh - 64px);
        bottom: 64px;
        z-index: 60;
        padding-bottom: 80px; /* Ensure space for input */
    }
    .message {
        max-width: 90%;
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
        border-radius: 14px;
    }
    .welcome-header {
        font-size: 1.125rem;
    }
    .welcome-subheader {
        font-size: 0.7rem;
    }
}