:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    
    --border-color: #e5e7eb;
    --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-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    --transition: all 0.2s ease;
}

/* ==================== Dark Theme ==================== */
[data-theme="dark"] {
    --primary-color: #818cf8;
    --primary-dark: #6366f1;
    --primary-light: #a5b4fc;
    --secondary-color: #34d399;
    --danger-color: #f87171;
    --warning-color: #fbbf24;

    --bg-primary: #1e1e2e;
    --bg-secondary: #181825;
    --bg-tertiary: #313244;

    --text-primary: #cdd6f4;
    --text-secondary: #a6adc8;
    --text-tertiary: #6c7086;

    --border-color: #45475a;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .chat-input,
[data-theme="dark"] .form-group input,
[data-theme="dark"] .prompt-input,
[data-theme="dark"] .audit-filter-group input[type="date"] {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .toast {
    background-color: var(--bg-tertiary);
}

[data-theme="dark"] img,
[data-theme="dark"] .folder-icon-svg {
    filter: brightness(0.9);
}

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

html {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    overflow-x: hidden;
    max-width: 100vw;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Improve touch interactions on mobile */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.main-content > .container {
    height: 100%;
}

/* Header */
.header {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    overflow-x: hidden;
    max-width: 100%;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
}

.logo-icon {
    font-size: 2rem;
}

.nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    padding: 0.5rem 1.25rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    /* Better mobile touch target */
    min-height: 44px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

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

.nav-btn:active {
    transform: scale(0.97);
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 0;
    flex-shrink: 1;
}

.language-selector {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.language-selector:hover {
    border-color: var(--primary-color);
}

.language-selector:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Theme Toggle */
.theme-toggle-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-size: 1.15rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.theme-toggle-btn:hover {
    border-color: var(--primary-color);
    background: var(--bg-tertiary);
    transform: scale(1.1);
}

/* Mobile Sidebar Toggle */
.mobile-sidebar-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-primary);
    border-radius: var(--radius-md);
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.mobile-sidebar-toggle:hover {
    background: var(--bg-tertiary);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--secondary-color);
    animation: pulse 2s infinite;
}

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

/* Main Content */
.main-content {
    padding: 2rem 0;
    height: calc(100vh - 80px);
    overflow: hidden;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

.tab-content::-webkit-scrollbar {
    width: 8px;
}

.tab-content::-webkit-scrollbar-track {
    background: transparent;
}

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

/* Chat Layout */
.chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    height: 100%;
}

/* Sidebar */
.sidebar {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-md);
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

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

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.sidebar-section {
    margin-bottom: 2rem;
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

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

/* Sidebar Section Header (title + action button) */
.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.sidebar-section-header .sidebar-title {
    margin-bottom: 0;
}

.btn-icon-sm {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: var(--transition);
    line-height: 1;
}

.btn-icon-sm:hover {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* Conversation List */
.conversation-search {
    width: 100%;
    padding: 6px 10px;
    margin-bottom: 6px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.8rem;
    outline: none;
    transition: var(--transition);
    box-sizing: border-box;
}

.conversation-search:focus {
    border-color: var(--primary-color);
    background: var(--bg-primary);
}

.conversation-search::placeholder {
    color: var(--text-tertiary);
}

.conversation-list {
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

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

.conversation-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

.conversation-item.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.conversation-item.active .conversation-item-meta {
    color: rgba(255, 255, 255, 0.75);
}

.conversation-item-info {
    flex: 1;
    min-width: 0;
}

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

.conversation-item-meta {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.conversation-item-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.conversation-item-pin {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.7rem;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 2px;
}
.conversation-item-pin.pinned {
    opacity: 0.7;
}
.conversation-item:hover .conversation-item-pin {
    opacity: 0.6;
}
.conversation-item-pin:hover {
    opacity: 1 !important;
}
.conversation-item.pinned {
    border-left: 2px solid var(--primary-color);
}

.conversation-item-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 2px;
}

.conversation-item:hover .conversation-item-delete {
    opacity: 0.6;
}

.conversation-item-delete:hover {
    opacity: 1 !important;
}

/* Source links in chat */
.source-link {
    cursor: pointer;
    color: var(--primary-color);
    text-decoration: underline;
    transition: color 0.15s;
}

.source-link:hover {
    color: var(--primary-dark);
}

/* Chunk context tooltip on source hover */
.source-with-preview {
    position: relative;
}
.source-with-preview[data-chunk-preview]:hover::after {
    content: attr(data-chunk-preview);
    position: absolute;
    bottom: 110%;
    left: 0;
    z-index: 100;
    max-width: 360px;
    min-width: 200px;
    padding: 10px 12px;
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    white-space: pre-wrap;
    word-break: break-word;
    pointer-events: none;
}

/* Edit message button & inline editor */
.edit-msg-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 0 4px;
}
.message.user:hover .edit-msg-btn {
    opacity: 0.6;
}
.edit-msg-btn:hover {
    opacity: 1 !important;
}

.edit-msg-textarea {
    width: 100%;
    min-height: 60px;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 0.9rem;
    border: 1px solid var(--primary-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    resize: vertical;
    outline: none;
}

.edit-msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    justify-content: flex-end;
}

.edit-msg-confirm {
    padding: 4px 12px !important;
    font-size: 0.8rem !important;
}
.edit-msg-cancel {
    padding: 4px 12px !important;
    font-size: 0.8rem !important;
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-secondary) !important;
}

/* Workspace Selector */
.workspace-selector {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.workspace-selector:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

/* Chat Header Actions */
.chat-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Copy Message Button */
.copy-msg-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    margin-left: auto;
}

.message:hover .copy-msg-btn {
    opacity: 0.5;
}

.copy-msg-btn:hover {
    opacity: 1 !important;
    background: var(--bg-tertiary);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.stat-card {
    background-color: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--radius-md);
    text-align: center;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.upload-area:hover {
    border-color: var(--primary-color);
    background-color: var(--bg-secondary);
}

.upload-area.drag-over {
    border-color: var(--primary-color);
    background-color: var(--primary-light);
    background-opacity: 0.1;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.upload-text {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.upload-subtext {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.upload-info {
    margin-top: 0.75rem;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

/* Upload List */
.upload-list {
    max-height: 300px;
    overflow-y: auto;
}

.upload-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.upload-item-icon {
    font-size: 1.25rem;
}

.upload-item-info {
    flex: 1;
    min-width: 0;
}

.upload-item-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-item-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.upload-item-chunks {
    font-size: 0.7rem;
    color: var(--primary-color);
    font-weight: 500;
    margin-top: 0.15rem;
}

.upload-item-status {
    font-size: 1rem;
}

/* Chat Area */
.chat-area {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    height: 100%;
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    flex-shrink: 0;
}

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

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    min-height: 0;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Welcome Message */
.welcome-message {
    max-width: 600px;
    margin: 2rem auto;
    text-align: center;
}

.welcome-message h2 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.welcome-message p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.quick-tips {
    background-color: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    text-align: left;
}

.quick-tips h4 {
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.quick-tips ul {
    list-style-position: inside;
    color: var(--text-secondary);
}

.quick-tips li {
    margin-bottom: 0.5rem;
}

/* Chat Messages */
.message {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

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

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

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

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

.message-content {
    flex: 1;
    min-width: 0;
}

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

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

.message-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.message-text {
    color: var(--text-primary);
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Keep pre-wrap only for user messages (plain text) */
.message.user .message-text {
    white-space: pre-wrap;
}

/* ==================== Markdown Rendering ==================== */

/* --- Paragraphs --- */
.message-text.markdown-body p {
    margin: 0 0 0.6em 0;
    line-height: 1.65;
}
.message-text.markdown-body p:last-child {
    margin-bottom: 0;
}

/* --- Headings --- */
.message-text.markdown-body h1,
.message-text.markdown-body h2,
.message-text.markdown-body h3,
.message-text.markdown-body h4 {
    margin: 1.25em 0 0.4em 0;
    font-weight: 700;
    line-height: 1.25;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}
.message-text.markdown-body h1:first-child,
.message-text.markdown-body h2:first-child,
.message-text.markdown-body h3:first-child,
.message-text.markdown-body h4:first-child {
    margin-top: 0;
}
.message-text.markdown-body h1 {
    font-size: 1.45em;
    padding-bottom: 0.3em;
    border-bottom: 2px solid var(--border-color);
}
.message-text.markdown-body h2 {
    font-size: 1.25em;
    padding-bottom: 0.25em;
    border-bottom: 1px solid var(--border-color);
}
.message-text.markdown-body h3 { font-size: 1.1em; }
.message-text.markdown-body h4 {
    font-size: 1em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
}

/* --- Lists --- */
.message-text.markdown-body ul,
.message-text.markdown-body ol {
    margin: 0.5em 0 0.75em 0;
    padding-left: 1.6em;
}
.message-text.markdown-body ul {
    list-style-type: disc;
}
.message-text.markdown-body li {
    margin: 0.3em 0;
    line-height: 1.6;
}
.message-text.markdown-body li::marker {
    color: var(--primary-color);
}
.message-text.markdown-body li > p {
    margin-bottom: 0.3em;
}
.message-text.markdown-body li > ul,
.message-text.markdown-body li > ol {
    margin: 0.2em 0 0.1em 0;
}

/* --- Blockquotes --- */
.message-text.markdown-body blockquote {
    margin: 0.8em 0;
    padding: 0.6em 1em;
    border-left: 3px solid var(--primary-color);
    background: var(--bg-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
    font-style: italic;
}
.message-text.markdown-body blockquote p {
    margin: 0 0 0.3em 0;
}
.message-text.markdown-body blockquote p:last-child {
    margin-bottom: 0;
}
.message-text.markdown-body blockquote blockquote {
    margin: 0.4em 0;
    border-left-color: var(--text-tertiary);
}

/* --- Inline code --- */
.message-text.markdown-body code {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
    font-size: 0.85em;
    padding: 0.15em 0.45em;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--primary-color);
    word-break: break-word;
}

/* --- Code blocks --- */
.code-block-wrapper {
    margin: 0.85em 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
}
.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4em 0.85em;
    background: var(--bg-tertiary, var(--border-color));
    font-size: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
.code-lang-label {
    color: var(--text-tertiary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}
.code-copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0.2em 0.5em;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
}
.code-copy-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.code-block-wrapper pre {
    margin: 0;
    padding: 0.9em 1em;
    overflow-x: auto;
    font-size: 0.84rem;
    line-height: 1.55;
}
.code-block-wrapper pre code {
    padding: 0;
    background: none;
    border: none;
    color: inherit;
    font-size: inherit;
    word-break: normal;
}

/* --- Tables --- */
.message-text.markdown-body table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0.85em 0;
    font-size: 0.88em;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.message-text.markdown-body th,
.message-text.markdown-body td {
    padding: 0.55em 0.85em;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.message-text.markdown-body th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}
.message-text.markdown-body tr:last-child td {
    border-bottom: none;
}
.message-text.markdown-body tbody tr:nth-child(even) {
    background: var(--bg-secondary);
}
.message-text.markdown-body tbody tr:hover {
    background: var(--bg-tertiary);
}

/* --- Horizontal rule --- */
.message-text.markdown-body hr {
    margin: 1.25em 0;
    border: none;
    height: 2px;
    background: linear-gradient(to right, var(--primary-color), var(--border-color), transparent);
    border-radius: 1px;
}

/* --- Links --- */
.message-text.markdown-body a {
    color: var(--primary-color);
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 2px;
    transition: text-decoration-color 0.2s;
}
.message-text.markdown-body a:hover {
    text-decoration-color: var(--primary-color);
}

/* --- Bold / Italic --- */
.message-text.markdown-body strong {
    font-weight: 650;
    color: var(--text-primary);
}
.message-text.markdown-body em {
    font-style: italic;
    color: var(--text-secondary);
}

/* --- Images --- */
.message-text.markdown-body img {
    max-width: 100%;
    border-radius: var(--radius-md);
    margin: 0.5em 0;
}

.message-sources {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--primary-color);
}

.message-sources-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.message-sources-list {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Feedback buttons */
.message-feedback {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.feedback-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm, 6px);
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    opacity: 0.5;
    transition: opacity 0.2s, background-color 0.2s, border-color 0.2s;
}

.feedback-btn:hover {
    opacity: 1;
    background-color: var(--bg-tertiary);
}

.feedback-btn.active {
    opacity: 1;
    border-color: var(--primary-color);
    background-color: var(--primary-color);
    color: #fff;
}

.feedback-btn.active.feedback-up {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.feedback-btn.active.feedback-down {
    background-color: var(--danger-color);
    border-color: var(--danger-color);
}

/* Follow-up suggestion chips */
.follow-up-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.follow-up-chip {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 0.35rem 0.85rem;
    font-size: 0.82rem;
    color: var(--primary-color);
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    text-align: left;
    line-height: 1.3;
}

.follow-up-chip:hover {
    background-color: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* Inline citation badges */
.citation-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.1rem;
    height: 1.1rem;
    padding: 0 0.2rem;
    font-size: 0.7rem;
    font-weight: 700;
    background-color: var(--primary-color);
    color: #fff;
    border-radius: 0.35rem;
    cursor: pointer;
    vertical-align: super;
    line-height: 1;
    margin: 0 0.1rem;
    transition: background-color 0.2s;
}

.citation-badge:hover {
    background-color: var(--primary-dark);
}

/* Citation popover (chunk preview on click) */
.citation-popover {
    position: fixed;
    z-index: 10000;
    max-width: 420px;
    min-width: 240px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    overflow: hidden;
    animation: popoverIn 0.15s ease-out;
}

@keyframes popoverIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.citation-popover-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.citation-popover-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 0.25rem;
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--primary-color);
    color: #fff;
    border-radius: 0.35rem;
    flex-shrink: 0;
}

.citation-popover-source {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.citation-popover-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 0 0.2rem;
    line-height: 1;
    flex-shrink: 0;
}

.citation-popover-close:hover {
    color: var(--text-primary);
}

.citation-popover-text {
    padding: 0.8rem;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-secondary);
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.typing .message-text {
    display: flex;
    gap: 0.25rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-tertiary);
    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% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Streaming cursor */
.message.streaming .message-text::after {
    content: '\25CB';
    display: inline-block;
    animation: streamBlink 0.6s infinite;
    color: var(--primary-color);
    margin-left: 2px;
    font-weight: bold;
}

@keyframes streamBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

/* Chat Input */
.chat-input-container {
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    flex-shrink: 0;
    background-color: var(--bg-primary);
}

/* Model Selector */
.model-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.model-toggle-btn {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-height: 40px;
    touch-action: manipulation;
    user-select: none;
}

.model-toggle-btn:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--primary-color);
}

.model-toggle-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.model-toggle-btn:active {
    transform: scale(0.98);
}

.chat-input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: var(--transition);
}

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

.voice-btn {
    width: 38px;
    height: 38px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}
.voice-btn:hover {
    background: var(--primary-light, rgba(99,102,241,0.1));
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.voice-btn.recording {
    background: #fee2e2;
    border-color: #ef4444;
    color: #ef4444;
    animation: pulse-record 1s ease-in-out infinite;
}
[data-theme="dark"] .voice-btn.recording {
    background: rgba(239,68,68,0.15);
}
@keyframes pulse-record {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
    50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--primary-dark);
    transform: scale(1.05);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.send-btn:disabled {
    background-color: var(--text-tertiary);
    cursor: not-allowed;
}

.send-btn.stop-mode {
    background-color: var(--danger-color, #ef4444);
    animation: pulse-stop 1.5s ease-in-out infinite;
}
.send-btn.stop-mode:hover {
    background-color: #dc2626;
    transform: scale(1.05);
}
@keyframes pulse-stop {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

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

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    /* Better mobile touch target */
    min-height: 44px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

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

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

.btn-primary:active {
    transform: scale(0.98);
}

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

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

.btn-secondary:active {
    transform: scale(0.98);
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    gap: 0.35rem;
    min-height: 36px;
}

.btn-sm svg {
    width: 14px;
    height: 14px;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
    margin-right: 0.5rem;
    margin-top: 0.5rem;
}

.btn-danger:active {
    transform: scale(0.98);
}

.btn-danger:hover {
    background-color: #dc2626;
}

/* Documents */
.documents-container {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.documents-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.documents-header h2 {
    margin: 0;
}

/* Storage usage bar */
.storage-bar {
    margin-bottom: 1rem;
}

.storage-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.storage-track {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 999px;
    overflow: hidden;
}

.storage-fill {
    height: 100%;
    background: var(--primary-color);
    border-radius: 999px;
    transition: width 0.4s ease, background 0.4s ease;
}

.storage-fill.warning {
    background: #f59e0b;
}

.storage-fill.danger {
    background: var(--danger-color);
}

.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

/* Document toolbar */
.doc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.doc-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.doc-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.doc-search-wrap {
    position: relative;
    flex: 1;
    max-width: 320px;
    min-width: 160px;
}

.doc-search-icon {
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    pointer-events: none;
    opacity: 0.5;
}

.doc-search-input {
    width: 100%;
    padding: 0.45rem 0.6rem 0.45rem 2rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: var(--transition);
}

.doc-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

/* Search mode/method toggle buttons */
.doc-search-toggles {
    display: none;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.doc-toggle-group {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.doc-toggle {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.doc-toggle:not(:last-child) {
    border-right: 1px solid var(--border-color);
}

.doc-toggle.active {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.doc-toggle:hover:not(.active) {
    background: var(--bg-tertiary, var(--bg-secondary));
    color: var(--text-primary);
}

.doc-sort-select {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.doc-sort-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.doc-select-all-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

#docBulkToggle.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Bulk action bar */
.doc-bulk-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    margin-bottom: 1rem;
    background: var(--primary-color);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
    animation: slideDown 0.2s ease;
}

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

.doc-bulk-bar .btn {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.3);
    color: white;
    font-size: 0.78rem;
}

.doc-bulk-bar .btn:hover {
    background: rgba(255,255,255,0.35);
}

.doc-bulk-bar .btn-danger {
    background: rgba(239, 68, 68, 0.7);
    border-color: rgba(239, 68, 68, 0.8);
}

.doc-bulk-count {
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
    margin-right: 0.5rem;
}

/* Bulk checkbox on document cards */
.doc-bulk-checkbox {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    width: 18px;
    height: 18px;
    cursor: pointer;
    z-index: 2;
    accent-color: var(--primary-color);
}

.document-card.bulk-mode {
    padding-left: 2.5rem;
}

.document-card.bulk-mode .document-icon {
    margin-left: 0;
}

/* Pagination */
.doc-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.doc-page-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.doc-pagination .btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Responsive: stack toolbar on mobile */
@media (max-width: 600px) {
    .doc-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .doc-toolbar-left {
        flex-direction: column;
    }
    .doc-search-wrap {
        max-width: none;
    }
    .doc-search-toggles {
        justify-content: flex-start;
    }
    .doc-bulk-bar {
        flex-wrap: wrap;
    }
}

/* Profiles bar */
.profiles-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.profiles-list {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 1;
    min-height: 2rem;
}

.profiles-empty {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.profile-chip {
    display: inline-flex;
    align-items: center;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 0.25rem 0.5rem 0.25rem 0.75rem;
    font-size: 0.85rem;
    transition: var(--transition);
}

.profile-chip:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.profile-chip-name {
    cursor: pointer;
    color: var(--text-primary);
    white-space: nowrap;
}

.profile-chip-name:hover {
    color: var(--primary-color);
}

.profile-chip-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 0.25rem;
    margin-left: 0.25rem;
    line-height: 1;
    border-radius: 50%;
    transition: var(--transition);
}

.profile-chip-delete:hover {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

.profile-chip-edit {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0 0.2rem;
    margin-left: 0.15rem;
    line-height: 1;
    border-radius: 50%;
    transition: var(--transition);
}

.profile-chip-edit:hover {
    color: var(--primary-color);
    background-color: rgba(99, 102, 241, 0.1);
}

/* Workspace Manager Modal */
.ws-manager-content {
    max-width: 600px;
    width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.ws-manager-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.ws-manager-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.ws-manager-tree-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0.75rem 0 0.5rem;
}

.ws-manager-tree-header label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.ws-manager-tree-actions {
    display: flex;
    gap: 0.4rem;
}

.ws-manager-tree {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    min-height: 200px;
    max-height: 45vh;
    background: var(--bg-primary);
}

.ws-tree-folder {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    cursor: default;
}

.ws-tree-folder:hover {
    background: var(--bg-tertiary);
}

.ws-tree-doc {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
}

.ws-tree-doc:hover {
    background: var(--bg-tertiary);
}

.ws-tree-toggle {
    width: 1rem;
    text-align: center;
    font-size: 0.7rem;
    cursor: pointer;
    color: var(--text-secondary);
    user-select: none;
    flex-shrink: 0;
}

.ws-tree-no-toggle {
    cursor: default;
}

.ws-tree-cb {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.ws-tree-folder-icon,
.ws-tree-doc-icon {
    font-size: 0.9rem;
    flex-shrink: 0;
}

.ws-tree-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.ws-tree-meta {
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin-left: 0.25rem;
    flex-shrink: 0;
}

.ws-tree-children {
    /* children container for expand/collapse */
}

.ws-tree-unfiled {
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
}

.ws-manager-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.ws-manager-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.ws-manager-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

.document-card {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: var(--transition);
    cursor: pointer;
    position: relative;
}

.document-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.delete-doc-btn {
    background-color: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: var(--transition);
}

.delete-doc-btn:hover,
.btn-icon-sm.delete-doc-btn:hover {
    background-color: rgba(239, 68, 68, 0.1) !important;
    color: #ef4444 !important;
    border-color: transparent !important;
}

.document-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.document-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    word-break: break-word;
}

.document-description {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
    min-height: 1.4rem;
}

.document-description .desc-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    transition: color 0.2s;
}

.document-description .desc-text:hover {
    color: var(--primary);
}

.document-description .desc-placeholder {
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.5;
    cursor: pointer;
    font-style: italic;
}

.document-description .desc-placeholder:hover {
    opacity: 0.8;
    color: var(--primary);
}

.desc-regen-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.1rem;
    opacity: 0.4;
    transition: opacity 0.2s, transform 0.3s;
    flex-shrink: 0;
}

.desc-regen-btn:hover {
    opacity: 1;
}

.desc-regen-btn.spinning {
    animation: spin 0.8s linear infinite;
}

.desc-edit-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
}

.desc-edit-input {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
}

.desc-edit-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.desc-save-btn,
.desc-cancel-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.15rem;
    flex-shrink: 0;
}

.document-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.document-meta > div {
    margin-bottom: 0.25rem;
}

.document-status {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.document-status.indexed {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--secondary-color);
}

.document-status.pending {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

/* Document actions row */
.document-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.doc-actions-left {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
    flex: 1;
}

.doc-actions-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.doc-actions-right .delete-doc-btn {
    position: static;
    opacity: 1;
    color: var(--text-secondary);
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background-color: var(--text-secondary);
    border-radius: 22px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--secondary-color);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* Disabled document card */
.document-card.disabled {
    opacity: 0.55;
}

.document-card.disabled .document-icon {
    filter: grayscale(1);
}

/* Disabled sidebar item */
.upload-item.disabled {
    opacity: 0.55;
}

/* Settings */
.settings-container {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 800px;
    box-shadow: var(--shadow-md);
}

.settings-container h2 {
    margin-bottom: 2rem;
}

.settings-section {
    margin-bottom: 2.5rem;
}

.settings-section h3 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.settings-hint {
    display: block;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.profession-group-hint {
    display: block;
    margin-top: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-style: italic;
}

.setting-item {
    margin-bottom: 1.5rem;
}

.setting-item label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.setting-item input[type="number"],
.setting-item input[type="range"] {
    width: 100%;
    max-width: 300px;
}

.setting-item small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-secondary);
}

.about-info {
    background-color: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: var(--radius-md);
}

.about-info p {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-tertiary);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background-color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left: 4px solid var(--secondary-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

.toast.info {
    border-left: 4px solid var(--primary-color);
}

.toast-icon {
    font-size: 1.5rem;
}

.toast-message {
    flex: 1;
    color: var(--text-primary);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

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

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: white;
    margin-top: 1rem;
    font-size: 1.125rem;
}

/* Responsive */

/* Tablet and below */
@media (max-width: 1024px) {
    .chat-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .sidebar {
        order: 2;
        height: auto;
        max-height: none;
    }
    
    .chat-area {
        order: 1;
        height: 60vh;
        min-height: 400px;
    }
    
    .container {
        padding: 0 1rem;
    }
    
    .main-content {
        padding: 1.5rem 0;
    }
}

/* Mobile landscape and below */
@media (max-width: 768px) {
    .header-content {
        flex-wrap: nowrap;
        gap: 0.5rem;
        padding: 0.75rem 0;
    }
    
    .logo {
        font-size: 1.25rem;
        gap: 0.5rem;
    }
    
    .logo-icon {
        font-size: 1.5rem;
    }
    
    .user-info {
        font-size: 0.8rem;
        gap: 0.4rem;
    }
    
    .container {
        padding: 0 0.75rem;
    }
    
    .main-content {
        padding: 1rem 0;
        padding-bottom: 60px;
        overflow-y: auto;
    }
    
    .chat-layout {
        gap: 1rem;
    }
    
    .chat-area {
        height: calc(100vh - 120px - 56px);
        min-height: 350px;
    }
    
    .chat-header {
        padding: 0.75rem 1rem;
    }
    
    .chat-header h2 {
        font-size: 1rem;
    }
    
    .btn-secondary {
        padding: 0.375rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .chat-messages {
        padding: 1rem;
    }
    
    .message {
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
    
    .chat-input-container {
        padding: 0.75rem 1rem;
    }
    
    .chat-input-wrapper {
        gap: 0.5rem;
    }
    
    .chat-input {
        font-size: 0.9rem;
        padding: 0.625rem 0.875rem;
    }
    
    .send-btn {
        padding: 0.625rem;
        font-size: 1.25rem;
    }
    
    .sidebar {
        padding: 1rem;
    }
    
    .sidebar-section {
        margin-bottom: 1.5rem;
    }
    
    .stats-grid {
        gap: 0.5rem;
    }
    
    .stat-card {
        padding: 0.75rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .upload-area {
        padding: 1.5rem 0.75rem;
    }
    
    .upload-icon {
        font-size: 2.5rem;
    }
    
    .document-card {
        padding: 1rem;
    }
    
    .settings-section {
        padding: 1rem;
    }
}

/* Mobile portrait */
@media (max-width: 480px) {
    .header-content {
        padding: 0.5rem 0;
    }
    
    .container {
        padding: 0 0.5rem;
    }
    
    .main-content {
        padding: 0.75rem 0;
    }
    
    .chat-layout {
        gap: 0.75rem;
        height: auto;
    }
    
    .chat-area {
        height: calc(100vh - 110px - 56px);
        min-height: 300px;
        border-radius: var(--radius-md);
    }
    
    .chat-header {
        padding: 0.625rem 0.875rem;
    }
    
    .chat-header h2 {
        font-size: 0.9rem;
    }
    
    .btn-secondary {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .chat-messages {
        padding: 0.75rem;
    }
    
    .message {
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.875rem;
    }
    
    .message-text {
        font-size: 0.9rem;
    }
    
    .message-sources {
        padding: 0.625rem;
        font-size: 0.8rem;
    }
    
    .chat-input-container {
        padding: 0.625rem 0.75rem;
    }
    
    .chat-input {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
        max-height: 100px;
    }
    
    .send-btn {
        padding: 0.5rem;
        font-size: 1.1rem;
    }
    
    .sidebar {
        padding: 0.875rem;
    }
    
    .sidebar-title {
        font-size: 0.9rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    
    .stat-card {
        padding: 0.625rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .upload-area {
        padding: 1.25rem 0.5rem;
    }
    
    .upload-icon {
        font-size: 2rem;
    }
    
    .upload-text {
        font-size: 0.9rem;
    }
    
    .document-card {
        padding: 0.875rem;
    }
    
    .document-meta {
        font-size: 0.75rem;
    }
    
    .settings-section {
        padding: 0.875rem;
        margin-bottom: 1rem;
    }
    
    .settings-section h3 {
        font-size: 0.9rem;
    }
    
    .setting-item label {
        font-size: 0.85rem;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .chat-area {
        height: calc(100vh - 120px);
    }
}

/* Auth Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    overflow-y: auto;
}

.modal[style*="display: none"] {
    display: none !important;
}

.modal-content {
    background: var(--bg-primary);
    padding: 2.5rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    max-width: 450px;
    width: 90%;
    margin: auto;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 1.75rem;
}

/* ==================== Help Guide Modal ==================== */
.help-guide-modal {
    max-width: 640px;
    width: 95%;
    padding: 2rem;
}

.help-guide-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.help-guide-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.help-guide-intro {
    color: var(--text-secondary);
    font-size: 0.92rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.help-accordion {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.help-section {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.help-section-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1rem;
    background: var(--bg-secondary);
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: background 0.15s;
}

.help-section-toggle:hover {
    background: var(--bg-tertiary);
}

.help-chevron {
    font-size: 1rem;
    transition: transform 0.2s;
    color: var(--text-tertiary);
}

.help-section.open .help-chevron {
    transform: rotate(90deg);
}

.help-section-content {
    display: none;
    padding: 1rem 1.25rem;
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--text-primary);
    border-top: 1px solid var(--border-color);
}

.help-section.open .help-section-content {
    display: block;
}

.help-section-content ol,
.help-section-content ul {
    padding-left: 1.25rem;
    margin: 0.5rem 0;
}

.help-section-content li {
    margin-bottom: 0.45rem;
}

.help-section-content p {
    margin: 0.5rem 0;
}

.help-section-content strong {
    color: var(--primary-color);
}

.help-section-content em {
    background: var(--bg-tertiary);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-style: normal;
    font-size: 0.88rem;
}

.modal-subtitle {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

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

.form-group label {
    display: block;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--bg-secondary);
}

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

.btn-primary {
    width: 100%;
    padding: 0.875rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* Login form acceptance checkbox */
.form-check-group {
    margin-top: 0.25rem;
}
.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1.4;
}
.checkbox-label input[type="checkbox"] {
    margin-top: 0.15rem;
    accent-color: var(--primary-color);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
}
.checkbox-label a {
    color: var(--primary-color);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.checkbox-label a:hover {
    color: var(--primary-dark);
}

.form-footer {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

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

.logout-btn {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

/* Document Viewer Modal */
.doc-viewer-modal {
    max-width: 900px;
    width: 95%;
    height: 85vh;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden; /* let internal flex children control scroll */
}

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

.doc-viewer-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* In-document search bar */
.doc-search-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.doc-search-input {
    flex: 1;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    min-width: 0;
}

.doc-search-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.doc-search-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 3.5rem;
    text-align: center;
}

mark.doc-search-highlight {
    background: #fef08a;
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

mark.doc-search-current {
    background: #f97316;
    color: #fff;
    border-radius: 2px;
    padding: 0 1px;
}

[data-theme="dark"] mark.doc-search-highlight {
    background: #713f12;
    color: #fef9c3;
}

[data-theme="dark"] mark.doc-search-current {
    background: #c2410c;
    color: #fff;
}

.doc-viewer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    font-size: 0.92rem;
    line-height: 1.7;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 0; /* required for flex children to shrink correctly */
}

.doc-editor-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    font-size: 0.9rem;
    line-height: 1.7;
    font-family: 'Courier New', Courier, monospace;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: none;
    resize: none;
    outline: none;
    width: 100%;
    box-sizing: border-box;
    min-height: 0; /* required for flex children to shrink correctly */
}

.doc-viewer-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}

/* Rendered markdown inside doc viewer */
.doc-rendered-content {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.doc-rendered-content h1,
.doc-rendered-content h2,
.doc-rendered-content h3 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: var(--text-primary);
}

.doc-rendered-content h1 { font-size: 1.6rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.3em; }
.doc-rendered-content h2 { font-size: 1.3rem; }
.doc-rendered-content h3 { font-size: 1.1rem; }

.doc-rendered-content p {
    margin: 0.6em 0;
}

.doc-rendered-content ul,
.doc-rendered-content ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.doc-rendered-content li {
    margin: 0.25em 0;
}

.doc-rendered-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
    font-size: 0.85rem;
}

.doc-rendered-content th,
.doc-rendered-content td {
    border: 1px solid var(--border-color);
    padding: 0.5em 0.75em;
    text-align: left;
}

.doc-rendered-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.doc-rendered-content blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 1em;
    margin: 0.8em 0;
    color: var(--text-secondary);
}

.doc-rendered-content code {
    background: var(--bg-secondary);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-size: 0.88em;
}

.doc-rendered-content pre {
    background: var(--bg-secondary);
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.doc-rendered-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5em 0;
}

/* Page section highlight in doc viewer */
.doc-page-section.highlight {
    background: rgba(251, 191, 36, 0.12);
    border-left: 3px solid var(--warning-color);
    padding-left: 0.8em;
    margin: 0.5em 0;
    border-radius: 4px;
}

.doc-viewer-body .doc-line {
    padding: 1px 8px;
    border-radius: 2px;
}

.doc-viewer-body .doc-line.highlight {
    background: rgba(251, 191, 36, 0.25);
    border-left: 3px solid var(--warning-color);
    padding-left: 5px;
}

.doc-viewer-body .loading-text {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.doc-viewer-body .error-state {
    text-align: center;
    padding: 2rem;
    color: var(--danger-color);
}

/* Summary Modal */
.summary-modal {
    max-width: 700px;
    width: 95%;
    height: 80vh;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

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

.summary-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.summary-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary);
    min-height: 0;
}

.summary-content {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
}

.summary-content strong {
    color: var(--primary-color);
}

.summary-content ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.summary-content li {
    margin-bottom: 0.3rem;
}

.summary-loading {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Suggested Questions */
.suggested-questions {
    margin-top: 1.5rem;
}

.suggested-questions h4 {
    margin-bottom: 0.8rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.question-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.question-chip {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    max-width: 100%;
}

.question-chip:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.suggestions-loading {
    text-align: center;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Document card action button (small) */
.btn-xs {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
}

/* ==================== Prompt Modal ==================== */

.prompt-modal {
    max-width: 420px;
    width: 92%;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

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

.prompt-modal-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.prompt-modal-body {
    padding: 1.25rem 1.5rem;
}

.prompt-modal-body .form-group {
    margin-bottom: 1rem;
}

.prompt-modal-body .form-group:last-child {
    margin-bottom: 0;
}

.prompt-input {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: var(--transition);
}

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

.prompt-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.85rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

/* Color Picker */
.color-picker-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.25rem;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    padding: 0;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--text-secondary);
}

/* Tag Checkbox List */
.tag-checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 260px;
    overflow-y: auto;
}

.tag-checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.tag-checkbox-item:hover {
    background: var(--bg-secondary);
}

.tag-checkbox-item input[type="checkbox"] {
    accent-color: var(--primary-color);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.tag-checkbox-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tag-checkbox-name {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* ==================== Folder Explorer ==================== */

.folder-explorer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0 0.75rem;
    flex-wrap: wrap;
}

.folder-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.breadcrumb-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.breadcrumb-item.clickable {
    cursor: pointer;
    color: var(--primary-color);
}

.breadcrumb-item.clickable:hover {
    text-decoration: underline;
}

.breadcrumb-item.active {
    color: var(--text-primary);
}

.breadcrumb-sep {
    color: var(--text-tertiary);
    font-size: 1.1rem;
    margin: 0 0.1rem;
    user-select: none;
}

.breadcrumb-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.folder-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Folder Card */
.folder-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 2px solid transparent;
    user-select: none;
}

.folder-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    border-color: var(--border-color);
}

.folder-card.drop-target {
    border-color: var(--primary-light);
    border-style: dashed;
}

.folder-card.drag-over {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.07);
    transform: translateY(-3px) scale(1.02);
    box-shadow: var(--shadow-lg), 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.folder-icon-wrap {
    width: 64px;
    height: 48px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.folder-icon-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.1));
    transition: var(--transition);
}

.folder-card:hover .folder-icon-svg {
    transform: scale(1.05);
}

.folder-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
    word-break: break-word;
    line-height: 1.3;
}

.folder-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.folder-action-btn {
    position: absolute;
    top: 0.5rem;
    background: transparent;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
    padding: 0.2rem 0.35rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.folder-rename-btn {
    right: 2.2rem;
}

.folder-delete-btn {
    right: 0.5rem;
}

.folder-card:hover .folder-action-btn {
    opacity: 1;
}

.folder-rename-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
}

.folder-delete-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

/* Subfolder badge indicator */
.folder-subfolder-badge {
    position: absolute;
    bottom: 0.1rem;
    right: 0.1rem;
    font-size: 0.7rem;
    line-height: 1;
    pointer-events: none;
}

/* Drag states for document cards */
.document-card[draggable="true"] {
    cursor: grab;
}

.document-card[draggable="true"]:active {
    cursor: grabbing;
}

.document-card.dragging {
    opacity: 0.4;
    transform: scale(0.97);
    box-shadow: none;
}

/* Empty folder drop zone */
.folder-empty-drop {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-secondary);
    grid-column: 1 / -1;
    transition: var(--transition);
}

.folder-empty-drop.drag-over {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
    color: var(--primary-color);
}

/* Document card tag chips (folder badges) */
.document-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin: 0.5rem 0;
    min-height: 0;
}

.doc-tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 500;
}

/* ==================== Audit Log ==================== */

.audit-container {
    padding: 1rem 0;
}

.audit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.audit-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.audit-filters {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.audit-filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.audit-filter-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.audit-filter-group input[type="date"] {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.audit-table-wrapper {
    overflow: auto;
    max-height: calc(100vh - 340px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.audit-table thead {
    background: var(--bg-tertiary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.audit-table th {
    padding: 0.65rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.audit-table td {
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-primary);
}

.audit-table tbody tr:hover {
    background: var(--bg-secondary);
}

.audit-question-cell {
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audit-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding: 0.5rem 0;
}

.audit-page-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ==================== Admin Panel ==================== */

.admin-container {
    max-width: 100%;
}

/* Admin sub-tabs (Users / Groups) */
.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.password-wrapper input {
    flex: 1;
    padding-right: 2.5rem;
}
.password-toggle {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem;
    opacity: 0.5;
    transition: opacity 0.2s;
    line-height: 1;
}
.password-toggle:hover {
    opacity: 1;
}

.admin-subtabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    align-items: center;
}
.admin-refresh-btn {
    margin-left: auto;
    padding: 0.4rem 0.7rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: var(--transition);
}
.admin-refresh-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.admin-refresh-btn.spinning {
    animation: spin-refresh 0.8s linear infinite;
    pointer-events: none;
}
@keyframes spin-refresh {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.admin-subtab {
    padding: 0.6rem 1.25rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition);
}
.admin-subtab:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}
.admin-subtab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}
.admin-subtab-content {
    display: none;
}
.admin-subtab-content.active {
    display: block;
}

/* Admin message badge */
.admin-msg-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--danger-color);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    margin-left: 6px;
    line-height: 1;
}

/* ==================== Inbox ==================== */
.inbox-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.inbox-filter {
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.inbox-filter:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.inbox-filter.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.inbox-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.inbox-stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    min-width: 90px;
}

.inbox-stat-card.inbox-stat-unread {
    border-color: var(--primary-color);
    background: rgba(99,102,241,0.05);
}

.inbox-stat-num {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
}

.inbox-stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.inbox-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inbox-item {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all 0.2s;
}

.inbox-item:hover {
    border-color: var(--primary-light);
}

.inbox-item-unread {
    background: rgba(99,102,241,0.03);
    border-left: 3px solid var(--primary-color);
}

.inbox-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    cursor: pointer;
    gap: 16px;
}

.inbox-item-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.inbox-item-indicator {
    color: var(--primary-color);
    font-size: 0.7rem;
    flex-shrink: 0;
}

.inbox-item-type {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.inbox-item-info {
    min-width: 0;
}

.inbox-item-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.inbox-item-unread .inbox-item-name {
    font-weight: 700;
}

.inbox-item-email {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inbox-item-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.inbox-item-type-badge {
    font-size: 0.75rem;
    padding: 2px 10px;
    border-radius: 100px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: 500;
}

.inbox-item-date {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.inbox-plan-badge {
    font-size: 0.7rem;
    padding: 1px 8px;
    border-radius: 6px;
    background: rgba(16,185,129,0.1);
    color: var(--secondary-color);
    font-weight: 600;
    text-transform: capitalize;
}

.inbox-item-detail {
    border-top: 1px solid var(--border-color);
    padding: 18px;
    background: var(--bg-secondary);
}

.inbox-detail-body p {
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.inbox-detail-body strong {
    color: var(--text-primary);
}

.inbox-detail-message {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 8px;
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: pre-wrap;
    line-height: 1.6;
}

.inbox-detail-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.inbox-detail-actions .btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.inbox-detail-actions .btn-sm:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.inbox-detail-actions .btn-sm.btn-primary {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.inbox-detail-actions .btn-sm.btn-danger {
    color: var(--danger-color);
}

.inbox-detail-actions .btn-sm.btn-danger:hover {
    background: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

@media (max-width: 768px) {
    .inbox-item-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .inbox-item-right { width: 100%; justify-content: space-between; }
    .inbox-stats { gap: 8px; }
    .inbox-stat-card { min-width: 70px; padding: 8px 12px; }
    .inbox-stat-num { font-size: 1.2rem; }
}

/* Group plan badges */
.admin-badge-free { background: rgba(107,114,128,0.1); color: #6b7280; }
.admin-badge-pro { background: rgba(99,102,241,0.1); color: var(--primary-color); }
.admin-badge-enterprise { background: rgba(245,158,11,0.1); color: #f59e0b; }

/* Usage bar for groups table */
.admin-usage-bar {
    width: 100%;
    height: 5px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 0.25rem;
}
.admin-usage-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.admin-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.admin-stat-cards {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.admin-stat-cards .stat-card {
    flex: 1;
}

.admin-table-wrapper {
    max-height: calc(100vh - 340px);
    overflow: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.admin-table thead th {
    background: var(--bg-tertiary);
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    border-bottom: 2px solid var(--border-color);
}

.admin-table tbody td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    white-space: nowrap;
}

.admin-table tbody tr:hover {
    background: var(--bg-secondary);
}

.admin-table tbody tr:last-child td {
    border-bottom: none;
}

.admin-row-inactive {
    opacity: 0.55;
}

.admin-email-cell {
    font-weight: 500;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.admin-badge-admin {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.admin-badge-manager {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.admin-badge-user {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary-color);
}

.admin-badge-active {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.admin-badge-inactive {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.admin-badge-you {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    font-weight: 400;
}

.admin-actions-cell {
    display: flex;
    gap: 4px;
    align-items: center;
}

.btn-admin-action {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: var(--transition);
}

.btn-admin-action:hover {
    transform: scale(1.1);
}

.btn-admin-edit:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary-color);
}

.btn-admin-delete:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
}

/* Admin Group Selector Info */
.admin-group-info {
    margin-top: 0.5rem;
}

.admin-group-detail {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.admin-group-detail strong {
    color: var(--text-primary);
}

.admin-new-group-fields {
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    margin-top: 0.5rem;
    background: var(--bg-secondary);
}

.admin-group-props {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
}

.admin-group-props .form-group {
    margin-bottom: 0;
}

.admin-group-props .prompt-input {
    font-size: 0.82rem;
    padding: 6px 8px;
}

/* ==================== Upload Modal ==================== */

.upload-modal-content {
    max-width: 540px;
    padding: 1.75rem 2rem;
}

.upload-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.upload-modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.modal-close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Dropzone */
.upload-modal-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.upload-modal-dropzone:hover,
.upload-modal-dropzone.drag-over {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.04);
}

.upload-dropzone-icon {
    font-size: 2.5rem;
    margin-bottom: 0.25rem;
}

.upload-dropzone-text {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.upload-dropzone-sub {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.upload-dropzone-hint {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 0.5rem;
}

/* Selected files list */
.upload-modal-files-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.upload-modal-files-count {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.upload-modal-files-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.upload-modal-file-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
}

.upload-modal-file-icon {
    flex-shrink: 0;
}

.upload-modal-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    font-weight: 500;
}

.upload-modal-file-size {
    color: var(--text-secondary);
    font-size: 0.75rem;
    flex-shrink: 0;
}

.upload-modal-file-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 0.15rem 0.35rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    flex-shrink: 0;
}

.upload-modal-file-remove:hover {
    background: var(--danger-color);
    color: white;
}

.upload-modal-add-more {
    align-self: flex-start;
    font-size: 0.8rem;
}

/* Folder & Workspace selectors */
.upload-modal-section {
    margin-top: 1rem;
}

.upload-modal-label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.upload-modal-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.upload-modal-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.upload-modal-workspaces {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.upload-modal-ws-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-primary);
    background: var(--bg-secondary);
    user-select: none;
}

.upload-modal-ws-chip:hover {
    border-color: var(--primary-color);
}

.upload-modal-ws-chip:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.08);
    color: var(--primary-color);
    font-weight: 600;
}

.upload-modal-ws-chip input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--primary-color);
}

.upload-modal-hint {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-style: italic;
}

/* Actions */
.upload-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.upload-modal-actions .btn {
    min-width: 100px;
}

/* Upload Modal Tabs */
.upload-modal-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.upload-modal-tab {
    flex: 1;
    padding: 0.55rem 0.75rem;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.upload-modal-tab:not(:last-child) {
    border-right: 1px solid var(--border-color);
}

.upload-modal-tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.upload-modal-tab.active {
    background: var(--primary-color);
    color: white;
}

/* URL panel */
.upload-url-section {
    text-align: center;
    padding: 1.25rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.upload-url-icon {
    font-size: 2.2rem;
}

.upload-url-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
    max-width: 380px;
}

.upload-url-input {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: var(--transition);
}

.upload-url-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.upload-url-hint {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* ==================== Upload Progress Overlay ==================== */

.upload-progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 800;
}

.upload-progress-overlay.active {
    display: flex;
}

.upload-progress-panel {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    padding: 1.75rem 2rem;
    min-width: 380px;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: fadeIn 0.3s ease;
}

.upload-progress-panel h3 {
    font-size: 1.1rem;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
}

.upload-progress-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 360px;
    overflow-y: auto;
}

.upload-progress-item {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.upload-progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.upload-progress-name {
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 0.5rem;
}

.upload-progress-status {
    color: var(--text-secondary);
    font-size: 0.8rem;
    flex-shrink: 0;
}

.upload-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 999px;
    overflow: hidden;
}

.upload-progress-fill {
    height: 100%;
    background: var(--primary-color);
    border-radius: 999px;
    transition: width 0.4s ease;
}

.upload-progress-fill.success {
    background: var(--secondary-color);
}

.upload-progress-fill.error {
    background: var(--danger-color);
}

/* ==================== Sidebar Backdrop (mobile) ==================== */

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 149;
}

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

/* ==================== Mobile-Responsive Enhancements ==================== */

@media (max-width: 768px) {
    .mobile-sidebar-toggle {
        display: flex;
    }

    .chat-layout {
        grid-template-columns: 1fr;
        height: 100%;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 360px;
        z-index: 150;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        border-radius: 0;
        height: 100vh;
        overflow-y: auto;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* ── Bottom Tab Bar ── */
    .nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 120;
        background: var(--bg-primary);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        padding: 0;
        gap: 0;
        width: 100%;
        order: unset;
        overflow-x: hidden;
        -webkit-overflow-scrolling: auto;
    }

    .nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        padding: 0.4rem 0.25rem;
        font-size: 0;    /* hide original text */
        border-radius: 0;
        min-height: 52px;
        white-space: nowrap;
        position: relative;
        background: transparent;
        color: var(--text-secondary);
        transition: color 0.2s, background 0.2s;
    }

    .nav-btn::before {
        content: attr(data-icon);
        font-size: 1.25rem;
        line-height: 1;
    }

    .nav-btn::after {
        content: attr(data-i18n-short);
        font-size: 0.65rem;
        line-height: 1;
        color: inherit;
    }

    .nav-btn.active {
        color: var(--primary-color);
        background: transparent;
    }

    .nav-btn.active::after {
        font-weight: 600;
    }

    .nav-btn:hover {
        background: var(--bg-tertiary);
    }

    /* Header compact — no nav in header */
    .header-content {
        flex-wrap: nowrap;
        gap: 0.5rem;
    }

    /* Adjust main content for bottom bar */
    .main-content {
        height: calc(100vh - 60px);
        padding-bottom: 56px;  /* bottom tab bar height */
    }

    .chat-area {
        height: calc(100vh - 120px);
        min-height: unset;
        order: unset;
    }

    .user-info {
        gap: 0.4rem;
        min-width: 0;
        flex-shrink: 1;
    }

    .user-info .status-indicator,
    .user-info .status-text,
    .user-info #userInfo {
        display: none;
    }

    .logout-btn {
        padding: 0.35rem 0.6rem;
        font-size: 0.78rem;
        margin-left: 0 !important;
        white-space: nowrap;
    }

    /* Documents grid responsive */
    .documents-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 0.75rem;
    }

    .folder-card {
        padding: 1rem;
    }

    .folder-icon-wrap {
        width: 48px;
        height: 36px;
    }

    .documents-container {
        padding: 1rem;
    }

    .documents-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    /* Modals full-width on mobile */
    .modal-content {
        width: 96%;
        max-width: unset;
        padding: 1.5rem;
        margin: 0.5rem;
    }

    .doc-viewer-modal,
    .summary-modal {
        width: 98%;
        max-height: 90vh;
    }

    .prompt-modal {
        width: 95%;
    }

    /* Help Guide responsive */
    .help-guide-modal {
        padding: 1.25rem;
        max-height: 85vh;
        overflow-y: auto;
    }

    .help-guide-header h2 {
        font-size: 1.15rem;
    }

    .help-guide-intro {
        font-size: 0.85rem;
        margin-bottom: 1rem;
    }

    .help-section-toggle {
        padding: 0.7rem 0.85rem;
        font-size: 0.88rem;
    }

    .help-section-content {
        padding: 0.85rem 1rem;
        font-size: 0.85rem;
    }

    /* Chat header compact */
    .chat-header-actions {
        gap: 4px;
    }

    .chat-header-actions .btn-sm span {
        display: none;
    }

    /* Upload progress panel */
    .upload-progress-panel {
        min-width: unset;
        width: 95%;
        bottom: 60px;   /* above bottom bar */
    }

    /* Audit table scroll */
    .audit-filters {
        flex-direction: column;
        align-items: stretch;
    }

    /* Admin panel responsive */
    .admin-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .admin-stat-cards {
        flex-direction: column;
    }

    .admin-table-wrapper {
        max-height: calc(100vh - 400px);
    }

    .admin-table {
        font-size: 0.78rem;
    }

    .admin-table thead th,
    .admin-table tbody td {
        padding: 0.5rem 0.6rem;
    }
}

@media (max-width: 480px) {
    .logo-text {
        display: none;
    }

    .theme-toggle-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .language-selector {
        padding: 0.3rem 0.4rem;
        font-size: 0.78rem;
    }

    .documents-grid {
        grid-template-columns: 1fr;
    }

    .model-selector {
        gap: 0.25rem;
    }

    .model-toggle-btn {
        font-size: 0.78rem;
        padding: 0.4rem 0.5rem;
        min-height: 36px;
    }

    /* Help Guide extra-compact */
    .help-guide-modal {
        padding: 1rem;
    }

    .help-guide-header h2 {
        font-size: 1.05rem;
    }

    .help-section-toggle {
        padding: 0.6rem 0.75rem;
        font-size: 0.82rem;
    }

    .help-section-content {
        padding: 0.75rem 0.85rem;
        font-size: 0.82rem;
        line-height: 1.55;
    }

    .help-section-content ol,
    .help-section-content ul {
        padding-left: 1rem;
    }

    /* Hide logout text, show icon only */
    .logout-btn {
        font-size: 0;
        padding: 0.3rem 0.5rem;
        min-width: 32px;
        min-height: 32px;
    }

    .logout-btn::before {
        content: '🚪';
        font-size: 1rem;
    }
}

/* ── Retry Button on Error Messages ── */
.retry-msg-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.5rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--primary-color);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.retry-msg-btn:hover {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* ==================== Legal Analysis Templates ==================== */

.model-toggle-btn.mode-active {
    background-color: var(--accent-color, #7c3aed);
    color: #fff;
    border-color: var(--accent-color, #7c3aed);
}

.templates-bar {
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    padding: 0.6rem 0.75rem 0.5rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin-bottom: 0.25rem;
}

.templates-bar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.templates-bar-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.templates-add-btn {
    background: none;
    border: 1px solid var(--border-color);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1rem;
    padding: 0 0.35rem;
    border-radius: 4px;
    line-height: 1.3;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.templates-add-btn:hover,
.templates-add-btn.active {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 8%, transparent);
}

/* Inline form for creating a custom template */
.template-add-form {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.65rem 0.5rem 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
}
.tpl-form-input {
    width: 100%;
    padding: 0.4rem 0.55rem;
    font-size: 0.82rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-sizing: border-box;
    font-family: inherit;
    resize: none;
}
.tpl-form-input:focus {
    outline: none;
    border-color: var(--primary-color);
}
.tpl-form-icon {
    width: 3.5rem;
}
.tpl-form-textarea {
    min-height: 3.5rem;
}
.tpl-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
.tpl-form-cancel {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
}
.tpl-form-cancel:hover { background: var(--bg-secondary); }
.tpl-form-save {
    padding: 0.3rem 0.9rem;
    font-size: 0.8rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-color);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
}
.tpl-form-save:hover { filter: brightness(1.1); }

/* Custom template card variant */
.template-card-custom {
    border-style: dashed;
    position: relative;
}
.template-delete-btn {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.65rem;
    padding: 1px 4px;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.template-card-custom:hover .template-delete-btn {
    opacity: 1;
}
.template-delete-btn:hover {
    color: #ef4444;
}

.templates-bar-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0 0.2rem;
    border-radius: 4px;
    line-height: 1;
}
.templates-bar-close:hover { color: var(--text-primary); }

.templates-scroll {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    scrollbar-width: thin;
}
.templates-scroll::-webkit-scrollbar { height: 4px; }
.templates-scroll::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.template-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    min-width: 140px;
    max-width: 175px;
    padding: 0.5rem 0.65rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    text-align: left;
    flex-shrink: 0;
}
.template-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.template-card.active {
    border-color: var(--accent-color, #7c3aed);
    background: color-mix(in srgb, var(--accent-color, #7c3aed) 10%, var(--bg-primary));
}

.template-icon {
    font-size: 1.1rem;
    line-height: 1;
}
.template-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.template-desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.templates-empty {
    font-size: 0.82rem;
    color: var(--text-secondary);
    padding: 0.25rem 0;
}

/* ==================== Cross-Document Compare Panel ==================== */

.compare-panel {
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    padding: 0.6rem 0.75rem 0.6rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin-bottom: 0.25rem;
    max-height: 260px;
    overflow-y: auto;
}

.compare-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.compare-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0.5rem;
}

.compare-doc-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
}

.compare-doc-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.3rem 0.4rem;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
    font-size: 0.85rem;
}
.compare-doc-checkbox:hover { background: var(--bg-primary); }
.compare-doc-checkbox input[type="checkbox"] {
    accent-color: var(--primary-color);
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}
.compare-doc-name {
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 25px);
}

.compare-queries {
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
}
.compare-queries-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.4rem;
}
.compare-query-chip {
    display: inline-block;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
    color: var(--text-primary);
    cursor: pointer;
    margin: 0.2rem 0.25rem 0.2rem 0;
    transition: border-color 0.15s, background 0.15s;
    text-align: left;
    line-height: 1.4;
}
.compare-query-chip:hover {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 8%, var(--bg-primary));
}
.compare-min-hint {
    color: var(--warning-color, #d97706);
    font-size: 0.78rem;
    margin-top: 0.25rem;
}

/* ==================== Regulatory Reference Links ==================== */

.legal-ref-link {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dashed var(--primary-color);
    font-weight: 500;
    transition: color 0.15s, border-color 0.15s;
}
.legal-ref-link:hover {
    color: var(--accent-color, #7c3aed);
    border-bottom-style: solid;
    border-color: var(--accent-color, #7c3aed);
}

/* ==================== Case / Matter Mode ==================== */

.ws-case-ref-group {
    margin-top: 0.25rem;
}
.ws-case-ref-input {
    font-size: 0.88rem;
}
.case-ref-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 10%, var(--bg-primary));
    border: 1px solid color-mix(in srgb, var(--primary-color) 30%, transparent);
    border-radius: 4px;
    padding: 0.05rem 0.35rem;
    margin-left: 0.25rem;
    vertical-align: middle;
    letter-spacing: 0.03em;
}
