/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f8f6f3;
    --bg-card: #ffffff;
    --bg-sidebar: #faf9f7;
    --text: #2d2d2d;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --primary: #1e3a5f;
    --primary-light: #2d5a8e;
    --primary-bg: #e8f0fe;
    --accent: #b8860b;
    --accent-light: #daa520;
    --border: #e5e2dc;
    --border-light: #f0ede8;
    --success: #059669;
    --error: #dc2626;
    --warning: #d97706;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
    --font-body: 'Inter', -apple-system, sans-serif;
    --font-serif: 'Crimson Pro', Georgia, serif;
    --header-height: 56px;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* ===== Login ===== */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #2d5a8e 50%, #b8860b 100%);
}

.login-container {
    background: white;
    padding: 48px 40px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-logo {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 16px;
}

.login-container h1 {
    font-family: var(--font-serif);
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.error-msg {
    color: var(--error);
    font-size: 13px;
    margin-top: 12px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

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

.btn-accent {
    background: var(--accent);
    color: white;
}
.btn-accent:hover { background: var(--accent-light); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover { background: var(--border-light); color: var(--text); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 12px; }
.btn-danger { background: var(--error); color: white; }
.btn-danger:hover { background: #b91c1c; }

/* ===== Header ===== */
.app-header {
    height: var(--header-height);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-serif);
    font-size: 20px;
    font-weight: 700;
}

.header-nav {
    display: flex;
    gap: 4px;
    flex: 1;
}

.nav-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
}
.nav-btn:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-btn.active { color: white; background: rgba(255,255,255,0.2); }

.header-right { margin-left: auto; }
.header-right .btn-ghost { color: rgba(255,255,255,0.7); }
.header-right .btn-ghost:hover { color: white; background: rgba(255,255,255,0.1); }

/* ===== Main ===== */
.app-main {
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

.tab-panel {
    display: none;
    height: 100%;
    overflow-y: auto;
}
.tab-panel.active { display: flex; }

/* ===== Library ===== */
.library-layout {
    display: flex;
    width: 100%;
    height: 100%;
}

.library-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.library-content {
    flex: 1;
    overflow-y: auto;
}

/* Document table */
.doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.doc-table thead th {
    text-align: left;
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-sidebar);
    position: sticky;
    top: 0;
    z-index: 1;
}
.doc-row {
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border-light);
}
.doc-row:hover { background: var(--primary-bg); }
.doc-row.selected { background: var(--primary-bg); }
.doc-row td { padding: 10px 12px; vertical-align: top; }
.doc-row-icon { color: var(--text-muted); font-size: 16px; text-align: center; }
.doc-row-title { font-weight: 500; line-height: 1.3; }
.doc-row-tags { margin-top: 3px; display: flex; gap: 3px; flex-wrap: wrap; }
.doc-row-tags .tag { font-size: 10px; padding: 1px 5px; }
.doc-row-meta { font-size: 12px; color: var(--text-muted); }

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

.sidebar-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.sidebar-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-body);
}
.sidebar-search input:focus {
    outline: none;
    border-color: var(--primary);
}

.filter-tags {
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    max-height: 120px;
    overflow-y: auto;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: var(--primary-bg);
    color: var(--primary);
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}
.tag:hover, .tag.active { background: var(--primary); color: white; }
.tag small { opacity: 0.7; margin-left: 2px; }
.tag i { margin-right: 3px; font-size: 10px; }

.doc-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px;
}

.doc-item {
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}
.doc-item:hover { background: white; border-color: var(--border); }
.doc-item.selected { background: var(--primary-bg); border-color: var(--primary); }

.doc-item-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
    line-height: 1.3;
}

.doc-item-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.doc-item-tags {
    margin-top: 4px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}


.library-empty, .content-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 12px;
}
.library-empty i, .content-empty i { font-size: 48px; opacity: 0.3; }

/* Document detail */
.doc-detail {
    padding: 32px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.doc-detail h1 {
    font-family: var(--font-serif);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--primary);
}

.doc-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.doc-detail-meta span { display: flex; align-items: center; gap: 4px; }

