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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    height: 100vh;
    overflow: hidden;
}

.header {
    background: #2d5a2d;
    color: white;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 14px;
}

.header-left {
    font-size: 16px;
}

.header-right {
    display: flex;
    gap: 12px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.toolbar {
    background: white;
    padding: 8px 16px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    gap: 12px;
    align-items: center;
}

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

.toggle-btn {
    background: #f0f0f0;
    border: 1px solid #ccc;
    padding: 4px 8px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

.witness-pill {
    background: #e0e0e0;
    border: 1px solid #bbb;
    padding: 4px 8px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.2s;
}

.witness-pill.active {
    background: #2196F3;
    color: white;
    border-color: #2196F3;
}

/* Reference-only sigla — visible but lighter, no reading page */
.witness-pill.reference-only {
    opacity: 0.45;
    cursor: default;
    border-style: dashed;
}
.witness-pill.reference-only:hover {
    opacity: 0.6;
}

/* Reference-only in export dialog */
.export-sigla-item.reference-only {
    opacity: 0.55;
}

/* Error state for witness pills when validation fails */
.witness-pill.error {
    background: #f44336 !important;
    border-color: #f44336 !important;
    color: #fff !important;
}

.sigla-tags {
    background: #f8f8f8;
    padding: 8px 16px;
    border-bottom: 1px solid #ddd;
    font-size: 12px;
    color: #666;
}

.sigla-tag {
    margin-right: 16px;
    display: inline-block;
}

.main-container {
    display: flex;
    height: calc(100vh - 190px);
}

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

.splitter {
    width: 8px;
    background: #ddd;
    cursor: col-resize;
    position: relative;
    flex-shrink: 0;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
}

.splitter:hover {
    background: #bbb;
}

.splitter:focus {
    outline: 2px solid #2196F3;
    outline-offset: -2px;
}

.preview-pane {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 64px; /* keep content visible above fixed footer */
    background: white;
    min-width: 0;
}

.preview-error {
    outline: 2px solid #f44336;
    outline-offset: -2px;
}

.error-item {
    background: #ffebee; /* light red */
    box-shadow: inset 0 0 0 2px #ef9a9a;
}

.editor-container {
    flex: 1;
    position: relative;
    min-height: 0;
}

#editor {
    height: 100%;
    width: 100%;
    border: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    padding: 16px;
    resize: none;
    outline: none;
    box-sizing: border-box;
}

.CodeMirror {
    height: 100% !important;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding-left: 16px; /* prevent left-edge clipping */
    padding-right: 16px; /* prevent right-edge clipping in LTR */
}

.CodeMirror-scroll {
    min-height: 100%;
    padding-right: 16px; /* avoid right-edge clipping with RTL runs in LTR */
}

.CodeMirror-lines {
    padding: 4px 0;
}

.CodeMirror-line {
    padding: 0 16px; /* give extra horizontal breathing room */
    margin-left: 8px;
    unicode-bidi: plaintext; /* auto base direction per line to reduce RTL clipping in LTR */
}

.CodeMirror-gutters {
    background: #f7f7f7;
    border-right: 1px solid #ddd;
}

/* Extra padding on the visual right edge when in RTL to prevent clipping */
.CodeMirror.cm-rtl {
    padding-right: 16px;
}

.CodeMirror-linenumber {
    color: #999;
}

/* Preview RTL mode */
.preview-rtl {
    direction: rtl;
    text-align: right;
}

.preview-rtl .apparatus,
.preview-rtl .paragraph,
.preview-rtl .apparatus-paragraph,
.preview-rtl .apparatus-sentences {
    direction: rtl;
}

/* Syntax highlighting styles */
.cm-header {
    color: #2d5a2d !important;
    font-weight: bold !important;
}

.cm-yaml-key {
    color: #0066cc !important;
    font-weight: bold !important;
}

.cm-yaml-value {
    color: #cc6600 !important;
}

.cm-yaml-list {
    color: #0066cc !important;
}

.cm-sentence {
    color: #333 !important;
    background: #e6f3ff !important;
    padding: 0 !important; /* avoid layout shift on click */
    border-radius: 3px !important;
    font-weight: bold !important;
}

.cm-apparatus-set {
    color: #8b4513 !important;
    background: #fff8dc !important;
    font-weight: bold !important;
    padding: 0 !important; /* avoid layout shift on click */
    border-radius: 3px !important;
}

.cm-apparatus-content {
    color: #8b4513 !important;
    background: #fff8dc !important;
}

.cm-variant {
    color: #0066cc !important;
    background: #e6f3ff !important;
    font-weight: bold !important;
    padding: 0 !important; /* avoid layout shift on click */
    border-radius: 3px !important;
}

.cm-note {
    color: #666 !important;
    font-style: italic !important;
    background: #f5f5f5 !important;
    padding: 0 !important; /* avoid layout shift on click */
    border-radius: 3px !important;
}

.cm-override {
    color: #cc0000 !important;
    background: #ffe6e6 !important;
    font-weight: bold !important;
    padding: 0 !important; /* avoid layout shift on click */
    border-radius: 3px !important;
}

.cm-omission {
    color: #999 !important;
    font-style: italic !important;
    background: #f0f0f0 !important;
    padding: 0 !important; /* avoid layout shift on click */
    border-radius: 3px !important;
}

.cm-strikethrough {
    text-decoration: line-through !important;
    color: #999 !important;
}

.cm-witness-condition {
    color: #cc6600 !important;
    background: #fff2cc !important;
    font-weight: bold !important;
    padding: 0 !important; /* avoid layout shift on click */
    border-radius: 3px !important;
}

.preview-title {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 8px;
    color: #333;
}

.preview-subtitle {
    font-size: 16px;
    color: #666;
    margin-bottom: 16px;
}

.preview-footer {
    margin-top: 32px;
    padding-top: 12px;
    font-size: 14px;
    color: #555;
    line-height: 1.5;
}

.footer-separator {
    border: none;
    border-top: 1px solid #ccc;
    margin-bottom: 12px;
}

.preview-paragraph {
    margin-bottom: 16px;
    line-height: 1.6;
}

.paragraph-number {
    font-weight: bold;
    color: #666;
    margin-right: 8px;
}

.sentence {
    display: inline;
    margin-right: 8px;
}

.sentence-number {
    font-size: 10px;
    color: #999;
    vertical-align: super;
    margin-right: 2px;
}

.variant {
    background: #f0f0f0;
    padding: 1px 3px;
    border-radius: 3px;
    font-size: 0.9em;
    font-weight: 600;
}

.variant-siglum {
    font-size: 10px;
    vertical-align: super;
    color: #666;
    margin-left: 2px;
}

.omission {
    font-style: italic;
    color: #999;
}

.apparatus {
    margin-top: 32px;
    border-top: 2px solid #ddd;
    padding-top: 16px;
}

.apparatus-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 16px;
    color: #333;
}

