/**
 * AI Editor - Editor Panel Styles
 * Editor panel, tabs bar, split pane, preview, diff viewer, line numbers
 */

/* ============================================
   EDITOR PANEL (Center)
   ============================================ */

.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

.editor-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    min-height: 35px;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-hover) transparent;
}

.editor-tabs::-webkit-scrollbar {
    height: 4px;
}

.editor-tabs::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 2px;
}

.editor-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-right: 1px solid var(--border);
    cursor: pointer;
    font-size: var(--font-md);
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    white-space: nowrap;
    min-width: 0;
    max-width: 180px;
}

.editor-tab .tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.editor-tab.preview .tab-name {
    font-style: italic;
}

.editor-tab:hover {
    background: var(--bg-hover);
}

.editor-tab.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-bottom: 1px solid var(--bg-primary);
    margin-bottom: -1px;
}

.editor-tab .modified {
    color: var(--warning);
}

.editor-tab .close {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px;
    border-radius: 3px;
    line-height: 1;
}

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

.editor-tab .close:hover {
    background: var(--bg-hover);
    color: var(--error);
}

.editor-container {
    flex: 1;
    overflow: hidden;
}

/* CodeMirror customization */
.editor-container .cm-editor {
    height: 100%;
    font-family: var(--font-mono);
    font-size: var(--editor-font-size);
}

.editor-container .cm-scroller {
    overflow: auto;
}

/* Editor status bar */
.editor-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 1rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    font-size: var(--font-sm);
    color: var(--text-secondary);
}