.doc-detail-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.doc-detail section {
    margin-bottom: 24px;
}

.doc-detail section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.doc-notes {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 13px;
    resize: vertical;
}
.doc-notes:focus { outline: none; border-color: var(--primary); }

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

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

.modal h2 {
    font-family: var(--font-serif);
    font-size: 22px;
    margin-bottom: 20px;
    color: var(--primary);
}

.modal .form-group {
    margin-bottom: 14px;
}

.modal .form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal .form-group input,
.modal .form-group textarea,
.modal .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font-body);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
}
.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-bg);
    color: var(--primary);
}
.drop-zone i { font-size: 32px; margin-bottom: 8px; display: block; }

/* ===== Research Chat ===== */
.research-layout {
    display: flex;
    width: 100%;
    height: 100%;
}

.chat-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}
.chat-item:hover { background: white; }
.chat-item.active { background: var(--primary-bg); color: var(--primary); font-weight: 500; }
.chat-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
}
.chat-item:hover .chat-item-delete { opacity: 1; }

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-doc-bar {
    padding: 8px 16px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    flex-wrap: wrap;
}

.chat-doc-bar .tag { cursor: pointer; }
.chat-doc-bar .tag .fa-times { margin-left: 4px; font-size: 10px; }

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

.chat-msg {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
}

.chat-msg .btn-delete-msg {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: inherit;
    opacity: 0;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 11px;
    transition: opacity 0.15s, background 0.15s;
}

.chat-msg:hover .btn-delete-msg {
    opacity: 0.4;
}

.chat-msg .btn-delete-msg:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
    align-self: flex-start;
    background: white;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-msg.assistant h1,
.chat-msg.assistant h2,
.chat-msg.assistant h3 {
    font-family: var(--font-serif);
    margin: 12px 0 6px;
}
.chat-msg.assistant h1 { font-size: 18px; }
.chat-msg.assistant h2 { font-size: 16px; }
.chat-msg.assistant h3 { font-size: 14px; }

.chat-msg.assistant p { margin-bottom: 8px; }
.chat-msg.assistant ul, .chat-msg.assistant ol { padding-left: 20px; margin-bottom: 8px; }
.chat-msg.assistant code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}
.chat-msg.assistant pre {
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 8px 0;
}
.chat-msg.assistant blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    color: var(--text-muted);
    margin: 8px 0;
}

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: white;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-mode-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-body);
    background: white;
    min-width: 120px;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font-body);
    resize: none;
    min-height: 44px;
    max-height: 150px;
}
.chat-input:focus { outline: none; border-color: var(--primary); }

/* ===== Editor ===== */
.editor-layout {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

.editor-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.2s, min-width 0.2s, opacity 0.2s;
}
.editor-sidebar.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
    opacity: 0;
    pointer-events: none;
}

/* Expand button when sidebar is collapsed */
.sidebar-expand-btn {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 24px;
    height: 48px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 11px;
    transition: background 0.15s, color 0.15s;
}
.sidebar-expand-btn:hover {
    background: var(--primary-bg);
    color: var(--primary);
}
.sidebar-expand-btn.hidden { display: none; }

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

