/* ==========================================================================
   Savans.ai — "Galley" design system (t-017)
   The manuscript is the hero: a typeset journal canvas in a quiet, precise
   instrument. Tracked changes read as a copyeditor's redline, not a diff.
   ========================================================================== */

:root {
    /* Surfaces — warm paper canvas, cooler chrome */
    --paper:        #FAFAF8;  /* manuscript canvas / cards */
    --paper-2:      #F4F4F1;  /* recessed paper (hover, wells) */
    --surface:      #FFFFFF;
    --surface-2:    #EEEFEB;  /* app workspace behind cards */
    --canvas:       #F1F2EE;  /* page background */

    /* Ink */
    --ink:          #16181D;  /* primary text */
    --ink-strong:   #0D1B1A;  /* headings */
    --ink-muted:    #5A6066;  /* secondary text */
    --ink-faint:    #8B9097;  /* tertiary / captions */

    /* Lines */
    --line:         #DCDDD7;
    --line-soft:    #E8E9E3;

    /* Brand — petrol: scientific, ownable, deliberately not SaaS-blue */
    --accent:       #0F5C57;
    --accent-deep:  #0A3F3B;
    --accent-soft:  #E2EEEC;  /* tinted fill */
    --accent-bright:#3E9C92;  /* on-dark highlight */

    /* Editorial redline — tracked changes */
    --insert:       #1E7A4D;
    --insert-deep:  #156138;
    --insert-soft:  #E6F2EA;
    --delete:       #B23A48;
    --delete-deep:  #8E2D39;
    --delete-soft:  #F7E7E9;

    /* Sealed / protected zones (equations, citations) — muted ink-gold */
    --protected:    #8A6D1F;
    --protected-soft:#F3ECD8;

    /* Editorial note (instructions) — muted slate-violet */
    --note:         #5B5470;
    --note-soft:    #ECEAF1;

    /* Dark sidebar — petrol-tinted ink */
    --sidebar-bg:   #122220;
    --sidebar-fg:   #DBE0DC;
    --sidebar-muted:#7E8C87;
    --sidebar-line: rgba(255,255,255,0.08);

    /* Type */
    --font-serif: 'Spectral', Georgia, 'Times New Roman', serif;
    --font-sans:  'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono:  'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

    /* Shape & depth */
    --r-sm: 6px;
    --r:    10px;
    --r-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(13,27,26,0.05), 0 1px 3px rgba(13,27,26,0.06);
    --shadow:    0 2px 6px rgba(13,27,26,0.06), 0 6px 20px rgba(13,27,26,0.06);

    /* Layout */
    --sidebar-w: 248px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    line-height: 1.6;
    color: var(--ink);
    background: var(--canvas);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    font-family: var(--font-serif);
    color: var(--ink-strong);
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

a {
    color: var(--accent);
}

code, kbd, samp {
    font-family: var(--font-mono);
    font-size: 0.92em;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/* ----- Application shell ----- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1.1rem;
    gap: 1.75rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--sidebar-fg);
    padding: 0.25rem 0.4rem;
}

.brand-full {
    width: 100%;
    max-width: 196px;
    height: auto;
    display: block;
}

.brand-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.brand-word {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.05;
}

.brand-dot {
    color: var(--accent-bright);
}

.brand-tagline {
    font-family: var(--font-mono);
    font-size: 0.52rem;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.side-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--r-sm);
    color: var(--sidebar-fg);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.side-link:hover {
    background: rgba(255,255,255,0.06);
}

.side-link.active {
    background: rgba(62,156,146,0.16);
    color: #F1F7F6;
    box-shadow: inset 2px 0 0 var(--accent-bright);
}

.side-sep {
    margin: 0.85rem 0.7rem 0.3rem;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
}

.side-beta {
    font-family: var(--font-mono);
    font-size: 0.55rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0.05rem 0.3rem;
    margin-left: 0.35rem;
    border: 1px solid var(--sidebar-line);
    border-radius: 999px;
    color: var(--accent-bright);
    vertical-align: middle;
}

.sidebar-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding-top: 1rem;
    border-top: 1px solid var(--sidebar-line);
}

.side-tag {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent-bright);
}

.side-note {
    font-size: 0.78rem;
    color: var(--sidebar-muted);
    line-height: 1.5;
}

.app-main {
    min-width: 0;
}

/* Container — fluid: fills the workspace beside the sidebar (no centered cap) */
.container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 2.25rem 3rem;
}

@media (max-width: 860px) {
    .app {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: 1rem;
        padding: 0.75rem 1rem;
    }
    .sidebar-foot { display: none; }
    .side-nav { flex-direction: row; margin-left: auto; }
    .container { padding: 1.5rem 1.25rem; }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    cursor: pointer;
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 0.94rem;
    font-weight: 500;
    line-height: 1.2;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #F4FBFA;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--accent-deep);
}

.btn-small {
    padding: 0.32rem 0.8rem;
    font-size: 0.85rem;
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line);
}