.apparatus-paragraph {
    margin-bottom: 16px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.apparatus-paragraph:hover {
    background-color: #f8f8f8;
}

.apparatus-paragraph-header {
    font-weight: bold;
    color: #666;
    margin-bottom: 8px;
}

.apparatus-sentences {
    margin-left: 16px;
    margin-bottom: 8px;
    font-size: 14px;
}

.apparatus-sentence {
    margin-bottom: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 2px 4px;
    border-radius: 4px;
}

.apparatus-sentence:hover {
    background-color: #f0f0f0;
}

.apparatus-variants {
    margin: 4px 0 0 20px;
    padding: 0;
}

.apparatus-variants li {
    display: inline-block;
    margin-right: 8px;
    margin-bottom: 2px;
    list-style-type: disc;
}

.apparatus-variants li:last-child {
    margin-right: 0;
}

/* Make individual variants hoverable */
.apparatus-variants .variant {
    cursor: pointer;
    padding: 1px 2px;
    border-radius: 2px;
    transition: background-color 0.2s;
}

.apparatus-variants .variant:hover {
    background-color: #f0f0f0;
}

.apparatus-note {
    margin-left: 24px;
    font-style: italic;
    color: #666;
    font-size: 12px;
}

.note {
    font-style: italic;
    color: #666;
}

del {
    text-decoration: line-through;
    color: inherit;
}

.hidden {
    display: none;
}

.highlight {
    background: #ffeb3b;
    padding: 1px 2px;
    border-radius: 2px;
}

.file-input {
    display: none;
}

/* Footer Styles */
.footer {
    background: #f8f8f8;
    border-top: 1px solid #ddd;
    padding: 8px 16px;
    text-align: center;
    font-size: 12px;
    color: #666;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.footer a {
    color: #2196F3;
    text-decoration: none;
    transition: color 0.2s;
}

.footer a:hover {
    color: #1976D2;
    text-decoration: underline;
}

/* Validation Bar Styles */
#validationBar.validation-bar {
    background: #fce4ec; /* light pink */
    color: #880e4f; /* dark pink */
    border: 1px solid #f8bbd9;
    padding: 8px 12px;
    font-size: 12px;
    display: none;
    text-align: left;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1002; /* above everything */
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
}

