:root {
    color-scheme: dark;
    --diff-line-modified: rgba(248, 113, 113, 0.25);
    --diff-char-modified: rgba(248, 113, 113, 0.6);
}

body {
    min-height: 100vh;
}

body.is-resizing {
    cursor: col-resize;
    user-select: none;
}

.workspace {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pane-root {
    display: flex;
    flex-direction: column;
    min-height: 60vh;
    gap: 0.75rem;
}

.pane {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
    width: 100%;
    border-radius: 0.5rem;
}

.pane--active .pane-tab-bar {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

.pane-tab-bar {
    min-height: 44px;
    position: relative;
}

.tabs-wrapper {
    display: flex;
    overflow: hidden;
    align-items: stretch;
    gap: 0.5rem;
}

.tabs-wrapper .tab-sort-mode {
    flex: 0 0 auto;
    align-self: center;
    min-width: 0;
    width: auto;
    max-width: 7rem;
}

.tabs-container {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    flex: 1 1 0;
    min-width: 0;
    align-items: stretch;
}

.tabs-container::-webkit-scrollbar {
    height: 6px;
}

.pane-editor-surface {
    min-height: 60vh;
    height: 100%;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
    min-width: 0;
    background: rgba(15, 23, 42, 0.4);
}

.pane-editor-layer {
    position: absolute;
    inset: 0;
}

.pane-editor-structured {
    padding: 0;
    height: 100%;
}

.pane-editor-structured .jsoneditor {
    border: none;
    height: 100%;
}

.pane-editor-structured .jsoneditor-outer {
    height: 100%;
}

.pane-split {
    display: flex;
    gap: 0.75rem;
    min-height: 60vh;
}

.pane-split-row {
    flex-direction: row;
}

.pane-split-column {
    flex-direction: column;
}

.split-child {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.split-resizer {
    background: rgba(148, 163, 184, 0.4);
    border-radius: 999px;
    transition: background 150ms ease;
    flex: 0 0 10px;
}

.pane-split-row .split-resizer {
    cursor: col-resize;
}

.pane-split-column .split-resizer {
    cursor: row-resize;
}

.split-resizer:hover {
    background: rgba(148, 163, 184, 0.7);
}

.menu-select {
    min-width: 160px;
}

/* Cursor-style tab bar: flat, contiguous, dark */
.tab-bar {
    min-height: 36px;
    position: relative;
    gap: 0;
    flex-wrap: nowrap;
    border-bottom: 1px solid #333;
    background: #1e1e1e;
}

.tab-item {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem 0.4rem;
    border-radius: 0;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    user-select: none;
    min-width: 0;
    max-width: 220px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.tab-item:hover {
    color: #d1d5db;
}

.tab-item.dragging {
    opacity: 0.6;
}

.tab-drop-indicator {
    position: absolute;
    top: 6px;
    bottom: 6px;
    width: 2px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 2px;
    pointer-events: none;
}

.tab-item.active {
    background: #252526;
    color: #fff;
    border-bottom-color: #007acc;
    max-width: none;
    font-weight: 600;
}

.tab-item .tab-title {
    font-weight: 400;
    font-size: 0.8125rem;
}

.tab-item .tab-actions button,
.tab-item .tab-actions .file-actions-btn {
    border: none;
    background: transparent;
    color: inherit;
    padding: 0 0.25rem;
    opacity: 0.8;
    text-decoration: none;
}

.tab-item .tab-actions button:hover,
.tab-item .tab-actions .file-actions-btn:hover {
    color: inherit;
    opacity: 1;
    background: transparent;
}

.tab-item .tab-close {
    border: none;
    background: transparent;
    color: inherit;
    opacity: 0.6;
    padding: 0 0.25rem;
    line-height: 1.2;
    font-size: 1rem;
    margin-left: 0.25rem;
}

.tab-item .tab-close:hover {
    opacity: 1;
}

.tab-item.active .tab-close {
    opacity: 0.8;
}

/* Keep other tab buttons compact */
.tab-item button.btn {
    line-height: 1.2;
    height: auto;
    min-height: 0;
    padding-top: 0.0625rem;
    padding-bottom: 0.0625rem;
}

.tab-item button.btn i {
    font-size: 0.8125rem;
    line-height: 1.2;
}

.editor-shell {
    --editor-left-width: minmax(320px, 1fr);
    --editor-right-width: minmax(260px, 0.55fr);
    --editor-splitter-width: 10px;
    display: grid;
    grid-template-columns: var(--editor-left-width) var(--editor-splitter-width) var(--editor-right-width);
    gap: 1rem;
    min-height: 60vh;
}

.editor-splitter {
    width: var(--editor-splitter-width);
    cursor: col-resize;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.4);
    transition: background 150ms ease;
}

.editor-splitter:hover {
    background: rgba(148, 163, 184, 0.7);
}

.editor-shell--secondary-hidden {
    grid-template-columns: 1fr;
}

.editor-shell--secondary-hidden .editor-splitter {
    display: none;
}

.editor-pane {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
    width: 100%;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.4rem 0.6rem;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    background: rgba(15, 23, 42, 0.6);
    min-width: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex-wrap: wrap;
}

.toolbar-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    white-space: nowrap;
}

.toolbar-btn--wide {
    width: auto;
    padding: 0 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Ensure icons have high contrast on dark toolbar background */
.toolbar-btn i {
    color: var(--bs-light, #f8f9fa);
}

/* Dark mode: light icons on dark background */
[data-bs-theme="dark"] .toolbar-btn i,
body.bg-dark .toolbar-btn i,
.editor-toolbar .toolbar-btn i {
    color: var(--bs-light, #f8f9fa);
}

/* Light mode: dark icons on light background */
[data-bs-theme="light"] .toolbar-btn i,
body.bg-light .toolbar-btn i {
    color: var(--bs-dark, #212529);
}

/* Active state: even higher contrast */
.toolbar-btn.is-active {
    border-color: rgba(59, 130, 246, 0.7);
    color: #e2e8f0;
    background: rgba(59, 130, 246, 0.18);
}

.toolbar-btn.is-active i {
    color: var(--bs-white, #ffffff);
}

/* Hover state: maintain high contrast */
.toolbar-btn:hover:not(:disabled) i {
    color: var(--bs-white, #ffffff);
}

[data-bs-theme="light"] .toolbar-btn:hover:not(:disabled) i,
body.bg-light .toolbar-btn:hover:not(:disabled) i {
    color: var(--bs-dark, #212529);
}

.toolbar-btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* File actions button: fade to black on hover */
.file-actions-btn {
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.file-actions-btn:hover {
    background-color: rgba(0, 0, 0, 0.9) !important;
    border-color: rgba(0, 0, 0, 1) !important;
}

.toolbar-select {
    flex: 1 1 12rem;
    min-width: 10rem;
}

.toolbar-counts {
    font-size: 0.8rem;
    white-space: nowrap;
}

.toolbar-garbage {
    font-size: 0.75rem;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.toolbar-error {
    font-size: 0.75rem;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.toolbar-error .btn-close {
    width: 0.6rem;
    height: 0.6rem;
    padding: 0;
}

.editor-surface {
    min-height: 60vh;
    height: 100%;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
    min-width: 0;
}

.editor-layer {
    position: absolute;
    inset: 0;
}

.secondary-panel {
    border: 1px solid #334155;
    border-radius: 0.5rem;
    background: #0b1220;
    display: flex;
    flex-direction: column;
    min-height: 60vh;
}

.editor-shell--single {
    grid-template-columns: 1fr;
}

.editor-shell--single .editor-splitter {
    display: none;
}

.merge-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 0.35fr;
    grid-template-rows: 1fr 1fr;
    gap: 0.75rem;
    height: 100%;
    padding: 0.5rem;
}

.merge-diff {
    border: 1px solid #334155;
    border-radius: 0.5rem;
    overflow: hidden;
    min-height: 220px;
}

.merge-result {
    grid-column: 1 / span 2;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    overflow: hidden;
    min-height: 240px;
}

.merge-conflicts {
    grid-row: 1 / span 2;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    background: #0b1220;
    display: flex;
    flex-direction: column;
}

.merge-conflicts__header {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #334155;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
}

.merge-conflicts__list {
    padding: 0.75rem;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.merge-conflict-item {
    border: 1px solid #334155;
    border-radius: 0.5rem;
    padding: 0.5rem;
    background: rgba(15, 23, 42, 0.6);
}

.merge-conflict-title {
    font-size: 0.85rem;
    color: #fbbf24;
    margin-bottom: 0.4rem;
}

.merge-conflict-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.merge-conflict-line {
    background: rgba(239, 68, 68, 0.12);
}

.tree-diff {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
    overflow: auto;
    height: 100%;
}

.tree-diff-row {
    border: 1px solid #334155;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(15, 23, 42, 0.6);
}

.tree-diff-row .label {
    color: #94a3b8;
    margin-right: 0.25rem;
}

.tree-diff-path {
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.tree-diff-row.tree-diff-left {
    border-color: rgba(34, 197, 94, 0.5);
}

.tree-diff-row.tree-diff-right {
    border-color: rgba(59, 130, 246, 0.5);
}

.tree-diff-row.tree-diff-both {
    border-color: rgba(234, 179, 8, 0.6);
}

.tree-diff-row.tree-diff-conflict {
    border-color: rgba(239, 68, 68, 0.7);
}

.secondary-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #334155;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
}

.secondary-close {
    flex: 0 0 auto;
}

.secondary-content {
    padding: 0.75rem;
    overflow: auto;
    max-height: 70vh;
}

.secondary-content--structured {
    padding: 0;
    height: 100%;
}

.secondary-content--structured .jsoneditor {
    border: none;
    height: 100%;
}

.secondary-content--structured .jsoneditor-outer {
    height: 100%;
}

.tree-node {
    margin-left: 0.75rem;
}

.tree-node button {
    background: none;
    border: none;
    color: #cbd5f5;
    font-size: 0.85rem;
    text-align: left;
    padding: 0.1rem 0.2rem;
}

.tree-node button:hover {
    color: #f8fafc;
}

.tree-key {
    color: #93c5fd;
    margin-right: 0.25rem;
}

.tree-value {
    color: #d8b4fe;
}

.diff-line {
    white-space: pre-wrap;
    font-family: "SFMono-Regular", "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
}

.diff-add {
    background: rgba(34, 197, 94, 0.2);
}

.diff-remove {
    background: rgba(239, 68, 68, 0.2);
}

.diff-neutral {
    color: #cbd5f5;
}

.diff-modified-line {
    background: var(--diff-line-modified);
}

.diff-char {
    background: var(--diff-char-modified);
    border-radius: 0.15rem;
    padding: 0 0.05rem;
}

.garbage-overlay {
    color: rgba(180, 120, 120, 0.45);
    font-style: italic;
    margin-left: 2px;
    pointer-events: none;
    user-select: none;
}

.garbage-highlight {
    background: rgba(239, 68, 68, 0.12);
    border-radius: 0.2rem;
}

.garbage-preview-banner {
    font-size: 0.9rem;
    color: #94a3b8;
}

.garbage-preview-body {
    height: 65vh;
    min-height: 360px;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    overflow: hidden;
}

.status-bar {
    display: flex;
    justify-content: space-between;
}

/* Lightweight page load overlay – visible on first paint, hidden when init completes */
.page-load-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1040;
    transition: opacity 0.2s ease-out, visibility 0.2s ease-out;
}
.page-load-overlay.page-load-overlay--hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.page-load-overlay.page-load-overlay--instant {
    transition: none;
}
.page-load-overlay__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}
.page-load-overlay__spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(248, 250, 252, 0.2);
    border-top-color: #f1f5f9;
    border-radius: 50%;
    animation: page-load-spin 0.7s linear infinite;
}
@keyframes page-load-spin {
    to { transform: rotate(360deg); }
}
.page-load-overlay__status {
    margin: 0;
    font-size: 0.875rem;
    color: #cbd5e1;
}

.busy-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
}

.busy-card {
    background: #0f172a;
    padding: 1.5rem;
    border-radius: 0.75rem;
    border: 1px solid #334155;
    text-align: center;
}

.toast {
    background: #111827;
    border: 1px solid #334155;
    color: #e5e7eb;
}

/* Tree Edit Mode Styles */
.toolbar-tree-edit {
    font-size: 0.75rem;
    letter-spacing: 0.01em;
    white-space: nowrap;
    animation: tree-edit-pulse 2s ease-in-out infinite;
}

@keyframes tree-edit-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.tree-edit-banner {
    padding: 0.75rem 1rem;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 0.5rem;
    color: #e2e8f0;
}

.tree-edit-banner i {
    color: #60a5fa;
}

.tree-edit-change-desc {
    font-family: "SFMono-Regular", "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
}

.tree-edit-stats {
    display: flex;
    gap: 1.5rem;
}

.tree-edit-diff-body {
    height: 55vh;
    min-height: 320px;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    overflow: hidden;
}

/* Tree Edit Status Indicator in JSONEditor */
.secondary-content--structured .jsoneditor .tree-edit-indicator {
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.4);
    border-radius: 0.35rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    color: #93c5fd;
    z-index: 10;
}

/* Tree Edit Pending State */
.tree-edit-pending {
    position: relative;
}

.tree-edit-pending::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(59, 130, 246, 0.05);
    pointer-events: none;
    border: 2px solid rgba(59, 130, 246, 0.3);
    border-radius: 0.5rem;
    animation: tree-edit-border-pulse 1.5s ease-in-out infinite;
}

@keyframes tree-edit-border-pulse {
    0%, 100% {
        border-color: rgba(59, 130, 246, 0.3);
    }
    50% {
        border-color: rgba(59, 130, 246, 0.6);
    }
}

/* Diff Preview Enhancements */
#tree-edit-diff-container .monaco-diff-editor {
    border-radius: 0.5rem;
}

#tree-edit-diff-container .monaco-editor-background {
    background: #0b1220;
}

/* Tree Edit Modal Footer */
#tree-edit-modal .modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#tree-edit-modal .modal-footer .btn-success {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    border-color: #059669;
}

#tree-edit-modal .modal-footer .btn-success:hover {
    background: linear-gradient(135deg, #047857 0%, #059669 100%);
    border-color: #047857;
}

@media (max-width: 992px) {
    .editor-shell {
        grid-template-columns: 1fr;
    }

    .editor-splitter {
        display: none;
    }

    .secondary-panel {
        max-height: 40vh;
    }
    
    .tree-edit-diff-body {
        height: 40vh;
        min-height: 240px;
    }
}
