:root {
    --bg-color: #0d1117;
    --sidebar-bg: rgba(22, 27, 34, 0.6);
    --panel-bg: rgba(22, 27, 34, 0.3);
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --accent-color: #79c0ff;
    --ai-gradient-start: #10b981;
    --ai-gradient-end: #059669;
    --border-color: rgba(255, 255, 255, 0.1);
    --topbar-height: 60px;
}

[data-theme="light"] {
    --bg-color: #ffffff;
    --sidebar-bg: rgba(255, 255, 255, 0.8);
    --panel-bg: rgba(255, 255, 255, 0.6);
    --text-primary: #24292f;
    --text-secondary: #57606a;
    --accent-color: #0969da;
    --border-color: rgba(0, 0, 0, 0.1);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background-image: radial-gradient(circle at 15% 50%, rgba(16, 185, 129, 0.04), transparent 35%), 
                      radial-gradient(circle at 85% 30%, rgba(121, 192, 255, 0.04), transparent 35%);
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, .logo, p {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    transition: color 0.3s ease;
}

p, span, div { font-family: 'Inter', sans-serif; font-weight: 400; }
h1, h2, h3 { font-family: 'Outfit', sans-serif; font-weight: 600; }

.glass-panel {
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.top-bar {
    height: var(--topbar-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    z-index: 10;
    border-bottom: 1px solid var(--border-color);
}
.top-bar-left, .top-bar-right { display: flex; align-items: center; gap: 16px; }
.top-bar-left { min-width: 0; }
.top-bar-right { flex-shrink: 0; }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s ease, opacity 0.2s ease;
}
.icon-btn:hover { background: rgba(121, 192, 255, 0.1); }
.text-btn { font-size: 14px; font-weight: 600; }

.context-info { display: flex; gap: 12px; margin-left: 10px; }
.manuscript-badge {
    display: inline-block;
    max-width: min(52vw, 520px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    padding: 6px 14px;
    border-radius: 20px;
    background: rgba(121, 192, 255, 0.1);
    color: var(--accent-color);
    font-weight: 500;
    border: 1px solid rgba(121, 192, 255, 0.2);
    background: rgba(16, 185, 129, 0.1);
    color: var(--ai-gradient-start);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.feedback-modal {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(8px);
}
.feedback-dialog {
    width: min(560px, 100%);
    border-radius: 12px;
    padding: 22px;
}
.feedback-dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.feedback-dialog-header h3 {
    margin-bottom: 6px;
    color: var(--text-primary);
}
.feedback-dialog-header p,
#feedback-status {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}
#feedback-message {
    width: 100%;
    min-height: 180px;
    resize: vertical;
    background: rgba(0, 0, 0, 0.24);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 12px;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
}
#feedback-message:focus {
    border-color: var(--accent-color);
}
.feedback-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.app-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-width: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.app-wrapper.mobile-simulate {
    max-width: 420px;
    margin: 20px auto;
    border: 12px solid #1a1b1e;
    border-radius: 40px;
    height: calc(100vh - var(--topbar-height) - 40px);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
[data-theme="light"] .app-wrapper.mobile-simulate { border-color: #e1e4e8; box-shadow: 0 20px 50px rgba(0,0,0,0.1); }

/* Sidebar */
.sidebar {
    width: 250px;
    flex-shrink: 0;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}
.sidebar.hidden {
    width: 0; padding-left: 0; padding-right: 0; opacity: 0; overflow: hidden; border: none;
}
.sidebar-backdrop {
    display: none;
}
.logo { font-size: 24px; margin-bottom: 24px; padding-left: 8px;}
.logo .accent { color: var(--accent-color); }

.sidebar nav ul {
    list-style: none; overflow-y: auto; flex: 1; margin-bottom: 16px; scrollbar-width: thin;
}
.sidebar nav li {
    padding: 10px 14px; margin-bottom: 4px; border-radius: 8px; color: var(--text-secondary);
    font-size: 14px; cursor: pointer; transition: all 0.2s ease;
}
.sidebar nav li:hover { background: rgba(121, 192, 255, 0.05); color: var(--text-primary); }
.sidebar nav li.active { background: rgba(121, 192, 255, 0.1); color: var(--accent-color); font-weight: 500; }

.ai-meta-box {
    margin-top: auto; background: rgba(16, 185, 129, 0.05);
    border: 1px solid rgba(16, 185, 129, 0.2); border-radius: 12px; padding: 16px;
}
.ai-meta-box h3 {
    font-size: 13px; margin-bottom: 12px;
    background: -webkit-linear-gradient(left, var(--ai-gradient-start), var(--ai-gradient-end));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.meta-item { margin-bottom: 8px; font-size: 12px; }
.meta-label { color: var(--text-secondary); display: block; margin-bottom: 2px;}
.meta-value { color: var(--text-primary); font-style: italic; transition: color 0.5s ease;}

.usage-box {
    margin-top: 12px;
    background: rgba(121, 192, 255, 0.05);
    border: 1px solid rgba(121, 192, 255, 0.18);
    border-radius: 12px;
    padding: 8px;
}
.usage-toggle {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
}
.usage-toggle:hover {
    color: var(--text-primary);
}
.usage-chevron {
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    transform: rotate(0deg);
    transition: transform 0.2s ease;
}
.usage-box:not(.collapsed) .usage-chevron {
    transform: rotate(90deg);
}
.usage-details {
    padding: 6px 8px 8px;
}
.usage-row { margin-bottom: 12px; }
.usage-label {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 6px;
}
.usage-label span:last-child { color: var(--text-primary); }
.usage-bar {
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 6px;
    overflow: hidden;
}
.usage-bar div {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--ai-gradient-start), var(--ai-gradient-end));
    border-radius: 6px;
    transition: width 0.3s ease;
}
.usage-row p, #usage-status {
    color: var(--text-secondary);
    font-size: 11px;
    line-height: 1.4;
    margin-top: 5px;
}
.sidebar-user-card {
    margin-top: 12px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.035);
}
.sidebar-user-info {
    display: grid;
    gap: 4px;
    margin-bottom: 12px;
}
.sidebar-user-label {
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0;
}
.sidebar-user-info strong {
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.3;
}
.sidebar-user-info > span:not(.sidebar-user-label):not(.role-badge) {
    color: var(--text-secondary);
    font-size: 12px;
    overflow-wrap: anywhere;
}
.role-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    margin-top: 6px;
    font-size: 11px;
    padding: 5px 9px;
    border-radius: 999px;
    background: rgba(121, 192, 255, 0.1);
    color: var(--accent-color);
    font-weight: 500;
    border: 1px solid rgba(121, 192, 255, 0.2);
}
.sidebar-user-card .btn {
    width: 100%;
    justify-content: center;
    padding: 8px 10px;
    font-size: 12px;
}

