/* frontend/styles.css - COMPLETE FINAL VERSION */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root{
    --bg: #ffffff;
    --panel: #f7f7f8;
    --border: #e5e5e5;
    --text: #1a1a1a;
    --muted: #8e8e93;
    --accent: #6366f1;
    --danger: #e5484d;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--bg);
    height: 100vh;
    overflow: hidden;
    color: var(--text);
}

/* ============ APP LAYOUT ============ */
.app {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* ============ SIDEBAR ============ */
.sidebar {
    width: 280px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #d9d9e3;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #2c2c2e;
    cursor: pointer;
    transition: all 0.2s ease;
}
.new-chat-btn:hover {
    background: var(--panel);
    border-color: #c5c5d2;
}
.new-chat-btn svg { flex-shrink: 0; }

/* Search Section */
.search-section {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    position: relative;
    flex-shrink: 0;
}
.search-box {
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
    gap: 8px;
}
.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}
.search-icon { flex-shrink: 0; color: var(--muted); }

#search-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: 13px;
}

.clear-search {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 16px;
    padding: 0 4px;
}
.clear-search:hover { color: var(--danger); }

.search-results {
    position: absolute;
    top: 100%;
    left: 8px;
    right: 8px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 350px;
    overflow-y: auto;
    z-index: 100;
    margin-top: 4px;
}
.search-results.hidden { display: none; }

.search-header, .search-empty, .search-error{
    padding: 10px 12px;
    font-size: 12px;
    color: #475569;
    border-bottom: 1px solid #f1f5f9;
}
.search-result-item{
    padding: 10px 12px;
    cursor: pointer;
}
.search-result-item:hover{ background: #f7f7f8; }
.result-title{ font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.result-preview{ font-size: 12px; color: #475569; margin-bottom: 6px; }
.result-meta{ font-size: 11px; color: var(--muted); display: flex; gap: 12px; }

/* Recents Section */
.recents-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
    min-height: 0;
}

.recents-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin: 0 0 8px 8px;
    padding: 0 4px;
}

.recents-subheader {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin: 12px 0 6px 8px;
    padding: 0 4px;
}

/* Conversation Item */
.conversation-item {
    padding: 10px 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
    position: relative;
}
.conversation-item:hover { background: #efefef; }
.conversation-item.active { background: #e6e6ea; }

.conversation-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.conversation-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 500;
}

.conversation-time {
    font-size: 10px;
    color: var(--muted);
    margin-top: 2px;
}

/* 3-dot menu */
.conv-menu-container { position: relative; flex-shrink: 0; }

.conv-menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    transition: all 0.2s;
    opacity: 0;
}
.conversation-item:hover .conv-menu-btn { opacity: 1; }
.conv-menu-btn:hover { background: #e5e5e5; color: var(--text); }

/* Dropdown opens upward */
.conv-dropdown {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 140px;
    z-index: 1000;
    overflow: hidden;
    margin-bottom: 8px;
}
.conv-dropdown.hidden { display: none; }

.conv-dropdown-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.conv-dropdown-item:hover { background: var(--panel); }
.conv-dropdown-item.delete-item { color: var(--danger); }
.conv-dropdown-item.delete-item:hover { background: #fee2e2; }

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--panel);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: 10px;
    margin-bottom: 8px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    font-size: 16px;
    flex-shrink: 0;
}

.user-details { flex: 1; min-width: 0; }
.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-id {
    font-size: 10px;
    color: var(--muted);
    margin-top: 2px;
}

/* ============ API KEY SECTION ============ */
.api-key-section {
    margin-bottom: 12px;
    padding: 0 4px;
}

.api-key-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: #f0f0f4;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    color: #2c2c2e;
    cursor: pointer;
    transition: all 0.2s;
}

.api-key-btn:hover {
    background: #e8e8ef;
    border-color: #c5c5d2;
}

/* ============ ADMIN LINKS SECTION ============ */
.admin-links {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.admin-links.hidden {
    display: none;
}

.admin-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin-bottom: 10px;
    padding: 0 4px;
}

.dashboard-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    border-radius: 8px;
    margin-bottom: 5px;
    transition: all 0.2s;
}

.dashboard-link:hover {
    background: #f0f0f4;
    color: #4f46e5;
}

/* Export Section */
.export-section { padding: 8px 0; position: relative; }

.export-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: #f0f0f4;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    color: #2c2c2e;
    cursor: pointer;
    transition: all 0.2s;
}
.export-btn:hover { background: #e8e8ef; border-color: #c5c5d2; }

.export-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    overflow: hidden;
    margin-bottom: 8px;
}
.export-dropdown.hidden { display: none; }