.btn-small:hover {
    background: var(--paper-2);
    border-color: var(--ink-faint);
}

.btn-large {
    padding: 0.75rem 2rem;
    font-size: 1.125rem;
}

.btn-block {
    display: block;
    width: 100%;
    text-align: center;
}

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

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

.page-header h1 {
    margin: 0;
}

.subtitle {
    color: var(--ink-muted);
    margin: 0.25rem 0 0;
}

/* Table */
.table {
    width: 100%;
    background: white;
    border-collapse: collapse;
    border-radius: var(--r);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table th,
.table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.table th {
    background: var(--paper-2);
    font-weight: 600;
}

.table tbody tr:hover {
    background: var(--paper-2);
}

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-created {
    background: var(--accent-soft);
    color: var(--accent);
}

.status-processing {
    background: #fff3e0;
    color: var(--protected);
}

.status-review {
    background: #e8f5e9;
    color: #388e3c;
}

.status-completed {
    background: #e0f2f1;
    color: #00796b;
}

.status-failed {
    background: #ffebee;
    color: #c62828;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: white;
    border-radius: var(--r);
    box-shadow: var(--shadow-sm);
}

.empty-state p {
    color: var(--ink-muted);
    margin-bottom: 1.5rem;
}

/* Upload form */
.upload-form {
    background: white;
    border-radius: var(--r);
    padding: 2rem;
    box-shadow: var(--shadow-sm);
}

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

.form-section h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: var(--ink-strong);
}

.form-hint {
    font-size: 0.875rem;
    color: var(--ink-muted);
    margin-bottom: 0.75rem;
}

/* File input */
.file-input-wrapper {
    position: relative;
}

.file-input-wrapper input[type="file"] {
    position: absolute;
    left: -9999px;
}

.file-label {
    display: block;
    padding: 2rem;
    border: 2px dashed #ccc;
    border-radius: var(--r);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
}

.file-label:hover {
    border-color: var(--accent);
}

.file-name {
    display: block;
    margin-top: 0.5rem;
    color: var(--ink-muted);
    font-size: 0.875rem;
}

/* Radio and checkbox groups */
.radio-group,
.checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.radio-label,
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: border-color 0.2s;
}

.radio-label:hover,
.checkbox-label:hover {
    border-color: var(--accent);
}

.radio-label input:checked + span,
.checkbox-label input:checked + span {
    color: var(--accent);
    font-weight: 500;
}

/* Select */
.form-select {
    width: 100%;
    max-width: 300px;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

/* Text/Number inputs */
.form-input {
    width: 100%;
    max-width: 300px;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(15,92,87,0.20);
}

/* Input with suffix (e.g., % symbol) */
.input-with-suffix {
    display: inline-flex;
    align-items: center;
    max-width: 150px;
}

.input-with-suffix .form-input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    max-width: none;
}

.input-suffix {
    padding: 0.75rem;
    background: #eee;
    border: 1px solid #ddd;
    border-left: none;
    border-radius: 0 4px 4px 0;
    font-size: 1rem;
    color: var(--ink-muted);
}

/* Form actions */
.form-actions {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid #eee;
}

/* Upload status */
.upload-status {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 4px;
}

.upload-status.success {
    background: #e8f5e9;
    color: #388e3c;
}

.upload-status.error {
    background: #ffebee;
    color: #c62828;
}