/* Main Content & SPA */
.main-content {
    flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; padding: 24px 32px; overflow-y: auto; position: relative;
}
.view-section {
    display: flex; flex-direction: column; min-height: 100%; flex: 1; min-width: 0;
    animation: fadeIn 0.3s ease;
}
.hidden, .view-section.hidden { display: none !important; }

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

.header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.header-info p { color: var(--text-secondary); font-size: 14px; margin-top: 6px; font-weight: 400; }
.badge {
    font-size: 12px; padding: 4px 10px; border-radius: 12px;
    background: rgba(121, 192, 255, 0.1); vertical-align: middle; margin-left: 12px;
    border: 1px solid rgba(121, 192, 255, 0.3);
}
.badge.glowing {
    background: rgba(16, 185, 129, 0.1); border: 1px solid rgba(16, 185, 129, 0.4);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.btn {
    padding: 10px 18px; border-radius: 8px; border: none; font-family: 'Inter', sans-serif;
    font-weight: 500; font-size: 14px; cursor: pointer; transition: all 0.2s ease;
}
.btn-secondary { background: transparent; border: 1px solid var(--border-color); color: var(--text-primary); }
.btn-secondary:hover { background: rgba(121, 192, 255, 0.05); }
.btn-primary { background: var(--text-primary); color: var(--bg-color); }
.btn-primary:hover { opacity: 0.9; box-shadow: 0 0 15px rgba(255,255,255,0.2); }
.tool-menu {
    position: relative;
}
.tool-menu summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tool-menu summary::-webkit-details-marker {
    display: none;
}
.tool-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 20;
    min-width: 210px;
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #161b22;
    box-shadow: 0 18px 40px rgba(0,0,0,0.28);
}
[data-theme="light"] .tool-menu-panel {
    background: #ffffff;
}
.tool-menu-panel .btn {
    display: flex;
    justify-content: flex-start;
    width: 100%;
    text-align: left;
}