.export-option {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    text-align: center;
}
.export-option:hover { background: var(--panel); }
.export-option:first-child { border-bottom: 1px solid var(--border); }

/* Feedback Badge */
.feedback-badge {
    margin-top: 8px;
    padding: 6px 10px;
    background: #10b981;
    color: white;
    border-radius: 20px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.badge-icon { font-size: 12px; }
#feedback-total { font-weight: 600; }

/* ============ MAIN CHAT ============ */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
}

.main-header {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #2c2c2e;
}

.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1180px;
    margin: 0 auto;
    width: 100%;
    padding: 0 32px;
    overflow: hidden;
}

.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    border: none;
    background: transparent;
}

/* ============ MESSAGE STYLES ============ */
.message {
    margin-bottom: 28px;
    display: flex;
    position: relative;
}

.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    margin-right: 12px;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    order: 2;
    margin-right: 0;
    margin-left: 12px;
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, #111827 0%, #2563eb 100%);
    color: white;
}

.message-content {
    max-width: 80%;
    flex: 1;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}

.message-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.message-time {
    font-size: 10px;
    color: var(--muted);
}

.message-body {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
}

.message.user .message-body {
    background: #f0f0f4;
    padding: 12px 18px;
    border-radius: 20px;
    color: var(--text);
}

.message.assistant .message-body {
    background: transparent;
    padding: 0;
}

/* Answer formatting */
.message-body p {
    margin-bottom: 1em;
}

.message-body p:last-child {
    margin-bottom: 0;
}

.message-body h1, .message-body h2, .message-body h3 {
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-weight: 600;
}

.message-body h2 {
    font-size: 1.3em;
    border-bottom: 1px solid #e5e5e5;
    padding-bottom: 0.3em;
}

.message-body h3 {
    font-size: 1.1em;
}

.message-body ul, .message-body ol {
    margin: 0.8em 0;
    padding-left: 1.5em;
}

.message-body li {
    margin: 0.3em 0;
}

.message-body code {
    background: #f0f0f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.message-body pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1em 0;
}

.message-body a {
    color: #6366f1;
    text-decoration: none;
}

.message-body a:hover {
    text-decoration: underline;
}

/* Citation styling */
.citation {
    display: inline-block;
    background: #e8e8ef;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 11px;
    margin: 0 2px;
}

/* Citations Section */
.citations-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e9e9ef;
}

.citations-summary {
    font-size: 12px;
    font-weight: 500;
    color: #6c6c6e;
    cursor: pointer;
    margin-bottom: 8px;
}

.citations-list {
    list-style: none;
    padding-left: 0;
    font-size: 12px;
}

.citations-list li {
    margin: 6px 0;
    padding-left: 20px;
    position: relative;
}

.citations-list li:before {
    content: "📄";
    position: absolute;
    left: 0;
}

/* Follow-ups Section */
.followups-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e9e9ef;
}

.followups-title {
    font-size: 12px;
    font-weight: 500;
    color: #6c6c6e;
    margin-bottom: 10px;
}

.followups-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.followup-button {
    background: #f0f0f4;
    border: 1px solid #e5e5e5;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.followup-button:hover {
    background: #e8e8ef;
    transform: translateY(-1px);
}

/* Images Section */
.images-section {
    margin-top: 16px;
}

.images-title {
    font-size: 12px;
    font-weight: 500;
    color: #6c6c6e;
    margin-bottom: 10px;
}

