*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #07080a;
    --surface:  #0d0f12;
    --surface2: #0a0c0e;
    --border:   #1a1f26;
    --border2:  #2d3748;
    --accent:   #2563eb;
    --accent2:  #60a5fa;
    --text:     #f0f2f4;
    --muted:    #6b7280;
    --muted2:   #9ca3af;
    --danger:   #f87171;
    --success:  #4ade80;
    --warning:  #facc15;
}

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 13px;
}

/* ── Layout ──────────────────────────────────────────────────── */
.container { display: flex; width: 100%; height: 100%; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    min-width: 150px;
    max-width: 500px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.resize-handle {
    width: 4px;
    flex-shrink: 0;
    background: var(--border);
    cursor: ew-resize;
    transition: background 0.15s;
    position: relative;
    z-index: 1;
}
.resize-handle:hover,
.resize-handle.dragging { background: var(--accent); }

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 10px;
    border-bottom: 0.5px solid var(--border);
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.head-actions { display: flex; gap: 2px; }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.07); }

.sidebar-section-label {
    padding: 10px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    flex-shrink: 0;
}

/* ── Tree ────────────────────────────────────────────────────── */
.sidebar-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2px 0 8px;
}
.sidebar-tree::-webkit-scrollbar { width: 3px; }
.sidebar-tree::-webkit-scrollbar-track { background: transparent; }
.sidebar-tree::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.tree-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px 5px 10px;
    cursor: pointer;
    border-radius: 5px;
    margin: 1px 4px;
    transition: background 0.1s;
    min-width: 0;
}
.tree-item:hover:not(.active) { background: rgba(255,255,255,0.04); }
.tree-item.active { background: rgba(37,99,235,0.15); }
.tree-item:hover .tree-actions { opacity: 1; }

.tree-item-left {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    flex: 1;
}

.tree-arrow {
    font-size: 12px;
    color: var(--muted);
    display: inline-block;
    transition: transform 0.15s;
    flex-shrink: 0;
    width: 12px;
    text-align: center;
}
.tree-arrow.open { transform: rotate(90deg); }

.tree-icon {
    font-size: 10px;
    color: var(--muted);
    flex-shrink: 0;
    width: 12px;
    text-align: center;
    font-family: 'Cascadia Code', 'Consolas', monospace;
}

.tree-label {
    font-size: 12px;
    color: var(--muted2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Cascadia Code', 'Consolas', monospace;
}
.tree-item.active .tree-label { color: var(--accent2); }
.tree-item[data-type="folder"] .tree-label { color: var(--text); font-weight: 500; }
.tree-item[data-type="folder"].active .tree-label { color: var(--accent2); }

.tree-actions { opacity: 0; display: flex; gap: 2px; flex-shrink: 0; transition: opacity 0.1s; }

.tree-action-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 13px;
    line-height: 1;
    transition: color 0.1s, background 0.1s;
}
.tree-action-btn:hover { color: var(--danger); background: rgba(248,113,113,0.1); }

.tree-empty {
    padding: 20px 14px;
    font-size: 11px;
    color: var(--muted);
    text-align: center;
}
.tree-error { color: var(--danger); }

/* ── Multi-select bar ────────────────────────────────────────── */
.multi-bar {
    padding: 6px 8px;
    border-top: 0.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    background: rgba(37,99,235,0.07);
}
.multi-bar span {
    font-size: 11px;
    color: var(--accent2);
}
.multi-bar button {
    font-size: 10px;
    padding: 3px 9px;
    border-radius: 4px;
    border: 0.5px solid rgba(248,113,113,0.3);
    background: rgba(248,113,113,0.1);
    color: var(--danger);
    cursor: pointer;
    transition: opacity 0.15s;
}
.multi-bar button:hover { opacity: 0.8; }

.tree-item.multi-selected {
    background: rgba(37,99,235,0.1);
    outline: 0.5px solid rgba(37,99,235,0.3);
    outline-offset: -1px;
}

/* ── Sidebar footer ──────────────────────────────────────────── */
.sidebar-footer {
    padding: 8px;
    border-top: 0.5px solid var(--border);
    flex-shrink: 0;
}

#btn-trash {
    width: 100%;
    background: transparent;
    border: 0.5px solid var(--border2);
    border-radius: 4px;
    color: var(--muted);
    font-size: 11px;
    padding: 5px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    text-align: center;
}
#btn-trash:hover { color: var(--danger); border-color: var(--danger); }

