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

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0a0;
    --accent: #6c8cff;
    --accent-hover: #5a7aee;
    --border: #333;
    --user-bubble: #2b3a55;
    --ai-bubble: #1e1e1e;
    --success: #4caf50;
    --danger: #e74c3c;
    --sidebar-width: 300px;

    /* Aliases used by login/admin pages */
    --bg: var(--bg-primary);
    --sidebar-bg: var(--bg-secondary);
    --text: var(--text-primary);
    --text-muted: var(--text-secondary);
    --hover-bg: var(--bg-tertiary);
}

/* Light mode theme */
[data-theme="light"] {
    --bg-primary: #f4f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eaecf0;
    --text-primary: #1a1a2e;
    --text-secondary: #5e6470;
    --accent: #4c6ef5;
    --accent-hover: #3b5bdb;
    --border: #d0d4db;
    --user-bubble: #dce8ff;
    --ai-bubble: #ffffff;
    --success: #2e7d32;
    --danger: #c62828;

    --bg: var(--bg-primary);
    --sidebar-bg: var(--bg-secondary);
    --text: var(--text-primary);
    --text-muted: var(--text-secondary);
    --hover-bg: var(--bg-tertiary);
}

/* Theme toggle button */
.theme-toggle-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}
.theme-toggle-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Floating theme toggle — auto-injected on pages without sidebar */
.floating-theme-toggle {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 999;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.floating-theme-toggle:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 14px 12px;
    flex-shrink: 0;
    overflow: hidden;
    gap: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 0 4px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.3px;
}

.sidebar-brand svg { flex-shrink: 0; }

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 6px;
}

.sidebar-username {
    font-size: 0.78rem;
    color: var(--text-secondary);
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Primary new-chat button */
.sidebar-new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    padding: 9px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.15s, transform 0.1s;
    margin-bottom: 8px;
}

.sidebar-new-chat-btn:hover { background: var(--accent-hover); }
.sidebar-new-chat-btn:active { transform: scale(0.98); }

/* Admin link */
.sidebar-admin-link {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    background: rgba(124,58,237,0.15);
    color: #a78bfa;
    border: 1px solid rgba(124,58,237,0.3);
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    transition: background 0.15s;
    margin-bottom: 10px;
    box-sizing: border-box;
}

.sidebar-admin-link:hover { background: rgba(124,58,237,0.25); color: #c4b5fd; }

/* Nav */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 4px;
    min-height: 0;
    flex: 1 1 0;
    overflow: hidden;
    flex-shrink: 1;
}

.sidebar-nav-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    opacity: 0.6;
    padding: 8px 8px 3px;
}

/* Collapsible nav groups */
.sidebar-nav-group {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex-shrink: 1;
}
.sidebar-nav-group + .sidebar-nav-group {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}
.sidebar-nav-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    width: 100%;
    padding: 6px 8px 3px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.12s;
    flex-shrink: 0;
}
.sidebar-nav-toggle:hover { opacity: 0.85; }
.sidebar-nav-toggle span { flex: 1; text-align: left; }
.sidebar-nav-toggle .nav-chevron {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    transition: transform 0.2s;
}
.sidebar-nav-group.collapsed { flex: 0 0 auto; }
.sidebar-nav-group:not(.collapsed) { flex: 1 1 0; }
.sidebar-nav-group.collapsed .nav-chevron { transform: rotate(-90deg); }
.sidebar-nav-items {
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow-y: auto;
    min-height: 0;
    flex: 1 1 auto;
    max-height: 500px;
    transition: max-height 0.3s ease;
}
.sidebar-nav-group.collapsed .sidebar-nav-items {
    max-height: 0 !important;
    overflow: hidden !important;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 8px;
    border-radius: 7px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.82rem;
    transition: background 0.12s, color 0.12s;
    border-left: 2px solid transparent;
}

.sidebar-nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-nav-item.active {
    background: rgba(108,140,255,0.1);
    color: var(--text-primary);
    border-left-color: var(--accent);
}

.sidebar-nav-item svg { flex-shrink: 0; opacity: 0.75; }
.sidebar-nav-item:hover svg, .sidebar-nav-item.active svg { opacity: 1; }

.sidebar-nav-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--accent);
}

.selector-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.selector-row .mode-selector {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.mode-selector {
    margin-bottom: 16px;
}

.mode-selector label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mode-selector select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    cursor: pointer;
    outline: none;
}

.mode-selector select:focus {
    border-color: var(--accent);
}

.mode-description {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 6px;
    line-height: 1.4;
}

/* Upload Section */
.upload-section {
    margin-bottom: 16px;
}