/* Grid Components for Modules */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}
.card { padding: 24px; border-radius: 16px; border: 1px solid var(--border-color); }
.card.interactive { cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; }
.card.interactive:hover {
    transform: translateY(-4px); box-shadow: 0 10px 30px rgba(121, 192, 255, 0.1);
    border-color: var(--accent-color);
}
.card h3 { margin-bottom: 8px; font-size: 18px; color: var(--text-primary); }
.card-meta { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }
.app-intro-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: start;
    padding: 22px;
    border-radius: 8px;
    margin-bottom: 18px;
}
.app-intro-copy {
    display: grid;
    gap: 8px;
    max-width: 860px;
}
.app-intro-kicker {
    color: var(--ai-gradient-start);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0;
}
.app-intro-copy h3 {
    color: var(--text-primary);
    font-size: 24px;
    line-height: 1.15;
}
.app-intro-copy p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    font-weight: 400;
}
.app-intro-note {
    font-size: 12px !important;
}
.app-intro-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.app-intro-steps {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.app-intro-steps div {
    display: grid;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
}
.app-intro-steps strong {
    color: var(--text-primary);
    font-size: 13px;
}
.app-intro-steps span {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.45;
}

.workflow-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 16px;
}
.workflow-summary div {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
}
.workflow-summary strong,
.workflow-summary span {
    display: block;
}
.workflow-summary strong {
    font-size: 20px;
    color: var(--text-primary);
}
.workflow-summary span {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}
.workflow-steps {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}
.workflow-step {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
}
.workflow-step-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.12);
    color: var(--ai-gradient-start);
    font-size: 13px;
    font-weight: 700;
}
.workflow-step.running .workflow-step-icon {
    background: linear-gradient(135deg, var(--ai-gradient-start), var(--ai-gradient-end));
    color: #fff;
}
.workflow-step.done .workflow-step-icon {
    background: rgba(16, 185, 129, 0.18);
    color: #059669;
}
.workflow-step.error .workflow-step-icon {
    background: rgba(239, 68, 68, 0.14);
    color: #ef4444;
}
.workflow-step strong {
    display: block;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.workflow-step p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

@media (max-width: 820px) {
    .illustration-cover-grid {
        grid-template-columns: 1fr !important;
    }
    .app-intro-card {
        grid-template-columns: 1fr;
        padding: 16px;
    }
    .app-intro-actions {
        justify-content: stretch;
    }
    .app-intro-actions .btn {
        flex: 1 1 160px;
    }
    .app-intro-steps {
        grid-template-columns: 1fr;
    }
    .workflow-grid,
    .workflow-summary {
        grid-template-columns: 1fr !important;
    }
}

/* Timeline Component */
.timeline { padding: 30px; border-radius: 16px; border: 1px solid var(--border-color); position: relative; }
.timeline::before {
    content: ''; position: absolute; top: 30px; left: 45px; bottom: 30px; width: 2px;
    background: var(--border-color);
}
.timeline-item { position: relative; padding-left: 50px; margin-bottom: 30px; }
.timeline-item:last-child { margin-bottom: 0; }
.timeline-marker {
    position: absolute; left: 9px; top: 0; width: 14px; height: 14px; border-radius: 50%;
    background: var(--bg-color); border: 2px solid var(--border-color); z-index: 1;
}
.timeline-item.completed .timeline-marker { background: #238636; border-color: #238636; box-shadow: 0 0 10px rgba(35, 134, 54, 0.5); }
.timeline-item.active .timeline-marker { background: var(--accent-color); border-color: var(--accent-color); box-shadow: 0 0 10px rgba(121, 192, 255, 0.5); }
.timeline-item h4 { margin-bottom: 6px; color: var(--text-secondary); font-size: 15px;}
.timeline-item.active h4, .timeline-item.completed h4 { color: var(--text-primary); }
.timeline-item p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

/* Analysis specific */
.glow-text {
    background: -webkit-linear-gradient(left, var(--ai-gradient-start), var(--ai-gradient-end));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { opacity: 0.7; filter: drop-shadow(0 0 2px rgba(16,185,129,0.2));}
    50% { opacity: 1; filter: drop-shadow(0 0 10px rgba(16,185,129,0.8)); }
    100% { opacity: 0.7; filter: drop-shadow(0 0 2px rgba(16,185,129,0.2));}
}

/* Workspace Editor */
.editor-workspace { display: flex; gap: 16px; flex: 1; min-height: 400px; }
.editor-workspace.hide-editor-nav #editor-nav-panel,
.editor-workspace.hide-editor-comments #editor-comments-panel {
    display: none !important;
}
.editor-panel {
    flex: 1; border-radius: 12px; display: flex; flex-direction: column;
    border: 1px solid var(--border-color); overflow: hidden;
}
.original-panel { background: rgba(0, 0, 0, 0.1); }
[data-theme="light"] .original-panel { background: rgba(0,0,0,0.03); }
.editable-panel { background: var(--panel-bg); }
.panel-header {
    padding: 14px 20px; border-bottom: 1px solid var(--border-color); background: rgba(0, 0, 0, 0.15);
}
[data-theme="light"] .panel-header { background: rgba(0,0,0,0.02); }
.panel-header h3 { font-size: 14px; color: var(--text-secondary); }
.panel-status-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    margin-left: auto;
}
.save-timestamp {
    display: inline-block;
    color: var(--text-secondary);
    font-size: 11px;
    line-height: 1.3;
    opacity: 0.78;
}
.save-timestamp.is-pending {
    color: #d97706;
}
.save-timestamp.is-saved {
    color: var(--ai-gradient-start);
}
.editor-content {
    padding: 20px; font-family: inherit; font-size: 15px; line-height: 1.8; flex: 1; overflow-y: auto; color: var(--text-secondary);
}
.editor-content.editable {
    background: transparent; color: var(--text-primary); border: none; resize: none; outline: none; transition: background-color 0.3s ease;
    white-space: pre-wrap;
}
.chapter-list {
    display: grid;
    gap: 8px;
    overflow-y: auto;
    min-height: 0;
}
.chapter-group {
    display: grid;
    gap: 5px;
}
.chapter-group-label {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0;
    margin: 10px 0 2px;
}
.chapter-nav-item {
    display: grid;
    gap: 6px;
}
.chapter-nav-btn {
    width: 100%;
    text-align: left;
    border: 1px solid transparent;
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
    color: var(--text-primary);
    padding: 8px 9px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.35;
}
.chapter-nav-btn:hover {
    border-color: var(--border-color);
    background: rgba(255,255,255,0.06);
}
.chapter-nav-btn.active {
    border-color: var(--ai-gradient-start);
    background: rgba(16, 185, 129, 0.12);
}
.chapter-nav-btn.subchapter {
    margin-left: 12px;
    width: calc(100% - 12px);
}
.chapter-nav-title {
    display: block;
    font-weight: 600;
}
.chapter-title-input {
    width: 100%;
    margin-top: 6px;
    padding: 7px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    outline: none;
}
.chapter-title-input:focus {
    border-color: var(--ai-gradient-start);
}
.chapter-nav-meta {
    display: block;
    margin-top: 2px;
    color: var(--text-secondary);
    font-size: 11px;
}
.paragraph-list {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
    overflow: hidden;
    min-height: 0;
}
.paragraph-nav-btn {
    min-width: 42px;
    text-align: center;
    border: 1px solid transparent;
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    color: var(--text-secondary);
    padding: 7px 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.35;
}
.chapter-nav-item .paragraph-list {
    padding-left: 12px;
}
.paragraph-nav-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-color);
}
.paragraph-nav-btn.active {
    color: var(--text-primary);
    background: rgba(16, 185, 129, 0.12);
    border-color: var(--ai-gradient-start);
}
.paragraph-nav-btn span {
    display: block;
    color: inherit;
}
.paragraph-nav-btn small,
.paragraph-range-note {
    display: block;
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 11px;
    flex-basis: 100%;
}
.mass-edit-panel {
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    overflow: hidden;
    font-size: 11px;
}
.mass-edit-toggle {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    text-align: left;
}
.mass-edit-toggle[aria-expanded="true"] span:last-child {
    transform: rotate(90deg);
}
.mass-edit-toggle span:last-child {
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    transition: transform 0.2s ease;
}
.mass-edit-body {
    display: grid;
    gap: 8px;
    padding: 0 12px 12px;
}
.mass-edit-body label {
    color: var(--text-secondary);
    font-size: 11px;
}
.mass-edit-body input,
.mass-edit-body select {
    width: 100%;
    padding: 7px;
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    border: 1px solid #333;
    font-family: inherit;
    font-size: 11px;
}
.italic-rule-list {
    display: grid;
    gap: 6px;
    max-height: 150px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid #333;
    border-radius: 4px;
    background: rgba(255,255,255,0.03);
}
.italic-rule-list label {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    color: var(--text-secondary);
    line-height: 1.35;
}
.italic-rule-list input {
    width: auto;
    margin-top: 2px;
    padding: 0;
}
.mass-edit-body .btn {
    font-size: 11px;
    padding: 7px 8px;
}
#mass-edit-status {
    min-height: 16px;
    color: var(--text-secondary);
    font-size: 11px;
    line-height: 1.4;
}
.rich-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-secondary);
    font-style: italic;
    pointer-events: none;
}
.diff-preview {
    max-height: 34%;
    overflow-y: auto;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.8;
    white-space: pre-wrap;
}
.diff-preview.is-empty { display: none; }
.diff-sentence {
    background: rgba(254, 249, 195, 0.18);
    border-radius: 4px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}
