/* ============================================================
   PaperWriter — Design System
   A refined, editorial-style scholarly workspace.
   Palette: Slate/Navy (#0f172a → #f8fafc)
   Fonts:   Inter (UI) + Lora (body/serif)
   ============================================================ */

/* --- Design Tokens --- */
:root {
    /* Brand palette (slate) */
    --brand-50:  #f8fafc;
    --brand-100: #f1f5f9;
    --brand-200: #e2e8f0;
    --brand-300: #cbd5e1;
    --brand-400: #94a3b8;
    --brand-500: #64748b;
    --brand-600: #475569;
    --brand-700: #334155;
    --brand-800: #1e293b;
    --brand-900: #0f172a;
    --brand-950: #020617;

    /* Accent */
    --accent: #0f172a;
    --accent-hover: #334155;

    /* Semantic */
    --bg-app:     #fafafa;
    --bg-surface: #ffffff;
    --bg-muted:   #f4f4f4;
    --text-primary:   var(--brand-900);
    --text-secondary: var(--brand-500);
    --text-muted:     var(--brand-400);
    --border:     #e5e7eb;
    --border-light: #f3f4f6;

    /* Layout */
    --sidebar-width: 224px;
    --header-height: 48px;
    --right-panel-width: 480px;

    /* Radius & Shadow */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-pill: 9999px;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-modal: 0 40px 80px rgba(0,0,0,0.15);
    --shadow-paper: 0 1px 4px rgba(0,0,0,0.06);

    /* Transitions */
    --ease-smooth: cubic-bezier(0.25, 0.1, 0.25, 1);
}

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

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.5;
}

body.is-resizing * {
    transition: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
}

body.is-resizing iframe {
    pointer-events: none !important;
}

/* --- Custom Scrollbars (thin, slate) --- */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--brand-200);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--brand-300);
}

.scroll-minimal::-webkit-scrollbar { width: 4px; }
.scroll-minimal::-webkit-scrollbar-track { background: transparent; }
.scroll-minimal::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 3px; }
.scroll-minimal::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.15); }

/* ============================================================
   LAYOUT
   ============================================================ */

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    overflow: hidden;
    background: var(--bg-app);
}

/* --- Top Header Bar --- */
.main-header {
    height: var(--header-height);
    min-height: var(--header-height);
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 30;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 24px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-icon {
    width: 24px;
    height: 24px;
    background: var(--brand-900);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 11px;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--brand-950);
    letter-spacing: -0.01em;
    text-transform: uppercase;
}

.header-divider {
    width: 1px;
    height: 16px;
    background: var(--brand-200);
}

.header-doc-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-doc-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--brand-500);
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: none;
    background: transparent;
    outline: none;
    font-family: inherit;
    padding: 4px 0;
    cursor: text;
}

.header-doc-title:focus {
    color: var(--brand-900);
}

.header-autosave {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--brand-400);
    font-weight: 500;
}

.header-autosave svg {
    width: 10px;
    height: 10px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--brand-400);
    padding: 4px;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.header-menu-btn:hover {
    color: var(--brand-900);
}

.header-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--brand-50);
    border: 1px solid var(--brand-100);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand-600);
    font-weight: 500;
    font-size: 10px;
}

/* --- Main Content Area (below header) --- */
.main-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
    width: var(--sidebar-width);
    min-width: 60px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    transition: width 0.3s var(--ease-smooth), padding 0.3s;
}

.sidebar.collapsed {
    width: 72px !important;
}

/* Nav container */
#section-nav {
    flex: 1;
    overflow-y: auto;
    padding: 32px 16px 16px;
}

.sidebar.collapsed #section-nav {
    padding: 16px 8px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.sidebar.collapsed #section-nav::-webkit-scrollbar {
    display: none;
}

/* Section group labels */
.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--brand-400);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    padding: 0 8px;
    margin-bottom: 16px;
}

.sidebar.collapsed .nav-section-label {
    display: none;
}

.nav-section-group {
    margin-bottom: 32px;
}

/* Nav items */
.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    font-size: 14px;
    color: var(--brand-500);
    cursor: pointer;
    transition: color 0.2s, background 0.15s;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    position: relative;
    border-left: 2px solid transparent;
    margin-left: -1px;
}

.nav-item:hover {
    color: var(--brand-900);
}

.nav-item.active {
    color: var(--brand-950);
    font-weight: 600;
    border-left-color: var(--brand-950);
}

.nav-item::before {
    display: none; /* remove the counter */
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px 0;
    margin-left: 0;
    border-left: none;
}

