/**
 * More Brains — File Editor Styles
 */

/* ========================================
   Modal Overrides
   ======================================== */
.file-editor-modal .modal__container {
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel, #ffffff);
    border: 1px solid var(--border-default, #e0e0e0);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.file-editor-modal .modal__header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
}

.file-editor-modal .modal__title {
    margin-right: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.file-editor-modal .modal__body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0;
    background: var(--bg-panel, #ffffff);
}

.file-editor-modal .modal__footer {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    background: var(--bg-elevated, #f5f5f5);
    border-top: 1px solid var(--border-default, #e0e0e0);
    padding: var(--space-3) var(--space-4);
}

.file-editor-modal .modal__header {
    background: var(--bg-elevated, #f5f5f5);
    border-bottom: 1px solid var(--border-default, #e0e0e0);
}

/* ========================================
   Tabs
   ======================================== */
.file-editor__tabs {
    display: flex;
    gap: var(--space-1);
}

.file-editor__tab {
    padding: var(--space-1) var(--space-3);
    background: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.file-editor__tab:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.file-editor__tab--active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* Backdrop */
.file-editor-modal .modal__backdrop {
    background: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .file-editor-modal .modal__container {
    background: var(--bg-panel, #1e1e2e);
    border-color: var(--border-default, #333);
}

/* ========================================
   Loading / Error / Empty States
   ======================================== */
.file-editor__loading,
.file-editor__error,
.file-editor__empty {
    padding: var(--space-8);
    text-align: center;
    color: var(--text-muted);
}

.file-editor__error {
    color: var(--accent-danger);
}

/* ========================================
   Editor Textarea
   ======================================== */
.file-editor__textarea {
    width: 100%;
    height: 100%;
    min-height: 400px;
    padding: var(--space-4);
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono, 'JetBrains Mono', 'Fira Code', 'Consolas', monospace);
    font-size: var(--text-sm);
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-panel);
    tab-size: 2;
    white-space: pre;
    overflow: auto;
}

.file-editor__textarea:focus {
    outline: none;
}

/* ========================================
   Status Bar
   ======================================== */
.file-editor__status {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-right: auto;
}

/* ========================================
   History View
   ======================================== */
.file-editor__history {
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.file-editor__revision {
    padding: var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-panel);
    transition: border-color 0.15s ease;
}

.file-editor__revision:hover {
    border-color: var(--border-strong);
}

.file-editor__revision--current {
    border-color: var(--accent-primary);
    border-width: 2px;
}

.file-editor__revision-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.file-editor__revision-hash {
    font-family: var(--font-mono, monospace);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--accent-primary);
    background: var(--bg-elevated);
    padding: 1px var(--space-2);
    border-radius: var(--radius-sm);
}

.file-editor__revision-msg {
    font-size: var(--text-sm);
    color: var(--text-primary);
    font-weight: 500;
}

.file-editor__revision-badge {
    font-size: var(--text-xs);
    color: var(--accent-success);
    background: rgba(0, 128, 0, 0.1);
    padding: 1px var(--space-2);
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.file-editor__revision-meta {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-1);
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.file-editor__revision-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.file-editor__revert-btn {
    color: var(--accent-danger) !important;
}

.file-editor__revert-btn:hover {
    background: rgba(157, 0, 6, 0.1) !important;
}

[data-theme="dark"] .file-editor__revert-btn:hover {
    background: rgba(249, 38, 114, 0.1) !important;
}

/* ========================================
   Revision Preview
   ======================================== */
.file-editor__revision-label,
.file-editor__diff-label {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-default);
    background: var(--bg-elevated);
}

.file-editor__revision-label code,
.file-editor__diff-label code {
    font-family: var(--font-mono, monospace);
    background: var(--bg-panel);
    padding: 1px var(--space-2);
    border-radius: var(--radius-sm);
    font-weight: 600;
    color: var(--accent-primary);
}

.file-editor__preview {
    padding: var(--space-4);
    margin: 0;
    font-family: var(--font-mono, monospace);
    font-size: var(--text-sm);
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--text-primary);
    background: var(--bg-panel);
    overflow: auto;
    max-height: 60vh;
}

/* ========================================
   Diff View
   ======================================== */
.file-editor__diff {
    font-family: var(--font-mono, monospace);
    font-size: var(--text-sm);
    line-height: 1.6;
    overflow: auto;
    max-height: 60vh;
}

.diff-line {
    padding: 0 var(--space-4);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.diff-line--add {
    background: rgba(0, 128, 0, 0.12);
    color: var(--text-primary);
}

.diff-line--del {
    background: rgba(200, 0, 0, 0.12);
    color: var(--text-primary);
}

.diff-line--hunk {
    background: var(--bg-elevated);
    color: var(--accent-primary);
    font-weight: 600;
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
    margin-top: var(--space-2);
}

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

[data-theme="dark"] .diff-line--add {
    background: rgba(0, 200, 0, 0.08);
}

[data-theme="dark"] .diff-line--del {
    background: rgba(255, 50, 50, 0.08);
}

/* ========================================
   Aider (AI Edit) View
   ======================================== */
.aider__container {
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.aider__section {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.aider__label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
}

.aider__files {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.aider__file {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.aider__file-icon {
    flex-shrink: 0;
}

.aider__file-name {
    color: var(--text-primary);
    font-weight: 500;
}

.aider__prompt {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--text-sm);
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-panel);
    resize: vertical;
}

.aider__prompt:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.aider__output-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.aider__output {
    padding: var(--space-3);
    margin: 0;
    font-family: var(--font-mono, monospace);
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    max-height: 300px;
    overflow: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.aider__result {
    padding: var(--space-3);
}

.aider__result-success {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.aider__result-header {
    font-weight: 600;
    color: var(--accent-success);
    font-size: var(--text-sm);
}

.aider__result-error {
    color: var(--accent-danger);
    font-weight: 500;
}

.aider__result-empty {
    color: var(--text-muted);
    font-style: italic;
}

.aider__commit {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
}

.aider__diffs {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-top: var(--space-2);
}

.aider__diff-file {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.aider__diff-filename {
    padding: var(--space-2) var(--space-3);
    background: var(--bg-elevated);
    font-family: var(--font-mono, monospace);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-default);
}

/* ========================================
   Files Sidebar Dropdown
   ======================================== */
.files-sidebar__file {
    position: relative;
    padding-right: 28px;
}

.files-sidebar__file .files-sidebar__file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.files-sidebar__file-actions-btn {
    display: none;
    position: absolute;
    right: var(--space-1, 4px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-elevated, #f5f5f5);
    border: 1px solid var(--border-default, #e0e0e0);
    border-radius: var(--radius-sm, 4px);
    color: var(--text-secondary, #666);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 1px 5px;
    z-index: 2;
    transition: background 0.1s, color 0.1s;
}

.files-sidebar__file:hover .files-sidebar__file-actions-btn,
.files-sidebar__file-actions-btn:focus {
    display: block;
}

.files-sidebar__file-actions-btn:hover {
    background: var(--accent-primary, #af3a03);
    color: #fff;
}

.files-sidebar__dropdown {
    position: fixed;
    min-width: 180px;
    background: var(--bg-panel, #fff);
    border: 1px solid var(--border-default, #e0e0e0);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    padding: var(--space-1, 4px) 0;
    animation: dropdown-fade-in 0.1s ease;
}

@keyframes dropdown-fade-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.files-sidebar__dropdown button {
    display: block;
    width: 100%;
    padding: var(--space-2, 8px) var(--space-3, 12px);
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font-sans, sans-serif);
    font-size: var(--text-sm, 0.875rem);
    color: var(--text-primary, #333);
    transition: background-color 0.1s;
    white-space: nowrap;
}

.files-sidebar__dropdown button:hover {
    background-color: var(--bg-elevated, #f5f5f5);
}

.files-sidebar__dropdown .files-sidebar__ctx-danger {
    color: var(--accent-danger, #9d0006);
}

.files-sidebar__dropdown .files-sidebar__ctx-danger:hover {
    background-color: rgba(157, 0, 6, 0.08);
}

[data-theme="dark"] .files-sidebar__dropdown .files-sidebar__ctx-danger:hover {
    background-color: rgba(249, 38, 114, 0.1);
}

.files-sidebar__dropdown-divider {
    height: 1px;
    background: var(--border-muted, #eee);
    margin: var(--space-1, 4px) 0;
}

[data-theme="dark"] .files-sidebar__dropdown {
    background: var(--bg-panel, #1e1e2e);
    border-color: var(--border-default, #333);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .files-sidebar__file-actions-btn {
    background: var(--bg-elevated, #2a2a3a);
    border-color: var(--border-default, #444);
}

/* ========================================
   Aider Output Block (in chat messages)
   ======================================== */
.aider-output-block {
    margin: var(--space-3) 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-elevated);
}

.aider-output-block__header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-default);
    cursor: pointer;
    user-select: none;
    font-size: var(--text-sm);
    transition: background 0.15s;
}

.aider-output-block__header:hover {
    background: var(--bg-elevated);
}

.aider-output-block__icon {
    flex-shrink: 0;
}

.aider-output-block__title {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary);
}

.aider-output-block__toggle {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.aider-output-block--collapsed .aider-output-block__toggle {
    transform: rotate(-90deg);
}

.aider-output-block__content {
    margin: 0;
    padding: var(--space-3);
    font-family: var(--font-mono, 'JetBrains Mono', 'Fira Code', 'Consolas', monospace);
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    max-height: 200px;
    overflow: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.aider-output-block--collapsed .aider-output-block__content {
    display: none;
}

/* ========================================
   Mobile
   ======================================== */
@media (max-width: 768px) {
    .file-editor-modal .modal__container {
        max-height: 95vh;
    }

    .file-editor-modal .modal__title {
        max-width: 150px;
    }

    .file-editor__textarea {
        min-height: 300px;
        font-size: var(--text-xs);
    }

    .file-editor__revision-actions {
        flex-wrap: wrap;
    }

    /* Show action button always on mobile (no hover) */
    .files-sidebar__file-actions-btn {
        display: block;
    }
}