.diff-word {
    background: rgba(250, 204, 21, 0.65);
    color: #111827;
    border-radius: 3px;
    padding: 0 2px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}
.analysis-editor {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 18px;
}
.analysis-section {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    overflow: hidden;
}
.analysis-section label {
    display: block;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
}
.analysis-section textarea {
    width: 100%;
    min-height: 160px;
    padding: 12px;
    background: transparent;
    border: none;
    outline: none;
    resize: vertical;
    color: var(--text-secondary);
    font: inherit;
    line-height: 1.6;
}
.analysis-summary {
    display: grid;
    gap: 14px;
}
.analysis-summary-title {
    color: var(--text-primary);
    font-weight: 600;
}
.analysis-summary-item {
    line-height: 1.65;
}
.analysis-summary-label {
    color: var(--text-primary);
    font-weight: 600;
}
.book-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 18px;
}
.book-preview-panel,
.layout-offers,
.reader-settings {
    border-radius: 8px;
    overflow: hidden;
}
.book-full-text {
    min-height: 560px;
    max-height: calc(100vh - 240px);
    overflow: auto;
    margin: 0;
    padding: 22px;
    white-space: pre-wrap;
    color: var(--text-primary);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 16px;
    line-height: 1.8;
    max-width: 72ch;
    margin: 0 auto;
}
.book-side-panel {
    display: grid;
    gap: 18px;
    align-self: start;
}
.layout-offers,
.reader-settings {
    padding: 18px;
}
.layout-offers p {
    margin: 12px 0 18px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}