.hidden {
    display: none !important;
}

/* Review layout */
.review-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
}

/* Sidebar */
.review-sidebar {
    background: white;
    border-radius: var(--r);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    height: fit-content;
    position: sticky;
    top: 1rem;
}

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

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

.sidebar-section h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 0.75rem;
}

.info-list {
    margin: 0;
}

.info-list dt {
    font-size: 0.875rem;
    color: var(--ink-muted);
}

.info-list dd {
    margin: 0 0 0.75rem;
    font-weight: 500;
}

.tag-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.action-hint {
    font-size: 0.75rem;
    color: var(--ink-muted);
    margin-top: 0.5rem;
}

/* Document view */
.review-main {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.document-view,
.edits-panel {
    background: white;
    border-radius: var(--r);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.document-view h2,
.edits-panel h2 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

/* Document elements */
.elements-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.element {
    padding: 1rem;
    border-radius: 4px;
    border-left: 3px solid transparent;
}

.element.editable {
    background: var(--paper);
    border-left-color: var(--accent);
}

/* Sealed zone — the integrity promise made visible (equations, citations, refs) */
.element.protected {
    background: var(--protected-soft);
    border-left-color: var(--protected);
    background-image: repeating-linear-gradient(
        135deg,
        transparent 0,
        transparent 9px,
        rgba(138,109,31,0.06) 9px,
        rgba(138,109,31,0.06) 10px
    );
}

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

.element-type {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.protected-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-family: var(--font-mono);
    font-size: 0.625rem;
    letter-spacing: 0.03em;
    background: transparent;
    color: var(--protected);
    border: 1px solid var(--protected);
    padding: 0.075rem 0.45rem;
    border-radius: 999px;
}

.protected-badge::before {
    content: "\25C8"; /* sealed mark */
    font-size: 0.7em;
}

.element-content {
    font-family: var(--font-serif);
    font-size: 1.0625rem;
    line-height: 1.75;
    color: var(--ink);
}

/* Edits panel */
.edits-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.edit-item {
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

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

.edit-type {
    font-size: 0.75rem;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.edit-original {
    background: #ffebee;
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    text-decoration: line-through;
    color: var(--ink-muted);
}

.edit-suggested {
    background: #e8f5e9;
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.edit-explanation {
    font-size: 0.875rem;
    color: var(--ink-muted);
    font-style: italic;
}

.edit-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* Error page */
.error-page {
    text-align: center;
    padding: 4rem 2rem;
}

.error-message {
    color: #c62828;
    font-size: 1.25rem;
    margin-bottom: 2rem;
}

/* Additional button styles */
.btn-success {
    background: var(--insert);
    color: white;
}

.btn-success:hover {
    background: var(--insert-deep);
}

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

.btn-danger:hover {
    background: var(--delete-deep);
}

/* Quiet danger button — for destructive secondary actions (e.g. permanent delete) */
.btn-danger-ghost {
    background: transparent;
    color: var(--delete);
    border: 1px solid var(--line);
}
.btn-danger-ghost:hover {
    background: var(--delete-soft);
    border-color: var(--delete);
    color: var(--delete-deep);
}

/* Upload privacy / AI-disclosure note */
.upload-privacy-note {
    background: var(--paper-2);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-sm);
    padding: 0.85rem 1rem;
    margin: 0 0 1.25rem;
}
.upload-privacy-note p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--ink-muted);
    line-height: 1.6;
}
.upload-privacy-note a { color: var(--accent); }

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

.btn-accept:hover {
    background: var(--insert-deep);
}

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

.btn-reject:hover {
    background: var(--delete-deep);
}

/* Bulk actions */
.bulk-actions {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--ink);
}

.stat-value.stat-accepted {
    color: var(--insert);
}

.stat-value.stat-rejected {
    color: var(--delete);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--ink-muted);
}

/* Progress bar */
.progress-bar {
    height: 6px;
    background: #eee;
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--insert) var(--accepted-pct, 0%), var(--delete) var(--accepted-pct, 0%) var(--reviewed-pct, 0%), #ddd var(--reviewed-pct, 0%));
    transition: all 0.3s;
}