.upload-section label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.upload-area {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.upload-area:hover {
    border-color: var(--accent);
    background: rgba(108, 140, 255, 0.05);
}

.upload-area svg {
    color: var(--text-secondary);
}

.upload-area span {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.uploaded-doc {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    border: 1px solid var(--success);
    border-radius: 8px;
    padding: 8px 12px;
    margin-top: 8px;
}

.uploaded-doc-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.uploaded-doc-info svg {
    color: var(--success);
    flex-shrink: 0;
}

.uploaded-doc-info span {
    font-size: 0.8rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-doc-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
    flex-shrink: 0;
}

.remove-doc-btn:hover {
    color: var(--danger);
}

.upload-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.progress-bar {
    flex: 1;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Buttons */
.new-chat-btn {
    width: 100%;
    padding: 10px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
    margin-top: 8px;
}

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

/* Chat History */
.chat-history-section {
    flex: 1 1 0;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 6px;
    overflow: hidden;
}

.chat-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 0 2px;
}

.chat-history-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.chat-history-add-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 22px;
    height: 22px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    line-height: 1;
    flex-shrink: 0;
}

.chat-history-add-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.chat-history-list::-webkit-scrollbar {
    width: 4px;
}

.chat-history-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.chat-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 8px 7px 10px;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    gap: 6px;
    border-left: 2px solid transparent;
}

.chat-history-item:hover {
    background: var(--bg-tertiary);
    border-left-color: rgba(108,140,255,0.35);
}

.chat-history-item.active {
    background: rgba(108, 140, 255, 0.1);
    border-left-color: var(--accent);
}

.chat-item-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-history-title {
    font-size: 0.81rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-item.active .chat-history-title {
    color: var(--text-primary);
    font-weight: 500;
}

.chat-history-item:hover .chat-history-title {
    color: var(--text-primary);
}

.chat-item-date {
    font-size: 0.67rem;
    color: var(--text-secondary);
    opacity: 0.55;
}

.chat-delete-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 2px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
}

.chat-history-item:hover .chat-delete-btn {
    opacity: 1;
}

.chat-delete-btn:hover {
    color: var(--danger);
}

.no-chats {
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 12px;
}


.sidebar-footer {
    padding-top: 20px;
    padding-bottom: 4px;
    margin-top: 8px;
}

.sidebar-footer p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.sidebar-footer .version {
    margin-top: 4px;
    opacity: 0.5;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.mobile-header {
    display: none;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Welcome */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.welcome-message h1 {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.welcome-message > p {
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.5;
}

.example-questions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.example-btn {
    padding: 14px 16px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    text-align: left;
    transition: border-color 0.2s, background 0.2s;
}

.example-btn:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
}

/* Messages */
.message {
    display: flex;
    gap: 12px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    flex-direction: row-reverse;
}

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

.message.user .message-avatar {
    background: var(--user-bubble);
    color: var(--accent);
}

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

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    font-size: 0.92rem;
    max-width: 85%;
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}

.message-timestamp {
    font-size: 0.68rem;
    color: var(--text-secondary);
    align-self: flex-end;
    margin-bottom: 4px;
    white-space: nowrap;
    opacity: 0.6;
}

.message.user .message-content {
    background: var(--user-bubble);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--ai-bubble);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-content p {
    margin-bottom: 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent);
    margin: 16px 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.message-content h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 12px 0 6px 0;
}

.message-content h5 {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 10px 0 4px 0;
}

.message-content ul, .message-content ol {
    margin-left: 20px;
    margin-bottom: 10px;
    padding-left: 4px;
}

.message-content li {
    margin-bottom: 4px;
    line-height: 1.6;
}

.message-content li::marker {
    color: var(--accent);
}

.message-content ol li::marker {
    font-weight: 600;
}

.message-content code {
    background: var(--bg-tertiary);
    color: var(--accent);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.message-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

.message-content strong {
    color: var(--text-primary);
    font-weight: 600;
}

.message-content em {
    color: var(--text-secondary);
    font-style: italic;
}

/* ── Response tables (spreadsheet style) ──────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    margin: 14px 0;
    border-radius: 3px;
    border: 1.5px solid #4a5568;
    display: inline-block;
    min-width: 100%;
}

.response-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.86rem;
    line-height: 1.5;
}

.response-table th {
    background: #1a2035;
    color: #a8c4f0;
    font-weight: 600;
    padding: 8px 16px;
    text-align: left;
    border: 1px solid #3d4f6a;
    white-space: nowrap;
}

.response-table td {
    padding: 7px 16px;
    border: 1px solid #333d4d;
    color: var(--text-primary);
    vertical-align: top;
    white-space: nowrap;
    background: #111318;
}

.response-table tbody tr:nth-child(even) td {
    background: #13161e;
}

.response-table tbody tr:hover td {
    background: #1a2235;
}

/* Export Menu */
.export-menu {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    z-index: 300;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    min-width: 180px;
}

.export-menu button {
    display: block;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.82rem;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
}

.export-menu button:hover {
    background: var(--bg-tertiary);
}

/* System Messages */
.system-message {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    max-width: 600px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    transition: background 0.2s;
}

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

.continue-btn {
    background: var(--accent);
    color: white;
    font-weight: 600;
}

.continue-btn:hover {
    background: #2563eb;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

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

.input-toolbar {
    display: flex;
    align-items: center;
    max-width: 800px;
    margin: 0 auto 8px;
    gap: 12px;
}

.length-selector {
    display: flex;
    align-items: center;
    gap: 6px;
}

.length-selector label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.length-selector select {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.length-selector select:focus,
.length-selector select:hover {
    border-color: var(--accent);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

#userInput {
    flex: 1;
    background: transparent;
    color: var(--text-primary);
    border: none;
    outline: none;
    font-size: 0.92rem;
    resize: none;
    max-height: 150px;
    line-height: 1.5;
    padding: 4px 0;
    font-family: inherit;
}

#userInput::placeholder {
    color: var(--text-secondary);
}

#sendBtn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

#sendBtn:hover {
    background: var(--accent-hover);
}

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

#stopBtn {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

#stopBtn:hover {
    background: #c0392b;
}


