/**
 * File Explorer Window Styles
 *
 * Window chrome (container, header, title, close, resize handles,
 * hidden/focused/dragging states) is inherited from BaseWindow via
 * the debug-window classes in debug-windows.css.
 * This file only contains file-explorer-specific content styles.
 */

/* Override the BaseWindow content wrapper for file explorer layout:
   remove default padding and overflow so the internal panels handle it */
#file-explorer-window > .debug-window-content {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Toolbar */
.fe-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--glass-border);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* Source selector (Floppy / HD) */
.fe-source-selector {
    display: flex;
    gap: 2px;
    background: var(--input-bg-deeper);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.fe-source-selector.hidden {
    display: none;
}

.fe-source-btn {
    padding: 2px 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition:
        background 0.15s,
        color 0.15s;
}

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

.fe-source-btn.active {
    background: var(--accent-blue);
    color: white;
}

.fe-drive-selector {
    display: flex;
    align-items: center;
    gap: 6px;
}

.fe-drive-selector label {
    font-family: var(--font-sans);
    font-size: 11px;
    color: var(--text-secondary);
}

.fe-drive-btn {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.fe-drive-btn:hover {
    border-color: var(--accent-blue);
    color: var(--text-primary);
}

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

.fe-refresh-btn {
    padding: 4px 10px;
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 11px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.fe-refresh-btn:hover {
    border-color: var(--accent-blue);
    color: var(--text-primary);
}

.fe-disk-info {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Content area */
.fe-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Catalog panel */
.fe-catalog-panel {
    width: 280px;
    min-width: 200px;
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
}

.fe-panel-header {
    padding: 6px 10px;
    background: var(--glass-bg-header);
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-sans);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.fe-catalog-list {
    flex: 1;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--input-bg-dark);
}

.fe-catalog-item {
    display: grid;
    grid-template-columns: 28px 1fr 36px;
    gap: 4px;
    padding: 4px 8px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
}

.fe-catalog-item:hover {
    background: var(--bg-light);
}

.fe-catalog-item.selected {
    background: var(--accent-blue-bg);
    border-color: var(--accent-blue);
}

.fe-file-type {
    color: var(--accent-yellow);
    text-align: center;
}

.fe-file-type.locked {
    color: var(--accent-red);
}

.fe-file-name {
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fe-file-sectors {
    color: var(--text-muted);
    text-align: right;
}

.fe-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 12px;
}

/* ProDOS Path Bar */
.fe-path-bar {
    padding: 6px 10px;
    background: var(--control-bg);
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fe-path-bar.hidden {
    display: none;
}

.fe-path-item {
    color: var(--accent-blue);
    cursor: pointer;
}

.fe-path-item:hover {
    text-decoration: underline;
}

.fe-path-item:last-child {
    color: var(--text-primary);
    cursor: default;
}

.fe-path-item:last-child:hover {
    text-decoration: none;
}

/* ProDOS Directory entries */
.fe-catalog-item.fe-directory .fe-file-type {
    color: var(--accent-blue);
}

.fe-catalog-item.fe-directory .fe-file-name {
    color: var(--accent-blue);
}

.fe-catalog-item.fe-parent-dir {
    background: var(--control-bg);
}

.fe-catalog-item.fe-parent-dir:hover {
    background: var(--control-bg-hover);
}

/* File panel */
.fe-file-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: transparent;
}

.fe-file-panel .fe-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.fe-file-title {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: normal;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fe-file-info {
    font-family: var(--font-sans);
    font-size: 10px;
    font-weight: normal;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text-muted);
}

/* View toggle (ASM/HEX/MERLIN, TEXT/MERLIN) */
.fe-view-toggle,
.fe-text-view-toggle {
    display: flex;
    gap: 2px;
    background: var(--input-bg-deeper);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.fe-view-toggle.hidden,
.fe-text-view-toggle.hidden {
    display: none;
}

.fe-view-btn {
    padding: 2px 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition:
        background 0.15s,
        color 0.15s;
}

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

.fe-view-btn.active {
    background: var(--accent-blue);
    color: white;
}

.fe-experimental {
    margin-left: 4px;
    padding: 1px 4px;
    font-size: 8px;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--accent-orange, #f0883e);
    color: #000;
    border-radius: 3px;
    vertical-align: middle;
}

/* ASM Legend */
.fe-asm-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 6px 10px;
    background: var(--input-bg);
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-mono);
    font-size: 10px;
    flex-shrink: 0;
}

.fe-asm-legend.hidden {
    display: none;
}

.fe-asm-legend span {
    display: inline-flex;
    align-items: center;
}

.fe-asm-legend span::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    margin-right: 4px;
}

.fe-asm-legend .dis-branch::before {
    background: var(--syntax-flow);
}

.fe-asm-legend .dis-load::before {
    background: var(--syntax-load);
}

.fe-asm-legend .dis-math::before {
    background: var(--syntax-math);
}

.fe-asm-legend .dis-stack::before {
    background: var(--syntax-stack);
}

.fe-asm-legend .dis-address::before {
    background: var(--syntax-math);
}

.fe-asm-legend .dis-immediate::before {
    background: var(--syntax-flag);
}

.fe-asm-legend .dis-comment::before {
    background: var(--syntax-comment);
}

.fe-asm-legend .dis-data::before {
    background: var(--syntax-data);
}

/* Hex dump legend */
.fe-hex-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 6px 10px;
    background: var(--input-bg);
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-mono);
    font-size: 10px;
    flex-shrink: 0;
}