/* ── Main area ───────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ── Tab bar ─────────────────────────────────────────────────── */
.tab-bar {
    height: 36px;
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
    display: flex;
    align-items: flex-end;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-list { display: flex; align-items: flex-end; height: 100%; }

.tab {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 12px 0 14px;
    height: 32px;
    cursor: pointer;
    border-right: 0.5px solid var(--border);
    background: transparent;
    transition: background 0.1s;
    flex-shrink: 0;
    min-width: 80px;
    max-width: 180px;
}
.tab:hover:not(.active) { background: rgba(255,255,255,0.04); }
.tab.active {
    background: var(--bg);
    border-bottom: 1.5px solid var(--accent);
}

.tab-name {
    font-size: 11.5px;
    color: var(--muted2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    font-family: 'Cascadia Code', 'Consolas', monospace;
}
.tab.active .tab-name { color: var(--text); }

.tab-close {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 1px 3px;
    border-radius: 3px;
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.1s, background 0.1s;
}
.tab-close:hover { color: var(--text); background: rgba(255,255,255,0.1); }

/* ── Content area ────────────────────────────────────────────── */
.content-area { flex: 1; position: relative; overflow: hidden; background: var(--bg); }

.content-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: none;
    background: var(--bg);
}
.content-frame.active { display: block; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--surface);
    border: 0.5px solid var(--border2);
    border-radius: 8px;
    padding: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

.modal-body {
    font-size: 12px;
    color: var(--muted2);
    line-height: 1.6;
}

.modal-body p { margin-bottom: 6px; }

.modal-input {
    width: 100%;
    background: var(--bg);
    border: 0.5px solid var(--border2);
    border-radius: 5px;
    color: var(--text);
    font-size: 13px;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.15s;
}
.modal-input:focus { border-color: var(--accent); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.btn-primary, .btn-secondary, .btn-danger {
    padding: 6px 16px;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
}
.btn-primary:hover, .btn-secondary:hover, .btn-danger:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: transparent; border: 0.5px solid var(--border2); color: var(--muted2); }
.btn-danger { background: rgba(248,113,113,0.15); color: var(--danger); border: 0.5px solid rgba(248,113,113,0.3); }

/* ── Trash modal ─────────────────────────────────────────────── */
.trash-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }

.trash-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: 5px;
    border: 0.5px solid var(--border);
}

.trash-row-name {
    font-size: 12px;
    color: var(--text);
    font-family: 'Cascadia Code', 'Consolas', monospace;
    grid-column: 1 / -1;
}

.trash-row-path {
    font-size: 10px;
    color: var(--muted);
    grid-column: 1 / -1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trash-restore-btn, .trash-purge-btn {
    background: transparent;
    border: 0.5px solid var(--border2);
    border-radius: 4px;
    font-size: 10px;
    padding: 3px 8px;
    cursor: pointer;
    transition: color 0.1s, border-color 0.1s;
}
.trash-restore-btn { color: var(--accent2); }
.trash-restore-btn:hover { border-color: var(--accent2); }
.trash-purge-btn { color: var(--danger); }
.trash-purge-btn:hover { border-color: var(--danger); }

/* ── Context menu ────────────────────────────────────────────── */
.ctx-menu {
    position: fixed;
    background: var(--surface);
    border: 0.5px solid var(--border2);
    border-radius: 6px;
    padding: 4px;
    min-width: 160px;
    z-index: 3000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    opacity: 0;
    transform: scale(0.96);
    transform-origin: top left;
    transition: opacity 0.1s, transform 0.1s;
    pointer-events: none;
}
.ctx-menu.open {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}
.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--muted2);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    white-space: nowrap;
}
.ctx-item:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.ctx-item.danger:hover { background: rgba(248,113,113,0.1); color: var(--danger); }
.ctx-icon { font-size: 13px; width: 14px; text-align: center; flex-shrink: 0; }
.ctx-separator { height: 0.5px; background: var(--border); margin: 3px 4px; }

/* ── Drag-and-drop ───────────────────────────────────────────── */
.tree-item[draggable="true"] { cursor: grab; }
.tree-item.dragging { opacity: 0.35; }
.tree-item.drop-target {
    background: rgba(37,99,235,0.15) !important;
    outline: 0.5px solid var(--accent);
    outline-offset: -1px;
    border-radius: 5px;
}

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 12px;
    background: var(--surface);
    border: 0.5px solid var(--border2);
    color: var(--text);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.2s, transform 0.2s;
    z-index: 2000;
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: rgba(74,222,128,0.3); color: var(--success); }
.toast-error   { border-color: rgba(248,113,113,0.3); color: var(--danger); }