.editor-status .status-left,
.editor-status .status-right {
    display: flex;
    gap: 1rem;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.status-item.modified {
    color: var(--warning);
}

.status-item.saved {
    color: var(--success);
}

/* ============================================


/* ============================================
   v0.3.6 - EDITOR TABS BAR (tabs + toolbar)
   ============================================ */

.editor-tabs-bar {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    min-height: 35px;
}

.editor-tabs-bar .editor-tabs {
    flex: 1;
    min-width: 0;
    border-bottom: none;
    min-height: unset;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 4px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
}

.btn-toolbar {
    padding: 2px 6px !important;
    font-size: var(--font-sm) !important;
    border: none !important;
    background: transparent !important;
    color: var(--text-muted) !important;
    cursor: pointer;
    border-radius: 3px !important;
    white-space: nowrap;
}

.btn-toolbar:hover:not(:disabled) {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

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

.btn-toolbar.active {
    background: var(--bg-active) !important;
    color: var(--text-primary) !important;
}

/* ============================================
   v0.3.6 - EDITOR SPLIT PANE
   ============================================ */

.editor-split {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-split .editor-container {
    flex: 1;
    min-width: 0;
}

/* Preview mode: side-by-side */
.editor-split.split-active .editor-container {
    flex: 1;
    min-width: 200px;
}

/* Diff mode: overlay — hides editor, secondary pane fills entire width */
.editor-split.diff-overlay .editor-container {
    display: none;
}

.editor-split.diff-overlay .secondary-pane {
    width: 100%;
    max-width: 100%;
    border-left: none;
}

.secondary-pane {
    display: flex;
    flex-direction: column;
    width: 45%;
    min-width: 200px;
    max-width: 60%;
    border-left: 2px solid var(--accent);
    background: var(--bg-primary);
    overflow: hidden;
}

.secondary-pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.secondary-pane-actions {
    display: flex;
    gap: 2px;
    align-items: center;
}

/* Resize handle between editor and preview/diff pane */
.resize-handle-preview {
    width: 4px;
    cursor: col-resize;
    background: var(--border);
    transition: background 0.15s;
    flex-shrink: 0;
}

.resize-handle-preview:hover,
.resize-handle-preview.dragging {
    background: var(--accent);
}

/* Fullscreen mode: secondary pane fills entire editor-split */
.editor-split.secondary-fullscreen .editor-container {
    display: none;
}

.editor-split.secondary-fullscreen .resize-handle-preview {
    display: none !important;
}

.editor-split.secondary-fullscreen .secondary-pane {
    width: 100% !important;
    max-width: 100%;
    border-left: none;
}

.secondary-pane-content {
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex child to shrink */
}

/* ============================================
   v0.3.6 - PREVIEW PANE
   ============================================ */

.preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.preview-markdown {
    padding: 1rem 1.5rem;
    font-family: var(--font-sans);
    font-size: var(--font-lg);
    line-height: 1.6;
    color: var(--text-primary);
}

.preview-markdown h1 { font-size: 1.8em; margin: 1em 0 0.5em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.preview-markdown h2 { font-size: 1.5em; margin: 0.8em 0 0.4em; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
.preview-markdown h3 { font-size: 1.25em; margin: 0.6em 0 0.3em; }
.preview-markdown h4, .preview-markdown h5, .preview-markdown h6 { font-size: 1.1em; margin: 0.5em 0 0.25em; }
.preview-markdown p { margin: 0.5em 0; }
.preview-markdown code { background: var(--bg-tertiary); padding: 0.15em 0.4em; border-radius: 3px; font-family: var(--font-mono); font-size: 0.9em; }
.preview-markdown pre { background: var(--bg-secondary); padding: 1rem; border-radius: 4px; overflow-x: auto; margin: 0.75rem 0; }
.preview-markdown pre code { background: none; padding: 0; }
.preview-markdown blockquote { border-left: 3px solid var(--accent); padding: 0.25rem 1rem; margin: 0.5rem 0; color: var(--text-secondary); background: var(--bg-secondary); border-radius: 0 4px 4px 0; }
.preview-markdown ul { padding-left: 1.5rem; margin: 0.5em 0; }
.preview-markdown li { margin: 0.25em 0; }
.preview-markdown hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.preview-markdown a { color: var(--accent); text-decoration: none; }
.preview-markdown a:hover { text-decoration: underline; }
.preview-markdown img { max-width: 100%; border-radius: 4px; }

.preview-svg {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    min-height: 100%;
    background: var(--bg-primary);
}

.preview-svg svg {
    max-width: 100%;
    max-height: 100%;
}

.preview-unsupported {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: var(--font-base);
}

/* ============================================
   v0.3.6 - DIFF VIEW
   ============================================ */

.diff-view {
    font-family: var(--font-mono);
    font-size: var(--font-md);
    line-height: 1.5;
    padding: 0;
    /* Fill remaining space in flex parent */
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Unified: entire view scrolls as one */
.diff-view-unified {
    overflow-y: auto;
    overflow-x: auto;
}

/* Side-by-side: each pane scrolls independently (vimdiff) */
.diff-view-side-by-side {
    overflow: hidden;
}

.diff-line {
    display: flex;
    padding: 0;
    border-bottom: 1px solid rgba(60, 60, 60, 0.3);
    min-height: 20px;
}

.diff-ln {
    width: 40px;
    min-width: 40px;
    text-align: right;
    padding: 0 6px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    user-select: none;
    border-right: 1px solid var(--border);
    font-size: var(--font-sm);
}

.diff-text {
    padding: 0 8px;
    white-space: pre-wrap;
    word-break: break-all;
    flex: 1;
}

.diff-equal {
    color: var(--text-secondary);
}

.diff-added {
    background: rgba(78, 201, 176, 0.1);
    color: var(--success);
}

.diff-added .diff-ln {
    background: rgba(78, 201, 176, 0.15);
    color: var(--success);
}

.diff-removed {
    background: rgba(241, 76, 76, 0.1);
    color: var(--error);
}

.diff-removed .diff-ln {
    background: rgba(241, 76, 76, 0.15);
    color: var(--error);
}

.diff-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: var(--font-base);
    padding: 2rem;
}

/* Side-by-side spacer rows must NOT be height:100% — they should match line height */
.diff-view-side-by-side .diff-line.diff-empty {
    height: auto;
    padding: 0;
    justify-content: flex-start;
}

/* ============================================
   v0.3.6 - LINE NUMBERS TOGGLE
   ============================================ */

.editor-container.hide-line-numbers .cm-lineNumbers {
    display: none !important;
}

/* Also collapse the gutter column when line numbers are hidden */
.editor-container.hide-line-numbers .cm-gutters {
    border-right: none;
    min-width: 0 !important;
    width: auto !important;
}

/* Hide fold gutter and active line gutter alongside line numbers */
.editor-container.hide-line-numbers .cm-foldGutter,
.editor-container.hide-line-numbers .cm-activeLineGutter {
    display: none !important;
}

/* ============================================
   v0.3.6 - MODEL DROPDOWN FIX
   ============================================ */

.model-selector {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.model-selector select {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 0.25rem 0.3rem;
    font-size: var(--font-sm);
    max-width: 130px;
    min-width: 0;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
    max-width: 100%;
    overflow: hidden;
}

/* Ensure the chat header doesn't overflow */
.chat-header {
    padding: 0.5rem 0.5rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Role + Model selectors wrap properly on narrow panels */
#roleSelect {
    max-width: 75px;
}

#modelSelect {
    max-width: 120px;
    text-overflow: ellipsis;
}

/* Version badge */
.version {
    color: var(--text-muted);
    font-size: var(--font-sm);
    font-weight: 400;
}

/* ============================================
/**
 * Enhanced Diff Viewer Styles for Issue #18
 * Side-by-side and unified diff views with navigation
 * ALL font sizes now scale with --ui-font-size variable
 */

/* ============================================
   DIFF HEADER (Stats + Controls)
   ============================================ */

.diff-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.diff-stats {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    font-size: var(--font-md);
    font-family: var(--font-mono);
}

.diff-stat-additions {
    color: var(--success);
    font-weight: 600;
}

.diff-stat-deletions {
    color: var(--error);
    font-weight: 600;
}

.diff-stat-info {
    color: var(--text-muted);
    font-size: var(--font-sm);
}

.diff-controls {
    display: flex;
    gap: 0.25rem;
}

.diff-btn {
    padding: 0.25rem 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-secondary);
    font-size: var(--font-sm);
    cursor: pointer;
    transition: all 0.15s;
}

.diff-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

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

/* ============================================
   SIDE-BY-SIDE VIEW
   ============================================ */

.diff-view-side-by-side .diff-side-by-side-container {
    display: flex;
    /* CRITICAL: flex:1 fills remaining height after diff-header,
       allowing each pane to scroll independently (vimdiff behavior) */
    flex: 1;
    min-height: 0; /* Allow flex child to shrink below content height */
    overflow: hidden;
}

.diff-pane {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    border-right: 1px solid var(--border);
    min-height: 0; /* Allow flex child to shrink below content height */
}

.diff-pane:last-child {
    border-right: none;
}

.diff-pane-left {
    background: var(--bg-primary);
}

.diff-pane-right {
    background: var(--bg-primary);
}

/* Side-by-side specific line styling */
.diff-view-side-by-side .diff-line {
    border-bottom: 1px solid rgba(60, 60, 60, 0.2);
    padding: 0;
    min-height: 20px;
}

.diff-view-side-by-side .diff-ln {
    width: 45px;
    min-width: 45px;
}

.diff-view-side-by-side .diff-text {
    padding: 0 10px;
}

.diff-view-side-by-side .diff-empty {
    min-height: 20px;
    background: repeating-linear-gradient(
        45deg,
        var(--bg-secondary),
        var(--bg-secondary) 10px,
        var(--bg-tertiary) 10px,
        var(--bg-tertiary) 20px
    );
}

/* ============================================
   UNIFIED VIEW ENHANCEMENTS
   ============================================ */

.diff-view-unified .diff-hunk-header {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: var(--font-sm);
    color: var(--accent);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.diff-hunk-info {
    user-select: none;
}

/* ============================================
   CURRENT CHANGE HIGHLIGHT
   ============================================ */

.diff-line.diff-current {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    z-index: 2;
    position: relative;
}

/* ============================================
   CHARACTER-LEVEL DIFF (for modified lines)
   ============================================ */

.diff-char-added {
    background: rgba(78, 201, 176, 0.3);
    color: var(--success);
    padding: 0 2px;
    border-radius: 2px;
}

.diff-char-removed {
    background: rgba(241, 76, 76, 0.3);
    color: var(--error);
    padding: 0 2px;
    border-radius: 2px;
    text-decoration: line-through;
}

/* ============================================
   MODIFIED LINE HIGHLIGHTING (yellow/orange)
   ============================================ */

.diff-modified {
    background: rgba(220, 220, 170, 0.1);
    color: var(--warning);
}

.diff-modified .diff-ln {
    background: rgba(220, 220, 170, 0.15);
    color: var(--warning);
}

/* ============================================
   DIFF VIEW RESPONSIVENESS
   ============================================ */

@media (max-width: 1200px) {
    .diff-view-side-by-side .diff-pane {
        font-size: var(--font-sm);
    }
    
    .diff-view-side-by-side .diff-ln {
        width: 38px;
        min-width: 38px;
    }
}

@media (max-width: 900px) {
    /* Stack side-by-side vertically on small screens */
    .diff-view-side-by-side .diff-side-by-side-container {
        flex-direction: column;
    }
    
    .diff-pane {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 50%;
    }
}

/* ============================================
   DIFF LOADING/EMPTY STATES
   ============================================ */

.diff-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: var(--font-base);
}

.diff-loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 0.5rem;
}

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

/* ============================================
   ACCESSIBILITY & FOCUS STATES
   ============================================ */

.diff-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.diff-line:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* ============================================
   BLAME VIEW
   ============================================ */

.blame-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: var(--font-base);
}

.blame-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: var(--font-sm);
    color: var(--text-secondary);
    flex-shrink: 0;
}

.blame-path {
    font-weight: 600;
}

.blame-stats {
    color: var(--text-muted);
}

.blame-view {
    overflow: auto;
    height: calc(100% - 2.25rem);
}

.blame-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono, 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace);
    font-size: 12px;
    line-height: 1.5;
}