/* Tabs */
.tab-nav {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    background: white;
    border-radius: var(--r);
    padding: 0.25rem;
    box-shadow: var(--shadow-sm);
}

.tab-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    color: var(--ink-muted);
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--ink);
}

.tab-btn.active {
    background: var(--accent);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: var(--delete);
    color: white;
    border-radius: 10px;
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

/* Edit item states */
.edit-item {
    transition: all 0.3s;
}

.edit-item.accepted {
    border-color: var(--insert);
    background: #f0fff4;
}

.edit-item.rejected {
    border-color: var(--delete);
    background: #fff5f5;
    opacity: 0.7;
}

.edit-item.accepted .edit-actions,
.edit-item.rejected .edit-actions {
    display: none;
}

.edit-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}

.edit-status.accepted {
    background: var(--insert);
    color: white;
}

.edit-status.rejected {
    background: var(--delete);
    color: white;
}

/* Element with edit indicator */
.element-edit-indicator {
    font-size: 0.625rem;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    margin-left: auto;
}

.element-edit-indicator.has-edit {
    background: #fff3e0;
    color: var(--protected);
}

.element-edit-indicator.has-edit::before {
    content: "Has edits";
}

.element.has-accepted-edit {
    border-left-color: var(--insert);
}

.element.has-pending-edit {
    border-left-color: var(--protected);
}

/* Empty edits */
.empty-edits {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--ink-muted);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 0;
}

.modal-content {
    position: relative;
    z-index: 1;
    background: white;
    padding: 2rem;
    border-radius: var(--r);
    width: 100%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.modal-subtitle {
    color: var(--ink-muted);
    margin-bottom: 1rem;
}

.modal-content textarea {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* Letter modal - larger size for displaying generated letters */
.modal-content-large {
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--ink-muted);
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.modal-close-btn:hover {
    color: var(--ink);
}

/* ============================================================
   Branded dialogs (UI.confirm / UI.alert) and toasts (UI.toast)
   ============================================================ */
.ui-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 11000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(13, 27, 26, 0.42);
    opacity: 0;
    transition: opacity 0.16s ease;
}
.ui-dialog-backdrop.ui-dialog-show { opacity: 1; }
.ui-dialog-backdrop.ui-dialog-out { opacity: 0; }

.ui-dialog {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    padding: 1.5rem 1.6rem 1.4rem;
    transform: translateY(8px) scale(0.98);
    opacity: 0;
    transition: transform 0.16s ease, opacity 0.16s ease;
}
.ui-dialog-show .ui-dialog { transform: translateY(0) scale(1); opacity: 1; }
.ui-dialog-out .ui-dialog { transform: translateY(4px) scale(0.99); opacity: 0; }

.ui-dialog-title {
    margin: 0 0 0.5rem;
    font-family: var(--font-serif);
    font-size: 1.18rem;
    font-weight: 600;
    color: var(--ink-strong);
}
.ui-dialog-msg {
    margin: 0 0 1.25rem;
    color: var(--ink-muted);
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-line;
}
.ui-dialog-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
}

/* Toasts */
.toast-host {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 12000;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-width: min(380px, calc(100vw - 2.5rem));
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.7rem 0.8rem 0.7rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--r-sm);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--ink);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.toast-in { opacity: 1; transform: translateY(0); }
.toast.toast-out { opacity: 0; transform: translateY(6px); }
.toast-success { border-left-color: var(--insert); }
.toast-error   { border-left-color: var(--delete); }
.toast-info    { border-left-color: var(--accent); }
.toast-msg { flex: 1; white-space: pre-line; }
.toast-x {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    color: var(--ink-faint);
    padding: 0 0.1rem;
}
.toast-x:hover { color: var(--ink); }

.letter-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #fafafa;
    border: 1px solid #eee;
    border-radius: 4px;
    font-size: 0.95rem;
    line-height: 1.7;
}

.letter-content h2 {
    font-size: 1.25rem;
    color: var(--ink-strong);
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 2px solid var(--ink-strong);
}

.letter-content h2:first-child {
    margin-top: 0;
}

.letter-content h3 {
    font-size: 1.1rem;
    color: #555;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.letter-content p {
    margin-bottom: 0.75rem;
}