.fe-hex-legend.hidden {
    display: none;
}

.fe-hex-legend span {
    display: inline-flex;
    align-items: center;
}

.fe-hex-legend span::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    margin-right: 4px;
}

.fe-hex-legend .hex-legend-printable::before {
    background: var(--syntax-hex-printable);
}

.fe-hex-legend .hex-legend-control::before {
    background: var(--syntax-hex-byte);
}

.fe-hex-legend .hex-legend-highbit::before {
    background: var(--syntax-hex-highbit);
}

.fe-hex-legend .hex-legend-zero::before {
    background: var(--syntax-hex-zero);
}

.fe-file-content {
    flex: 1;
    overflow: auto;
    padding: 8px;
    background: var(--input-bg-dark);
    /* Isolate layout calculations to improve resize performance */
    contain: strict;
}

/* Virtual scroll container for large disassemblies */
.fe-file-content .virtual-scroll-container {
    contain: strict;
}

.fe-file-content .virtual-scroll-content {
    color: var(--text-primary);
}

.fe-file-content pre {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-all;
}

/* Hex dump styling */
.fe-file-content.hex pre {
    color: var(--text-primary);
    white-space: pre;
    line-height: 1;
}

.hex-line {
    display: flex;
    align-items: baseline;
    padding: 1px 0;
}

.hex-line:hover {
    background: var(--overlay-faint);
}

.hex-addr {
    color: var(--syntax-addr);
    font-weight: 500;
    flex-shrink: 0;
}

.hex-separator {
    color: var(--syntax-separator);
    flex-shrink: 0;
    margin-right: 0.5em;
}

.hex-byte {
    color: var(--syntax-hex-byte);
}

.hex-byte.hex-zero {
    color: var(--syntax-hex-zero);
}

.hex-byte.hex-printable {
    color: var(--syntax-hex-printable);
}

.hex-byte.hex-highbit {
    color: var(--syntax-hex-highbit);
}

.hex-bytes {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
}

.hex-group-gap {
    display: inline-block;
    width: 0.75em;
}

.hex-ascii-separator {
    color: var(--syntax-ascii-separator);
    flex-shrink: 0;
    margin: 0 0.4em;
}

.hex-ascii {
    letter-spacing: 0;
    flex-shrink: 0;
    white-space: pre;
}

.hex-ascii-printable {
    color: var(--syntax-ascii-printable);
}

.hex-ascii-dot {
    color: var(--syntax-ascii-dot);
}

.hex-truncated {
    color: var(--syntax-addr);
    font-style: italic;
    margin-top: 8px;
    display: block;
}

/* Disassembler syntax highlighting */
.fe-file-content.asm pre {
    color: var(--text-primary);
    white-space: pre;
}