.sidebar.collapsed .nav-item span {
    display: none;
}

.sidebar.collapsed .nav-actions {
    display: none !important;
}

.sidebar.collapsed .add-section-nav {
    display: none !important;
}

/* Sub-items */
.nav-subitem {
    padding: 5px 8px 5px 24px;
    font-size: 13px;
    color: var(--brand-500);
    cursor: pointer;
    transition: color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: var(--radius-sm);
    margin-bottom: 1px;
}

.nav-subitem:hover {
    color: var(--brand-900);
}

.nav-subitem.active {
    color: var(--brand-950);
    font-weight: 600;
}

.sidebar.collapsed .nav-subitem {
    display: none !important;
}

/* Nav actions (hover buttons) */
.nav-actions {
    display: flex;
    gap: 2px;
}

.action-btn {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    background: transparent;
    color: var(--brand-400);
    transition: all 0.15s;
    cursor: pointer;
    border: none;
}

.action-btn:hover {
    background: var(--brand-100);
    color: var(--brand-900);
}

.action-btn.delete-btn:hover {
    background: #fef2f2;
    color: #ef4444;
}

/* Add section */
.add-section-nav {
    margin-top: 8px;
    border-top: 1px solid var(--border-light);
    padding-top: 8px !important;
    border-left: none !important;
}

.add-section-nav::before {
    display: none !important;
}

/* --- Library Section (bottom nav) --- */
.sidebar-library {
    padding: 0 16px;
    margin-bottom: 8px;
}

.sidebar.collapsed .sidebar-library {
    padding: 0 8px;
}

/* --- Export Controls (bottom of sidebar) --- */
.export-controls {
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border-light);
}

.sidebar.collapsed .export-controls {
    padding: 12px 8px;
    gap: 6px;
}

/* --- Buttons --- */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: inherit;
}

.btn-primary {
    background: var(--brand-900);
    color: white;
    border: 1px solid var(--brand-900);
}

.btn-primary:hover {
    background: var(--brand-800);
    border-color: var(--brand-800);
}

.btn-secondary {
    background: transparent;
    color: var(--brand-500);
    border: 1px solid var(--brand-200);
}

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

.btn-primary.sm {
    width: auto;
    padding: 5px 12px;
    font-size: 11px;
    border-radius: var(--radius-sm);
}

/* Collapsed sidebar buttons */
.sidebar.collapsed .btn-primary span,
.sidebar.collapsed .btn-secondary span {
    display: none;
}

.sidebar.collapsed .btn-primary,
.sidebar.collapsed .btn-secondary {
    padding: 10px;
    width: 44px;
    height: 44px;
    min-width: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    justify-content: center;
    margin: 0 auto;
}

/* ============================================================
   RESIZER HANDLES
   ============================================================ */

.resizer {
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 200;
    background: transparent;
    transition: background 0.2s;
    flex-shrink: 0;
    position: relative;
    margin: 0 -3px;
}

.resizer::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 1px;
    height: 30px;
    background: var(--brand-200);
    border-radius: 1px;
    transition: height 0.2s, background 0.2s;
}

.resizer:hover,
.resizer.dragging {
    background: var(--brand-900);
}

.resizer:hover::after,
.resizer.dragging::after {
    background: white;
    height: 100%;
}

/* ============================================================
   EDITOR AREA (Center)
   ============================================================ */

.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: var(--bg-surface);
}

/* Top bar (document title + index terms) */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    gap: 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.doc-title-input {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    border: none;
    background: transparent;
    padding: 4px 0;
    width: 100%;
    font-family: 'Inter', sans-serif;
    outline: none;
    letter-spacing: -0.03em;
    transition: color 0.2s;
}

.doc-title-input:hover {
    color: var(--brand-700);
}

.doc-title-input:focus {
    color: var(--text-primary);
}

.index-terms-container {
    margin-top: -4px;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.index-terms-container label {
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--brand-400);
    white-space: nowrap;
}

.index-terms-container input {
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 13px;
    color: var(--brand-600);
    outline: none;
    width: 350px;
    padding: 2px 0;
}

.status {
    font-size: 11px;
    font-weight: 500;
    color: var(--brand-400);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Formatting toolbar */
.formatting-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 32px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.formatting-toolbar .toolbar-btn {
    padding: 6px 8px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--brand-900);
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.formatting-toolbar .toolbar-btn:hover {
    background: var(--brand-50);
}

.formatting-toolbar .toolbar-btn.active {
    background: var(--brand-100);
}

.formatting-toolbar .toolbar-btn .btn-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--brand-600);
}

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