.letter-content ul, .letter-content ol {
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

.letter-content strong {
    color: var(--ink);
}

.letter-loading {
    text-align: center;
    padding: 2rem;
    color: var(--ink-muted);
}

.letter-loading .spinner {
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid #eee;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* Edit feedback display */
.edit-feedback {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #fff3e0;
    border-radius: 4px;
    font-size: 0.875rem;
}

.edit-feedback strong {
    color: var(--protected);
}

/* Section dividers and headers */
.section-divider {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(90deg, var(--ink-strong) 0%, var(--accent) 100%);
    color: white;
    border-radius: 4px;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.section-divider:first-child {
    margin-top: 0;
}

.section-name {
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-instructions-btn {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255,255,255,0.5);
    background: transparent;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.section-instructions-btn:hover {
    background: rgba(255,255,255,0.2);
    border-color: white;
}

/* Section header elements (like "Abstract", "Introduction") */
.element.section-header {
    background: #f0f4f8;
    border-left-color: var(--ink-strong);
    padding: 0.5rem 1rem;
}

.section-header-content {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--ink-strong);
}

/* Paragraph instruction button */
.para-instructions-btn {
    width: 20px;
    height: 20px;
    border: 1px solid #ccc;
    background: white;
    color: var(--ink-muted);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    transition: all 0.2s;
    opacity: 0;
}

.element:hover .para-instructions-btn {
    opacity: 1;
}

.para-instructions-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Instruction indicator */
.element.has-instructions {
    position: relative;
    border-left-color: var(--note) !important;
}

.element.has-instructions::after {
    content: "Has instructions";
    position: absolute;
    top: 0.25rem;
    right: 2.5rem;
    font-size: 0.625rem;
    background: var(--note);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
}

.section-instructions-btn.has-instructions {
    background: rgba(255,255,255,0.3);
    border-color: white;
}

/* Instructions preview in modal */
.instructions-preview {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #f0f4f8;
    border-radius: 4px;
    font-size: 0.875rem;
    color: var(--ink-muted);
}

/* Inline edits container */
.element-edits-container {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed #ddd;
}

.inline-edit-item {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.inline-edit-item.accepted {
    border-color: var(--insert);
    background: #f0fff4;
}

.inline-edit-item.rejected {
    border-color: var(--delete);
    background: #fff5f5;
    opacity: 0.8;
}

.inline-edit-type {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 0.5rem;
}

.inline-edit-comparison {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.inline-edit-original {
    flex: 1;
    background: #ffebee;
    padding: 0.5rem;
    border-radius: 4px;
    text-decoration: line-through;
    color: var(--ink-muted);
    font-size: 0.875rem;
}

.inline-edit-arrow {
    color: var(--ink-muted);
    font-weight: bold;
    padding-top: 0.5rem;
}

.inline-edit-suggested {
    flex: 1;
    background: #e8f5e9;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.inline-edit-explanation {
    font-size: 0.8rem;
    color: var(--ink-muted);
    font-style: italic;
    margin-bottom: 0.5rem;
}

.inline-edit-actions,
.inline-edit-status {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.inline-edit-empty {
    text-align: center;
    color: var(--ink-faint);
    font-size: 0.875rem;
    padding: 1rem;
}

/* Make edit indicator look clickable */
.element-edit-indicator {
    cursor: pointer;
    padding: 0.125rem 0.5rem;
    border: none;
    border-radius: 10px;
    font-size: 0.625rem;
    background: #fff3e0;
    color: var(--protected);
    margin-left: auto;
    margin-right: 0.5rem;
}

.element-edit-indicator:hover {
    background: #ffe0b2;
}

.element-edit-indicator.has-edit::before {
    content: "▼ Has edits - click to expand";
}

.element-edits-container:not(.hidden) + .element-edit-indicator.has-edit::before,
.element.expanded .element-edit-indicator.has-edit::before {
    content: "▲ Hide edits";
}

/* Responsive */
@media (max-width: 768px) {
    .review-layout {
        grid-template-columns: 1fr;
    }

    .review-sidebar {
        position: static;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .para-instructions-btn {
        opacity: 1;
    }


}

/* Selection Mode Styles */
body.selection-mode-active .element {
    cursor: pointer;
    transition: all 0.2s;
}

body.selection-mode-active .element:hover {
    box-shadow: 0 0 5px rgba(15,92,87,0.30);
}

.element.selected {
    border-left-color: var(--accent) !important;
    background-color: var(--accent-soft) !important;
    position: relative;
}

.element.selected::after {
    content: "✓ Selected";
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-weight: 500;
}

/* --- Track Changes View Styling --- */

/* Deleted text: Red strikethrough */
.diff-del {
    text-decoration: line-through;
    color: var(--delete-deep);      /* Dark Red */
    background: var(--delete-soft); /* Light Pink Background */
}

/* Inserted text: Green underline */
.diff-ins {
    text-decoration: none;
    border-bottom: 2px solid var(--insert); /* Green Underline */
    color: var(--insert);       /* Dark Green */
    background: var(--insert-soft);  /* Light Green Background */
}

/* Ensure whitespace is preserved exactly in the paragraph view */
.element-content {
    white-space: pre-wrap; 
}

.citation-highlight{
  background: rgba(255, 220, 120, 0.6);
  border-radius: 4px;
  padding: 0 2px;
  cursor: pointer;
}
.has-citations .element-header::after{
  content: " • cites";
  opacity: 0.6;
  font-size: 0.85em;
}

/* ============================================================
   Sidebar signed-in profile (mock auth)
   ============================================================ */
.side-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.side-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--sidebar-line);
}
.side-user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}
.side-user-name {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--sidebar-fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.side-user-email {
    font-size: 0.72rem;
    color: var(--sidebar-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.side-user-out {
    margin-left: auto;
    flex-shrink: 0;
    color: var(--sidebar-muted);
    text-decoration: none;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.2rem;
    border-radius: var(--r-sm);
    transition: color 0.15s, background 0.15s;
}
.side-user-out:hover {
    color: var(--accent-bright);
    background: rgba(255,255,255,0.06);
}

/* ============================================================
   Welcome / sign-in screen
   ============================================================ */
.welcome-body {
    margin: 0;
    background: var(--canvas);
}
.welcome {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    min-height: 100vh;
}

.welcome-hero {
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    padding: 3rem 3.5rem;
    position: relative;
    overflow: hidden;
}
.welcome-hero::after {
    /* subtle petrol glow */
    content: "";
    position: absolute;
    width: 520px;
    height: 520px;
    right: -180px;
    bottom: -180px;
    background: radial-gradient(circle, rgba(62,156,146,0.18), transparent 70%);
    pointer-events: none;
}
.welcome-logo {
    width: 188px;
    height: auto;
    display: block;
}
.welcome-hero-body {
    margin-top: auto;
    margin-bottom: auto;
    max-width: 30rem;
    position: relative;
    z-index: 1;
}
.welcome-headline {
    font-family: var(--font-serif);
    font-size: 2.5rem;
    font-weight: 600;
    line-height: 1.12;
    letter-spacing: -0.015em;
    margin: 0 0 1rem;
    color: #F4F8F7;
}
.welcome-sub {
    font-size: 1.02rem;
    line-height: 1.6;
    color: var(--sidebar-fg);
    opacity: 0.82;
    margin: 0 0 1.75rem;
}
.welcome-points {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}
.welcome-points li {
    position: relative;
    padding-left: 1.5rem;
    font-size: 0.94rem;
    color: var(--sidebar-fg);
    opacity: 0.9;
}
.welcome-points li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.5em;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-bright);
}
.welcome-foot {
    position: relative;
    z-index: 1;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    margin: 0;
}

.welcome-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
}
.signin-card {
    width: 100%;
    max-width: 380px;
}
.signin-eyebrow {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
}
.signin-title {
    font-family: var(--font-serif);
    font-size: 1.7rem;
    font-weight: 600;
    color: var(--ink-strong);
    margin: 0.3rem 0 1.75rem;
}
.signin-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.field-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ink-muted);
}
.signin-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.83rem;
    margin-top: -0.2rem;
}
.signin-remember {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--ink-muted);
    cursor: pointer;
}
.signin-link {
    color: var(--accent);
    text-decoration: none;
}
.signin-link:hover { text-decoration: underline; }