.project-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.project-item {
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}
.project-item:hover { background: white; border-color: var(--border); }
.project-item.selected { background: var(--primary-bg); border-color: var(--primary); }
.project-item-title { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.project-item-meta { font-size: 11px; color: var(--text-muted); display: flex; gap: 12px; }

.project-status {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}
.project-status.draft { background: var(--border-light); color: var(--text-muted); }
.project-status.in_progress { background: #dbeafe; color: #1d4ed8; }
.project-status.review { background: #fef3c7; color: #92400e; }
.project-status.final { background: #d1fae5; color: #065f46; }

.editor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-toolbar {
    padding: 8px 16px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.editor-toolbar input {
    font-family: var(--font-serif);
    font-size: 20px;
    font-weight: 700;
    border: none;
    outline: none;
    flex: 1;
    min-width: 200px;
    color: var(--primary);
}

.editor-toolbar-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.editor-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Project Brief */
.project-brief {
    padding: 10px 16px;
    background: var(--bg-subtle, rgba(99, 102, 241, 0.04));
    border-bottom: 1px solid var(--border);
}

.project-brief-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.project-brief-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.project-brief-hint {
    font-weight: 400;
    font-size: 11px;
    color: var(--primary);
    text-transform: none;
    letter-spacing: 0;
}

.btn-upload-brief {
    cursor: pointer;
    font-size: 11px !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
}

.project-brief textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    min-height: 60px;
    max-height: 200px;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
}

.project-brief textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Project Docs / Sources Panel */
.project-docs-empty {
    padding: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

.project-doc-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.project-doc-item:hover {
    background: var(--bg-hover, rgba(0,0,0,0.03));
}

.project-doc-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: var(--primary-light, rgba(99, 102, 241, 0.1));
    color: var(--primary);
    font-size: 13px;
}

.project-doc-info {
    flex: 1;
    min-width: 0;
}

.project-doc-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-doc-meta {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-doc-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}
.project-doc-item:hover .project-doc-actions { opacity: 1; }

/* ========================================
   Ruler — Word-style margin control
   ======================================== */

.editor-ruler-wrapper {
    background: #e8e8e8;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
    z-index: 10;
    padding: 0;
    border-bottom: 1px solid #ccc;
}

.editor-ruler {
    width: 8.5in;
    height: 24px;
    position: relative;
    background: #f0f0f0;
    border-bottom: 1px solid #bbb;
    user-select: none;
}

.ruler-track {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    --ruler-left-pct: 14.7%;  /* 1.25/8.5 */
    --ruler-right-pct: 14.7%;
}

/* Shaded margin zones */
.ruler-track::before,
.ruler-track::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    background: #ddd;
    z-index: 1;
}
.ruler-track::before {
    left: 0;
    width: var(--ruler-left-pct);
}
.ruler-track::after {
    right: 0;
    width: var(--ruler-right-pct);
}

/* Tick marks */
.ruler-tick {
    position: absolute;
    top: 0;
    width: 1px;
    background: #bbb;
    transform: translateX(-0.5px);
    z-index: 2;
}
.ruler-tick-minor {
    height: 4px;
    top: auto;
    bottom: 0;
}
.ruler-tick-half {
    height: 7px;
    top: auto;
    bottom: 0;
}
.ruler-tick-major {
    height: 11px;
    top: auto;
    bottom: 0;
    background: #999;
}
.ruler-tick-label {
    position: absolute;
    bottom: 11px;
    left: 50%;
    transform: translateX(-50%);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 8px;
    color: #888;
    white-space: nowrap;
}

/* Draggable margin handles */
.ruler-handle {
    position: absolute;
    top: 2px;
    width: 0;
    height: 0;
    z-index: 5;
    cursor: col-resize;
    transform: translateX(-6px);
}

/* Triangle pointing down */
.ruler-handle::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 10px solid #555;
    transition: border-top-color 0.15s;
}

.ruler-handle:hover::after,
.ruler-handle:active::after {
    border-top-color: #2563eb;
}

/* Wider hit area for easier grabbing */
.ruler-handle::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    width: 20px;
}

/* ========================================
   US Letter page simulation (8.5" × 11")
   Turabian/Chicago: 1" margins, Times 12pt, double-spaced
   ======================================== */

.editor-content {
    flex: 1;
    min-width: 0;
    background: #e8e8e8;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.editor-content .EasyMDEContainer {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.editor-content .EasyMDEContainer .CodeMirror {
    flex: 1;
    background: #e8e8e8;
    border: none;
    border-radius: 0;
    padding: 40px 0;
}

/* The actual "page" — white paper centered */
.editor-content .CodeMirror-scroll {
    padding: 0;
    overflow-x: auto !important;
}

.editor-content .CodeMirror-sizer {
    width: 8.5in;
    min-width: 8.5in;
    max-width: 8.5in;
    margin: 0 auto !important;
    padding: var(--ruler-margin-top, 1in) var(--ruler-margin-right, 1.25in) var(--ruler-margin-bottom, 1in) var(--ruler-margin-left, 1.25in) !important;
    min-height: 11in;
    background: white;
    box-shadow: 2px 0 12px rgba(0,0,0,0.1), -2px 0 12px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

/* Typography: Times New Roman 12pt, double-spaced */
.editor-content .CodeMirror pre {
    font-family: 'Times New Roman', 'Crimson Pro', Georgia, serif;
    font-size: 12pt;
    line-height: 2; /* double-spaced */
    color: #1a1a1a;
    text-align: justify;
}

/* Paragraph indent matching Word export (0.5in first line) */
.editor-content .CodeMirror pre.CodeMirror-line {
    text-indent: 0.5in;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* No indent on headings, footnote defs, blank lines, lists, blockquotes, HR, comments */
.editor-content pre.CodeMirror-line:has(.cm-header-1),
.editor-content pre.CodeMirror-line:has(.cm-header-2),
.editor-content pre.CodeMirror-line:has(.cm-header-3),
.editor-content pre.CodeMirror-line:has(.cm-header-4),
.editor-content pre.CodeMirror-line:has(.cm-header-5),
.editor-content pre.CodeMirror-line:has(.cm-header-6),
.editor-content .cm-footdef-line pre.CodeMirror-line,
.editor-content pre.CodeMirror-line:has(.cm-hr),
.editor-content pre.CodeMirror-line:has(.cm-formatting-list),
.editor-content pre.CodeMirror-line:has(.cm-formatting-quote),
.editor-content pre.CodeMirror-line:has(.cm-comment) {
    text-indent: 0 !important;
}

/* Headings — matching Word export (Final Hintermüller format) */
.editor-content .cm-header-1 {
    font-size: 16pt;
    font-weight: 700;
    color: #1a1a1a;
}
.editor-content .cm-header-2 {
    font-size: 14pt;
    font-weight: 700;
    color: #1a1a1a;
}
.editor-content .cm-header-3 {
    font-size: 12pt;
    font-weight: 700;
    color: #1a1a1a;
}
.editor-content .cm-header-4,
.editor-content .cm-header-5,
.editor-content .cm-header-6 {
    font-size: 12pt;
    font-weight: 400;
    font-style: italic;
    color: #333;
}

/* Center heading lines + hide # markers for WYSIWYG feel */
.editor-content .CodeMirror-line:has(.cm-header-1),
.editor-content .CodeMirror-line:has(.cm-header-2),
.editor-content .CodeMirror-line:has(.cm-header-3) {
    text-align: center;
}
.editor-content .cm-formatting-header {
    font-size: 0;
    letter-spacing: 0;
    width: 0;
    display: inline-block;
    overflow: hidden;
    vertical-align: baseline;
}

/* HTML comments (<!-- orientation notes -->) — subtle, won't print */
.editor-content .cm-comment {
    color: #9ca3af;
    font-style: italic;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 10pt;
    background: #f0f4ff;
    border-radius: 3px;
    padding: 1px 4px;
    border-left: 2px solid #a5b4fc;
}

/* Horizontal rules — page break indicator */
.editor-content .cm-hr {
    color: #d1d5db;
}

/* Bold / italic — hide markdown syntax markers for WYSIWYG feel */
.editor-content .cm-strong { font-weight: 700; }
.editor-content .cm-em { font-style: italic; }
.editor-content .cm-formatting-em,
.editor-content .cm-formatting-strong {
    font-size: 0;
    letter-spacing: 0;
    width: 0;
    display: inline-block;
    overflow: hidden;
    vertical-align: baseline;
}

/* Footnote references [^N] in editor — superscript, compact */
.editor-content .cm-overlay.cm-footref {
    font-size: 9pt;
    vertical-align: super;
    line-height: 0;
    font-weight: 600;
    letter-spacing: -0.5px;
}

/* Unverified footnotes — red highlight */
.editor-content .cm-overlay.cm-footref-unverified {
    color: #dc3545;
    background: rgba(220, 53, 69, 0.12);
    border-radius: 2px;
    padding: 1px 2px;
}

/* Verified footnotes — normal blue */
.editor-content .cm-overlay.cm-footref-verified {
    color: var(--primary, #4472C4);
}

/* Footnote definitions [^N]: ... — source data, dimmed since rendered per-page */
.editor-content .cm-footdef-line .CodeMirror-line,
.editor-content .cm-footdef-line .CodeMirror-line span {
    font-size: 9pt !important;
    line-height: 1.2 !important;
    color: #999 !important;
}

/* Separator + label above first footnote definition */
.editor-content .cm-footdef-line:not(.cm-footdef-line + .cm-footdef-line) {
    border-top: 1px dashed #bbb;
    padding-top: 6px;
    margin-top: 4px;
}

/* Hide list formatting markers */
.editor-content .cm-formatting-list {
    color: #ccc;
}

/* Blockquote formatting — match Word (indented, smaller, single-spaced) */
.editor-content .cm-quote {
    font-size: 11pt;
}
.editor-content .cm-formatting-quote {
    color: #ccc;
}

/* Links — hide [](url) syntax, show text only */
.editor-content .cm-formatting-link,
.editor-content .cm-formatting-link-string,
.editor-content .cm-url {
    font-size: 0;
    letter-spacing: 0;
    width: 0;
    display: inline-block;
    overflow: hidden;
    vertical-align: baseline;
}
.editor-content .cm-link {
    color: #1a1a1a;
    text-decoration: none;
}

/* Cursor line highlight */
.editor-content .CodeMirror-activeline-background {
    background: rgba(59, 130, 246, 0.04);
}

/* Page number feel — bottom margin visual */
.editor-content .CodeMirror-lines {
    padding-bottom: 40px;
}

/* Force all line widgets to stay within the sizer content area */
.editor-content .CodeMirror-linewidget {
    overflow: hidden;
}

/* Per-page footnotes */
.page-fn-area {
    font-family: 'Times New Roman', Times, serif;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.page-fn-rule {
    border: none;
    border-top: 1px solid #000;
    width: 2in;
    margin: 0 0 4px 0;
}

.page-fn-entry {
    font-size: 10pt;
    line-height: 1.3;
    color: #000;
    margin: 0;
}

.page-fn-entry sup {
    font-size: 8pt;
    margin-right: 2px;
}

/* Page gap — gray divider between pages */
.page-break-gap {
    height: 12px;
    background: #e8e8e8;
    position: relative;
    box-shadow:
        inset 0 6px 6px -4px rgba(0,0,0,0.15),
        inset 0 -6px 6px -4px rgba(0,0,0,0.15);
}

/* Page number label */
.page-break-gap .page-break-label {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 9px;
    color: #aaa;
    position: absolute;
    right: var(--ruler-margin-right, 1.25in);
    top: 50%;
    transform: translateY(-50%);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Vertical margin controls next to ruler */
.ruler-vertical-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px;
    flex-shrink: 0;
}

.ruler-vertical-controls label {
    display: flex;
    align-items: center;
    gap: 3px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 9px;
    color: #888;
    cursor: default;
}

.ruler-vertical-controls input {
    width: 42px;
    height: 18px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 9px;
    text-align: center;
    padding: 0 2px;
    background: white;
    color: #555;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.ruler-vertical-controls input:focus {
    outline: none;
    border-color: #2563eb;
}

/* ========================================
   Preview mode — same letter format
   ======================================== */

.editor-content .editor-preview,
.editor-content .editor-preview-side {
    background: #e8e8e8;
    padding: 40px;
}

.editor-content .editor-preview-active,
.editor-content .editor-preview-active-side {
    background: #e8e8e8;
}

/* Preview page text styles — applied during measurement AND display */
.preview-pages-wrapper,
.preview-page-content,
.editor-content .editor-preview-side > * {
    font-family: 'Times New Roman', 'Crimson Pro', Georgia, serif;
    font-size: 12pt;
    line-height: 2;
    color: #1a1a1a;
}

.editor-content .editor-preview {
    max-width: none;
    margin: 0;
    background: #e8e8e8;
    box-shadow: none;
    padding: 40px 20px;
    min-height: auto;
    overflow-x: auto;
}

.preview-pages-wrapper h1,
.preview-page-content h1 {
    font-family: 'Times New Roman', 'Crimson Pro', Georgia, serif;
    font-size: 16pt;
    font-weight: 700;
    color: #1a1a1a;
    text-align: center;
    margin: 12pt 0 0;
    line-height: 2;
    border: none;
    padding: 0;
}
.preview-pages-wrapper h2,
.preview-page-content h2 {
    font-family: 'Times New Roman', 'Crimson Pro', Georgia, serif;
    font-size: 14pt;
    font-weight: 700;
    text-align: center;
    margin: 12pt 0 0;
    line-height: 2;
}
.preview-pages-wrapper h3,
.preview-page-content h3 {
    font-family: 'Times New Roman', 'Crimson Pro', Georgia, serif;
    font-size: 12pt;
    font-weight: 700;
    text-align: center;
    margin: 12pt 0 0;
    line-height: 2;
}
.preview-pages-wrapper p,
.preview-page-content p {
    text-indent: 0.5in;
    margin: 0;
}
.preview-pages-wrapper p:first-child,
.preview-pages-wrapper h1 + p,
.preview-pages-wrapper h2 + p,
.preview-pages-wrapper h3 + p,
.preview-page-content p:first-child,
.preview-page-content h1 + p,
.preview-page-content h2 + p,
.preview-page-content h3 + p {
    text-indent: 0; /* no indent after headings per Turabian */
}
.preview-pages-wrapper ul,
.preview-pages-wrapper ol,
.preview-page-content ul,
.preview-page-content ol {
    padding-left: 0.5in;
    margin: 0.5em 0;
}
.preview-pages-wrapper li,
.preview-page-content li {
    margin: 0.2em 0;
}
.preview-pages-wrapper blockquote,
.preview-page-content blockquote {
    margin: 1em 0 1em 0.5in;
    padding: 0;
    border-left: none;
    font-size: 11pt;
    line-height: 1.5; /* block quotes single-spaced per Turabian */
}
.preview-pages-wrapper hr,
.preview-page-content hr {
    border: none;
    border-top: 1px solid #d1d5db;
    margin: 2em auto;
    width: 2in;
}

/* Links in preview */
.preview-pages-wrapper a,
.preview-page-content a {
    color: #1a1a1a;
    text-decoration: none;
    border-bottom: 1px dotted #999;
}

/* Footnote references [^N] — superscript in preview */
.fn-ref {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
}
.fn-ref a {
    color: var(--primary) !important;
    border-bottom: none !important;
    font-weight: 600;
    text-decoration: none;
}
.fn-ref a:hover { text-decoration: underline; }

/* Footnote hover tooltip */
.fn-tooltip {
    position: fixed;
    z-index: 10000;
    max-width: 400px;
    padding: 10px 14px;
    background: #1a1a2e;
    color: #e8e8e8;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.5;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    animation: fnTooltipIn 0.15s ease-out;
}
.fn-tooltip p {
    margin: 0;
}
.fn-tooltip em {
    color: #c8c8ff;
}
@keyframes fnTooltipIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Footnote section at bottom of preview */
.fn-separator {
    border: none;
    border-top: 1px solid #999;
    width: 2in;
    margin: 2em 0 1em !important;
    text-align: left;
}
.footnotes {
    font-size: 10pt;
    line-height: 1;
    color: #1a1a1a;
}
.fn-list {
    padding-left: 0;
    margin: 0;
    list-style: none;
}
.fn-list li {
    margin: 0;
    text-indent: 0.5in;
}
.fn-text p {
    display: inline;
    text-indent: 0 !important;
    margin: 0;
}

/* Footnote dialog bibliography items */
.fn-bib-item:hover {
    background: var(--primary-bg) !important;
    border-color: var(--border) !important;
}
.fn-modal { max-height: 80vh; }

/* ===== Preview Pages with Per-Page Footnotes ===== */
.preview-pages-wrapper {
    padding: 0;
    min-width: 8.5in;
}

.preview-page {
    width: 8.5in;
    min-width: 8.5in;
    max-width: 8.5in;
    height: 11in;
    margin: 0 auto 32px;
    background: white;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    padding: 1in 1.25in;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

.preview-page-content {
    flex: 1;
}

.preview-page-footnotes {
    margin-top: auto;
    padding-top: 8px;
    font-family: 'Times New Roman', Georgia, serif;
    font-size: 10pt;
    line-height: 1;
    color: #1a1a1a;
}

.preview-page-footnotes .fn-separator {
    border: none;
    border-top: 1px solid #666;
    width: 2in;
    margin: 12px 0 8px !important;
    text-align: left;
}

.preview-page-footnotes .fn-entry {
    margin: 0;
    text-indent: 0.5in;
    padding-left: 0;
}

.preview-page-footnotes .fn-entry sup {
    font-size: 10pt;
    margin-right: 2px;
}

.preview-page-number {
    position: absolute;
    bottom: 0.5in;
    left: 0;
    right: 0;
    text-align: center;
    font-family: 'Times New Roman', Georgia, serif;
    font-size: 11pt;
    color: #666;
}

/* Override EasyMDE preview background for pages */
.editor-content .editor-preview-active {
    background: #e8e8e8;
    padding: 40px 20px;
    overflow-x: auto;
}

/* Footnote markers in editor (CodeMirror) — highlight [^N] */
.editor-content .cm-line .cm-footref,
.editor-content .CodeMirror-line [class*="bracket"] {
    /* handled by CodeMirror natively */
}

.editor-content .editor-toolbar {
    border-top: none;
    background: #f3f3f3;
    border-bottom: 1px solid var(--border);
}

/* Resize handle between editor and side panel */
.panel-resize-handle {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    flex-shrink: 0;
    transition: background 0.15s;
}
.panel-resize-handle:hover,
.panel-resize-handle:active {
    background: var(--primary);
    opacity: 0.3;
}
.panel-resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 32px;
    border-left: 1px dotted var(--text-muted);
    border-right: 1px dotted var(--text-muted);
    opacity: 0;
    transition: opacity 0.15s;
}
.panel-resize-handle:hover::after { opacity: 1; }

/* Editor body with side panels */
.editor-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Panel toggle buttons in toolbar */
.editor-panel-btns {
    display: flex;
    gap: 4px;
}
.editor-panel-btns .btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Shared side panel styles */
.side-panel {
    width: 400px;
    min-width: 400px;
    background: white;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.side-panel-header h4 {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.side-panel-body .chat-msg {
    max-width: 100%;
    font-size: 13px;
}

.side-panel-input {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 6px;
    align-items: flex-end;
}

.side-panel-input textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-body);
    resize: none;
    min-height: 36px;
    max-height: 120px;
}
.side-panel-input textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.panel-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    gap: 8px;
    flex: 1;
}
.panel-placeholder p { font-size: 13px; }
.panel-placeholder .hint { font-size: 11px; color: var(--text-light); }
.panel-placeholder ul {
    text-align: left;
    padding-left: 16px;
    line-height: 2;
    font-size: 13px;
}

/* Research panel specifics */
.research-session-bar {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    gap: 6px;
}

.research-session-select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    font-family: var(--font-body);
    background: white;
}

.research-doc-bar {
    padding: 6px 12px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 11px;
}

.doc-bar-label { color: var(--text-muted); }

.tag-sm {
    padding: 1px 6px;
    font-size: 10px;
}
.tag-sm .fa-times { margin-left: 3px; cursor: pointer; }

.btn-xs { padding: 3px 6px; font-size: 11px; }

.research-mode-select {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 11px;
    font-family: var(--font-body);
    background: white;
    min-width: 90px;
}

.doc-picker-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid var(--border-light);
    margin-bottom: 6px;
}

/* Bibliography panel */
.bib-toolbar {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.bib-toolbar select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    font-family: var(--font-body);
    background: white;
}

.bib-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-muted);
}
.bib-search-bar i { font-size: 12px; }
.bib-search-bar input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 13px;
    background: transparent;
    color: var(--text);
    font-family: var(--font-body);
}
.bib-search-bar input::placeholder { color: var(--text-muted); }

