:root {
    /* Light Theme (Default) */
    --bg-main: #f3f3f5;
    --bg-sidebar: #ffffff;
    --bg-input: #ffffff;
    --text-main: #1a1a1a;
    --text-secondary: #6e6e73;
    --accent: #10a37f;
    --accent-hover: #0d8a6a;
    --border: #e5e5e7;
    --user-bubble: #ececf1;
    --bot-bubble: transparent;
    --shadow: 0 4px 16px rgba(0,0,0,0.04);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark-theme {
    /* Dark Theme Variables */
    --bg-main: #141416;
    --bg-sidebar: #202022;
    --bg-input: #29292c;
    --text-main: #ececec;
    --text-secondary: #a0a0a5;
    --border: #333336;
    --user-bubble: #2f2f33;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    height: 100dvh;
    overflow: hidden;
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Sidebar Styling */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin: 16px 0 16px 16px;
    height: calc(100dvh - 32px);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    transition: var(--transition);
    z-index: 100;
    box-shadow: var(--shadow);
}

.new-chat-btn {
    background: transparent;
    color: var(--text-main);
    border: 1px solid transparent;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
}

.new-chat-btn:hover {
    background: var(--user-bubble);
}

.sidebar-history {
    flex: 1;
    margin-top: 20px;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
}

.search-container {
    margin-bottom: 15px;
}

.search-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-main);
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--text-main);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--border);
    background: var(--bg-sidebar);
    box-shadow: 0 0 0 2px rgba(16,163,127,0.1);
}

.sidebar-history p.history-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    padding-left: 5px;
}

#chat-list {
    flex: 1;
    overflow-y: auto;
}

/* Chat History List Item */
.history-item {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
}

.history-item:hover {
    background: var(--user-bubble);
}

.history-item.active {
    font-weight: 500;
    background: var(--bg-main);
    border: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

/* Theme Toggle Button */
.sidebar-footer {
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.theme-toggle-btn {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Main Content Layout */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-main);
}

header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-main);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 50;
}

header .header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.model-select {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-main);
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.chat-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

/* Message Styles */
.message {
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
    width: 100%;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-items: flex-end;
}

.message.bot {
    align-items: flex-start;
}

.message.user .bubble {
    background: var(--user-bubble);
    padding: 14px 20px;
    border-radius: 22px;
    border-bottom-right-radius: 6px;
    max-width: 85%;
    font-size: 0.95rem;
    color: var(--text-main);
    display: inline-block;
}

.message.bot .bubble {
    font-size: 1rem;
    color: var(--text-main);
    width: 100%;
}

/* Metadata / Stats Display */
.message-metadata {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 15px;
    display: flex;
    gap: 15px;
    font-weight: 500;
}

.message-metadata span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Thought Container */
.thought-container {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 16px;
    margin: 10px 0 20px 0;
}

.thought-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.thought-content {
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.88rem;
    border-top: 1px dashed var(--border);
    padding-top: 8px;
    margin-top: 4px;
}

/* Markdown Content Styling */
.reply-content p, .thought-content p {
    margin-bottom: 10px;
}

.reply-content p:last-child, .thought-content p:last-child {
    margin-bottom: 0;
}

.reply-content ul, .reply-content ol, .thought-content ul, .thought-content ol {
    margin-bottom: 10px;
    padding-left: 24px;
}

.reply-content li, .thought-content li {
    margin-bottom: 4px;
}

.reply-content table, .thought-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.reply-content th, .reply-content td, .thought-content th, .thought-content td {
    border: 1px solid var(--border);
    padding: 10px 14px;
    text-align: left;
}

.reply-content th, .thought-content th {
    background-color: var(--user-bubble);
    font-weight: 600;
}

.reply-content blockquote, .thought-content blockquote {
    border-left: 4px solid var(--border);
    padding-left: 14px;
    margin-left: 0;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.reply-content h1, .reply-content h2, .reply-content h3, .thought-content h1, .thought-content h2, .thought-content h3 {
    margin-top: 24px;
    margin-bottom: 12px;
    font-weight: 600;
}

/* Code Block Styling */
.message.bot pre {
    background: #1e1e1e;
    border-radius: 12px;
    margin: 16px 0;
    position: relative;
    overflow: hidden;
}

.message.bot pre code {
    display: block;
    padding: 20px;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    overflow-x: auto;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    cursor: pointer;
}

/* Input Area */
.input-container {
    padding: 20px;
    background: linear-gradient(to top, var(--bg-main) 70%, transparent);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 12px;
    display: flex;
    align-items: flex-end;
    box-shadow: var(--shadow);
}

#user-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px;
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    background: transparent;
    color: var(--text-main);
    font-family: inherit;
    line-height: 1.5;
}