.signin-divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: var(--ink-faint);
    font-size: 0.78rem;
    margin: 1.5rem 0;
    gap: 0.75rem;
}
.signin-divider::before,
.signin-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

.signin-as {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--r);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.signin-as:hover {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.signin-as-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.signin-as-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.3;
}
.signin-as-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink-strong);
}
.signin-as-email {
    font-size: 0.78rem;
    color: var(--ink-muted);
}
.signin-note {
    text-align: center;
    font-size: 0.83rem;
    color: var(--ink-muted);
    margin: 1.5rem 0 0;
}
.signin-note a {
    color: var(--accent);
    text-decoration: none;
}
.signin-note a:hover { text-decoration: underline; }
.signin-error {
    background: var(--delete-soft);
    color: var(--delete-deep);
    border: 1px solid var(--delete);
    border-radius: var(--r-sm);
    padding: 0.6rem 0.8rem;
    font-size: 0.86rem;
    margin: 0 0 1.1rem;
}

@media (max-width: 820px) {
    .welcome {
        grid-template-columns: 1fr;
    }
    .welcome-hero {
        padding: 2rem 2rem 2.5rem;
    }
    .welcome-headline { font-size: 1.9rem; }
    .welcome-points { display: none; }
}

/* ==========================================================================
   Admin dashboard (t-060)
   ========================================================================== */