.reader-settings h3,
.layout-offers h3 {
    color: var(--text-primary);
}
.reader-settings label {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 12px;
}
.reader-settings select {
    width: 100%;
    margin-top: 6px;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}
.settings-row {
    margin-top: 14px;
}
.settings-row label {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 6px;
}
.settings-row select,
.settings-row input,
.settings-row textarea {
    width: 100%;
    padding: 9px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    font-family: inherit;
    line-height: 1.5;
}
.translation-tabs {
    display: flex;
    gap: 8px;
    margin: 0 0 18px;
    flex-wrap: wrap;
}
.translation-tab {
    padding: 9px 14px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
}
.translation-tab.active {
    color: var(--text-primary);
    border-color: var(--ai-gradient-start);
    background: rgba(121, 192, 255, 0.12);
}
.translation-review-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.translation-review-header p {
    color: var(--text-secondary);
    font-size: 13px;
    margin: 6px 0 0;
}
.translation-review-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.translation-review-actions select {
    min-width: 220px;
    padding: 9px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}
.translation-review-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    height: calc(100vh - 250px);
    min-height: 520px;
}
.translation-review-column {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-width: 0;
}
.translation-review-column h4 {
    color: var(--text-primary);
    margin: 0 0 8px;
}
.translation-review-text,
.translation-review-textarea {
    width: 100%;
    height: 100%;
    overflow: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.24);
    color: var(--text-primary);
    padding: 16px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 16px;
    line-height: 1.75;
    white-space: pre-wrap;
}
.translation-review-textarea {
    resize: none;
}
@media (max-width: 980px) {
    .translation-review-header {
        display: grid;
    }
    .translation-review-actions {
        justify-content: flex-start;
    }
    .translation-review-grid {
        grid-template-columns: 1fr;
        height: auto;
    }
    .translation-review-text,
    .translation-review-textarea {
        height: 420px;
    }
}
.layout-offers button {
    width: 100%;
    margin-bottom: 10px;
}
.book-full-text.book-font-serif {
    font-family: Georgia, "Times New Roman", serif;
}
.book-full-text.book-font-sans {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.book-full-text.book-font-mono {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
.book-full-text.book-size-xsmall { font-size: 13px; }
.book-full-text.book-size-small { font-size: 15px; }
.book-full-text.book-size-medium { font-size: 17px; }
.book-full-text.book-size-large { font-size: 19px; }
.book-full-text.book-size-xlarge { font-size: 21px; }
.book-full-text.book-width-narrow { max-width: 56ch; }
.book-full-text.book-width-medium { max-width: 72ch; }
.book-full-text.book-width-wide { max-width: 92ch; }
.btn-danger-soft {
    border-color: rgba(239, 68, 68, 0.45) !important;
    color: #fca5a5 !important;
    background: rgba(239, 68, 68, 0.08) !important;
}
.btn-danger-soft:hover {
    border-color: rgba(239, 68, 68, 0.75) !important;
    background: rgba(239, 68, 68, 0.16) !important;
}
.undo-toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 120;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: min(440px, calc(100vw - 32px));
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #161b22;
    color: var(--text-primary);
    box-shadow: 0 18px 45px rgba(0,0,0,0.32);
}
[data-theme="light"] .undo-toast {
    background: #ffffff;
}
.undo-toast span {
    min-width: 0;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.35;
}
.undo-toast button {
    border: none;
    background: transparent;
    color: var(--accent-color);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}
.undo-toast #app-undo-close {
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    padding: 0 2px;
}
.writing-workspace {
    display: grid;
    grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
    gap: 18px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 1;
    min-height: 0;
}
.writing-nav,
.writing-editor {
    border-radius: 8px;
    overflow: hidden;
    min-width: 0;
}
.writing-nav {
    padding: 16px;
    max-height: calc(100vh - 190px);
    overflow-y: auto;
}
.writing-nav h3 {
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 12px;
}
.writing-jump-panel {
    display: grid;
    gap: 7px;
    padding: 10px;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
}
.writing-jump-panel label {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0;
}
.writing-jump-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
    align-items: center;
}
.writing-jump-row input {
    min-width: 0;
    height: 34px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,0.06);
    color: var(--text-primary);
    padding: 0 9px;
    font-family: inherit;
}
.writing-jump-row .btn {
    height: 34px;
    padding: 0 10px;
    font-size: 12px;
}
.writing-jump-panel p,
.writing-tool-status {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.35;
}
.writing-tool-status {
    margin-left: auto;
}
.writing-structure-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
    margin: 0 0 12px;
}
.writing-structure-actions .btn {
    padding: 8px 9px;
    font-size: 12px;
}
.writing-nav .chapter-list,
#editor-chapter-list { max-height: calc(100vh - 250px); }
.writing-text {
    width: 100%;
    min-height: 420px;
    height: calc(100vh - 260px);
    padding: 24px;
    background: transparent;
    border: none;
    outline: none;
    resize: vertical;
    color: var(--text-primary);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 17px;
    line-height: 1.8;
}

