/**
 * Format Display Styles
 *
 * Styles for document, spreadsheet, and code displays.
 */

/* ============================================
   Document Display
   ============================================ */

.document-display {
    position: relative;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fff;
}

.document-content {
    position: relative;
    padding: 20px;
    line-height: 1.6;
}

/* Span target styling for document */
.span-target-document .document-content {
    padding-top: 30px; /* Extra space for span labels */
}

.span-target-document .span-overlays-field {
    overflow: visible;
    pointer-events: none;
}

.span-target-document .span-highlight {
    pointer-events: auto;
}

/* Document themes */
.document-theme-default .document-content {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.document-theme-minimal .document-content {
    font-family: Georgia, "Times New Roman", serif;
    max-width: 700px;
    margin: 0 auto;
}

.document-theme-print .document-content {
    font-family: "Times New Roman", serif;
    background: #fafafa;
}

/* Collapsible documents */
.document-collapsible {
    border: none;
}

.document-summary {
    cursor: pointer;
    padding: 10px 15px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    font-weight: 500;
}

.document-summary:hover {
    background: #ececec;
}

/* Document outline */
.document-outline {
    padding: 15px;
    background: #fafafa;
    border-bottom: 1px solid #e0e0e0;
}

.outline-title {
    font-weight: 600;
    margin-bottom: 10px;
    color: #333;
}

.outline-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.outline-list li {
    padding: 3px 0;
}

.outline-level-1 { padding-left: 0; }
.outline-level-2 { padding-left: 15px; }
.outline-level-3 { padding-left: 30px; }
.outline-level-4 { padding-left: 45px; }
.outline-level-5 { padding-left: 60px; }
.outline-level-6 { padding-left: 75px; }

.outline-link {
    color: #1976d2;
    text-decoration: none;
    font-size: 14px;
}

.outline-link:hover {
    text-decoration: underline;
}

/* Document metadata */
.document-metadata {
    padding: 10px 15px;
    background: #f5f5f5;
    border-top: 1px solid #e0e0e0;
    font-size: 12px;
    color: #666;
}

/* DOCX specific styles */
.docx-content {
    padding: 0;
}

.docx-heading {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.docx-h1 { font-size: 2em; }
.docx-h2 { font-size: 1.5em; }
.docx-h3 { font-size: 1.25em; }
.docx-h4 { font-size: 1.1em; }
.docx-h5 { font-size: 1em; font-weight: 600; }
.docx-h6 { font-size: 0.9em; font-weight: 600; }

.docx-paragraph {
    margin-bottom: 1em;
}

.docx-table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
}

.docx-table td,
.docx-table th {
    border: 1px solid #ccc;
    padding: 8px;
}

/* Markdown specific styles */
.markdown-content {
    padding: 0;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.markdown-content code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

.markdown-content pre {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
}

.markdown-content pre code {
    background: none;
    padding: 0;
}

.markdown-content blockquote {
    border-left: 4px solid #ddd;
    margin: 1em 0;
    padding-left: 15px;
    color: #666;
}

.markdown-content table {
    border-collapse: collapse;
    margin: 1em 0;
}

.markdown-content th,
.markdown-content td {
    border: 1px solid #ddd;
    padding: 8px 12px;
}

.markdown-content th {
    background: #f5f5f5;
}


/* ============================================
   Spreadsheet Display
   ============================================ */

.spreadsheet-display {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fff;
}

.spreadsheet-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.spreadsheet-table th,
.spreadsheet-table td {
    border: 1px solid #e0e0e0;
    padding: 8px 12px;
    text-align: left;
}

.spreadsheet-table th {
    background: #f5f5f5;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.spreadsheet-table th[data-sortable="true"] {
    cursor: pointer;
}

.spreadsheet-table th[data-sortable="true"]:hover {
    background: #e8e8e8;
}

/* Striped rows */
.table-striped tbody tr:nth-child(even) {
    background: #fafafa;
}

/* Hoverable rows */
.table-hoverable tbody tr:hover {
    background: #f0f7ff;
}

/* Compact mode */
.table-compact th,
.table-compact td {
    padding: 4px 8px;
    font-size: 13px;
}

/* Selection */
.select-col {
    width: 40px;
    text-align: center;
}

.selectable-row {
    cursor: pointer;
}

.selectable-row.selected {
    background: #e3f2fd !important;
}

.selectable-cell.selected {
    background: #bbdefb !important;
    outline: 2px solid #2196f3;
}

/* Selection summary */
.spreadsheet-selection-summary {
    padding: 8px 12px;
    background: #f5f5f5;
    border-top: 1px solid #e0e0e0;
    font-size: 13px;
    color: #666;
}

/* Span annotation mode */
.span-target-spreadsheet .selectable-row:hover,
.span-target-spreadsheet .selectable-cell:hover {
    outline: 2px solid #ff9800;
}

/* ============================================
   Code Display
   ============================================ */

.code-display {
    position: relative;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fafafa;
    font-family: "SF Mono", "Monaco", "Inconsolata", "Fira Code", monospace;
}

.code-content {
    position: relative;
    overflow-x: auto;
}

/* Simple code rendering for span annotation */
.code-content.code-simple {
    padding: 30px 16px 16px 16px; /* Extra top padding for span labels */
}

.code-content.code-simple .code-pre {
    margin: 0;
    padding: 0;
    background: transparent;
    font-family: "SF Mono", "Monaco", "Inconsolata", "Fira Code", monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.code-content.code-simple code {
    font-family: inherit;
}

.code-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 1.5;
}

.code-line {
    vertical-align: top;
}

.line-number {
    width: 50px;
    padding: 0 12px;
    text-align: right;
    color: #999;
    background: #f0f0f0;
    border-right: 1px solid #e0e0e0;
    user-select: none;
    position: sticky;
    left: 0;
}

.line-content {
    padding: 0 12px;
    white-space: pre;
}

.line-content code {
    font-family: inherit;
}

/* Line wrapping */
.code-nowrap .line-content {
    white-space: pre;
}

.code-wrap .line-content {
    white-space: pre-wrap;
    word-break: break-all;
}

/* Highlighted lines */
.highlighted-line {
    background: #fff8e1;
}

.highlighted-line .line-number {
    background: #ffecb3;
}

/* Copy button */
.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.code-display:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: #f5f5f5;
}

.code-copy-btn.copied {
    background: #4caf50;
    color: #fff;
    border-color: #4caf50;
}

/* Code themes */
.code-theme-dark {
    background: #1e1e1e;
    color: #d4d4d4;
}

.code-theme-dark .line-number {
    background: #252526;
    border-color: #3c3c3c;
    color: #858585;
}

.code-theme-dark .code-copy-btn {
    background: #333;
    color: #fff;
    border-color: #555;
}

/* Pygments highlight styles */
.code-highlight {
    background: transparent;
}

.code-highlight .linenos {
    color: #999;
    background: #f0f0f0;
    padding-right: 10px;
    border-right: 1px solid #e0e0e0;
}

/* Span annotation for code */
.span-target-code .line-content:hover {
    background: rgba(255, 152, 0, 0.1);
    cursor: text;
}

.span-target-code .code-line.span-selected {
    background: rgba(33, 150, 243, 0.2);
}