.blame-table tr {
    border-bottom: none;
}

.blame-ln {
    width: 3.5em;
    min-width: 3.5em;
    text-align: right;
    padding: 0 0.5em 0 0.25em;
    color: var(--text-muted);
    user-select: none;
    vertical-align: top;
    opacity: 0.6;
    border-right: 1px solid var(--border);
}

.blame-gutter {
    width: 18em;
    min-width: 14em;
    max-width: 22em;
    padding: 0 0.5em;
    vertical-align: top;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-right: 1px solid var(--border);
    font-family: var(--font-sans, system-ui, sans-serif);
    font-size: 11px;
    color: var(--text-secondary);
}

.blame-sha {
    font-family: var(--font-mono, monospace);
    color: var(--accent);
    cursor: pointer;
    margin-right: 0.5em;
}

.blame-sha:hover {
    text-decoration: underline;
}

.blame-author {
    margin-right: 0.5em;
    font-weight: 500;
}

.blame-date {
    color: var(--text-muted);
    font-size: 10px;
}

.blame-code {
    padding: 0 0.5em;
    vertical-align: top;
    white-space: pre;
    overflow-x: auto;
}

.blame-code pre {
    margin: 0;
    padding: 0;
    background: none;
    font-size: inherit;
    line-height: inherit;
    white-space: pre;
}

/* File History (fallback for GitHub) */

.file-history {
    overflow: auto;
    height: calc(100% - 2.25rem);
    padding: 0.5rem;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-sm);
}

.history-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary, var(--bg-secondary));
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
}

.history-table td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.history-sha code {
    font-family: var(--font-mono, monospace);
    color: var(--accent);
    font-size: 12px;
}

.history-author {
    white-space: nowrap;
    max-width: 10em;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    white-space: nowrap;
    color: var(--text-muted);
}

.history-msg {
    word-break: break-word;
}

.history-row {
    cursor: pointer;
    transition: background 0.15s;
}

.history-row:hover td {
    background: var(--bg-hover, rgba(255, 255, 255, 0.05));
}

.blame-back {
    color: var(--accent);
    font-size: var(--font-sm);
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    margin-left: auto;
}

.blame-back:hover {
    text-decoration: underline;
}

.commit-files {
    overflow: auto;
    padding: 0.5rem;
}

@media (max-width: 1200px) {
    .blame-gutter {
        min-width: 10em;
        max-width: 14em;
    }
}