#send-btn {
    background: var(--accent);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
}

#send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

footer {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 10px;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
    margin: auto;
    max-width: 800px;
    animation: fadeIn 0.8s ease backwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.welcome-hero {
    text-align: center;
    margin-bottom: 40px;
}

.welcome-avatar {
    width: 64px;
    height: 64px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px auto;
    color: var(--text-main);
    box-shadow: 0 8px 24px rgba(0,0,0,0.04);
}

.welcome-avatar svg {
    width: 32px;
    height: 32px;
}

.welcome-hero h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.welcome-hero p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.suggestions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    width: 100%;
    margin-bottom: 40px;
}

.suggestion-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: 16px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}

.suggestion-card:hover {
    transform: translateY(-2px);
    border-color: var(--border);
    box-shadow: 0 8px 24px rgba(0,0,0,0.06);
    background: var(--bg-main);
}

.sugg-icon {
    font-size: 1.5rem;
    background: var(--bg-main);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.sugg-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    text-align: left;
}

.sugg-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
    margin-bottom: 4px;
}

.sugg-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.welcome-footer {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.welcome-footer .badge {
    padding: 6px 12px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Overlay Styling */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sidebar-mobile-header {
    display: none;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        width: 100%;
        height: 100%;
        margin: 0;
        border-radius: 0;
        background: var(--bg-main);
        box-shadow: none;
        padding-top: 20px;
    }
    .sidebar.active { left: 0; }
    .menu-toggle { display: flex; align-items: center; justify-content: center; cursor: pointer; }
    
    .sidebar-mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
        padding: 0 5px;
    }
    
    .sidebar-mobile-header h3 {
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--text-main);
    }
    
    .close-sidebar-btn {
        background: transparent;
        border: none;
        color: var(--text-secondary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 4px;
    }
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: var(--accent);
    animation: pulse 2s infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Web Search Toggle */
.search-toggle-wrapper {
    max-width: 800px;
    margin: 0 auto 8px auto;
    display: flex;
    justify-content: flex-start;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    user-select: none;
    transition: var(--transition);
}

.toggle-container:hover {
    color: var(--text-main);
}

.toggle-container input {
    display: none;
}

.toggle-checkmark {
    width: 32px;
    height: 18px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    position: relative;
    transition: var(--transition);
}

.toggle-checkmark::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--text-secondary);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: var(--transition);
}

.toggle-container input:checked ~ .toggle-checkmark {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-container input:checked ~ .toggle-checkmark::after {
    background: white;
    transform: translateX(14px);
}

.toggle-container input:checked ~ .toggle-label-text {
    color: var(--accent);
    font-weight: 500;
}

/* Delete Button */
.history-item .delete-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    margin-left: auto;
    transition: var(--transition);
}

.history-item:hover .delete-btn {
    display: block;
}

.history-item .delete-btn:hover {
    color: #ff4d4f;
    background: rgba(255, 77, 79, 0.1);
}

/* Modal Pop-up */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center; justify-content: center;
    opacity: 0; visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1; visibility: visible;
}

.modal-content {
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-content h3 {
    margin-bottom: 10px;
    font-size: 1.2rem;
}

.modal-content p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex; gap: 12px; justify-content: flex-end;
}

.modal-btn {
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.9rem;
    border: none;
    transition: var(--transition);
}

.cancel-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
}
.cancel-btn:hover { background: var(--border); }

.delete-btn-confirm {
    background: #ff4d4f;
    color: white;
}
.delete-btn-confirm:hover { background: #d9363e; }

/* Custom Dropdown */
.custom-dropdown {
    position: relative;
    width: auto;
    min-width: 320px;
    user-select: none;
    font-size: 0.9rem;
    z-index: 1000;
}
.dropdown-selected {
    background: transparent;
    border: 1px solid transparent;
    padding: 8px 14px;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-main);
    transition: var(--transition);
}
.dropdown-selected:hover {
    background: var(--bg-main);
    border-color: var(--border);
}
.dropdown-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
    transition: var(--transition);
}
.custom-dropdown.open .dropdown-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.dropdown-option {
    padding: 10px 14px;
    cursor: pointer;
    color: var(--text-main);
    transition: var(--transition);
    border-bottom: 1px solid var(--bg-main);
}
.dropdown-option:last-child {
    border-bottom: none;
}
.dropdown-option:hover {
    background: var(--bg-main);
}
.dropdown-option.selected {
    color: var(--accent);
    background: var(--bg-main);
}