.images-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.image-card {
    width: 120px;
    cursor: pointer;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s;
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.image-card img {
    width: 100%;
    height: 80px;
    object-fit: cover;
}

.image-caption {
    font-size: 10px;
    padding: 6px;
    color: #666;
    text-align: center;
    word-break: break-word;
}

/* Confidence Badge */
.confidence-badge {
    display: inline-block;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 16px;
    background: #f0f0f4;
    margin-bottom: 12px;
}

/* Reasoning Trace Section */
.reasoning-trace-section {
    margin-top: 16px;
    border-top: 1px solid #e9e9ef;
    padding-top: 12px;
}

.reasoning-toggle {
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 16px;
    background: #f0f0f4;
}

.reasoning-body {
    margin-top: 10px;
    padding: 12px;
    background: #fafbfc;
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    color: #4a5568;
}

.reasoning-body.hidden {
    display: none;
}

/* Thinking Section */
.thinking-section {
    margin-top: 16px;
    border-top: 1px solid #e9e9ef;
    padding-top: 12px;
}

.thinking-toggle {
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 16px;
    background: #f0f0f4;
}

.thinking-body {
    margin-top: 10px;
    padding: 12px;
    background: #fafbfc;
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    color: #4a5568;
}

.thinking-body.hidden {
    display: none;
}

/* Classification Info */
.classification-info {
    margin-top: 12px;
}

.classification-toggle {
    font-size: 11px;
    color: #8b5cf6;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 12px;
    background: #f3e8ff;
}

.classification-body {
    margin-top: 8px;
    padding: 10px;
    background: #faf5ff;
    border-radius: 8px;
    font-size: 12px;
}

.classification-body.hidden {
    display: none;
}

.classification-detail {
    margin-bottom: 8px;
}

.semantic-scores {
    font-size: 11px;
    color: #6b7280;
}

/* Retrieval Info */
.retrieval-info {
    margin-top: 12px;
}

.retrieval-toggle {
    font-size: 11px;
    color: #10b981;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 12px;
    background: #d1fae5;
}

.retrieval-body {
    margin-top: 8px;
    padding: 10px;
    background: #ecfdf5;
    border-radius: 8px;
    font-size: 12px;
}

.retrieval-body.hidden {
    display: none;
}

.retrieval-detail {
    margin-bottom: 6px;
}

/* Feedback Actions */
.feedback-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.feedback-btn {
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 20px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.feedback-btn:hover {
    background: #f8fafc;
    transform: scale(1.02);
}

.feedback-thanks {
    font-size: 12px;
    color: #10b981;
}

/* ============ INPUT AREA ============ */
.input-container {
    padding: 16px 0 24px;
    border-top: 1px solid var(--border);
}

.upload-area {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.attach-btn {
    padding: 6px 12px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.attach-btn:hover { background: #e0e0e0; }

.clear-btn {
    padding: 6px 12px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.clear-btn:hover { background: #5a6268; }

.mode-area {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.95em;
}

#mode-select {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 6px 10px;
    background: #fff;
    color: #333;
    font-family: inherit;
}

#image-name {
    font-size: 0.9em;
    color: #555;
}

.input-area {
    display: flex;
    gap: 12px;
    position: relative;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 15px;
    outline: none;
}

#message-input:focus {
    border-color: #c5c5d2;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#send-button {
    padding: 10px 24px;
    background: var(--text);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}
#send-button:hover { background: #333333; }
#send-button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Stop Generation Button */
.stop-generation-btn {
    position: absolute;
    right: 100px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--danger);
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}
.stop-generation-btn.visible { display: flex; }
.stop-generation-btn:hover { background: #c73a3f; transform: translateY(-50%) scale(1.05); }
.stop-generation-btn svg { width: 16px; height: 16px; color: white; }

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--panel);
    border-radius: 20px;
    margin: 8px 0;
    width: fit-content;
}
.typing-dots { display: flex; gap: 4px; }
.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--muted);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

.typing-text { font-size: 13px; color: #6c6c6e; }

/* ============ CODE BLOCKS ============ */
pre {
    position: relative;
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}
code {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
}
.inline-code {
    background: #f0f0f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
    color: var(--danger);
}
.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #3c3c3c;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}
pre:hover .copy-code-btn { opacity: 1; }
.copy-code-btn:hover { background: #505050; }

/* ============ IMAGE MODAL ============ */
.image-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-content-container {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.image-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10001;
    background: rgba(0,0,0,0.5);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}
.image-modal-close:hover {
    color: #ccc;
    background: rgba(0,0,0,0.8);
}

.image-zoom-controls {
    position: absolute;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    background: rgba(0,0,0,0.7);
    padding: 8px 15px;
    border-radius: 30px;
    z-index: 10001;
}

.zoom-btn {
    background: #333;
    color: white;
    border: none;
    padding: 5px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}
.zoom-btn:hover { background: #555; }

.image-modal-wrapper {
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 90vw;
    max-height: 80vh;
}
.image-modal-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    transition: transform 0.1s ease;
    cursor: grab;
}
.image-modal-img:active { cursor: grabbing; }

.image-modal-caption {
    margin-top: 15px;
    text-align: center;
    color: white;
    max-width: 80vw;
}
.image-modal-title { font-size: 14px; font-weight: 500; margin-bottom: 5px; }
.image-modal-source { font-size: 12px; color: #aaa; }

/* ============ WELCOME SCREEN ============ */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 500px;
    text-align: center;
    padding: 40px 20px;
    max-width: 800px;
    margin: 0 auto;
}
.welcome-greeting {
    font-size: 18px;
    font-weight: 400;
    color: #6c6c6e;
    margin-bottom: 12px;
}
.welcome-screen h1 {
    font-size: 36px;
    font-weight: 600;
    letter-spacing: -0.5px;
    color: var(--text);
}

.suggested-questions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 32px;
    max-width: 700px;
}
.suggestion-btn {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 40px;
    padding: 10px 20px;
    font-size: 14px;
    color: #2c2c2e;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}
.suggestion-btn:hover {
    background: #efefef;
    border-color: #c5c5d2;
    transform: translateY(-1px);
}

.welcome-tip {
    margin-top: 40px;
    font-size: 13px;
    color: var(--muted);
    background: var(--panel);
    padding: 10px 20px;
    border-radius: 30px;
    display: inline-block;
}

/* ============ MODAL ============ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}
.modal.hidden { display: none; }

.modal-card {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
    text-align: center;
}
.modal-icon { font-size: 48px; margin-bottom: 16px; }
.modal-card h2 { margin-bottom: 8px; font-size: 24px; }
.modal-card p { color: #6c6c6e; margin-bottom: 24px; }

.modal-card input,
.modal-card textarea,
.modal-card select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    margin-bottom: 16px;
    font-family: inherit;
}
.modal-card input:focus,
.modal-card textarea:focus,
.modal-card select:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-card label {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
    text-align: left;
}

.modal-card input[type="password"] {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    font-size: 14px;
    width: 100%;
}

.modal-card input[type="password"]:focus {
    outline: none;
    border-color: var(--accent);
}

.remember-me {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
    text-align: left;
}
.remember-me input {
    width: auto;
    margin-bottom: 0;
}

.btn-primary {
    background: var(--text);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
}
.btn-primary:hover { background: #333333; }

.btn-muted {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #1e293b;
    padding: 8px 16px;
    border-radius: 24px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

/* ============ CONTEXT MENU ============ */
.context-menu {
    position: fixed;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 140px;
    overflow: hidden;
}
.context-menu.hidden { display: none; }

.context-menu-item {
    padding: 8px 12px;
    font-size: 13px;
    color: #2c2c2e;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}
.context-menu-item:hover { background: var(--panel); }
.context-menu-item svg { opacity: 0.7; }

/* ============ TOAST ============ */
.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    background: #0f172a;
    color: #fff;
    padding: 10px 20px;
    border-radius: 24px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: 1100;
    max-width: 70vw;
    font-size: 13px;
}
.toast.hidden { display: none; }

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: #d0d0d8; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b0b0b8; }

/* ============ UTILITY ============ */
.hidden { display: none !important; }

/* ============ RESPONSIVE ============ */
@media (max-width: 600px) {
    .sidebar { width: 260px; }
    .welcome-screen h1 { font-size: 28px; }
    .welcome-greeting { font-size: 16px; }
    .suggested-questions { gap: 8px; }
    .suggestion-btn { padding: 8px 16px; font-size: 12px; }
    .images-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
    .image-card { width: 100px; }
    .image-card img { height: 70px; }
}
/* Enhanced Image Preview Styles */
.image-preview {
    margin-bottom: 12px;
    display: inline-block;
}

.image-preview.hidden {
    display: none;
}

.image-preview-container {
    position: relative;
    display: inline-block;
}

.image-preview-container img {
    max-width: 80px;
    max-height: 80px;
    border-radius: 8px;
    border: 2px solid var(--accent);
    object-fit: cover;
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.remove-image-btn:hover {
    transform: scale(1.1);
    background: #ff6b6b;
}

/* Image name display */
.image-name {
    font-size: 12px;
    color: var(--muted);
    margin-top: 8px;
    padding: 4px 8px;
    background: var(--panel);
    border-radius: 6px;
    display: inline-block;
}

.image-name.hidden {
    display: none;
}

.clear-image-btn {
    margin-left: 8px;
    padding: 2px 8px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}

.clear-image-btn.hidden {
    display: none;
}
/* Add these styles at the end of your styles.css */

/* Better thinking trace styling */
.thinking-content {
    font-size: 14px;
    line-height: 1.6;
    color: #4a5568;
}

.thinking-content strong {
    color: #6366f1;
}

.thinking-content p {
    margin-bottom: 12px;
}

/* Better answer formatting */
.message-body ul, .message-body ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-body li {
    margin: 6px 0;
    line-height: 1.5;
}

.message-body strong {
    color: #1a1a1a;
    font-weight: 600;
}

.message-body h2 {
    font-size: 1.3em;
    margin-top: 20px;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid #e5e5e5;
}

.message-body h3 {
    font-size: 1.1em;
    margin-top: 16px;
    margin-bottom: 8px;
    color: #2c3e50;
}

/* Better code blocks */
.code-block {
    position: relative;
    margin: 16px 0;
}

.code-block pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
}

.code-block code {
    font-family: 'Consolas', 'Monaco', monospace;
}

/* Better citations */
.citation {
    display: inline-block;
    background: #e8e8ef;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    margin: 0 2px;
    color: #6366f1;
}

/* Reasoning section improvements */
.reasoning-section {
    margin-bottom: 16px;
}

.reasoning-toggle {
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 16px;
    background: #f0f0f4;
    transition: all 0.2s;
}

.reasoning-toggle:hover {
    background: #e8e8ef;
}

.reasoning-body {
    margin-top: 10px;
    padding: 12px;
    background: #fafbfc;
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    color: #4a5568;
}

.reasoning-body.hidden {
    display: none;
}

/* Image section improvements */
.images-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e9e9ef;
}

.images-title {
    font-size: 12px;
    font-weight: 500;
    color: #6c6c6e;
    margin-bottom: 10px;
}

.images-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.image-card {
    width: 120px;
    cursor: pointer;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.image-card img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    background: #f5f5f5;
}

.image-caption {
    font-size: 10px;
    padding: 6px;
    color: #666;
    text-align: center;
    word-break: break-word;
    line-height: 1.3;
}

/* Follow-ups improvements */
.followups-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e9e9ef;
}

.followups-title {
    font-size: 12px;
    font-weight: 500;
    color: #6c6c6e;
    margin-bottom: 10px;
}

.followups-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.followup-button {
    background: #f0f0f4;
    border: 1px solid #e5e5e5;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.followup-button:hover {
    background: #e8e8ef;
    transform: translateY(-1px);
}  
/* Upload Documents Section */
.upload-section {
    margin: 8px 0;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

.upload-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.2s;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

.upload-header:hover {
    background: #efefef;
}

.upload-icon {
    font-size: 16px;
}

.collapse-icon {
    margin-left: auto;
    font-size: 12px;
    transition: transform 0.2s;
    color: var(--muted);
}

.upload-header.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.upload-content {
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 500px;
}

.upload-content.collapsed {
    max-height: 0;
}

.upload-area-dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafbfc;
    margin: 8px;
}

.upload-area-dropzone:hover {
    border-color: var(--accent);
    background: #f0f4ff;
}

.upload-area-dropzone.drag-over {
    border-color: var(--accent);
    background: #e8edff;
}

.upload-icon-large {
    font-size: 32px;
    margin-bottom: 8px;
}

.upload-text {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 4px;
}

.upload-hint {
    font-size: 11px;
    color: var(--muted);
}

.upload-progress {
    margin: 12px;
    padding: 12px;
    background: #f0f0f4;
    border-radius: 8px;
}

.progress-bar {
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
}

.progress-status {
    font-size: 12px;
    color: var(--text);
    margin-top: 8px;
    text-align: center;
}

.upload-status {
    margin: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
}

.upload-status.success {
    background: #d1fae5;
    color: #065f46;
}

.upload-status.error {
    background: #fee2e2;
    color: #991b1b;
}

.upload-status-item {
    margin: 4px 0;
    word-break: break-word;
}
/* Logout Button */
.logout-section {
    margin-bottom: 12px;
    padding: 0 4px;
}

.logout-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    color: #dc2626;
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: #fecaca;
    border-color: #fca5a5;
}
/* Choice Buttons Container - For Info & Troubleshoot buttons */
.choice-buttons-container {
    margin: 16px 0 24px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 16px;
    border: 1px solid #e9ecef;
    text-align: center;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.choice-question {
    font-size: 16px;
    font-weight: 500;
    color: #2c3e50;
    margin-bottom: 16px;
}

.choice-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.choice-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 40px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.choice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.choice-btn:active {
    transform: translateY(0);
}

.choice-info {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

.choice-info:hover {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}

.choice-troubleshoot {
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
    color: white;
}

.choice-troubleshoot:hover {
    background: linear-gradient(135deg, #d97706 0%, #dc2626 100%);
}

.choice-hint {
    font-size: 12px;
    color: #6c757d;
    margin-top: 16px;
}
/* Citation styling - makes the span tags look like badges */
.citation {
    display: inline-block;
    background: #e8e8ef;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    margin: 0 2px;
    color: #6366f1;
    font-weight: normal;
    white-space: nowrap;
}

.message-body .citation {
    background: #f0f0f4;
}

/* Also style the page references */
.message-body a {
    color: #6366f1;
    text-decoration: none;
}

.message-body a:hover {
    text-decoration: underline;
}