.toolbar-divider {
    width: 1px;
    height: 16px;
    background: var(--border-light);
    margin: 0 6px;
}

.formatting-toolbar .heading-btn {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: -0.02em;
    color: var(--brand-500);
}

/* Editor scroll area */
#editor-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 48px 48px;
    background: var(--bg-surface);
    display: flex;
    justify-content: center;
}

#editor-content {
    max-width: 720px;
    width: 100%;
}

/* Section blocks */
.section-block {
    margin-bottom: 32px;
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    border: none;
}

.section-title-input {
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 16px;
    border: none;
    background: transparent;
    padding: 4px 0;
    width: 100%;
    outline: none;
    letter-spacing: -0.02em;
    font-family: 'Inter', sans-serif;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.section-title-input:focus {
    border-bottom-color: var(--brand-200);
}

.section-header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

/* TipTap Editor */
.ProseMirror {
    min-height: 80px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    outline: none;
}

.ProseMirror p {
    font-family: 'Lora', 'Georgia', serif;
    line-height: 1.9;
    font-size: 1.05rem;
    color: var(--brand-700);
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}

.ProseMirror h3 {
    font-family: 'Inter', sans-serif;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--brand-900);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.ProseMirror h4 {
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--brand-700);
    margin-top: 1.2rem;
    margin-bottom: 0.4rem;
}

.ProseMirror strong,
.ProseMirror b {
    font-weight: 700;
    color: var(--brand-900);
}

.ProseMirror em,
.ProseMirror i {
    font-style: italic;
    color: var(--brand-700);
}

.ProseMirror p.is-empty::before {
    color: var(--brand-300);
    content: attr(data-placeholder);
    float: left;
    height: 0;
    pointer-events: none;
    font-family: 'Lora', serif;
}

/* Figure ref bars */
.fig-ref-bar,
.cite-ref-bar {
    padding: 6px 0;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.fig-ref-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: var(--brand-50);
    border: 1px solid var(--brand-200);
    border-radius: 2px;
    font-size: 12px;
    font-weight: 500;
    color: var(--brand-900);
    cursor: pointer;
    transition: all 0.15s;
    font-family: 'Inter', sans-serif;
}

.fig-ref-chip:hover {
    background: var(--brand-100);
    border-color: var(--brand-300);
}

/* Citation chip styling */
.citation {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: var(--brand-500);
    background: var(--brand-100);
    padding: 1px 6px;
    border-radius: 2px;
    border: 1px solid var(--brand-200);
}

.fig-ref {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: var(--brand-900);
    background: var(--brand-50);
    padding: 1px 6px;
    border-radius: 2px;
    border: 1px solid var(--brand-300);
}

/* ============================================================
   RIGHT PANEL (Preview)
   ============================================================ */

.right-panel {
    width: var(--right-panel-width);
    flex-shrink: 0;
    border-left: 1px solid var(--border-light);
    background: var(--bg-muted);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 50;
}

/* Preview header */
.preview-header {
    height: 40px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--brand-200);
    flex-shrink: 0;
}

.preview-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.preview-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--brand-900);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.preview-format {
    font-size: 10px;
    color: var(--brand-400);
}

.preview-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-zoom-btn {
    padding: 4px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--brand-600);
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
}

.preview-zoom-btn:hover {
    background: var(--brand-100);
    color: var(--brand-900);
}

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

/* Preview content area */
#tab-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-muted);
    overflow: hidden;
}

.preview-frame-container {
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

#latex-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: calc(100% + 18px); /* hide native scrollbar */
    height: 100%;
    border: none;
    background: white;
}

/* Preview footer (stats) */
.preview-footer {
    padding: 12px 24px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.preview-stats {
    display: flex;
    gap: 16px;
}

.preview-stat {
    font-size: 10px;
    display: flex;
    gap: 4px;
}

.preview-stat-label {
    font-weight: 700;
    color: var(--brand-400);
    text-transform: uppercase;
    letter-spacing: -0.02em;
}

.preview-stat-value {
    font-weight: 500;
    color: var(--brand-900);
}

.preview-comments-btn {
    font-size: 10px;
    font-weight: 600;
    color: var(--brand-500);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
    font-family: inherit;
}

.preview-comments-btn:hover {
    color: var(--brand-900);
}

.comments-badge {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--brand-900);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 700;
}

