/* File Browser Dialog */

#file-browser-dialog {
    width: 95vw;
    max-width: 1600px;
}

#file-browser-dialog .modal-content {
    max-height: 88vh;
}

.file-browser-modal {
    width: 95vw !important;
    max-width: 1600px;
    height: 88vh;
    display: flex;
    flex-direction: column;
}

.file-browser-container {
    display: grid;
    grid-template-columns: minmax(240px, 350px) 1fr;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Tree Panel */

.file-tree-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    min-height: 0;
}

.file-tree-search {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

.file-tree-search input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
}

.file-tree-search input:focus {
    outline: none;
    border-color: var(--accent);
}

.file-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0 32px 0;
}

.file-tree-loading {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
}

.file-tree-item {
    display: flex;
    align-items: center;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    user-select: none;
}

.file-tree-item:hover {
    background: var(--bg-hover);
}

.file-tree-item.active {
    background: var(--accent);
    color: white;
}

.file-tree-item .tree-icon {
    width: 16px;
    margin-right: 4px;
    text-align: center;
    font-size: 11px;
    flex-shrink: 0;
}

.file-tree-item .tree-arrow {
    width: 16px;
    margin-right: 2px;
    text-align: center;
    font-size: 10px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.15s;
}

.file-tree-item .tree-arrow.expanded {
    transform: rotate(90deg);
}

.file-tree-item .tree-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-tree-symlink {
    opacity: 0.6;
    cursor: default;
}

.file-tree-symlink:hover {
    background: transparent;
}

.tree-symlink-target {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-tree-children {
    display: none;
}

.file-tree-children.expanded {
    display: block;
}

/* Viewer Panel */

.file-viewer-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    position: relative;
}

/* Font size controls */

.file-font-controls {
    position: absolute;
    bottom: 32px;
    right: 12px;
    display: flex;
    gap: 2px;
    z-index: 10;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.file-font-controls:hover {
    opacity: 1;
}

.file-font-controls button {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.file-font-controls button:first-child {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.file-font-controls button:last-child {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    border-left: none;
}

.file-font-controls button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Tabs */

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

.file-tabs:empty {
    display: none;
}

.file-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    border-right: 1px solid var(--border);
    user-select: none;
    flex-shrink: 0;
}

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

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

.file-tab .tab-close {
    font-size: 14px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 2px;
    border-radius: 2px;
}

.file-tab .tab-close:hover {
    color: var(--danger);
    background: var(--bg-hover);
}

/* Breadcrumb */

.file-breadcrumb {
    padding: 6px 12px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-light);
    display: none;
}

.file-breadcrumb.visible {
    display: block;
}

.file-breadcrumb .crumb {
    color: var(--accent);
    cursor: pointer;
}

.file-breadcrumb .crumb:hover {
    text-decoration: underline;
}

.file-breadcrumb .separator {
    margin: 0 4px;
    color: var(--text-muted);
}

/* Content Area */

.file-content {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

.file-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.file-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Code Viewer */

.file-code-viewer {
    margin: 0;
    padding: 12px;
    padding-bottom: 48px !important;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    overflow-x: auto;
    background: var(--bg-primary) !important;
    box-sizing: border-box;
}

.file-code-viewer code {
    font-family: inherit;
    background: none !important;
}

/* Line numbers (Prism plugin) */
.file-code-viewer.line-numbers {
    padding-left: 3.8em;
}

/* Image Viewer */

.file-image-viewer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    gap: 12px;
    height: 100%;
}

.file-image-viewer img {
    max-width: 100%;
    max-height: calc(85vh - 200px);
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}

.file-image-info {
    font-size: 12px;
    color: var(--text-muted);
}

/* Markdown Viewer */

.file-markdown-viewer {
    padding: 20px 24px 48px 24px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

.file-markdown-viewer h1,
.file-markdown-viewer h2,
.file-markdown-viewer h3 {
    margin-top: 1.2em;
    margin-bottom: 0.6em;
}

.file-markdown-viewer code {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

.file-markdown-viewer pre code {
    display: block;
    padding: 12px;
    overflow-x: auto;
}

.file-markdown-viewer a {
    color: var(--accent);
}

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

.file-markdown-viewer th,
.file-markdown-viewer td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.file-markdown-viewer th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.file-markdown-viewer tr:nth-child(even) {
    background: var(--bg-hover);
}

.file-markdown-toggle {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 11px;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
}

.file-markdown-toggle:hover {
    background: var(--bg-hover);
}

/* 3D Model Viewer */

.file-3d-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.file-3d-canvas-wrap {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.file-3d-canvas-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.file-3d-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    font-size: 12px;
}

.file-3d-info {
    color: var(--text-secondary);
    font-weight: 500;
}

.file-3d-hint {
    color: var(--text-muted);
}

/* Archive Viewer */

.file-archive-viewer {
    padding: 0;
    height: 100%;
    overflow-y: auto;
}

.file-archive-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.file-archive-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.file-archive-stats {
    font-size: 12px;
    color: var(--text-muted);
}

.file-archive-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.file-archive-table th {
    text-align: left;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 44px;
    z-index: 1;
}

.file-archive-table td {
    padding: 4px 12px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    white-space: nowrap;
}

.file-archive-table tr:hover {
    background: var(--bg-hover);
}

.file-archive-table .archive-dir td {
    color: var(--text-secondary);
    font-weight: 500;
}

.file-archive-table .archive-error td {
    color: var(--danger);
}

.file-archive-table .archive-truncated td {
    color: var(--text-muted);
    font-style: italic;
}

/* Binary placeholder */

.file-binary-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 8px;
}

.file-binary-icon {
    font-size: 36px;
    opacity: 0.5;
}

/* Hidden file placeholder */

.file-hidden-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 8px;
}

/* Error state */

.file-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--danger);
    gap: 12px;
}