.proofread-workspace {
    display: grid;
    grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) minmax(320px, 0.9fr);
    gap: 16px;
    height: calc(100vh - 160px);
    min-height: 560px;
}
.proofread-nav,
.proofread-text,
.proofread-suggestions {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.proofread-nav {
    padding: 16px;
    gap: 12px;
}
.proofread-nav select {
    width: 100%;
}
.proofread-nav p {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.45;
}
.proofread-text textarea {
    flex: 1;
    min-height: 0;
    height: auto;
    border-radius: 0;
    border: 0;
    resize: none;
}
.proofread-suggestions-list {
    padding: 14px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.proofread-suggestion {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(0,0,0,0.14);
    padding: 12px;
}
[data-theme="light"] .proofread-suggestion {
    background: rgba(0,0,0,0.03);
}
.proofread-suggestion p {
    margin: 8px 0;
    color: var(--text-secondary);
    line-height: 1.5;
    font-size: 13px;
}
.proofread-suggestion strong {
    color: var(--text-primary);
}
.proofread-suggestion-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.action-column { display: flex; align-items: center; justify-content: center; }
.ai-action-btn {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.1));
    border: 1px solid rgba(16, 185, 129, 0.3); border-radius: 16px; width: 60px; height: 60px;
    color: var(--text-primary); cursor: pointer; transition: all 0.3s ease; display: flex; flex-direction: column;
    align-items: center; justify-content: center; font-size: 11px; font-weight: 500;
}
.ai-action-btn:hover {
    transform: scale(1.05); background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.2));
    border-color: rgba(5, 150, 105, 0.8); box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