/* ============================================================
   MODALS
   ============================================================ */

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-width: 90vw;
    max-height: 90vh;
    animation: modalPop 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.authors-modal-content,
.references-modal-content {
    width: 900px;
    height: 85vh;
}

.images-modal-content {
    width: 1000px;
    height: 88vh;
}

.tables-modal-content {
    width: 900px;
    height: 85vh;
}

.equation-modal-content {
    width: 650px;
    height: auto;
    max-height: 85vh;
}

.confirm-modal-content {
    width: 360px;
    height: auto;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
}

.confirm-card-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.confirm-icon-container {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #fef2f2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ef4444;
    margin-bottom: 8px;
}

.confirm-icon-container.primary-accent {
    background: #eff6ff;
    color: #3b82f6;
}

.confirm-warning-icon {
    width: 24px;
    height: 24px;
}

.confirm-modal-content h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--brand-950);
}

.confirm-modal-content p {
    margin: 0;
    font-size: 13px;
    color: var(--brand-500);
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.confirm-card-footer {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-top: 24px;
}

.btn-confirm-secondary,
.btn-confirm-danger,
.btn-confirm-primary {
    flex: 1;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    outline: none;
}

.btn-confirm-secondary {
    background: #f1f5f9;
    color: var(--brand-600);
}

.btn-confirm-secondary:hover {
    background: #e2e8f0;
    color: var(--brand-900);
}

.btn-confirm-danger {
    background: #ef4444;
    color: white;
}

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

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

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

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

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--brand-900);
}

.close-modal {
    font-size: 18px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-50);
    border-radius: 50%;
    color: var(--brand-500);
    cursor: pointer;
    line-height: 0;
    transition: all 0.2s var(--ease-smooth);
}

.close-modal:hover {
    background: var(--brand-100);
    color: var(--brand-900);
    transform: scale(1.05);
}

.modal-body-split {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.modal-sidebar {
    width: 320px;
    border-right: 1px solid var(--border);
    background: var(--brand-50);
    display: flex;
    flex-direction: column;
}

.modal-sidebar.wider {
    width: 380px;
}

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

.modal-sidebar-header h4 {
    margin: 0;
    font-weight: 600;
    font-size: 14px;
    color: var(--brand-900);
}

.modal-sidebar-header.mini {
    padding: 16px 24px;
}

.modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.modal-list-item {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
}

.modal-list-item:hover {
    border-color: var(--brand-300);
}

.modal-list-item.active {
    border-color: var(--brand-900);
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.08);
}

.modal-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    overflow: hidden;
}

.modal-form-container {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
}

.modal-form-container h4 {
    margin-top: 0;
    margin-bottom: 28px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--brand-900);
}

.modal-input-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.modal-input-group label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--brand-400);
}

.modal-input,
.modal-select,
.modal-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--brand-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s;
    background: var(--bg-surface);
    color: var(--brand-900);
}

.modal-input:focus,
.modal-select:focus,
.modal-textarea:focus {
    border-color: var(--brand-900);
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.08);
}

.modal-input.mono,
.modal-textarea.mono {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
}

.modal-textarea {
    min-height: 180px;
    resize: vertical;
}

.modal-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.modal-form-grid .modal-input-group {
    margin-bottom: 0;
    min-width: 0;
}

.modal-actions-footer {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-info-box {
    background: var(--brand-50);
    border: 1px solid var(--brand-200);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 13px;
    color: var(--brand-600);
    margin-bottom: 20px;
    line-height: 1.5;
}

.btn-danger {
    padding: 8px 14px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

.modal-error {
    color: #ef4444;
    background: #fef2f2;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    display: none;
    border: 1px solid #fecaca;
}

/* Image modal specifics */
.modal-drop-zone {
    margin: 12px;
    padding: 16px 12px;
    border: 2px dashed var(--brand-200);
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-drop-zone:hover,
.modal-drop-zone.drag-over {
    border-color: var(--brand-900);
    background: rgba(15, 23, 42, 0.02);
}

.table-meta-card {
    background: #f8fafc;
    border: 1px solid var(--brand-100);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
}

/* Global input placeholder styles */
.modal-input::placeholder,
.modal-select::placeholder,
.modal-textarea::placeholder {
    font-family: 'Inter', sans-serif;
    color: #94a3b8 !important;
    font-size: 13px;
    font-weight: 400;
}

.drop-icon {
    font-size: 20px;
    margin-bottom: 6px;
}

.drop-text {
    font-weight: 600;
    margin: 0;
    font-size: 13px;
    color: var(--brand-900);
}

.drop-subtext {
    color: var(--brand-400);
    margin: 4px 0 0;
    font-size: 12px;
}

.modal-img-preview {
    width: 100%;
    height: 260px;
    background: var(--brand-50);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    overflow: hidden;
    border: 1px solid var(--brand-200);
    color: var(--brand-400);
    font-size: 13px;
}

.modal-img-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.img-thumb-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
    overflow: hidden;
}

.img-thumb-card:hover {
    border-color: var(--brand-300);
    transform: translateY(-1px);
    box-shadow: var(--shadow-card);
}

.img-thumb-card.selected {
    border-color: var(--brand-900);
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.08);
}

.img-thumb-card img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--brand-50);
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.04);
}

