:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --background: #ffffff;
    --surface: #f8fafc;
    --sidebar-bg: #f1f5f9;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --success: #10b981;
    --error: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 0.75rem;
    --radius-sm: 0.5rem;
    --grad-primary: linear-gradient(135deg,#2563eb,#1d4ed8);
    --chip-bg: var(--surface);
    --citation-bg: #eef2ff;
    --citation-border: #c7d2fe;
}

/* Dark theme overrides */
body.dark-theme {
    --background: #0f172a;
    --surface: #1e293b;
    --sidebar-bg: #1e293b;
    --border: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --chip-bg: #243248;
    --citation-bg: #1e3a8a;
    --citation-border: #1d4ed8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, color .2s;
}
.theme-toggle:hover { background: var(--primary); color:#fff; }

.close-sidebar {
    display: none;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 1;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Profile Section */
.profile-section {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--background);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.profile-image-container {
    text-align: center;
    margin-bottom: 1rem;
}

.profile-image {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary);
    box-shadow: var(--shadow-md);
    margin-bottom: 0.75rem;
}

.profile-caption {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.profile-info {
    text-align: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.profile-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.25rem 0;
}

.profile-subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0 0 0.5rem 0;
}

.profile-location {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

/* Social Links */
.social-links {
    padding-top: 0.5rem;
}

.social-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 0.75rem 0;
    text-align: center;
}

.social-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.social-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
    cursor: pointer;
    text-decoration: none;
}

.social-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.sidebar-content

.new-chat-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    transition: all 0.2s;
    margin-bottom: 1rem;
}

.new-chat-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.chat-history-actions { padding: 0.5rem 0.25rem; }
.clear-all-btn { width:100%; background: var(--surface); color: var(--text-secondary); border:1px solid var(--border); border-radius: var(--radius-sm); padding:0.5rem 0.75rem; font-size:0.7rem; cursor:pointer; transition:background .15s, color .15s; text-transform: uppercase; letter-spacing: .5px; }
.clear-all-btn:hover { background: var(--primary); color:#fff; }
.secondary-action-btn { width:100%; margin-top:0.25rem; background: var(--surface); color: var(--text-muted); border:1px solid var(--border); border-radius: var(--radius-sm); padding:0.4rem 0.6rem; font-size:0.65rem; cursor:pointer; transition:background .15s, color .15s; text-transform: uppercase; letter-spacing: .5px; }
.secondary-action-btn:hover { background: var(--primary-hover); color:#fff; }

.chat-item {
    padding: 0.75rem;
    background: var(--background);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}
.chat-item .delete-conv-btn { position:absolute; top:4px; right:4px; font-size:10px; background:transparent; border:none; color:var(--text-muted); cursor:pointer; padding:2px 4px; }
.chat-item .delete-conv-btn:hover { color:var(--primary); }
/* Improved visibility for delete button */
.chat-item .delete-conv-btn { font-size:12px; padding:4px 8px; border-radius:4px; background: var(--error); color:#fff; border:1px solid var(--error); font-weight:600; }
.chat-item .delete-conv-btn:hover { background:#b91c1c; border-color:#b91c1c; }

.chat-item:hover {
    border-color: var(--primary);
    background: white;
}

.chat-item.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.chat-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.chat-item.active .chat-item-time {
    color: rgba(255, 255, 255, 0.8);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.user-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s ease-in-out infinite;
}

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

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mobile-header {
    display: none;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    align-items: center;
    gap: 1rem;
    background: var(--surface);
}

.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.sidebar-toggle:hover {
    background: var(--border);
}

.mobile-header h1 {
    font-size: 1.125rem;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-content {
    max-width: 48rem;
    text-align: center;
}

.welcome-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.welcome-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}

.chip {
    padding: 0.75rem 1.25rem;
    background: var(--chip-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.chip:hover {
    border-color: var(--primary);
    background: white;
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
body.dark-theme .chip:hover { background: var(--primary); color:#fff; }

/* Messages */
.messages {
    padding: 2rem 1rem;
    max-width: 48rem;
    margin: 0 auto;
    width: 100%;
}

.message {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

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

.message-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
}

.message.user .message-avatar {
    background: var(--primary);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--success);
    color: white;
}

.message-role {
    font-weight: 600;
    font-size: 0.875rem;
}

.message-content {
    margin-left: 2.5rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-content p {
    margin-bottom: 0.75rem;
}

.message-content pre {
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 1rem 0;
}

.message-content code {
    background: var(--surface);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

/* Input Area */
.input-area {
    padding: 1rem;
    border-top: 1px solid var(--border);
    background: var(--background);
}

.input-container {
    max-width: 48rem;
    margin: 0 auto;
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9375rem;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
    transition: border-color 0.2s;
}

.message-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.send-btn {
    padding: 0.875rem 1.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Settings Button */
.settings-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 50;
}

.settings-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 1.25rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9375rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group small {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.form-group small a {
    color: var(--primary);
    text-decoration: none;
}

.form-group small a:hover {
    text-decoration: underline;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

.btn-primary,
.btn-secondary {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 0.9375rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
    }

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

    .close-sidebar {
        display: block;
    }

    .mobile-header {
        display: flex;
    }

    .welcome-title {
        font-size: 1.75rem;
    }

    .welcome-subtitle {
        font-size: 1rem;
    }

    .settings-btn {
        bottom: 5rem;
    }

    .messages {
        padding: 1rem;
    }

    .message-content {
        margin-left: 0;
        margin-top: 0.5rem;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Progress Bar */
.index-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 4px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    z-index: 300;
}
.index-progress .bar {
    height: 6px;
    background: var(--border);
    flex: 1;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}
.index-progress .bar::after {
    content: "";
    position: absolute;
    top:0; left:0;
    height:100%;
    width:0%;
    background: var(--grad-primary);
    transition: width .25s ease;
}
.index-progress.complete { display:none; }
.index-progress .label { white-space: nowrap; color: var(--text-secondary); }

/* Mode badge */
.mode-badge {
    position: fixed;
    top: 10px;
    right: 12px;
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    z-index: 310;
    display: flex;
    align-items: center;
    gap: 6px;
}
.mode-badge.local { color: var(--success); }
.mode-badge.hybrid { color: var(--primary); }

/* Citation chips */
.citation-chips { display:flex; flex-wrap:wrap; gap:6px; margin: 8px 0 0 2.5rem; }
.citation-chip { font-size:11px; padding:4px 8px; background: var(--citation-bg); color: var(--text-secondary); border:1px solid var(--citation-border); border-radius: 6px; cursor:pointer; transition: background .2s,color .2s; text-decoration:none; display:inline-flex; align-items:center; gap:4px; }
.citation-chip:hover { background: var(--primary); color:#fff; }
body.dark-theme .citation-chip { background: var(--chip-bg); border-color: var(--border); }
body.dark-theme .citation-chip:hover { background: var(--primary); }
.citation-global { max-width:48rem; margin:0 auto; padding:0 1rem 1rem; }

@media (max-width:768px){
    .mode-badge { top: 54px; }
    .index-progress { font-size:11px; }
    .citation-chips { margin-left:0; }
}