/* Responsive app shell */
@media (max-width: 860px) {
    body {
        height: 100dvh;
        overflow: hidden;
    }
    .top-bar {
        padding: 0 10px;
        gap: 8px;
    }
    .top-bar-left,
    .top-bar-right {
        gap: 6px;
    }
    .top-bar-left {
        flex: 1 1 auto;
        min-width: 0;
    }
    .top-bar-right {
        flex: 0 0 auto;
        max-width: 48vw;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .top-bar-right::-webkit-scrollbar {
        display: none;
    }
    .context-info {
        margin-left: 0;
        min-width: 0;
        flex: 1 1 auto;
    }
    .manuscript-badge {
        max-width: 100%;
        padding: 5px 9px;
        font-size: 12px;
    }
    .icon-btn {
        min-width: 38px;
        min-height: 38px;
        padding: 7px;
    }
    .text-btn {
        white-space: nowrap;
        font-size: 12px;
        padding: 7px 9px;
    }
    #toggle-lang,
    #toggle-mobile {
        display: none;
    }
    #feedback-open-btn,
    #logout-link {
        font-size: 0;
    }
    #feedback-open-btn::after {
        content: "Palaute";
        font-size: 12px;
    }
    #logout-link::after {
        content: "Ulos";
        font-size: 12px;
    }
    .app-wrapper {
        position: relative;
        height: calc(100dvh - var(--topbar-height));
    }
    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        bottom: 0;
        left: 0;
        z-index: 50;
        width: min(88vw, 320px);
        max-width: 320px;
        padding: 18px 14px;
        transform: translateX(-105%);
        opacity: 1;
        overflow-y: auto;
        border-left: 0;
        border-radius: 0 12px 12px 0;
        box-shadow: 12px 0 32px rgba(0, 0, 0, 0.22);
    }
    .sidebar.hidden {
        width: min(88vw, 320px);
        padding: 18px 14px;
        opacity: 1;
        overflow-y: auto;
        border: 1px solid var(--border-color);
        border-left: 0;
    }
    .app-wrapper.sidebar-open .sidebar {
        transform: translateX(0);
    }
    .sidebar-backdrop:not([hidden]) {
        display: block;
        position: fixed;
        inset: var(--topbar-height) 0 0 0;
        z-index: 45;
        background: rgba(0, 0, 0, 0.38);
        backdrop-filter: blur(3px);
    }
    .main-content {
        padding: 16px;
        width: 100%;
    }
    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }
    .header-info h2 {
        font-size: 24px;
        line-height: 1.15;
    }
    .header-info p {
        font-size: 13px;
        line-height: 1.45;
    }
    .header-actions {
        justify-content: flex-start;
        width: 100%;
    }
    .header-actions .btn {
        flex: 1 1 140px;
        min-width: 0;
    }
    .tool-menu {
        width: 100%;
    }
    .tool-menu-panel {
        left: 0;
        right: 0;
        min-width: 0;
    }
    .grid-cards,
    .book-workspace,
    .translation-review-grid,
    .proofread-workspace,
    #editor-workspace {
        grid-template-columns: 1fr !important;
    }
    .grid-cards {
        gap: 14px;
    }
    .card {
        padding: 16px;
        border-radius: 8px;
    }
    .translation-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 2px;
        scrollbar-width: thin;
    }
    .translation-tab {
        flex: 0 0 auto;
    }
    .writing-workspace {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .writing-nav {
        max-height: 250px;
    }
    .proofread-workspace {
        height: auto;
        min-height: 0;
    }
    .proofread-nav,
    .proofread-text,
    .proofread-suggestions {
        min-height: 280px;
    }
    .writing-nav .chapter-list,
    #editor-chapter-list {
        max-height: 190px;
    }
    .writing-text {
        min-height: 340px;
        height: 56dvh;
        padding: 16px;
        font-size: 16px;
    }
    .undo-toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
    #editor-workspace {
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }
    #editor-nav-panel {
        max-height: 250px;
    }
    .editor-panel {
        min-height: 360px;
    }
    .editor-content,
    .editor-content.editable {
        min-height: 280px;
    }
    .panel-header {
        padding: 12px 14px;
    }
    .panel-header,
    .panel-header > div {
        flex-wrap: wrap;
        gap: 8px;
    }
    .action-column {
        gap: 12px !important;
        padding-top: 0 !important;
    }
    .ai-action-btn {
        width: 100% !important;
        height: auto;
        min-height: 56px;
        aspect-ratio: auto !important;
        flex-direction: row;
        gap: 8px;
    }
    .book-full-text {
        min-height: 420px;
        max-height: none;
        padding: 16px;
    }
    .translation-review-grid {
        height: auto;
        min-height: 0;
    }
    .translation-review-text,
    .translation-review-textarea {
        height: 420px;
        font-size: 15px;
    }
    .translation-review-actions {
        justify-content: flex-start;
        width: 100%;
    }
    .translation-review-actions select,
    .settings-row select,
    .settings-row input,
    .settings-row textarea,
    textarea,
    input,
    select {
        font-size: 16px !important;
    }
    .feedback-dialog {
        max-height: calc(100dvh - 32px);
        overflow-y: auto;
        padding: 18px;
    }
}