.img-thumb-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.img-thumb-caption {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.img-thumb-label {
    font-size: 11px;
    color: var(--brand-500);
    font-family: 'SFMono-Regular', monospace;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Range slider */
.modal-range {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--brand-200);
    outline: none;
    margin-top: 4px;
}

.modal-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--brand-900);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ============================================================
   AI MODAL (Diff View)
   ============================================================ */

.diff-view {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.diff-panel {
    flex: 1;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--brand-50);
    font-size: 13px;
    white-space: pre-wrap;
    font-family: 'Lora', serif;
    line-height: 1.7;
}

.diff-panel h4 {
    margin-top: 0;
    font-size: 11px;
    color: var(--brand-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: 'Inter', sans-serif;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ============================================================
   PRINT STYLES
   ============================================================ */

@media print {
    @page {
        margin: 0.5in;
        size: auto;
    }

    body * {
        visibility: hidden;
    }

    #ieee-preview,
    #ieee-preview * {
        visibility: visible;
    }

    #app {
        height: auto;
        overflow: visible;
    }

    .sidebar,
    .export-controls,
    .top-bar,
    .main-header,
    .formatting-toolbar,
    .modal-overlay,
    .right-panel {
        display: none !important;
    }
}

/* ============================================================
   SPINNER
   ============================================================ */

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* ============================================================
   SIDEBAR TOGGLE BUTTON
   ============================================================ */

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px 0;
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-header {
    padding: 12px 8px 0;
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--brand-400);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
    background: var(--brand-50);
    color: var(--brand-900);
}

/* Hide sidebar header logo text on collapse */
.sidebar .logo {
    font-weight: 700;
    font-size: 13px;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    display: none; /* hidden - using main header instead */
}

/* ============================================================
   EDITOR TOOLBAR (legacy, kept for compat)
   ============================================================ */

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--brand-50);
    padding: 4px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 4px;
}

.toolbar-group:not(:last-child) {
    border-right: 1px solid var(--brand-200);
    margin-right: 4px;
}

.editor-toolbar button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--brand-500);
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.editor-toolbar button:hover {
    background: var(--brand-100);
    color: var(--brand-900);
}

/* ============================================================
   IFRAME PREVIEW (IEEE-style rendering within iframe)
   ============================================================ */

.ieee-paper h1.ieee-title {
    font-size: 24pt;
    text-align: center;
    margin-bottom: 0.5em;
    font-weight: bold;
    line-height: 1;
}