.admin-banner {
    padding: 0.7rem 1rem; border-radius: var(--r-sm); margin-bottom: 1.25rem;
    font-size: 0.9rem;
}
.admin-banner.ok  { background: var(--insert-soft); color: var(--insert-deep); border: 1px solid var(--insert); }
.admin-banner.err { background: var(--delete-soft); color: var(--delete-deep); border: 1px solid var(--delete); }

.admin-tiles {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem;
    margin-bottom: 2rem;
}
.admin-tile {
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
    padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm);
}
.admin-tile-value {
    display: block; font-family: var(--font-serif); font-size: 1.9rem;
    font-weight: 600; color: var(--ink-strong); line-height: 1.1;
}
.admin-tile-label {
    display: block; margin-top: 0.35rem; font-family: var(--font-mono);
    font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--ink-faint);
}

.admin-cols { display: grid; grid-template-columns: 1fr 320px; gap: 1.75rem; align-items: start; }
.admin-section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.admin-section-head h2 { margin: 0; font-size: 1.15rem; }

.admin-invite { position: relative; }
.admin-invite > summary { list-style: none; cursor: pointer; }
.admin-invite > summary::-webkit-details-marker { display: none; }
.admin-invite-form {
    display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
    margin-top: 0.75rem; padding: 1rem; background: var(--paper);
    border: 1px solid var(--line); border-radius: var(--r);
}
.admin-invite-form .form-input { flex: 1 1 150px; }
.admin-admincheck { font-size: 0.85rem; color: var(--ink-muted); display: flex; align-items: center; gap: 0.3rem; }

.admin-disabled { opacity: 0.5; }
.admin-you { color: var(--ink-faint); font-size: 0.85rem; }

.admin-panel {
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
    padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm); margin-bottom: 1.25rem;
}
.admin-panel h3 { margin: 0 0 0.85rem; font-size: 1rem; }
.admin-feed { list-style: none; margin: 0; padding: 0; }
.admin-feed li { padding: 0.6rem 0; border-bottom: 1px solid var(--line-soft); }
.admin-feed li:last-child { border-bottom: none; }
.admin-feed-main { display: block; font-weight: 500; color: var(--ink); font-size: 0.92rem; }
.admin-feed-sub { display: block; margin-top: 0.2rem; font-size: 0.78rem; color: var(--ink-faint); }
.admin-kv { list-style: none; margin: 0; padding: 0; }
.admin-kv li { display: flex; justify-content: space-between; padding: 0.4rem 0; font-size: 0.9rem; }
.admin-kv li span:first-child { color: var(--ink-muted); text-transform: capitalize; }

@media (max-width: 1100px) {
    .admin-tiles { grid-template-columns: repeat(2, 1fr); }
    .admin-cols { grid-template-columns: 1fr; }
}