/* Test Modal Styles */
.test-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.test-modal.hidden {
    display: none !important;
}

.test-modal-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    max-width: 80%;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.test-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #eee;
}

.test-modal-title {
    font-size: 24px;
    font-weight: bold;
    color: #333;
}

.test-modal-close {
    background: #ff4444;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

.test-results {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.test-pass {
    color: #4CAF50;
    font-weight: bold;
}

.test-fail {
    color: #f44336;
    font-weight: bold;
}

.test-section {
    margin-bottom: 20px;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Export Sigla Modal Styles */
.export-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.export-modal.hidden {
    display: none !important;
}

.export-modal-content {
    background: white;
    border-radius: 8px;
    width: 500px;
    max-width: 90%;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.export-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 0 20px;
    margin-bottom: 20px;
}

.export-modal-title {
    font-size: 20px;
    font-weight: bold;
    color: #333;
}

.export-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.export-modal-close:hover {
    color: #333;
}

.export-modal-body {
    padding: 0 20px 20px 20px;
}

.export-modal-body p {
    margin-bottom: 15px;
    color: #666;
}

.export-sigla-list {
    border: 1px solid #ddd;
    border-radius: 4px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.export-sigla-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.2s;
}

.export-sigla-item:last-child {
    border-bottom: none;
}

.export-sigla-item:hover {
    background-color: #f5f5f5;
}

.export-sigla-checkbox {
    margin-right: 10px;
}

.export-sigla-info {
    flex: 1;
}

.export-sigla-symbol {
    font-weight: bold;
    color: #333;
}

.export-sigla-title {
    font-size: 12px;
    color: #666;
    margin-top: 2px;
}

.export-sigla-drag-handle {
    cursor: grab;
    color: #999;
    font-size: 18px;
    margin-right: 8px;
    user-select: none;
    line-height: 1;
}

.export-sigla-drag-handle:active {
    cursor: grabbing;
}

.export-sigla-item.dragging {
    opacity: 0.4;
    background-color: #e8f0fe;
}

.export-modal-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.export-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px 20px 20px;
    border-top: 1px solid #eee;
}

.export-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
}

.export-btn.primary {
    background: #27ae60;
    color: white;
}

.export-btn.primary:hover {
    background: #219a52;
}

.export-btn.secondary {
    background: #f8f9fa;
    color: #333;
    border: 1px solid #ddd;
}

.export-btn.secondary:hover {
    background: #e9ecef;
}

/* Paragraph Order Modal Styles */
.paragraph-order-list {
    border: 1px solid #ddd;
    border-radius: 4px;
    max-height: 400px;
    overflow-y: auto;
}

.paragraph-order-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
}