.dis-addr {
    color: var(--text-muted, #6e7681);
}

.dis-bytes {
    color: var(--accent-blue);
}

.dis-branch {
    color: var(--syntax-flow);
    font-weight: 500;
}

.dis-load {
    color: var(--syntax-load);
    font-weight: 500;
}

.dis-math {
    color: var(--syntax-math);
    font-weight: 500;
}

.dis-stack {
    color: var(--syntax-stack);
    font-weight: 500;
}

.dis-flag {
    color: var(--syntax-flag);
    font-weight: 500;
}

.dis-mnemonic {
    color: var(--text-primary);
    font-weight: 500;
}

.dis-directive {
    color: var(--syntax-stack);
}

.dis-data {
    color: var(--syntax-data);
}

.dis-immediate {
    color: var(--syntax-flag);
}

.dis-address {
    color: var(--syntax-math);
}

.dis-target {
    color: var(--syntax-flow);
}

.dis-clickable {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}

.dis-clickable:hover {
    text-decoration-style: solid;
    filter: brightness(1.2);
}

.dis-highlight {
    background: var(--accent-blue-bg-strong);
    display: inline-block;
    width: 100%;
    margin: 0 -8px;
    padding: 0 8px;
}

.dis-register {
    color: var(--syntax-register);
}

.dis-punct {
    color: var(--text-muted, #6e7681);
}

.dis-comment {
    color: var(--syntax-comment);
    font-style: italic;
}

.dis-number {
    color: var(--syntax-number);
}

.dis-unknown {
    color: var(--accent-red);
}

/* BASIC syntax highlighting */
.fe-file-content.basic pre {
    color: var(--text-primary);
    white-space: pre;
}

.bas-linenum {
    color: var(--text-muted, #6e7681);
}

/* All keywords/commands - same color */
.bas-flow,
.bas-loop,
.bas-io,
.bas-graphics,
.bas-memory,
.bas-func,
.bas-var,
.bas-misc,
.bas-keyword {
    color: var(--syntax-keyword);
    font-weight: 500;
}

.bas-variable {
    color: var(--text-primary); /* White for variables */
}

.bas-string {
    color: var(--syntax-string);
}

.bas-number {
    color: var(--syntax-math);
}

.bas-comment {
    color: var(--syntax-comment);
    font-style: italic;
}

.bas-data {
    color: var(--syntax-string);
}

.bas-operator {
    color: var(--syntax-operator);
}

.bas-punct {
    color: var(--syntax-operator);
}

.bas-lineref {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}

.bas-lineref:hover {
    text-decoration-style: solid;
    filter: brightness(1.2);
}

.bas-highlight {
    background: var(--accent-blue-bg-strong);
    display: inline-block;
    width: 100%;
    margin: 0 -8px;
    padding: 0 8px;
}

.fe-file-content.text pre {
    color: var(--text-primary);
}

.fe-file-content .fe-error {
    color: var(--accent-red);
    padding: 20px;
    text-align: center;
}

/* Merlin assembler source view */
.fe-file-content.merlin pre {
    color: var(--text-primary);
    white-space: pre;
}

/* Each source line is a flex row with fixed-width columns */
.mer-line {
    display: flex;
    align-items: baseline;
}

.mer-line:hover {
    background: var(--overlay-faint);
}

.mer-col {
    flex-shrink: 0;
    white-space: pre;
}

.mer-col-label {
    min-width: 13ch;
    width: 13ch;
}

.mer-col-opcode {
    min-width: 7ch;
    width: 7ch;
}

.mer-col-operand {
    min-width: 20ch;
    width: 20ch;
}

.mer-col-comment {
    flex: 1;
    min-width: 0;
}

/* Full-line comments span the entire row */
.mer-comment-line {
    display: flex;
}

.mer-comment-line .mer-comment {
    flex: 1;
}

/* Label colours */
.mer-label     { color: var(--syntax-flow); }
.mer-local     { color: var(--syntax-math); }

/* Mnemonic categories - matching disassembler colour scheme */
.mer-branch    { color: var(--syntax-flow); font-weight: 500; }
.mer-load      { color: var(--syntax-load); font-weight: 500; }
.mer-math      { color: var(--syntax-math); font-weight: 500; }
.mer-stack     { color: var(--syntax-stack); font-weight: 500; }
.mer-flag      { color: var(--syntax-flag); font-weight: 500; }
.mer-macro     { color: var(--text-primary); font-weight: 500; }

/* Directives */
.mer-directive { color: var(--syntax-keyword); font-weight: 500; }

/* Operand sub-tokens */
.mer-number    { color: var(--syntax-number); }
.mer-string    { color: var(--syntax-string); }
.mer-immediate { color: var(--syntax-flag); }
.mer-symbol    { color: var(--text-primary); }
.mer-punct     { color: var(--text-muted); }

/* Comments */
.mer-comment   { color: var(--syntax-comment); font-style: italic; }

/* Scrollbar styling */
.fe-catalog-list::-webkit-scrollbar,
.fe-file-content::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.fe-catalog-list::-webkit-scrollbar-track,
.fe-file-content::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.fe-catalog-list::-webkit-scrollbar-thumb,
.fe-file-content::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 4px;
}

.fe-catalog-list::-webkit-scrollbar-thumb:hover,
.fe-file-content::-webkit-scrollbar-thumb:hover {
    background: var(--border-muted);
}