.disclaimer {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 8px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* Sources Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-header h3 {
    font-size: 1rem;
}

.modal-header button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 0.85rem;
    line-height: 1.6;
}

.source-item {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 8px;
}

.source-item .source-label {
    font-size: 0.7rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.source-item .source-title {
    font-weight: 500;
    margin-bottom: 2px;
}

.source-item .source-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* Source result-cards: badge row + title + preview. Two-column grid on
   wide viewports, single column on mobile. */
#sourcesBody {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}
.source-card {
    margin-bottom: 0;
    border: 1px solid var(--border);
}
.source-card-top {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 7px;
}
.source-badge {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
}
.sb-yargitay { background: rgba(108, 140, 255, 0.16); color: #7d9bff; }
.sb-danistay { background: rgba(45, 191, 179, 0.16); color: #38cabb; }
.sb-aym      { background: rgba(255, 105, 97, 0.16);  color: #ff7d75; }
.sb-mevzuat  { background: rgba(80, 200, 120, 0.16);  color: #4fc47e; }
.sb-belge    { background: rgba(200, 160, 255, 0.16); color: #bb95f5; }
.sb-canli    { background: rgba(160, 170, 190, 0.18); color: var(--text-secondary); }
[data-theme="light"] .sb-yargitay { color: #3a5fd9; }
[data-theme="light"] .sb-danistay { color: #0d8a7d; }
[data-theme="light"] .sb-aym      { color: #d0403a; }
[data-theme="light"] .sb-mevzuat  { color: #1f8a4d; }
[data-theme="light"] .sb-belge    { color: #7a4fd0; }
.source-date {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.source-outcome {
    font-size: 0.66rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    margin-left: auto;
    white-space: nowrap;
}
.oc-bozma  { background: rgba(255, 105, 97, 0.14); color: #ff7d75; }
.oc-onama  { background: rgba(80, 200, 120, 0.14); color: #4fc47e; }
.oc-kismen { background: rgba(255, 180, 0, 0.14);  color: #e0a800; }
[data-theme="light"] .oc-bozma { color: #d0403a; }
[data-theme="light"] .oc-onama { color: #1f8a4d; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
}

.sidebar-overlay.active {
    display: block;
}

/* ── Auth / User info sidebar additions ──────────────────────────────────── */

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 4px 8px;
    margin-bottom: 8px;
}

.sidebar-logout-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 2px;
    line-height: 1;
}
.sidebar-logout-btn:hover { color: var(--text-primary); }

.admin-link {
    display: block;
    text-align: center;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    background: #7c3aed;
    color: white;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
}
.admin-link:hover { opacity: 0.85; }

/* Usage stats widget */
.usage-stats-widget {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.usage-stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.usage-stat-row > span:first-child {
    width: 42px;
    flex-shrink: 0;
}

.usage-mini-bar-wrap {
    flex: 1;
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.usage-mini-bar {
    height: 5px;
    border-radius: 3px;
    background: var(--accent);
    width: 0%;
    transition: width 0.4s ease;
}

.usage-pct {
    width: 30px;
    text-align: right;
    flex-shrink: 0;
}

/* Mobile */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        border-bottom: 1px solid var(--border);
        background: var(--bg-secondary);
    }

    .menu-btn {
        background: none;
        border: none;
        color: var(--text-primary);
        cursor: pointer;
        padding: 4px;
    }

    .mobile-header h3 {
        font-size: 1rem;
        color: var(--accent);
    }

    .chat-messages {
        padding: 16px;
    }

    .example-questions {
        grid-template-columns: 1fr;
    }

    .input-area {
        padding: 12px 16px 16px;
    }

    .message-content {
        max-width: 95%;
    }
}

/* Citation Verification */
.citation-verification {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--bg-secondary, #f8f9fa);
    border: 1px solid var(--border-color, #e2e8f0);
    font-size: 13px;
}
.cv-header {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary, #1a202c);
}
.cv-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cv-item {
    padding: 4px 8px;
    border-radius: 4px;
}
.cv-ref {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 12px;
}
.cv-verified { background: rgba(72, 187, 120, 0.1); }
.cv-unverified { background: rgba(237, 137, 54, 0.1); }
.cv-not_found { background: rgba(245, 101, 101, 0.1); }

/* Feedback Buttons */
.feedback-btns { display: flex; gap: 2px; }
.feedback-btn { padding: 4px 6px !important; min-width: unset !important; }
.feedback-btn:hover { color: var(--accent-color, #4a90d9); }
.feedback-active { color: var(--accent-color, #4a90d9) !important; }