.bib-author {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.bib-entry {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    line-height: 1.5;
}
.bib-entry:last-child { border-bottom: none; }

/* Unread bibliography entries */
.bib-entry.bib-unread {
    background: rgba(220, 38, 38, 0.08);
    border-left: 3px solid #dc2626;
}

/* Read toggle button */
.btn-toggle-read {
    color: var(--text-muted) !important;
}
.bib-entry.bib-unread .btn-toggle-read {
    color: #dc2626 !important;
}
.bib-entry:not(.bib-unread) .btn-toggle-read {
    color: #16a34a !important;
}

.bib-entry-number {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    min-width: 24px;
    padding-top: 1px;
}

.bib-entry-content { flex: 1; }

.bib-citation { font-family: var(--font-serif); }

.bib-title-link {
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}
.bib-title-link:hover { text-decoration: underline; }

.bib-title-text { color: var(--text); }

.bib-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.bib-entry-actions {
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: opacity 0.15s;
}
.bib-entry-actions .btn-edit-bib,
.bib-entry-actions .btn-delete-bib {
    opacity: 0;
}
.bib-entry:hover .btn-edit-bib,
.bib-entry:hover .btn-delete-bib { opacity: 1; }

.bib-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 6px;
}
.bib-footer .btn-full { flex: 1; }

