/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
}

.modal-content {
    width: 95%;
    max-width: 1200px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.close-modal,
.close-diff-modal {
    font-size: 28px;
    cursor: pointer;
    color: var(--text-dim);
}

.modal-body {
    padding: 32px;
    overflow-y: auto;
}

.file-item {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.file-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.file-icon {
    font-size: 24px;
    margin-right: 20px;
}

.file-info {
    display: flex;
    flex-direction: column;
}

.file-name {
    font-weight: 600;
    font-size: 15px;
}

.file-path {
    font-size: 12px;
    color: var(--text-dim);
}

.modal-actions {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#commit-msg {
    width: 100%;
}

.upload-target-selector {
    display: flex;
    gap: 12px;
}

.upload-target-selector.hidden {
    display: none;
}

.upload-target-btn {
    flex: 1;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
}

.upload-target-btn:hover:not(:disabled) {
    opacity: 0.85;
}

.upload-target-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#upload-to-shared {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

#upload-to-branch {
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
}

body.light-mode #upload-to-shared {
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
}

body.light-mode #upload-to-branch {
    background: rgba(139, 92, 246, 0.12);
    color: #6d28d9;
}

.diff-container-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.diff-column {
    display: flex;
    flex-direction: column;
}

.diff-col-header {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.diff-view {
    background: #0a0f1d;
    padding: 0;
    border-radius: 12px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.5;
    color: #e2e8f0;
    height: 60vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.diff-line {
    display: flex;
    min-height: 1.5em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.line-num {
    width: 40px;
    padding: 0 8px;
    text-align: right;
    color: var(--text-dim);
    background: rgba(0, 0, 0, 0.2);
    user-select: none;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
}

.line-content {
    padding: 0 12px;
    flex-grow: 1;
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-line.added {
    background-color: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.diff-line.removed {
    background-color: rgba(244, 63, 94, 0.15);
    color: #fb7185;
}

.diff-line.placeholder {
    opacity: 0.3;
    background: repeating-linear-gradient(45deg,
            rgba(255, 255, 255, 0.05),
            rgba(255, 255, 255, 0.05) 10px,
            transparent 10px,
            transparent 20px);
}

.info-msg {
    margin-bottom: 16px;
    color: var(--text-dim);
    font-style: italic;
}

.warning-text {
    color: #fbbf24;
    font-weight: 600;
}

.preview-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
    margin-left: 10px;
    padding: 4px 12px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 20px;
    border: 1px solid var(--primary);
    font-size: 11px;
    transition: all 0.2s;
}

.preview-link:hover {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

/* Visual Preview System */
.visual-preview-wrapper {
    display: flex;
    gap: 20px;
    margin-top: 24px;
    animation: fadeIn 0.4s ease-out;
}

.visual-preview-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.visual-preview-label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    padding: 4px 12px;
    border-radius: 20px;
    align-self: flex-start;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.visual-preview-frame {
    width: 100%;
    height: 45vh;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #1e293b;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

.visual-preview-placeholder {
    width: 100%;
    height: 45vh;
    border: 2px dashed var(--border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-style: italic;
    background: rgba(255, 255, 255, 0.02);
}

.intra-unchanged {
    opacity: 0.4;
}

.diff-legend {
    display: flex;
    gap: 12px;
    margin-bottom: 6px;
    font-size: 11px;
    font-family: 'Monaco', 'Consolas', monospace;
}

.diff-legend-removed {
    color: #fb7185;
    background: rgba(244, 63, 94, 0.15);
    padding: 1px 8px;
    border-radius: 4px;
}

.diff-legend-added {
    color: #34d399;
    background: rgba(16, 185, 129, 0.15);
    padding: 1px 8px;
    border-radius: 4px;
}

.quick-summary-text {
    background: #0a0f1d;
    padding: 16px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    color: #e2e8f0;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    max-height: 250px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: 'Monaco', 'Consolas', monospace;
}

.warning-msg {
    padding: 12px 16px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 8px;
    color: #fbbf24;
    font-size: 14px;
    font-weight: 500;
}

/* Image preview */
.image-preview-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 20px;
}

.image-preview-box {
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 200px;
    width: 100%;
    height: 40vh;
}

.image-preview-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    display: block;
}

.image-metadata-grid {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    font-size: 13px;
    color: var(--text-dim);
    background: rgba(0, 0, 0, 0.2);
    padding: 12px 24px;
    border-radius: 8px;
    border: 1px solid var(--border);
    text-align: left;
    width: 100%;
    max-width: 500px;
}

.image-metadata-grid strong {
    color: var(--text-main);
    font-weight: 600;
}

.image-metadata-grid .value {
    color: var(--text-main);
}

.image-metadata-row {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-dim);
}

/* File info / quick preview header */
.file-info-header {
    color: var(--text-dim);
    margin-bottom: 12px;
    font-size: 13px;
}

.quick-preview-pre {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 14px;
    color: #cbd5e1;
    padding: 16px;
}

/* DOCX render */
.docx-render table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
}

.docx-render td,
.docx-render th {
    border: 1px solid #cbd5e1;
    padding: 6px 10px;
}

.docx-render p {
    margin: 0 0 10px 0;
}

/* Excel render */
.excel-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.excel-tab-btn {
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #f1f5f9;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
    font-size: 13px;
}

.excel-tab-btn.active {
    background: #2563eb;
    color: #fff;
}

.excel-sheet-content {
    display: none;
}

.excel-sheet-content.active {
    display: block;
}

.excel-sheet-content table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
}

.excel-sheet-content td,
.excel-sheet-content th {
    border: 1px solid #cbd5e1;
    padding: 4px 8px;
}

/* Excel embedded assets */
.excel-assets-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.excel-assets-heading {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-bottom: 8px;
}

.excel-images-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.excel-image-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.excel-image-item img {
    max-width: 200px;
    max-height: 150px;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 6px;
    object-fit: contain;
    background: #f8fafc;
}

.excel-image-label {
    font-size: 10px;
    color: #94a3b8;
}

.excel-shape-item {
    font-size: 13px;
    padding: 4px 0;
    color: #334155;
}

body.light-mode .excel-shape-item {
    color: #334155;
}

/* Cloud/local visual preview frame for docx/xlsx documents */
.visual-frame-document {
    overflow: auto;
    background-color: #fff;
    color: #000;
    padding: 20px;
    height: 45vh;
}

/* Light mode overrides for modal-specific hardcoded dark values */
body.light-mode .visual-preview-frame {
    background: #f8fafc;
}

body.light-mode .visual-preview-placeholder {
    background: rgba(0, 0, 0, 0.02);
}

body.light-mode .image-preview-box {
    background: rgba(0, 0, 0, 0.04);
}

body.light-mode .image-metadata-grid {
    background: rgba(0, 0, 0, 0.04);
}

body.light-mode .diff-view {
    background: #f8fafc;
    color: #1e293b;
    border-color: rgba(0, 0, 0, 0.12);
}

body.light-mode .diff-line {
    border-bottom-color: rgba(0, 0, 0, 0.05);
}

body.light-mode .diff-line.added {
    background-color: rgba(16, 185, 129, 0.1);
    color: #047857;
}

body.light-mode .diff-line.removed {
    background-color: rgba(244, 63, 94, 0.1);
    color: #be123c;
}

body.light-mode .line-num {
    background: rgba(0, 0, 0, 0.04);
}

body.light-mode .quick-preview-pre {
    color: #1e293b;
}

body.light-mode .docx-render td,
body.light-mode .docx-render th {
    border-color: #e2e8f0;
}

body.light-mode .excel-sheet-content td,
body.light-mode .excel-sheet-content th {
    border-color: #e2e8f0;
}

body.light-mode .modal {
    background: rgba(0, 0, 0, 0.5);
}

/* File action tags (shared / your version / history) */
.file-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
    align-items: center;
    flex-shrink: 0;
}

.version-tag {
    font-size: 12px;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
}

.version-tag:hover {
    opacity: 0.8;
}

.stable-tag {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.branch-tag {
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
}

body.light-mode .stable-tag {
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
}

body.light-mode .branch-tag {
    background: rgba(139, 92, 246, 0.12);
    color: #6d28d9;
}

.history-tag {
    background: rgba(148, 163, 184, 0.15);
    color: #94a3b8;
}

body.light-mode .history-tag {
    background: rgba(100, 116, 139, 0.12);
    color: #475569;
}

/* File history panel */
.file-history-panel {
    width: 100%;
    padding: 12px 24px 12px 60px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 24px;
    max-height: 150px;
    overflow-y: auto;
}

.file-history-panel.hidden {
    display: none;
}

.history-section {
    flex: 1;
    min-width: 0;
}

.history-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.history-commit {
    display: flex;
    gap: 12px;
    padding: 4px 0;
    font-size: 12px;
    align-items: baseline;
}

.history-meta {
    color: var(--text-dim);
    white-space: nowrap;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 11px;
}

.history-msg {
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-empty {
    font-size: 12px;
    color: var(--text-dim);
    font-style: italic;
}

.history-view-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0.5;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.history-view-btn:hover {
    opacity: 1;
}

/* Branch-only files section */
.branch-only-header {
    padding: 12px 24px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #a78bfa;
    background: rgba(139, 92, 246, 0.06);
    border-bottom: 1px solid var(--border);
    border-top: 2px solid rgba(139, 92, 246, 0.2);
}

body.light-mode .branch-only-header {
    color: #6d28d9;
    background: rgba(139, 92, 246, 0.04);
}

.branch-owner-label {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-dim);
}

/* ---------- Change Requests: status strip, queue, dialogs ---------- */
.cr-strip {
    flex-basis: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 12px 0 0 44px;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    cursor: default;
    color: var(--text-main);
    border: 1px solid var(--border);
}
.cr-strip-info { background: rgba(99, 102, 241, 0.12); border-color: rgba(99, 102, 241, 0.35); }
.cr-strip-busy { background: rgba(251, 191, 36, 0.10); border-color: rgba(251, 191, 36, 0.35); }
.cr-strip-warn { background: rgba(248, 113, 113, 0.10); border-color: rgba(248, 113, 113, 0.35); }
.cr-strip-ok   { background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.35); }
.cr-strip-text { flex: 1 1 260px; min-width: 0; }
.cr-strip-detail { color: var(--text-dim); }
.cr-strip-nudge { margin-top: 6px; color: #fbbf24; font-weight: 600; }
.cr-strip-note { color: var(--text-dim); font-size: 13px; align-self: center; }
.cr-strip-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.cr-btn {
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-main);
    cursor: pointer;
    white-space: nowrap;
}
.cr-btn:hover { opacity: 0.85; }
.cr-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.cr-btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.cr-btn-danger { color: #f87171; }
.cr-edit-tag { background: var(--primary); color: #fff; }

.cr-queue {
    margin: 0 0 16px;
    padding: 14px 18px;
    border-radius: 12px;
    border: 1px solid rgba(99, 102, 241, 0.4);
    background: rgba(99, 102, 241, 0.10);
}
.cr-queue-title { font-weight: 700; margin-bottom: 10px; color: var(--text-main); }
.cr-queue-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; color: var(--text-main); }

.cr-dialog { max-width: 560px; }
.cr-dialog-file { font-weight: 700; color: var(--text-main); margin-bottom: 12px; }
.cr-label { display: block; margin: 16px 0 6px; font-size: 14px; color: var(--text-main); }
.cr-textarea, .cr-select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.5);
    color: var(--text-main);
    font-family: inherit;
    font-size: 14px;
}
.cr-dialog-actions, .cr-review-actions { display: flex; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.cr-review-actions { margin: 0 0 16px; }
.cr-close { font-size: 28px; cursor: pointer; color: var(--text-dim); }
.cr-note {
    margin: 0 0 16px;
    padding: 10px 16px;
    border-left: 3px solid var(--primary);
    color: var(--text-main);
    font-style: italic;
}

body.light-mode .cr-strip { color: #0f172a; }
body.light-mode .cr-queue-title, body.light-mode .cr-queue-row, body.light-mode .cr-label, body.light-mode .cr-dialog-file, body.light-mode .cr-note { color: #0f172a; }
body.light-mode .cr-btn { color: #0f172a; background: rgba(100, 116, 139, 0.12); }
body.light-mode .cr-btn-primary { color: #fff; background: var(--primary); }
body.light-mode .cr-textarea, body.light-mode .cr-select { background: #fff; color: #0f172a; border-color: #cbd5e1; }