.paragraph-order-item:last-child {
    border-bottom: none;
}

.paragraph-order-witness {
    display: flex;
    align-items: center;
    gap: 10px;
}

.paragraph-order-symbol {
    font-weight: bold;
    color: #333;
    min-width: 30px;
}

.paragraph-order-title {
    font-size: 12px;
    color: #666;
}

.paragraph-order-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.paragraph-order-input {
    width: 80px;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    text-align: center;
}

.paragraph-order-input:focus {
    outline: none;
    border-color: #2196F3;
}

.paragraph-order-input:disabled {
    background: #f5f5f5;
    color: #999;
}

.paragraph-order-omit {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    user-select: none;
}

.paragraph-order-omit input[type="checkbox"] {
    cursor: pointer;
}

.paragraph-order-omit label {
    font-size: 12px;
    color: #666;
    cursor: pointer;
}

.test-section h3 {
    margin-top: 0;
    color: #333;
}

.test-details {
    margin-top: 10px;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 4px;
    font-size: 12px;
}

/* Responsive tabs for small screens */
@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
    }
    
    .splitter {
        display: none;
    }
    
    .editor-pane, .preview-pane, .metadata-pane {
        height: 50vh;
    }

    .main-container.show-editor .preview-pane,
    .main-container.show-editor .metadata-pane {
        display: none;
    }

    .main-container.show-preview .editor-pane,
    .main-container.show-preview .metadata-pane {
        display: none;
    }

    .main-container.show-metadata .editor-pane,
    .main-container.show-metadata .preview-pane,
    .main-container.show-metadata .splitter {
        display: none;
    }

    .main-container.show-metadata .metadata-pane {
        display: block;
        flex: 1;
    }
    
    .toolbar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 12px;
    }
    .toolbar-right {
        width: 100%;
        order: 1;
        padding-bottom: 4px;
        border-bottom: 1px solid #eee;
    }
    .toolbar-left {
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
        order: 2;
    }
    .toggle-btn {
        font-size: 11px;
        padding: 3px 6px;
    }

    .tab-bar {
        display: flex;
        background: #f8f8f8;
        border-bottom: 1px solid #ddd;
        padding: 0 16px;
    }
    
    .tab-button {
        background: none;
        border: none;
        padding: 8px 16px;
        cursor: pointer;
        border-bottom: 2px solid transparent;
        font-size: 14px;
        color: #666;
    }
    
    .tab-button.active {
        color: #2196F3;
        border-bottom-color: #2196F3;
        font-weight: bold;
    }
}

@media (min-width: 901px) {
    .tab-bar {
        display: flex;
        background: #f8f8f8;
        border-bottom: 1px solid #ddd;
        padding: 0 16px;
    }

    .tab-button {
        background: none;
        border: none;
        padding: 8px 16px;
        cursor: pointer;
        border-bottom: 2px solid transparent;
        font-size: 14px;
        color: #666;
    }

    .tab-button.active {
        color: #2196F3;
        border-bottom-color: #2196F3;
        font-weight: bold;
    }
}

/* Hover Preview Styles */
#hoverPreview {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.4;
}

#hoverPreview .hover-entry {
    margin-bottom: 8px;
}

#hoverPreview .hover-number {
    color: #4CAF50;
    font-weight: bold;
    margin-right: 4px;
}

#hoverPreview .hover-text {
    color: #fff;
    margin-right: 4px;
}

#hoverPreview .hover-siglum {
    font-weight: bold;
    margin-right: 4px;
    color: #fff; /* Default white for sigla without specific classes */
}

/* Ensure words stay white in hover preview */
#hoverPreview .hover-text {
    color: #fff !important;
    line-height: 1.6;
}