.ieee-paper .ieee-author-block {
    text-align: center;
    margin-bottom: 24pt;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.ieee-paper .ieee-author {
    font-size: 11pt;
    font-style: normal;
}

.ieee-paper .ieee-affiliation {
    font-size: 10pt;
    font-style: italic;
}

.ieee-body {
    column-count: 2;
    column-gap: 0.25in;
    text-align: justify;
    height: 100%;
    widows: 2;
    orphans: 2;
}

.ieee-body img {
    max-width: 100%;
    height: auto;
}

.ieee-section-title {
    font-variant: small-caps;
    font-weight: bold;
    font-size: 10pt;
    text-align: center;
    margin-top: 12pt;
    margin-bottom: 6pt;
    letter-spacing: 0.05em;
    break-after: avoid;
}

.ieee-abstract {
    font-weight: bold;
    margin-bottom: 0;
    font-style: italic;
}

.ieee-keywords {
    font-weight: bold;
    font-style: italic;
    margin-top: 0.5em;
    margin-bottom: 1em;
}

.ieee-body p {
    text-indent: 1em;
    margin: 0;
}

.ieee-abstract p {
    display: inline;
    font-weight: bold;
}

/* ============================================================
   ADDITIONS FOR CITE/REF, TABLES, EQUATIONS, FOOTNOTES, COMMENTS
   ============================================================ */

/* Floating Citation/Reference Trigger & Menu */
.floating-cite-trigger {
    transition: opacity 0.2s var(--ease-smooth);
}
.floating-cite-trigger button {
    background: var(--brand-950);
    color: white;
    border: none;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-pill);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.floating-cite-trigger button:hover {
    background: var(--brand-800);
}
.floating-cite-trigger button svg {
    stroke-width: 2.5;
}

.floating-cite-menu {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--brand-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    width: 220px;
    transition: opacity 0.15s;
    overflow: hidden;
}

.ref-menu-tab {
    transition: background 0.15s, color 0.15s;
}
.ref-menu-tab:hover {
    background: var(--brand-200);
    color: var(--brand-900);
}
.ref-menu-tab.active {
    background: var(--brand-950) !important;
    color: white !important;
}

.floating-cite-item {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--brand-800);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.12s, color 0.12s;
    text-align: left;
    border: none;
    background: transparent;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.floating-cite-item:hover {
    background: var(--brand-50);
    color: var(--brand-950);
}
.floating-cite-item .cite-key {
    font-family: monospace;
    font-weight: 600;
    color: var(--brand-900);
}
.floating-cite-item .cite-desc {
    color: var(--brand-500);
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Comment Highlighting and Cards */
.comment-highlight {
    background-color: rgba(253, 224, 71, 0.45) !important;
    border-bottom: 2px dashed #eab308 !important;
    border-radius: 2px;
    cursor: pointer;
}

.comment-card {
    background: white;
    border: 1px solid var(--brand-200);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    box-shadow: var(--shadow-card);
    transition: border-color 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.comment-card:hover {
    border-color: var(--brand-400);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
}
.comment-card .comment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.comment-card .comment-author {
    font-size: 11px;
    font-weight: 700;
    color: var(--brand-900);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.comment-card .comment-date {
    font-size: 10px;
    color: var(--brand-400);
}
.comment-card .comment-quote {
    font-size: 12px;
    font-style: italic;
    color: var(--brand-600);
    border-left: 2px solid var(--brand-300);
    padding-left: 8px;
    margin: 4px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.comment-card .comment-text {
    font-size: 13px;
    color: var(--brand-800);
    line-height: 1.4;
}
.comment-card .comment-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
}
.comment-card .comment-btn {
    background: none;
    border: 1px solid var(--brand-200);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--brand-600);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    transition: all 0.15s;
    width: auto;
}
.comment-card .comment-btn:hover {
    background: var(--brand-50);
    border-color: var(--brand-800);
    color: var(--brand-900);
}
.comment-card .comment-btn.resolve-btn {
    border-color: rgba(34, 197, 94, 0.2);
    color: #16a34a;
}
.comment-card .comment-btn.resolve-btn:hover {
    background: #f0fdf4;
    border-color: #16a34a;
    color: #15803d;
}

/* Spreadsheet Grid Editor */
.table-grid-cell {
    border: 1px solid var(--brand-200);
    padding: 4px;
    background: white;
}
.table-grid-cell input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 12px;
    padding: 4px;
    font-family: inherit;
}
.table-grid-header-cell {
    background: var(--brand-100);
    font-weight: bold;
    text-align: center;
    border: 1px solid var(--brand-300);
    padding: 4px;
    min-width: 80px;
}

/* Right Panel Tabs active styles */
.preview-tab-btn {
    transition: all 0.2s;
}
.preview-tab-btn:hover {
    color: var(--brand-900) !important;
}
.preview-tab-btn.active {
    color: var(--brand-950) !important;
    border-bottom-color: var(--brand-950) !important;
}

/* Equation Modal and Presets */
.eq-preset-card {
    background: white;
    border: 1px solid var(--brand-200);
    border-radius: var(--radius-md);
    padding: 12px;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}
.eq-preset-card:hover {
    border-color: var(--brand-900);
    box-shadow: var(--shadow-card);
    transform: translateY(-1px);
}
.eq-preset-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--brand-900);
    margin-bottom: 6px;
}
.eq-preset-math {
    font-family: monospace;
    font-size: 10px;
    color: var(--brand-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-delete-btn {
    background: none;
    border: none;
    color: var(--brand-400);
    cursor: pointer;
    padding: 4px;
    font-size: 18px;
    font-weight: 500;
    transition: all 0.2s var(--ease-smooth);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.card-delete-btn:hover {
    color: #ef4444 !important;
    background: rgba(239, 68, 68, 0.08);
}