.app-wrapper.mobile-simulate .editor-workspace,
.app-wrapper.mobile-simulate #editor-workspace,
.app-wrapper.mobile-simulate .writing-workspace,
.app-wrapper.mobile-simulate .book-workspace {
    grid-template-columns: 1fr !important;
}
.app-wrapper.mobile-simulate .header {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
}
.app-wrapper.mobile-simulate .main-content {
    padding: 20px 16px;
}
.app-wrapper.mobile-simulate {
    position: relative;
}
.app-wrapper.mobile-simulate .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(88%, 320px);
    padding: 18px 14px;
    transform: translateX(-105%);
    opacity: 1;
    overflow-y: auto;
    border-left: 0;
    border-radius: 0 12px 12px 0;
}
.app-wrapper.mobile-simulate.sidebar-open .sidebar {
    transform: translateX(0);
}
.app-wrapper.mobile-simulate .sidebar-backdrop:not([hidden]) {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, 0.38);
    backdrop-filter: blur(3px);
}

.om-grid input,
.om-grid select,
.om-grid textarea,
#view-om-projekti input,
#view-om-projekti select,
#view-om-ops input,
#view-om-ops select,
#view-om-brief input,
#view-om-brief select,
#view-om-materiaalit input,
#view-om-materiaalit select {
    width: 100%;
}
.om-editor {
    width: 100%;
    min-height: 560px;
    resize: vertical;
    background: rgba(0,0,0,0.24);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 16px;
    font-family: Inter, sans-serif;
    line-height: 1.6;
}
.om-list {
    display: grid;
    gap: 10px;
}
.om-list-item {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background: rgba(255,255,255,0.04);
}
.om-list-item h4 {
    font-size: 14px;
    margin-bottom: 6px;
}
.om-list-item p {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
    margin-top: 4px;
}
.om-pre,
.om-export-preview {
    white-space: pre-wrap;
    color: var(--text-primary);
    font-family: Inter, sans-serif;
    line-height: 1.6;
    min-height: 320px;
}
.om-status-select {
    width: 100%;
    margin-top: 10px;
}

/* Analysis pulse animation */
@keyframes analysisPulse {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