/* Add spacing around numbers in hover preview */
#hoverPreview .hover-text {
    white-space: pre-wrap;
}

/* Ensure proper spacing around numbers */
#hoverPreview .hover-text::before {
    content: '';
    white-space: pre;
}

/* Hover preview styling to match the images exactly */
#hoverPreview {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.4;
    padding: 10px 12px;
    background: rgba(0,0,0,0.9);
    border: 1px solid #4CAF50;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

#hoverPreview .hover-entry {
    margin-bottom: 8px;
    padding: 2px 0;
    display: flex;
    align-items: flex-start;
}

#hoverPreview .hover-number {
    color: #4CAF50 !important; /* Green for numbers like in images */
    font-weight: bold;
    margin-right: 4px;
    flex-shrink: 0;
    font-size: 14px;
}

#hoverPreview .hover-text {
    color: #fff !important;
    line-height: 1.4;
    flex: 1;
    font-size: 12px;
}

#hoverPreview .hover-separator {
    height: 1px;
    background: #666;
    margin: 6px 0;
    border-radius: 1px;
}

#hoverPreview .hover-note {
    margin-top: 8px;
    padding: 6px 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    border-left: 3px solid #4CAF50;
}

#hoverPreview .note-label {
    color: #fff !important;
    font-weight: bold;
    font-size: 12px;
}

#hoverPreview .note-text {
    color: #fff !important;
    font-style: italic;
    font-size: 11px;
}

/* Hover preview sigla coloring - ensure proper specificity */
#hoverPreview .sigla-A {
    color: #FF9800 !important; /* Orange for A */
    font-weight: bold;
}

/* Apparatus lemma (text from selected witness) */
.apparatus .lemma {
    font-weight: bold;
}

/* Apparatus variant sigla (witnesses with different readings) */
.apparatus .sigla-variant {
    color: #1976D2;
    font-weight: bold;
    padding: 0 2px;
}

/* Apparatus chosen siglum shown as closing bracket (deprecated) */
.apparatus .sigla-chosen {
    color: #666;
    font-weight: bold;
    padding: 0 2px;
}

#hoverPreview .sigla-B {
    color: #E91E63 !important; /* Magenta for B */
    font-weight: bold;
}

#hoverPreview .sigla-C {
    color: #9C27B0 !important; /* Purple for C */
    font-weight: bold;
}

#hoverPreview .sigla-D {
    color: #4CAF50 !important; /* Green for D */
    font-weight: bold;
}

#hoverPreview .sigla-E {
    color: #FF5722 !important; /* Deep Orange for E */
    font-weight: bold;
}

#hoverPreview .omission {
    display: inline-block;
    width: 50px;
    height: 1em;
    vertical-align: baseline;
    border: 1px solid #888;
    border-radius: 2px;
    background: transparent;
    color: transparent !important; /* hide 'om.' text inside hover */
}

#hoverPreview .hover-note {
    background: rgba(255,255,255,0.1);
    margin: 6px 0;
    padding: 8px 10px;
    border-radius: 4px;
    border-left: 3px solid #4CAF50;
    font-size: 12px;
    color: #fff;
}

#hoverPreview .hover-sentence {
    color: #4CAF50;
    font-weight: bold;
    margin-bottom: 4px;
}

#hoverPreview .hover-sentence-text {
    color: #fff;
}

#hoverPreview .hover-entry:last-child {
    margin-bottom: 0;
}

#hoverPreview .hover-note:last-child {
    margin-bottom: 0;
}

#hoverPreview::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    border-bottom-color: rgba(0,0,0,0.9);
}

#hoverPreview.positioned-above::before {
    top: auto;
    bottom: -12px;
    border-bottom-color: transparent;
    border-top-color: rgba(0,0,0,0.9);
}

/* Click highlighting styles */
.clicked-highlight {
    background-color: #ffeb3b !important;
    color: #000 !important;
    padding: 2px 4px !important;
    border-radius: 3px !important;
    animation: highlightPulse 0.5s ease-in-out;
}