.file-error button {
    padding: 6px 16px;
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--danger);
    cursor: pointer;
}

/* Truncation warning */

.file-truncated-banner {
    padding: 6px 12px;
    background: var(--warning);
    color: #000;
    font-size: 12px;
    text-align: center;
}

/* Loading spinner */

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

/* Focused tree item (keyboard nav) */

.file-tree-item.focused {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Responsive */

@media (max-width: 768px) {
    .file-browser-container {
        grid-template-columns: 1fr;
    }

    .file-tree-panel {
        display: none;
    }
}

/* Prism.js light theme overrides */
[data-theme="light"] .file-code-viewer,
[data-theme="light"] .file-code-viewer code {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

[data-theme="light"] .file-code-viewer .token.comment,
[data-theme="light"] .file-code-viewer .token.prolog,
[data-theme="light"] .file-code-viewer .token.doctype,
[data-theme="light"] .file-code-viewer .token.cdata {
    color: #708090;
}

[data-theme="light"] .file-code-viewer .token.punctuation {
    color: #555;
}

[data-theme="light"] .file-code-viewer .token.property,
[data-theme="light"] .file-code-viewer .token.tag,
[data-theme="light"] .file-code-viewer .token.boolean,
[data-theme="light"] .file-code-viewer .token.number,
[data-theme="light"] .file-code-viewer .token.constant,
[data-theme="light"] .file-code-viewer .token.symbol {
    color: #905;
}

[data-theme="light"] .file-code-viewer .token.selector,
[data-theme="light"] .file-code-viewer .token.attr-name,
[data-theme="light"] .file-code-viewer .token.string,
[data-theme="light"] .file-code-viewer .token.char,
[data-theme="light"] .file-code-viewer .token.builtin {
    color: #690;
}

[data-theme="light"] .file-code-viewer .token.operator,
[data-theme="light"] .file-code-viewer .token.entity,
[data-theme="light"] .file-code-viewer .token.url {
    color: #9a6e3a;
}

[data-theme="light"] .file-code-viewer .token.atrule,
[data-theme="light"] .file-code-viewer .token.attr-value,
[data-theme="light"] .file-code-viewer .token.keyword {
    color: #07a;
}

[data-theme="light"] .file-code-viewer .token.function,
[data-theme="light"] .file-code-viewer .token.class-name {
    color: #dd4a68;
}

[data-theme="light"] .file-code-viewer .token.regex,
[data-theme="light"] .file-code-viewer .token.important,
[data-theme="light"] .file-code-viewer .token.variable {
    color: #e90;
}

/* Line numbers light mode */
[data-theme="light"] .file-code-viewer.line-numbers .line-numbers-rows > span::before {
    color: #aaa;
}