/* ===== Notes Panel ===== */
.notes-toolbar {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: center;
}
.notes-toolbar select { flex: 1; }

.note-entry {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}
.note-entry:hover { background: var(--bg-hover, rgba(0,0,0,0.03)); }

.note-category-badge {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    margin-top: 2px;
    font-size: 13px;
}

.note-content {
    flex: 1;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.note-actions {
    display: flex;
    flex-direction: column;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}
.note-entry:hover .note-actions { opacity: 1; }

.notes-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 6px;
}
.notes-footer .btn-full { flex: 1; }

/* Research file upload */
.btn-research-upload {
    cursor: pointer;
    flex-shrink: 0;
}

.research-file-preview {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-subtle, rgba(99, 102, 241, 0.04));
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    background: var(--primary-light, rgba(99, 102, 241, 0.1));
    color: var(--primary);
}

.file-chip.uploading {
    opacity: 0.7;
}

.file-chip-size {
    color: var(--text-muted);
    font-size: 11px;
}

.btn-remove-file {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 2px;
    font-size: 11px;
}
.btn-remove-file:hover { color: var(--danger, #ef4444); }

/* Download-to-project button in chat */
.btn-download-doc {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    font-size: 11px;
    color: var(--primary);
    vertical-align: middle;
}
.btn-download-doc:hover { text-decoration: underline; }
.btn-download-doc.btn-success-done {
    color: var(--success, #10b981);
    cursor: default;
}

/* ===== Notifications ===== */
#notifications {
    position: fixed;
    top: 68px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notification {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.notification.success { background: #ecfdf5; color: #065f46; border-left: 3px solid var(--success); }
.notification.error { background: #fef2f2; color: #991b1b; border-left: 3px solid var(--error); }
.notification.info { background: #eff6ff; color: #1e40af; border-left: 3px solid #3b82f6; }

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

/* ===== Spinner ===== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}
.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-light);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Streaming cursor */
.streaming-cursor {
    display: inline;
    animation: blink 0.7s infinite;
    color: var(--primary);
    font-weight: 700;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .library-sidebar, .chat-sidebar, .editor-sidebar {
        width: 100%;
        min-width: unset;
        max-height: 40vh;
    }
    .library-layout, .research-layout, .editor-layout {
        flex-direction: column;
    }
    .side-panel {
        width: 100%;
        min-width: unset;
        max-height: 50vh;
    }
    .editor-body {
        flex-direction: column;
    }
}