@keyframes highlightPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Sigla coloring in preview */
.sentence .sigla-A {
    color: #FF9800 !important; /* Orange for A */
    font-weight: bold;
}

.sentence .sigla-B {
    color: #E91E63 !important; /* Magenta for B */
    font-weight: bold;
}

.sentence .sigla-C {
    color: #9C27B0 !important; /* Purple for C */
    font-weight: bold;
}

.sentence .sigla-D {
    color: #4CAF50 !important; /* Green for D */
    font-weight: bold;
}

.sentence .sigla-E {
    color: #FF5722 !important; /* Deep Orange for E */
    font-weight: bold;
}

/* Omission styling */
.sentence .omission {
    font-style: italic !important;
    color: #999 !important;
}

/* Apparatus sigla coloring */
.apparatus-entry .sigla-A {
    color: #FF9800 !important; /* Orange for A */
    font-weight: bold;
}

.apparatus-entry .sigla-B {
    color: #E91E63 !important; /* Magenta for B */
    font-weight: bold;
}

.apparatus-entry .sigla-C {
    color: #9C27B0 !important; /* Purple for C */
    font-weight: bold;
}

.apparatus-entry .sigla-D {
    color: #4CAF50 !important; /* Green for D */
    font-weight: bold;
}

.apparatus-entry .sigla-E {
    color: #FF5722 !important; /* Deep Orange for E */
    font-weight: bold;
}

/* Apparatus omission styling */
.apparatus-entry .omission {
    font-style: italic !important;
    color: #999 !important;
}

/* New HTML-based classes */
.adjusted-paragraph {
    display: none; /* Hide the marker span, it's just for data */
}

/* Variant visibility rules - hide all variants by default in apparatus entries */
.apparatus-entry .variant {
    display: none;
}

/* Witness visibility is now handled dynamically by JavaScript */

/* RTL bracket fixes */
.rtl-bracket-fixes {
    unicode-bidi: embed;
}

.rtl-bracket-fixes .sentence,
.rtl-bracket-fixes .apparatus {
    unicode-bidi: embed;
    direction: inherit;
}

/* Improve bracket visibility and selection in RTL */
.preview-rtl .sentence::before {
    content: '';
    unicode-bidi: embed;
    direction: ltr;
}

.preview-rtl .apparatus::before {
    content: '';
    unicode-bidi: embed;
    direction: ltr;
}

/* Better cursor behavior for RTL text in CodeMirror */
.cm-rtl .CodeMirror-line {
    unicode-bidi: plaintext;
}

.cm-rtl .CodeMirror-cursor {
    border-left: 1px solid black;
    border-right: none;
    margin-left: -1px;
    margin-right: 0;
}

/* Hide standalone variants by default */
.variant {
    display: none;
}

/* Omission placeholder: show as gray bar instead of "om." text in reading */
.variant.omitted {
    font-size: 0;
    line-height: 0;
    color: transparent;
    min-width: 2em;
    height: 1em;
    background: #e0e0e0;
    border-radius: 2px;
    vertical-align: baseline;
}

/* Hide notes in reading text, show in apparatus */
.paragraph .note {
    display: none;
}

.apparatus .note {
    display: inline;
    font-style: italic;
    color: #666;
}

.witness {
    font-weight: inherit;
}

.paragraph {
    margin-bottom: 16px;
    line-height: 1.6;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.paragraph:hover {
    background-color: #f8f8f8;
}

/* Paragraph absent from selected witness - shown with different styling */
.paragraph.paragraph-omitted {
    background-color: #fff3e0;
    border-left: 3px solid #ff9800;
    opacity: 0.7;
}

.paragraph.paragraph-omitted::before {
    content: "⟨absent⟩ ";
    color: #e65100;
    font-style: italic;
    font-size: 0.9em;
}

.paragraph .sentence {
    display: inline;
    margin-right: 8px;
}

.paragraph .paragraph-number {
    font-weight: bold;
    color: #666;
    margin-right: 8px;
}

.paragraph .sentence-number {
    font-size: 10px;
    color: #999;
    vertical-align: super;
    margin-right: 2px;
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 1px 2px;
    border-radius: 2px;
}

.paragraph-number:hover, .sentence-number:hover {
    background-color: #f0f0f0;
}

.paragraph-number {
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 2px 4px;
    border-radius: 2px;
}

.sentence-number {
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 1px 2px;
    border-radius: 2px;
}

/* Reading: show omissions as blank space for the selected witness (only in reading paragraphs) */
 #preview .paragraph .variant.omitted {
    color: transparent; /* hide 'om.' text */
    text-shadow: none;
}

/* Ensure omissions are still styled and visible in apparatus */
.apparatus .apparatus-entry .variant.omitted {
    display: inline;
}

/* YAML Error Bar Styles */
.yaml-error-bar {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 12px 16px;
    margin: 0;
    display: flex;
    align-items: center;
    font-size: 14px;
    animation: slideDown 0.3s ease-out;
    z-index: 100;
    position: relative;
}

.yaml-error-bar.critical {
    background: #f8d7da;
    border-left-color: #dc3545;
}

.yaml-error-bar.warning {
    background: #fff3cd;
    border-left-color: #ffc107;
}

.yaml-error-bar.success {
    background: #d4edda;
    border-left-color: #28a745;
}

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

.yaml-error-content {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 12px;
}

.yaml-error-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.yaml-error-text {
    flex: 1;
    line-height: 1.4;
}

.yaml-error-summary {
    margin-bottom: 8px;
}

.yaml-issue-detail {
    margin-bottom: 8px;
}

.yaml-issue-message {
    font-weight: 500;
    margin-bottom: 4px;
}

.yaml-issue-context {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    padding: 8px;
    margin-top: 4px;
    font-size: 12px;
}

.yaml-issue-context pre {
    margin: 0;
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;
    color: #333;
}

.yaml-error-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.yaml-fix-btn {
    background: #2d5a2d;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background-color 0.2s;
}

.yaml-fix-btn:hover {
    background: #1e3f1e;
}

.yaml-dismiss-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
    line-height: 1;
}

.yaml-dismiss-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Adjust main container to account for error bar */
.yaml-error-bar + .toolbar {
    border-top: 1px solid #ddd;
}

/* Temporary Notification Styles */
.temp-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideInRight 0.3s ease-out;
    max-width: 300px;
    word-wrap: break-word;
}

.temp-notification.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.temp-notification.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.temp-notification.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.temp-notification.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

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

/* YAML Button States */
#yamlValidateToggle.yaml-valid {
    background-color: #28a745;
    color: white;
    border-color: #28a745;
}

#yamlValidateToggle.yaml-invalid {
    background-color: #dc3545;
    color: white;
    border-color: #dc3545;
    animation: yamlErrorBlink 1.5s infinite;
}

#yamlValidateToggle.yaml-missing {
    background-color: #ffc107;
    color: #212529;
    border-color: #ffc107;
}

@keyframes yamlErrorBlink {
    0%, 50% {
        opacity: 1;
    }
    25%, 75% {
        opacity: 0.6;
    }
}

/* YAML Error Modal Styles */
.yaml-error-modal-content {
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

.yaml-modal-issues {
    margin: 16px 0;
}

.yaml-modal-issue {
    background: #f8f9fa;
    border-radius: 6px;
    margin-bottom: 12px;
    overflow: hidden;
    border-left: 4px solid #6c757d;
}

.yaml-modal-issue-error {
    border-left-color: #dc3545;
}

.yaml-modal-issue-info {
    border-left-color: #17a2b8;
}

.yaml-modal-issue-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.yaml-modal-issue-type {
    background: #6c757d;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
}

.yaml-modal-issue-error .yaml-modal-issue-type {
    background: #dc3545;
}

.yaml-modal-issue-info .yaml-modal-issue-type {
    background: #17a2b8;
}

.yaml-modal-issue-message {
    flex: 1;
    font-weight: 500;
}

.yaml-modal-issue-context {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px 16px;
    border-top: 1px solid #e9ecef;
}

.yaml-modal-issue-context pre {
    margin: 0;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    color: #495057;
}

.yaml-modal-issue-fix {
    background: #d4edda;
    color: #155724;
    padding: 8px 16px;
    border-top: 1px solid #c3e6cb;
    font-size: 14px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Modal backdrop and animation improvements */
.modal {
    display: block;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
    position: relative;
}

.modal-header {
    background: #2d5a2d;
    color: white;
    padding: 16px 20px;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.close {
    color: white;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.close:hover {
    opacity: 1;
}

.modal-body {
    padding: 20px;
    line-height: 1.5;
}

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

/* Hidden Character Visualization */
.cm-hidden-tab {
    position: relative;
}

.cm-hidden-tab::before {
    content: '→';
    position: absolute;
    color: #ccc;
    font-weight: bold;
    pointer-events: none;
}

.cm-hidden-space {
    position: relative;
}

.cm-hidden-space::before {
    content: '·';
    position: absolute;
    color: #ddd;
    font-size: 12px;
    pointer-events: none;
    top: 50%;
    transform: translateY(-50%);
}

.cm-hidden-unicode-space {
    position: relative;
    background: rgba(255, 0, 0, 0.1);
}

.cm-hidden-unicode-space::before {
    content: '⎵';
    position: absolute;
    color: #ff0000;
    font-weight: bold;
    pointer-events: none;
    font-size: 10px;
}

.cm-hidden-nbsp {
    position: relative;
    background: rgba(255, 165, 0, 0.1);
}

.cm-hidden-nbsp::before {
    content: '⍽';
    position: absolute;
    color: #ff8c00;
    font-weight: bold;
    pointer-events: none;
    font-size: 10px;
}

/* Metadata Editor Styles */
.metadata-pane {
    display: none;
    overflow-y: auto;
    background: #f9f9f9;
    padding: 20px;
}

.main-container.show-metadata .metadata-pane {
    display: block;
    flex: 1;
}

.main-container.show-metadata .editor-pane,
.main-container.show-metadata .splitter,
.main-container.show-metadata .preview-pane {
    display: none;
}

.metadata-editor {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.metadata-editor h2 {
    color: #2d5a2d;
    margin-bottom: 30px;
    font-size: 24px;
}

.metadata-section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.metadata-section:last-of-type {
    border-bottom: none;
}

.metadata-section h3 {
    color: #444;
    margin-bottom: 15px;
    font-size: 18px;
}

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

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: #555;
    font-size: 14px;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.form-group input[type="text"]:focus {
    outline: none;
    border-color: #2d5a2d;
    box-shadow: 0 0 0 2px rgba(45, 90, 45, 0.1);
}

.sigla-list {
    margin-bottom: 15px;
}

.sigla-row {
    display: grid;
    grid-template-columns: 100px 200px 1fr auto auto;
    gap: 10px;
    margin-bottom: 10px;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 4px;
    align-items: center;
}

.sigla-ref-label {
    font-size: 12px;
    color: #666;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sigla-row input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.sigla-row input:focus {
    outline: none;
    border-color: #2d5a2d;
}

.sigla-row button {
    background: #d32f2f;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.sigla-row button:hover {
    background: #b71c1c;
}

.metadata-actions {
    margin-top: 30px;
    display: flex;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.2s;
}

.btn-primary {
    background: #2d5a2d;
    color: white;
}

.btn-primary:hover {
    background: #234623;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

@media (hover: none) {
    #hoverPreview { display: none !important; }
}